-
Notifications
You must be signed in to change notification settings - Fork 463
Refactor/dashboard page #2723
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Refactor/dashboard page #2723
Changes from 49 commits
114328f
940cdf4
fcb1a39
92eeffd
a80c04b
4a5e1fe
eff6ed6
8653eb9
75769d3
be28f80
c4d503f
9f5d624
47ec420
18dadae
27eb9b8
8f7da60
2e502e9
d3d3e45
3610842
4e83b97
de6b877
cdc1ae9
98b4714
9292a2f
9d13c1b
59326b7
abff5a8
94b2eb9
f8fa340
5b6f0ee
ca6db43
7b35f28
3a9fc62
d8b34d3
4aacd78
12e64df
21ca830
d31da54
c41a961
03bd783
31005c4
dfbe506
4759ef5
0168761
33ea96b
5b5e2f6
fbc7f13
f7bf16b
857b056
adfb0c9
7f59af5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import { AaveClient, chainId, evmAddress, OrderDirection } from '@aave/client'; | ||
| import { userBorrows } from '@aave/client/actions'; | ||
| import { useQuery } from '@tanstack/react-query'; | ||
| import { MarketDataType } from 'src/ui-config/marketsConfig'; | ||
| import { queryKeysFactory } from 'src/ui-config/queries'; | ||
|
|
||
| type UseUserBorrowsDataParams = { | ||
| client: AaveClient; | ||
| marketData: MarketDataType; | ||
| account?: string | null; | ||
| }; | ||
|
|
||
| export const useUserBorrows = ({ client, marketData, account }: UseUserBorrowsDataParams) => { | ||
| const userAddress = account ? evmAddress(account) : undefined; | ||
|
|
||
| return useQuery({ | ||
| queryKey: [ | ||
| ...queryKeysFactory.market(marketData), | ||
| ...queryKeysFactory.user(userAddress ?? 'anonymous'), | ||
| 'userBorrows', | ||
| ], | ||
| enabled: !!client && !!userAddress, | ||
| queryFn: async () => { | ||
| const response = await userBorrows(client, { | ||
| markets: [ | ||
| { | ||
| chainId: chainId(marketData.chainId), | ||
| address: evmAddress(marketData.addresses.LENDING_POOL), | ||
| }, | ||
| ], | ||
| user: userAddress!, | ||
| orderBy: { debt: OrderDirection.Asc }, | ||
| }); | ||
|
|
||
| if (response.isErr()) throw response.error; | ||
| return response.value; | ||
| }, | ||
| }); | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import { AaveClient, chainId, evmAddress, OrderDirection } from '@aave/client'; | ||
| import { userSupplies } from '@aave/client/actions'; | ||
| import { useQuery } from '@tanstack/react-query'; | ||
| import { MarketDataType } from 'src/ui-config/marketsConfig'; | ||
| import { queryKeysFactory } from 'src/ui-config/queries'; | ||
|
|
||
| type UseUserSuppliesDataParams = { | ||
| client: AaveClient; | ||
| marketData: MarketDataType; | ||
| account?: string | null; | ||
| }; | ||
|
|
||
| export const useUserSupplies = ({ client, marketData, account }: UseUserSuppliesDataParams) => { | ||
| const userAddress = account ? evmAddress(account) : undefined; | ||
|
|
||
| return useQuery({ | ||
| queryKey: [ | ||
| ...queryKeysFactory.market(marketData), | ||
| ...queryKeysFactory.user(userAddress ?? 'anonymous'), | ||
| 'userSupplies', | ||
| ], | ||
| enabled: !!client && !!userAddress, | ||
| queryFn: async () => { | ||
| const response = await userSupplies(client, { | ||
| markets: [ | ||
| { | ||
| chainId: chainId(marketData.chainId), | ||
| address: evmAddress(marketData.addresses.LENDING_POOL), | ||
| }, | ||
| ], | ||
| user: userAddress!, | ||
| orderBy: { balance: OrderDirection.Asc }, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we order Desc so bigger first?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same answer |
||
| }); | ||
|
|
||
| if (response.isErr()) throw response.error; | ||
| return response.value; | ||
| }, | ||
| }); | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,6 @@ | ||
| import { normalize } from '@aave/math-utils'; | ||
| import { AaveV3Ethereum } from '@bgd-labs/aave-address-book'; | ||
| import { useRootStore } from 'src/store/root'; | ||
| import { CustomMarket } from 'src/ui-config/marketsConfig'; | ||
| import { amountToUsd } from 'src/utils/utils'; | ||
|
|
||
| import { useAppDataContext } from './app-data-provider/useAppDataProvider'; | ||
|
|
||
|
|
@@ -37,57 +35,42 @@ const wrappedTokenConfig: { | |
| }; | ||
|
|
||
| export const useWrappedTokens = () => { | ||
| const { marketReferencePriceInUsd, marketReferenceCurrencyDecimals, reserves } = | ||
| useAppDataContext(); | ||
| const { supplyReserves } = useAppDataContext(); | ||
| const currentMarket = useRootStore((store) => store.currentMarket); | ||
|
|
||
| if (!reserves || reserves.length === 0) { | ||
| if (!supplyReserves || supplyReserves.length === 0) { | ||
| return []; | ||
| } | ||
|
|
||
| const wrappedTokens = wrappedTokenConfig[currentMarket] ?? []; | ||
| let wrappedTokenReserves: WrappedTokenConfig[] = []; | ||
|
|
||
| wrappedTokenReserves = wrappedTokens.map<WrappedTokenConfig>((config) => { | ||
| const tokenInReserve = reserves.find((reserve) => reserve.underlyingAsset === config.tokenIn); | ||
| const tokenOutReserve = reserves.find((reserve) => reserve.underlyingAsset === config.tokenOut); | ||
| const tokenInReserve = supplyReserves.find( | ||
| (reserve) => reserve.underlyingToken.address.toLowerCase() === config.tokenIn | ||
| ); | ||
|
|
||
| const tokenOutReserve = supplyReserves.find( | ||
| (reserve) => reserve.underlyingToken.address.toLowerCase() === config.tokenOut | ||
| ); | ||
|
|
||
| if (!tokenInReserve || !tokenOutReserve) { | ||
| throw new Error('wrapped token reserves not found'); | ||
| } | ||
|
|
||
| const tokenInFormattedPriceInMarketReferenceCurrency = normalize( | ||
| tokenInReserve.priceInMarketReferenceCurrency, | ||
| marketReferenceCurrencyDecimals | ||
| ); | ||
|
|
||
| const tokenOutFormattedPriceInMarketReferenceCurrency = normalize( | ||
| tokenOutReserve.priceInMarketReferenceCurrency, | ||
| marketReferenceCurrencyDecimals | ||
| ); | ||
|
|
||
| return { | ||
| tokenIn: { | ||
| symbol: tokenInReserve.symbol, | ||
| underlyingAsset: tokenInReserve.underlyingAsset, | ||
| decimals: tokenInReserve.decimals, | ||
| priceInUSD: amountToUsd( | ||
| 1, | ||
| tokenInFormattedPriceInMarketReferenceCurrency, | ||
| marketReferencePriceInUsd | ||
| ).toString(), | ||
| formattedPriceInMarketReferenceCurrency: tokenInFormattedPriceInMarketReferenceCurrency, | ||
| symbol: tokenInReserve.underlyingToken.symbol, | ||
| underlyingAsset: tokenInReserve.underlyingToken.address, | ||
| decimals: tokenInReserve.underlyingToken.decimals, | ||
| priceInUSD: tokenInReserve.usdExchangeRate, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is usdExchangeRate giving the amount in usd as we had before or just the rate?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. usd amount per token |
||
| formattedPriceInMarketReferenceCurrency: tokenInReserve.size.usdPerToken, | ||
| }, | ||
| tokenOut: { | ||
| symbol: tokenOutReserve.symbol, | ||
| underlyingAsset: tokenOutReserve.underlyingAsset, | ||
| decimals: tokenOutReserve.decimals, | ||
| priceInUSD: amountToUsd( | ||
| 1, | ||
| tokenOutFormattedPriceInMarketReferenceCurrency, | ||
| marketReferencePriceInUsd | ||
| ).toString(), | ||
| formattedPriceInMarketReferenceCurrency: tokenOutFormattedPriceInMarketReferenceCurrency, | ||
| symbol: tokenOutReserve.underlyingToken.symbol, | ||
| underlyingAsset: tokenOutReserve.underlyingToken.address, | ||
| decimals: tokenOutReserve.underlyingToken.decimals, | ||
| priceInUSD: tokenOutReserve.usdExchangeRate, | ||
AGMASO marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| formattedPriceInMarketReferenceCurrency: tokenOutReserve.size.usdPerToken, | ||
| }, | ||
| tokenWrapperAddress: config.tokenWrapperContractAddress, | ||
| }; | ||
|
|
||
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we order Desc so bigger first?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it doesn’t sort based on the balance. It sorts according to the internal order in the backend. That’s why I think one ordering or the other makes no difference.