Skip to content

Commit

Permalink
feat(token): adds pair table to token and links
Browse files Browse the repository at this point in the history
  • Loading branch information
kenodressel authored and mmpetarpeshev committed Jun 25, 2024
1 parent 56a9f50 commit 351795b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/components/explore/PairTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default {
link: `/explore/pools/${pair.address}`,
},
txs: {
text: pair.transactions,
text: String(pair.transactions),
},
tvl: {
text: formatUsdPretty(pair.tvlUsd, 0),
Expand Down
4 changes: 4 additions & 0 deletions src/store/modules/dexBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,5 +196,9 @@ export default {
async fetchPairsByToken({ dispatch }, tokenId) {
return dispatch('safeFetch', { url: `tokens/by-address/${tokenId}/pairs` });
},

async fetchPairsByTokenUsd({ dispatch }, tokenId) {
return dispatch('safeFetch', { url: `pairs?token=${tokenId}` });
},
},
};
10 changes: 9 additions & 1 deletion src/views/PoolDetailView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@
<ExploreWrapper>
<div class="flex flex-row px-6 pt-6 items-center">
<span v-if="pairId" class="logo"><AddressAvatar :address="pairId" /></span>
<h1 class="text-2xl">{{ pair?.token0.symbol }} / {{ pair?.token1.symbol }}</h1>
<h1 class="text-2xl">
<router-link :to="`/explore/tokens/${pair?.token0.address}`">{{
pair?.token0.symbol
}}</router-link>
/
<router-link :to="`/explore/tokens/${pair?.token1.address}`">{{
pair?.token1.symbol
}}</router-link>
</h1>
</div>
<div class="flex">
<div class="flex-1 flex-auto p-6">
Expand Down
15 changes: 8 additions & 7 deletions src/views/TokenDetailView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<div class="border-2 border-gray-800"></div>
<div>
<h2 class="text-2xl text-left p-4 pb-0">Pools</h2>
<PairTable :pairs="pairList"></PairTable>
<PairTable :pairs="pairTable"></PairTable>
</div>

<DividerLine />
Expand Down Expand Up @@ -107,6 +107,7 @@ export default defineComponent({
pairs0: [],
pairs1: [],
},
pairTable: [],
pairMap: new Map(),
tokenIdMap: new Map(),
metaInfo: {
Expand Down Expand Up @@ -275,6 +276,12 @@ export default defineComponent({
]),
]);
const pairWithUSD = await this.$store.dispatch('backend/fetchPairsByTokenUsd', this.tokenId);
this.pairTable = pairWithUSD.map((pair) => ({
...pair,
token0: this.pairMap.get(pair.address).token0,
token1: this.pairMap.get(pair.address).token1,
}));
this.tokenIdMap = new Map([
...this.pairs.pairs0.map((pair) => [pair.address, 0]),
...this.pairs.pairs1.map((pair) => [pair.address, 1]),
Expand All @@ -289,12 +296,6 @@ export default defineComponent({
},
methods: {
shortenAddress,
getReserve(historyEntry) {
if (this.tokenIdMap.get(historyEntry.pairAddress) === 0) {
return historyEntry.reserve0;
}
return historyEntry.reserve1;
},
getDeltaReserve(historyEntry) {
if (this.tokenIdMap.get(historyEntry.pairAddress) === 0) {
return historyEntry.deltaReserve0;
Expand Down

0 comments on commit 351795b

Please sign in to comment.