|
1 | 1 | <script lang="ts" setup> |
2 | | -import { computed, ref } from '@vue/reactivity'; |
3 | | -import { useBaseStore, useBlockchain, useFormatter } from '@/stores'; |
4 | | -import { PageRequest, type AuthAccount, type Pagination, type Coin } from '@/types'; |
| 2 | +import { ref } from '@vue/reactivity'; |
| 3 | +import { useBlockchain, useFormatter } from '@/stores'; |
| 4 | +import { PageRequest, type Pagination, type Coin, type DenomMetadata } from '@/types'; |
5 | 5 | import { onMounted } from 'vue'; |
| 6 | +import type { Asset } from '@ping-pub/chain-registry-client/dist/types' |
6 | 7 | import PaginationBar from '@/components/PaginationBar.vue'; |
7 | 8 | const props = defineProps(['chain']); |
8 | 9 |
|
9 | 10 | const format = useFormatter(); |
10 | | -const chainStore = useBlockchain() |
| 11 | +const chainStore = useBlockchain(); |
11 | 12 |
|
12 | | -const list = ref([] as Coin[]) |
13 | | -
|
14 | | -function showType(v: string) { |
15 | | - return v.replace("/cosmos.auth.v1beta1.", "") |
16 | | -} |
| 13 | +const list = ref([] as ({ denom: string, amount: string, base: string, info: string, logo: string | undefined })[]) |
17 | 14 |
|
18 | 15 | const pageRequest = ref(new PageRequest()) |
19 | 16 | const pageResponse = ref({} as Pagination) |
20 | 17 |
|
| 18 | +interface SupplyAsset extends Asset { |
| 19 | + logo: string | undefined |
| 20 | +} |
| 21 | +
|
21 | 22 | onMounted(() => { |
22 | 23 | pageload(1) |
23 | 24 | }); |
24 | 25 |
|
| 26 | +function findGlobalAssetConfig(denom: string) { |
| 27 | + const assets = chainStore.current?.assets |
| 28 | + if (assets) { |
| 29 | + const conf = assets.find(a => a.base === denom) |
| 30 | + if (conf) { |
| 31 | + return conf |
| 32 | + } |
| 33 | + } |
| 34 | + return undefined |
| 35 | +} |
| 36 | +
|
| 37 | +async function mergeDenomMetadata(denom: string, denomsMetadatas: DenomMetadata[]): Promise<SupplyAsset> { |
| 38 | + const denomMetadata = denomsMetadatas.find(d => d.base.endsWith(denom)); |
| 39 | + let asset = findGlobalAssetConfig(denom) as SupplyAsset |
| 40 | + if (asset && denomMetadata) { |
| 41 | + asset = { ...denomMetadata, ...asset } |
| 42 | + asset.display = denomMetadata.display |
| 43 | + asset.logo = asset.logo_URIs?.svg || asset.logo_URIs?.png || asset.logo_URIs?.jpeg || undefined |
| 44 | + } else if (denomMetadata) { |
| 45 | + return denomMetadata as SupplyAsset |
| 46 | + } |
| 47 | + return asset; |
| 48 | +} |
| 49 | +
|
25 | 50 | function pageload(p: number) { |
26 | 51 | pageRequest.value.setPage(p) |
27 | | - chainStore.rpc.getBankSupply(pageRequest.value).then(x => { |
28 | | - list.value = x.supply |
29 | | - pageResponse.value = x.pagination |
30 | | - }); |
| 52 | + chainStore.rpc.getBankDenomMetadata().then(async (denomsMetaResponse) => { |
| 53 | + const bankSupplyResponse = await chainStore.rpc.getBankSupply(pageRequest.value); |
| 54 | + list.value = await Promise.all(bankSupplyResponse.supply.map(async (coin: Coin) => { |
| 55 | + const asset = await mergeDenomMetadata(coin.denom, denomsMetaResponse.metadatas) |
| 56 | + const denom = (asset?.symbol || coin.denom) |
| 57 | + return { |
| 58 | + denom: denom.split('/')[denom.split('/').length - 1].toUpperCase(), |
| 59 | + amount: format.tokenAmountNumber({ amount: coin.amount, denom: denom }).toString(), |
| 60 | + base: asset.base || coin.denom, |
| 61 | + info: asset.display || coin.denom, |
| 62 | + logo: asset?.logo_URIs?.svg || asset?.logo_URIs?.png || asset?.logo_URIs?.jpeg || "/logo.svg", |
| 63 | + } |
| 64 | + })); |
| 65 | + pageResponse.value = bankSupplyResponse.pagination |
| 66 | + }) |
31 | 67 | } |
32 | 68 |
|
33 | 69 | </script> |
34 | 70 | <template> |
35 | | - <div class="overflow-auto bg-base-100"> |
36 | | - <table class="table table-compact"> |
37 | | - <thead class=" bg-base-200"> |
38 | | - <tr> |
39 | | - <td>Token</td> |
40 | | - <td>Amount</td> |
41 | | - </tr> |
42 | | - </thead> |
43 | | - <tr v-for="item in list" class="hover"> |
44 | | - <td>{{ item.denom }}</td> |
45 | | - <td>{{ item.amount }}</td> |
46 | | - </tr> |
47 | | - </table> |
48 | | - <PaginationBar :limit="pageRequest.limit" :total="pageResponse.total" :callback="pageload" /> |
49 | | - </div> |
| 71 | + <div class="overflow-auto bg-base-100"> |
| 72 | + <table class="table table-compact"> |
| 73 | + <thead class=" bg-base-200"> |
| 74 | + <tr> |
| 75 | + <td>Logo</td> |
| 76 | + <td>Token</td> |
| 77 | + <td>Amount</td> |
| 78 | + <td>Info</td> |
| 79 | + <td>Base</td> |
| 80 | + </tr> |
| 81 | + </thead> |
| 82 | + <tr v-for="item in list" class="hover"> |
| 83 | + <td> |
| 84 | + <img v-if="item.logo" :src="item.logo" class="w-7 h-7" /> |
| 85 | + </td> |
| 86 | + <td>{{ item.denom }}</td> |
| 87 | + <td>{{ item.amount }}</td> |
| 88 | + <td>{{ item.info }}</td> |
| 89 | + <td>{{ item.base }}</td> |
| 90 | + </tr> |
| 91 | + </table> |
| 92 | + <PaginationBar :limit="pageRequest.limit" :total="pageResponse.total" :callback="pageload" /> |
| 93 | + </div> |
50 | 94 | </template> |
51 | 95 |
|
52 | 96 | <route> |
|
0 commit comments