Skip to content

Commit 67fd8f4

Browse files
committed
improve supply page
1 parent 06b7965 commit 67fd8f4

File tree

1 file changed

+72
-28
lines changed

1 file changed

+72
-28
lines changed

src/modules/[chain]/supply/index.vue

Lines changed: 72 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,96 @@
11
<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';
55
import { onMounted } from 'vue';
6+
import type { Asset } from '@ping-pub/chain-registry-client/dist/types'
67
import PaginationBar from '@/components/PaginationBar.vue';
78
const props = defineProps(['chain']);
89
910
const format = useFormatter();
10-
const chainStore = useBlockchain()
11+
const chainStore = useBlockchain();
1112
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 })[])
1714
1815
const pageRequest = ref(new PageRequest())
1916
const pageResponse = ref({} as Pagination)
2017
18+
interface SupplyAsset extends Asset {
19+
logo: string | undefined
20+
}
21+
2122
onMounted(() => {
2223
pageload(1)
2324
});
2425
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+
2550
function pageload(p: number) {
2651
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+
})
3167
}
3268
3369
</script>
3470
<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>
5094
</template>
5195

5296
<route>

0 commit comments

Comments
 (0)