diff --git a/src/components/Modals/LendAndReclaim/index.tsx b/src/components/Modals/LendAndReclaim/index.tsx index 52b2310b..53cb6186 100644 --- a/src/components/Modals/LendAndReclaim/index.tsx +++ b/src/components/Modals/LendAndReclaim/index.tsx @@ -7,6 +7,7 @@ import useLendAndReclaimModal from 'hooks/useLendAndReclaimModal' import DetailsHeader from 'components/Modals/LendAndReclaim/DetailsHeader' import AssetAmountSelectActionModal from 'components/Modals/AssetAmountSelectActionModal' import { BNCoin } from 'types/classes/BNCoin' +import { useUpdatedAccount } from 'hooks/useUpdatedAccount' function LendAndReclaimModalController() { const currentAccount = useCurrentAccount() @@ -28,6 +29,8 @@ function LendAndReclaimModal({ currentAccount, config }: Props) { const { close } = useLendAndReclaimModal() const [isConfirming, setIsConfirming] = useToggle() const [accountChange, setAccountChange] = useState() + const { setAddedLends, setRemovedLends, removeDeposits, addDeposits } = + useUpdatedAccount(currentAccount) const { data, action } = config const { asset } = data @@ -39,8 +42,17 @@ function LendAndReclaimModal({ currentAccount, config }: Props) { const handleAmountChange = useCallback( (value: BigNumber) => { setAccountChange(getAccountChange(isLendAction, value, asset.denom)) + + const coin = BNCoin.fromDenomAndBigNumber(asset.denom, value) + if (isLendAction) { + setAddedLends([coin]) + removeDeposits([coin]) + } else { + addDeposits([coin]) + setRemovedLends([coin]) + } }, - [asset.denom, isLendAction], + [addDeposits, asset.denom, isLendAction, removeDeposits, setAddedLends, setRemovedLends], ) const handleAction = useCallback( diff --git a/src/hooks/useUpdatedAccount/index.ts b/src/hooks/useUpdatedAccount/index.ts index eec93acc..ced67811 100644 --- a/src/hooks/useUpdatedAccount/index.ts +++ b/src/hooks/useUpdatedAccount/index.ts @@ -19,6 +19,8 @@ export function useUpdatedAccount(account?: Account) { const [addedDebt, addDebt] = useState([]) const [removedDebt, removeDebt] = useState([]) const [addedVaultValues, addVaultValues] = useState([]) + const [addedLends, setAddedLends] = useState([]) + const [removedLends, setRemovedLends] = useState([]) const removeDepositByDenom = useCallback( (denom: string) => { @@ -46,11 +48,22 @@ export function useUpdatedAccount(account?: Account) { accountCopy.vaults = addValueToVaults(addedVaultValues, [...accountCopy.vaults]) accountCopy.deposits = removeCoins(removedDeposits, [...accountCopy.deposits]) accountCopy.debts = removeCoins(removedDebt, [...accountCopy.debts]) + accountCopy.lends = addCoins(addedLends, [...accountCopy.lends]) + accountCopy.lends = removeCoins(removedLends, [...accountCopy.lends]) setUpdatedAccount(accountCopy) useStore.setState({ updatedAccount: accountCopy }) return () => useStore.setState({ updatedAccount: undefined }) - }, [account, addedDebt, removedDebt, addedDeposits, removedDeposits, addedVaultValues]) + }, [ + account, + addedDebt, + removedDebt, + addedDeposits, + removedDeposits, + addedVaultValues, + addedLends, + removedLends, + ]) return { updatedAccount, @@ -64,5 +77,7 @@ export function useUpdatedAccount(account?: Account) { addedDebt, removedDeposits, removedDebt, + setAddedLends, + setRemovedLends, } }