From 5c01ec687287a1a1632e5634d51e95587a94782c Mon Sep 17 00:00:00 2001 From: Linkie Link Date: Tue, 9 May 2023 17:22:11 +0200 Subject: [PATCH] Mp 2681 interact with credit account modal (#189) * MP-2681: fixed and simplified fund and withdraw ;. : * MP-2352: created the CreditAccountComposition * fix: adjusted according to feedback * fix: fixed funding account max * fix: fix portfolio --- src/components/Accordion.tsx | 9 +- src/components/Account/AccountComposition.tsx | 98 ++++++++++++ src/components/Account/AccountList.tsx | 11 +- src/components/Account/AccountMenuContent.tsx | 6 +- src/components/Account/AccountStats.tsx | 7 +- src/components/Account/AccountSummary.tsx | 34 ++++- src/components/Account/FundAccount.tsx | 9 +- src/components/Modal.tsx | 2 +- src/components/Modals/BorrowModal.tsx | 4 +- .../Modals/FundAndWithdrawModal.tsx | 140 ++++++++++++++++++ src/components/Modals/ModalsContainer.tsx | 4 +- src/components/Modals/VaultModal.tsx | 6 +- src/components/Modals/WithdrawModal.tsx | 96 ------------ src/components/Portfolio/AccountOverview.tsx | 2 +- src/components/Slider.tsx | 2 + src/components/TokenInput.tsx | 26 ++-- src/components/TokenInputWithSlider.tsx | 19 ++- src/store/slices/modal.ts | 2 +- src/types/interfaces/account.d.ts | 7 + src/types/interfaces/store/modals.d.ts | 2 +- src/utils/accounts.ts | 54 ++++++- src/utils/route.ts | 3 +- 22 files changed, 392 insertions(+), 151 deletions(-) create mode 100644 src/components/Account/AccountComposition.tsx create mode 100644 src/components/Modals/FundAndWithdrawModal.tsx delete mode 100644 src/components/Modals/WithdrawModal.tsx diff --git a/src/components/Accordion.tsx b/src/components/Accordion.tsx index d169cdeb..cdfa04b9 100644 --- a/src/components/Accordion.tsx +++ b/src/components/Accordion.tsx @@ -11,13 +11,18 @@ interface Props { interface Item { title: string content: React.ReactNode + open?: boolean } export default function Accordion(props: Props) { return ( - + {props.items.map((item) => ( -
+
s.prices) + const balance = calculateAccountBalance(props.account, prices) + const balanceChange = props.change ? calculateAccountBalance(props.change, prices) : BN(0) + const debtBalance = calculateAccountDebt(props.account, prices) + const debtBalanceChange = props.change ? calculateAccountDebt(props.change, prices) : BN(0) + const pnL = calculateAccountPnL(props.account, prices) + const pnLChange = props.change ? calculateAccountPnL(props.change, prices) : BN(0) + const apr = calculateAccountApr(props.account, prices) + const aprChange = props.change ? calculateAccountPnL(props.change, prices) : BN(0) + const borrowRate = calculateAccountBorrowRate(props.account, prices) + const borrowRateChange = props.change ? calculateAccountPnL(props.change, prices) : BN(0) + + return ( +
+ + + + + +
+ ) +} + +function Item(props: ItemProps) { + const baseCurrency = useStore((s) => s.baseCurrency) + const increase = props.current.isLessThan(props.change) + return ( +
+
+ + {props.title} + +
+
+ + {!props.current.isEqualTo(props.change) && ( + <> + + + + + + )} +
+
+ ) +} diff --git a/src/components/Account/AccountList.tsx b/src/components/Account/AccountList.tsx index 5a6a54d3..e97d8507 100644 --- a/src/components/Account/AccountList.tsx +++ b/src/components/Account/AccountList.tsx @@ -15,6 +15,7 @@ import useToggle from 'hooks/useToggle' import useStore from 'store' import { calculateAccountBalance } from 'utils/accounts' import { hardcodedFee } from 'utils/contants' +import { BN } from 'utils/helpers' import useParams, { getRoute } from 'utils/route' interface Props { @@ -41,7 +42,7 @@ export default function AccountList(props: Props) { const selectedAccountDetails = props.accounts.find((account) => account.id === selectedAccount) const selectedAccountBalance = selectedAccountDetails ? calculateAccountBalance(selectedAccountDetails, prices) - : 0 + : BN(0) async function deleteAccountHandler() { if (!accountSelected) return @@ -107,7 +108,9 @@ export default function AccountList(props: Props) { text='Fund' color='tertiary' leftIcon={} - onClick={() => props.setShowFundAccount(true)} + onClick={() => { + useStore.setState({ fundAndWithdrawModal: 'fund' }) + }} />