mars-v2-frontend/src/components/Account/AccountOverview.tsx
Linkie Link 22830289cf
Mp 3328 compare accounts via use updated account for withdraw (#407)
* Compare Accounts via useUpdatedAccount for withdraw

* fix: onChangeAsset fixed

* Mp 3250 update health bars (#403)

* [Story] Add HealthBar

* Update tooltip

* Fixes after rebase

* Fixes after rebase

* Fixes after rebase

* Finish health bar + gauge

* Finish health bar + gauge

* Finish health bar + gauge

* feat: added an svg mask to the HealthBar

* fix: added transitions

* tidy: value sanity

* fix: fixed the AccountStats

* tidy: design update

* fix: div adjustments

* update healthguagepercentage function

* make tooltiparrow responsive

---------

Co-authored-by: Linkie Link <linkielink.dev@gmail.com>

* Compare Accounts via useUpdatedAccount for withdraw

* Mp 3250 update health bars (#403)

* [Story] Add HealthBar

* Update tooltip

* Fixes after rebase

* Fixes after rebase

* Fixes after rebase

* Finish health bar + gauge

* Finish health bar + gauge

* Finish health bar + gauge

* feat: added an svg mask to the HealthBar

* fix: added transitions

* tidy: value sanity

* fix: fixed the AccountStats

* tidy: design update

* fix: div adjustments

* update healthguagepercentage function

* make tooltiparrow responsive

---------

Co-authored-by: Linkie Link <linkielink.dev@gmail.com>

* Mp 3250 update health bars (#403)

* [Story] Add HealthBar

* Update tooltip

* Fixes after rebase

* Fixes after rebase

* Fixes after rebase

* Finish health bar + gauge

* Finish health bar + gauge

* Finish health bar + gauge

* feat: added an svg mask to the HealthBar

* fix: added transitions

* tidy: value sanity

* fix: fixed the AccountStats

* tidy: design update

* fix: div adjustments

* update healthguagepercentage function

* make tooltiparrow responsive

---------

Co-authored-by: Linkie Link <linkielink.dev@gmail.com>

* fix: merge error

---------

Co-authored-by: Yusuf Seyrek <yusuf@delphilabs.io>
Co-authored-by: Bob van der Helm <34470358+bobthebuidlr@users.noreply.github.com>
2023-08-29 17:25:11 +02:00

93 lines
2.9 KiB
TypeScript

import classNames from 'classnames'
import { Suspense, useMemo } from 'react'
import AccountBalancesTable from 'components/Account/AccountBalancesTable'
import AccountComposition from 'components/Account/AccountComposition'
import Card from 'components/Card'
import Loading from 'components/Loading'
import Text from 'components/Text'
import useAccounts from 'hooks/useAccounts'
import useBorrowMarketAssetsTableData from 'hooks/useBorrowMarketAssetsTableData'
import useLendingMarketAssetsTableData from 'hooks/useLendingMarketAssetsTableData'
import useStore from 'store'
function Content() {
const address = useStore((s) => s.address)
const { data: account } = useAccounts(address)
const { availableAssets: borrowAvailableAssets, accountBorrowedAssets } =
useBorrowMarketAssetsTableData()
const { availableAssets: lendingAvailableAssets, accountLentAssets } =
useLendingMarketAssetsTableData()
const borrowAssetsData = useMemo(
() => [...borrowAvailableAssets, ...accountBorrowedAssets],
[borrowAvailableAssets, accountBorrowedAssets],
)
const lendingAssetsData = useMemo(
() => [...lendingAvailableAssets, ...accountLentAssets],
[lendingAvailableAssets, accountLentAssets],
)
if (!address) {
return (
<Card
className='justify-center w-full h-fit bg-white/5'
title='Portfolio'
contentClassName='px-4 py-6'
>
<Text size='sm' className='w-full text-center'>
You need to be connected to view the porfolio page
</Text>
</Card>
)
}
return (
<div
className={classNames('grid w-full grid-cols-1 gap-4', 'md:grid-cols-2', 'lg:grid-cols-3')}
>
{account.map((account: Account, index: number) => (
<Card
className='w-full h-fit bg-white/5'
title={`Credit Account ${account.id}`}
key={index}
>
<AccountComposition account={account} />
<Text className='w-full px-4 py-2 text-white bg-white/10'>Balances</Text>
<AccountBalancesTable
account={account}
borrowingData={borrowAssetsData}
lendingData={lendingAssetsData}
/>
</Card>
))}
</div>
)
}
function Fallback() {
const cardCount = 3
return (
<div
className={classNames('grid w-full grid-cols-1 gap-4', 'md:grid-cols-2', 'lg:grid-cols-3')}
>
{Array.from({ length: cardCount }, (_, i) => (
<Card key={i} className='w-full h-fit bg-white/5' title='Account' contentClassName='py-6'>
<div className='p-4'>
<Loading className='h-4 w-50' />
</div>
<Text className='w-full px-4 py-2 mt-3 text-white bg-white/10'>Balances</Text>
<Loading className='w-full h-4' />
</Card>
))}
</div>
)
}
export default function AccountOverview() {
return (
<Suspense fallback={<Fallback />}>
<Content />
</Suspense>
)
}