Portfolio access (#475)
* feat: view other users portfolio * fix: remove intro for unconnected users * fix: added empty wallet to prevent infinite pause * fix: changed useAccounts to have fallbackData
This commit is contained in:
parent
d7b91f4115
commit
419f2c04b7
@ -3,6 +3,7 @@ import { useParams } from 'react-router-dom'
|
|||||||
|
|
||||||
import AccountFundContent from 'components/Account/AccountFund/AccountFundContent'
|
import AccountFundContent from 'components/Account/AccountFund/AccountFundContent'
|
||||||
import Card from 'components/Card'
|
import Card from 'components/Card'
|
||||||
|
import { CircularProgress } from 'components/CircularProgress'
|
||||||
import FullOverlayContent from 'components/FullOverlayContent'
|
import FullOverlayContent from 'components/FullOverlayContent'
|
||||||
import useAccounts from 'hooks/useAccounts'
|
import useAccounts from 'hooks/useAccounts'
|
||||||
import useCurrentAccount from 'hooks/useCurrentAccount'
|
import useCurrentAccount from 'hooks/useCurrentAccount'
|
||||||
@ -12,7 +13,7 @@ export default function AccountFundFullPage() {
|
|||||||
const address = useStore((s) => s.address)
|
const address = useStore((s) => s.address)
|
||||||
const { accountId } = useParams()
|
const { accountId } = useParams()
|
||||||
|
|
||||||
const { data: accounts } = useAccounts(address)
|
const { data: accounts, isLoading } = useAccounts(address)
|
||||||
const currentAccount = useCurrentAccount()
|
const currentAccount = useCurrentAccount()
|
||||||
const [selectedAccountId, setSelectedAccountId] = useState<null | string>(null)
|
const [selectedAccountId, setSelectedAccountId] = useState<null | string>(null)
|
||||||
|
|
||||||
@ -29,6 +30,9 @@ export default function AccountFundFullPage() {
|
|||||||
copy='In order to start using this account, you need to deposit funds.'
|
copy='In order to start using this account, you need to deposit funds.'
|
||||||
docs='fund'
|
docs='fund'
|
||||||
>
|
>
|
||||||
|
{isLoading ? (
|
||||||
|
<CircularProgress size={40} />
|
||||||
|
) : (
|
||||||
<Card className='w-full p-6 bg-white/5'>
|
<Card className='w-full p-6 bg-white/5'>
|
||||||
<AccountFundContent
|
<AccountFundContent
|
||||||
account={currentAccount}
|
account={currentAccount}
|
||||||
@ -37,6 +41,7 @@ export default function AccountFundFullPage() {
|
|||||||
isFullPage
|
isFullPage
|
||||||
/>
|
/>
|
||||||
</Card>
|
</Card>
|
||||||
|
)}
|
||||||
</FullOverlayContent>
|
</FullOverlayContent>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,8 @@ import useStore from 'store'
|
|||||||
|
|
||||||
function Content() {
|
function Content() {
|
||||||
const address = useStore((s) => s.address)
|
const address = useStore((s) => s.address)
|
||||||
const { data: accounts } = useAccounts(address)
|
const { data: accounts, isLoading } = useAccounts(address)
|
||||||
|
if (isLoading) return <Loading className='h-8 w-35' />
|
||||||
if (!accounts) return null
|
if (!accounts) return null
|
||||||
return <AccountMenuContent accounts={accounts} />
|
return <AccountMenuContent accounts={accounts} />
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import classNames from 'classnames'
|
import classNames from 'classnames'
|
||||||
import { Suspense, useCallback, useMemo } from 'react'
|
import { Suspense, useCallback, useMemo } from 'react'
|
||||||
|
import { useParams } from 'react-router-dom'
|
||||||
|
|
||||||
import AccountBalancesTable from 'components/Account/AccountBalancesTable'
|
import AccountBalancesTable from 'components/Account/AccountBalancesTable'
|
||||||
import AccountComposition from 'components/Account/AccountComposition'
|
import AccountComposition from 'components/Account/AccountComposition'
|
||||||
@ -11,6 +12,7 @@ import Loading from 'components/Loading'
|
|||||||
import Text from 'components/Text'
|
import Text from 'components/Text'
|
||||||
import WalletBridges from 'components/Wallet/WalletBridges'
|
import WalletBridges from 'components/Wallet/WalletBridges'
|
||||||
import WalletConnectButton from 'components/Wallet/WalletConnectButton'
|
import WalletConnectButton from 'components/Wallet/WalletConnectButton'
|
||||||
|
import useAccounts from 'hooks/useAccounts'
|
||||||
import useBorrowMarketAssetsTableData from 'hooks/useBorrowMarketAssetsTableData'
|
import useBorrowMarketAssetsTableData from 'hooks/useBorrowMarketAssetsTableData'
|
||||||
import useCurrentWalletBalance from 'hooks/useCurrentWalletBalance'
|
import useCurrentWalletBalance from 'hooks/useCurrentWalletBalance'
|
||||||
import useLendingMarketAssetsTableData from 'hooks/useLendingMarketAssetsTableData'
|
import useLendingMarketAssetsTableData from 'hooks/useLendingMarketAssetsTableData'
|
||||||
@ -18,9 +20,25 @@ import useStore from 'store'
|
|||||||
import { defaultFee } from 'utils/constants'
|
import { defaultFee } from 'utils/constants'
|
||||||
import { BN } from 'utils/helpers'
|
import { BN } from 'utils/helpers'
|
||||||
|
|
||||||
|
function ConnectInfo() {
|
||||||
|
return (
|
||||||
|
<Card
|
||||||
|
className='w-full h-fit bg-white/5'
|
||||||
|
title='Portfolio'
|
||||||
|
contentClassName='px-4 py-6 flex justify-center flex-wrap'
|
||||||
|
>
|
||||||
|
<Text size='sm' className='w-full text-center'>
|
||||||
|
You need to be connected to view the porfolio page.
|
||||||
|
</Text>
|
||||||
|
<WalletConnectButton className='mt-4' />
|
||||||
|
</Card>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
function Content() {
|
function Content() {
|
||||||
const address = useStore((s) => s.address)
|
const { address: urlAddress } = useParams()
|
||||||
const accounts = useStore((s) => s.accounts)
|
const { data: accounts, isLoading } = useAccounts(urlAddress ?? '')
|
||||||
|
const walletAddress = useStore((s) => s.address)
|
||||||
const baseCurrency = useStore((s) => s.baseCurrency)
|
const baseCurrency = useStore((s) => s.baseCurrency)
|
||||||
const { availableAssets: borrowAvailableAssets, accountBorrowedAssets } =
|
const { availableAssets: borrowAvailableAssets, accountBorrowedAssets } =
|
||||||
useBorrowMarketAssetsTableData()
|
useBorrowMarketAssetsTableData()
|
||||||
@ -52,19 +70,9 @@ function Content() {
|
|||||||
useStore.setState({ focusComponent: { component: <AccountCreateFirst /> } })
|
useStore.setState({ focusComponent: { component: <AccountCreateFirst /> } })
|
||||||
}, [checkHasFunds])
|
}, [checkHasFunds])
|
||||||
|
|
||||||
if (!address)
|
if (isLoading) return <Fallback />
|
||||||
return (
|
|
||||||
<Card
|
if (!walletAddress && !urlAddress) return <ConnectInfo />
|
||||||
className='w-full h-fit bg-white/5'
|
|
||||||
title='Portfolio'
|
|
||||||
contentClassName='px-4 py-6 flex justify-center flex-wrap'
|
|
||||||
>
|
|
||||||
<Text size='sm' className='w-full text-center'>
|
|
||||||
You need to be connected to view the porfolio page.
|
|
||||||
</Text>
|
|
||||||
<WalletConnectButton className='mt-4' />
|
|
||||||
</Card>
|
|
||||||
)
|
|
||||||
|
|
||||||
if (!accounts || accounts.length === 0)
|
if (!accounts || accounts.length === 0)
|
||||||
return (
|
return (
|
||||||
@ -111,7 +119,9 @@ function Content() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function Fallback() {
|
function Fallback() {
|
||||||
|
const { address } = useParams()
|
||||||
const cardCount = 3
|
const cardCount = 3
|
||||||
|
if (!address) return <ConnectInfo />
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={classNames('grid w-full grid-cols-1 gap-4', 'md:grid-cols-2', 'lg:grid-cols-3')}
|
className={classNames('grid w-full grid-cols-1 gap-4', 'md:grid-cols-2', 'lg:grid-cols-3')}
|
||||||
|
@ -1,13 +1,27 @@
|
|||||||
|
import { useParams } from 'react-router-dom'
|
||||||
|
|
||||||
import Intro from 'components/Intro'
|
import Intro from 'components/Intro'
|
||||||
|
import useStore from 'store'
|
||||||
|
|
||||||
export default function PortfolioIntro() {
|
export default function PortfolioIntro() {
|
||||||
|
const { address } = useParams()
|
||||||
|
const walletAddress = useStore((s) => s.address)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Intro
|
<Intro
|
||||||
text={
|
text={
|
||||||
|
address && !walletAddress ? (
|
||||||
|
<>
|
||||||
|
This is the <span className='text-white'>Portfolio</span> of the address{' '}
|
||||||
|
<span className='text-white'>{address}</span>. You can see all Credit Accounts of this
|
||||||
|
address, but you can't interact with them.
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
<>
|
<>
|
||||||
This is your <span className='text-white'>Portfolio</span>. Use it to get an overview
|
This is your <span className='text-white'>Portfolio</span>. Use it to get an overview
|
||||||
about all your Credit Accounts and their balances.
|
about all your Credit Accounts and their balances.
|
||||||
</>
|
</>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
></Intro>
|
></Intro>
|
||||||
)
|
)
|
||||||
|
@ -29,8 +29,8 @@ function Content() {
|
|||||||
const address = useStore((s) => s.address)
|
const address = useStore((s) => s.address)
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
const { pathname } = useLocation()
|
const { pathname } = useLocation()
|
||||||
const { data: accounts } = useAccounts(address)
|
const { data: accounts, isLoading: isLoadingAccounts } = useAccounts(address)
|
||||||
const { data: walletBalances, isLoading } = useWalletBalances(address)
|
const { data: walletBalances, isLoading: isLoadingBalances } = useWalletBalances(address)
|
||||||
const baseAsset = getBaseAsset()
|
const baseAsset = getBaseAsset()
|
||||||
|
|
||||||
const baseBalance = useMemo(
|
const baseBalance = useMemo(
|
||||||
@ -48,7 +48,7 @@ function Content() {
|
|||||||
}
|
}
|
||||||
}, [accounts, baseBalance, navigate, pathname, address, walletBalances])
|
}, [accounts, baseBalance, navigate, pathname, address, walletBalances])
|
||||||
|
|
||||||
if (isLoading) return <FetchLoading />
|
if (isLoadingAccounts || isLoadingBalances) return <FetchLoading />
|
||||||
if (BN(baseBalance).isLessThan(defaultFee.amount[0].amount)) return <WalletBridges />
|
if (BN(baseBalance).isLessThan(defaultFee.amount[0].amount)) return <WalletBridges />
|
||||||
if (accounts.length === 0) return <AccountCreateFirst />
|
if (accounts.length === 0) return <AccountCreateFirst />
|
||||||
return null
|
return null
|
||||||
|
@ -5,7 +5,7 @@ import getAccounts from 'api/wallets/getAccounts'
|
|||||||
export default function useAccounts(address?: string) {
|
export default function useAccounts(address?: string) {
|
||||||
return useSWR(`accounts${address}`, () => getAccounts(address || ''), {
|
return useSWR(`accounts${address}`, () => getAccounts(address || ''), {
|
||||||
suspense: true,
|
suspense: true,
|
||||||
isPaused: () => !address,
|
fallbackData: [],
|
||||||
revalidateOnFocus: false,
|
revalidateOnFocus: false,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user