feat(lend): useUpdatedAccount implementation (#390)
* feat(lend): useUpdatedAccount implementation * feat(lend): addressed to PR comment
This commit is contained in:
parent
997171a185
commit
6dcc13affb
@ -7,6 +7,7 @@ import useLendAndReclaimModal from 'hooks/useLendAndReclaimModal'
|
|||||||
import DetailsHeader from 'components/Modals/LendAndReclaim/DetailsHeader'
|
import DetailsHeader from 'components/Modals/LendAndReclaim/DetailsHeader'
|
||||||
import AssetAmountSelectActionModal from 'components/Modals/AssetAmountSelectActionModal'
|
import AssetAmountSelectActionModal from 'components/Modals/AssetAmountSelectActionModal'
|
||||||
import { BNCoin } from 'types/classes/BNCoin'
|
import { BNCoin } from 'types/classes/BNCoin'
|
||||||
|
import { useUpdatedAccount } from 'hooks/useUpdatedAccount'
|
||||||
|
|
||||||
function LendAndReclaimModalController() {
|
function LendAndReclaimModalController() {
|
||||||
const currentAccount = useCurrentAccount()
|
const currentAccount = useCurrentAccount()
|
||||||
@ -28,6 +29,8 @@ function LendAndReclaimModal({ currentAccount, config }: Props) {
|
|||||||
const { close } = useLendAndReclaimModal()
|
const { close } = useLendAndReclaimModal()
|
||||||
const [isConfirming, setIsConfirming] = useToggle()
|
const [isConfirming, setIsConfirming] = useToggle()
|
||||||
const [accountChange, setAccountChange] = useState<AccountChange | undefined>()
|
const [accountChange, setAccountChange] = useState<AccountChange | undefined>()
|
||||||
|
const { setAddedLends, setRemovedLends, removeDeposits, addDeposits } =
|
||||||
|
useUpdatedAccount(currentAccount)
|
||||||
|
|
||||||
const { data, action } = config
|
const { data, action } = config
|
||||||
const { asset } = data
|
const { asset } = data
|
||||||
@ -39,8 +42,17 @@ function LendAndReclaimModal({ currentAccount, config }: Props) {
|
|||||||
const handleAmountChange = useCallback(
|
const handleAmountChange = useCallback(
|
||||||
(value: BigNumber) => {
|
(value: BigNumber) => {
|
||||||
setAccountChange(getAccountChange(isLendAction, value, asset.denom))
|
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(
|
const handleAction = useCallback(
|
||||||
|
@ -19,6 +19,8 @@ export function useUpdatedAccount(account?: Account) {
|
|||||||
const [addedDebt, addDebt] = useState<BNCoin[]>([])
|
const [addedDebt, addDebt] = useState<BNCoin[]>([])
|
||||||
const [removedDebt, removeDebt] = useState<BNCoin[]>([])
|
const [removedDebt, removeDebt] = useState<BNCoin[]>([])
|
||||||
const [addedVaultValues, addVaultValues] = useState<VaultValue[]>([])
|
const [addedVaultValues, addVaultValues] = useState<VaultValue[]>([])
|
||||||
|
const [addedLends, setAddedLends] = useState<BNCoin[]>([])
|
||||||
|
const [removedLends, setRemovedLends] = useState<BNCoin[]>([])
|
||||||
|
|
||||||
const removeDepositByDenom = useCallback(
|
const removeDepositByDenom = useCallback(
|
||||||
(denom: string) => {
|
(denom: string) => {
|
||||||
@ -46,11 +48,22 @@ export function useUpdatedAccount(account?: Account) {
|
|||||||
accountCopy.vaults = addValueToVaults(addedVaultValues, [...accountCopy.vaults])
|
accountCopy.vaults = addValueToVaults(addedVaultValues, [...accountCopy.vaults])
|
||||||
accountCopy.deposits = removeCoins(removedDeposits, [...accountCopy.deposits])
|
accountCopy.deposits = removeCoins(removedDeposits, [...accountCopy.deposits])
|
||||||
accountCopy.debts = removeCoins(removedDebt, [...accountCopy.debts])
|
accountCopy.debts = removeCoins(removedDebt, [...accountCopy.debts])
|
||||||
|
accountCopy.lends = addCoins(addedLends, [...accountCopy.lends])
|
||||||
|
accountCopy.lends = removeCoins(removedLends, [...accountCopy.lends])
|
||||||
setUpdatedAccount(accountCopy)
|
setUpdatedAccount(accountCopy)
|
||||||
useStore.setState({ updatedAccount: accountCopy })
|
useStore.setState({ updatedAccount: accountCopy })
|
||||||
|
|
||||||
return () => useStore.setState({ updatedAccount: undefined })
|
return () => useStore.setState({ updatedAccount: undefined })
|
||||||
}, [account, addedDebt, removedDebt, addedDeposits, removedDeposits, addedVaultValues])
|
}, [
|
||||||
|
account,
|
||||||
|
addedDebt,
|
||||||
|
removedDebt,
|
||||||
|
addedDeposits,
|
||||||
|
removedDeposits,
|
||||||
|
addedVaultValues,
|
||||||
|
addedLends,
|
||||||
|
removedLends,
|
||||||
|
])
|
||||||
|
|
||||||
return {
|
return {
|
||||||
updatedAccount,
|
updatedAccount,
|
||||||
@ -64,5 +77,7 @@ export function useUpdatedAccount(account?: Account) {
|
|||||||
addedDebt,
|
addedDebt,
|
||||||
removedDeposits,
|
removedDeposits,
|
||||||
removedDebt,
|
removedDebt,
|
||||||
|
setAddedLends,
|
||||||
|
setRemovedLends,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user