Skip to content

Commit

Permalink
fix: 🐛 fix transfer account selection (#12732)
Browse files Browse the repository at this point in the history
  • Loading branch information
heorhi-deriv committed Jan 4, 2024
1 parent ecbb36a commit 9ba2e69
Showing 1 changed file with 8 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,38 +62,19 @@ const TransferFormDropdown: React.FC<TProps> = ({ fieldName, mobileAccountsListR
(account: TInitialTransferFormValues['fromAccount']) => {
if (account?.loginid === selectedAccount?.loginid) return;

const swapAccounts = () => {
if (isFromAccountDropdown) {
setValues(prev => {
const toAccount = account?.loginid !== activeWallet?.loginid ? activeWallet : undefined;

return {
...prev,
activeAmountFieldName: undefined,
fromAccount: isFromAccountDropdown ? account : prev.toAccount,
fromAmount: prev.toAmount,
toAccount: isFromAccountDropdown ? prev.fromAccount : account,
toAmount: prev.fromAmount,
fromAccount: account,
fromAmount: 0,
toAccount,
toAmount: 0,
};
});
};

if (isFromAccountDropdown) {
if (account?.loginid === values.toAccount?.loginid) {
swapAccounts();
} else {
setValues(prev => {
const toAccount = account?.loginid !== activeWallet?.loginid ? activeWallet : undefined;

return {
...prev,
activeAmountFieldName: undefined,
fromAccount: account,
fromAmount: 0,
toAccount,
toAmount: 0,
};
});
}
} else if (account?.loginid === values.fromAccount?.loginid) {
swapAccounts();
} else {
setValues(prev => ({
...prev,
Expand All @@ -103,7 +84,7 @@ const TransferFormDropdown: React.FC<TProps> = ({ fieldName, mobileAccountsListR
}));
}
},
[activeWallet, isFromAccountDropdown, selectedAccount?.loginid, setValues, values.fromAccount, values.toAccount]
[activeWallet, isFromAccountDropdown, selectedAccount?.loginid, setValues]
);

return (
Expand Down

0 comments on commit 9ba2e69

Please sign in to comment.