Skip to content

Commit ed4a2b8

Browse files
committed
fix: dont allow sending from/to same address
1 parent c9b870e commit ed4a2b8

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

apps/namadillo/src/App/Transfer/DestinationAddressModal.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ type AddressOption = {
3131
type DestinationAddressModalProps = {
3232
onClose: () => void;
3333
onSelectAddress: (address: Address) => void;
34+
sourceAddress: string;
3435
sourceAsset?: Asset;
3536
};
3637

3738
export const DestinationAddressModal = ({
3839
sourceAsset,
40+
sourceAddress,
3941
onClose,
4042
onSelectAddress,
4143
}: DestinationAddressModalProps): JSX.Element => {
@@ -53,14 +55,21 @@ export const DestinationAddressModal = ({
5355
(account) => account.type === AccountType.ShieldedKeys
5456
);
5557

58+
// Dont display an address if it matches the source address
59+
const isSourceAddressMatch = (address: string): boolean =>
60+
address === sourceAddress;
61+
5662
// Build your addresses options
5763
const addressOptions: AddressOption[] = [];
5864
if (accounts) {
5965
const transparentAccount = accounts.find(
6066
(account) => account.type !== AccountType.ShieldedKeys
6167
);
6268

63-
if (transparentAccount) {
69+
if (
70+
transparentAccount &&
71+
!isSourceAddressMatch(transparentAccount.address)
72+
) {
6473
addressOptions.push({
6574
id: "transparent",
6675
label: "Transparent Address",
@@ -69,7 +78,7 @@ export const DestinationAddressModal = ({
6978
type: "transparent",
7079
});
7180
}
72-
if (shieldedAccount) {
81+
if (shieldedAccount && !isSourceAddressMatch(shieldedAccount.address)) {
7382
addressOptions.push({
7483
id: "shielded",
7584
label: "Shielded Address",

apps/namadillo/src/App/Transfer/TransferDestination.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ export const TransferDestination = ({
309309
onClose={handleCloseModal}
310310
onSelectAddress={handleSelectAddress}
311311
sourceAsset={sourceAsset}
312+
sourceAddress={sourceAddress ?? ""}
312313
/>
313314
)}
314315
</>

0 commit comments

Comments
 (0)