From f4fc2dcfccac931770695c64283c53da47560e23 Mon Sep 17 00:00:00 2001 From: Linkie Link Date: Tue, 8 Aug 2023 15:57:53 +0200 Subject: [PATCH] MP-2803: created fund already funded account flow (#350) --- src/components/Account/AccountFund.tsx | 36 ++-- src/components/Account/AccountList.tsx | 22 +-- src/components/Account/AccountSummary.tsx | 18 +- .../Modals/AssetsSelect/AssetSelectTable.tsx | 15 +- src/components/Modals/BorrowModal.tsx | 12 +- .../Modals/FundWithdraw/FundAccount.tsx | 164 ++++++++++++------ .../Modals/Vault/VaultBorrowings.tsx | 9 +- src/components/Modals/Vault/VaultDeposits.tsx | 4 +- .../WalletAssets/WalletAssetsModalContent.tsx | 6 +- src/components/Switch/SwitchAutoLend.tsx | 27 +++ .../{ => Switch}/SwitchWithLabel.tsx | 0 .../{Switch.tsx => Switch/index.tsx} | 0 src/styles/globals.css | 9 +- 13 files changed, 197 insertions(+), 125 deletions(-) create mode 100644 src/components/Switch/SwitchAutoLend.tsx rename src/components/{ => Switch}/SwitchWithLabel.tsx (100%) rename src/components/{Switch.tsx => Switch/index.tsx} (100%) diff --git a/src/components/Account/AccountFund.tsx b/src/components/Account/AccountFund.tsx index c8bfa6d2..ff9eccf7 100644 --- a/src/components/Account/AccountFund.tsx +++ b/src/components/Account/AccountFund.tsx @@ -5,13 +5,12 @@ import Button from 'components/Button' import Card from 'components/Card' import FullOverlayContent from 'components/FullOverlayContent' import { Plus } from 'components/Icons' -import SwitchWithLabel from 'components/SwitchWithLabel' +import SwitchAutoLend from 'components/Switch/SwitchAutoLend' import Text from 'components/Text' import TokenInputWithSlider from 'components/TokenInput/TokenInputWithSlider' import WalletBridges from 'components/Wallet/WalletBridges' import { BN_ZERO } from 'constants/math' import useAccounts from 'hooks/useAccounts' -import useAutoLendEnabledAccountIds from 'hooks/useAutoLendEnabledAccountIds' import useCurrentAccount from 'hooks/useCurrentAccount' import useToggle from 'hooks/useToggle' import useWalletBalances from 'hooks/useWalletBalances' @@ -34,8 +33,6 @@ export default function AccountFund() { const [fundingAssets, setFundingAssets] = useState([]) const { data: walletBalances } = useWalletBalances(address) const baseAsset = getBaseAsset() - const { autoLendEnabledAccountIds, toggleAutoLend } = useAutoLendEnabledAccountIds() - const isAutoLendEnabled = autoLendEnabledAccountIds.includes(accountId ?? '0') const hasAssetSelected = fundingAssets.length > 0 const hasFundingAssets = fundingAssets.length > 0 && fundingAssets.every((a) => a.toCoin().amount !== '0') @@ -88,7 +85,7 @@ export default function AccountFund() { const updateFundingAssets = useCallback( (amount: BigNumber, denom: string) => { - const assetToUpdate = fundingAssets.find((asset) => asset.denom === denom) + const assetToUpdate = fundingAssets.find(byDenom(denom)) if (assetToUpdate) { assetToUpdate.amount = amount setFundingAssets([...fundingAssets.filter((a) => a.denom !== denom), assetToUpdate]) @@ -116,21 +113,21 @@ export default function AccountFund() { copy='In order to start trading with this account, you need to deposit funds.' docs='fund' > - + {!hasAssetSelected && Please select an asset.} - {selectedDenoms.map((denom) => { - const asset = getAssetByDenom(denom) as Asset + {fundingAssets.map((coin) => { + const asset = getAssetByDenom(coin.denom) as Asset - const balance = walletBalances.find(byDenom(asset.denom))?.amount ?? '0' + const balance = walletBalances.find(byDenom(coin.denom))?.amount ?? '0' return (
updateFundingAssets(amount, asset.denom)} - amount={BN_ZERO} + amount={coin.amount ?? BN_ZERO} max={BN(balance)} balances={walletBalances} maxText='Max' @@ -140,24 +137,19 @@ export default function AccountFund() { })}