-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
addys summary for all native assets (#1720)
- Loading branch information
1 parent
b8964d1
commit e297955
Showing
4 changed files
with
78 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,28 @@ | ||
import { chainsNativeAsset } from '~/core/references/chains'; | ||
import { useAssets } from '~/core/resources/assets'; | ||
import { fetchAssets } from '~/core/resources/assets/assets'; | ||
import { currentCurrencyStore, useCurrentCurrencyStore } from '~/core/state'; | ||
import { useExternalTokens } from '~/core/resources/assets/externalToken'; | ||
import { useCurrentCurrencyStore } from '~/core/state'; | ||
import { ParsedAsset } from '~/core/types/assets'; | ||
import { ChainId } from '~/core/types/chains'; | ||
|
||
const NATIVE_ASSETS = [ | ||
{ address: chainsNativeAsset[ChainId.mainnet], chainId: ChainId.mainnet }, | ||
{ address: chainsNativeAsset[ChainId.bsc], chainId: ChainId.bsc }, | ||
{ address: chainsNativeAsset[ChainId.polygon], chainId: ChainId.polygon }, | ||
{ address: chainsNativeAsset[ChainId.avalanche], chainId: ChainId.avalanche }, | ||
{ address: chainsNativeAsset[ChainId.degen], chainId: ChainId.degen }, | ||
]; | ||
export async function getNativeAssets() { | ||
const { currentCurrency } = currentCurrencyStore.getState(); | ||
const assets = await fetchAssets({ | ||
assets: NATIVE_ASSETS, | ||
currency: currentCurrency, | ||
}); | ||
return assets; | ||
} | ||
const NATIVE_ASSETS = Object.keys(chainsNativeAsset).map((chainId) => ({ | ||
address: chainsNativeAsset[Number(chainId) as ChainId], | ||
chainId: Number(chainId) as ChainId, | ||
})); | ||
|
||
export function useNativeAssets() { | ||
const { currentCurrency: currency } = useCurrentCurrencyStore(); | ||
const { data: assets } = useAssets({ | ||
const response = useExternalTokens({ | ||
assets: NATIVE_ASSETS, | ||
currency, | ||
}); | ||
return assets; | ||
return response | ||
.map((asset) => (asset.data ? asset.data : null)) | ||
.filter(Boolean) | ||
.reduce( | ||
(acc, asset) => { | ||
acc[asset.chainId] = asset; | ||
return acc; | ||
}, | ||
{} as Record<ChainId, ParsedAsset>, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters