Skip to content

Commit d9ab990

Browse files
authored
Merge pull request ava-labs#61 from ava-labs/everest
Everest
2 parents 04a6af0 + b2e164e commit d9ab990

File tree

8 files changed

+236
-107
lines changed

8 files changed

+236
-107
lines changed

src/components/Asset/Metadata.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ import TooltipMeta from "../../components/misc/TooltipMeta.vue";
8080
return val === 0
8181
? `no fractional units`
8282
: val > 1
83-
? `${val} decimal digits`
84-
: `${val} decimal digit`;
83+
? `${val} decimal digits`
84+
: `${val} decimal digit`;
8585
}
8686
}
8787

src/components/Home/RecentTransactions.vue

Lines changed: 47 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -8,53 +8,52 @@
88
<span class="ava-btn-label">Refresh</span>
99
</v-btn>
1010
</div>
11-
<template v-if="assetsLoaded">
12-
<p class="chain right" bottom v-if="$vuetify.breakpoint.smAndUp">
13-
<span class="label">You are viewing transactions for</span>
14-
<v-tooltip>
15-
<template v-slot:activator="{ on }">
16-
<span v-on="on" class="tag">X-Chain</span>
17-
</template>
18-
<span>The X-Chain acts as a decentralized platform for creating and trading smart digital assets. (Think X for eXchanging assets.)</span>
19-
</v-tooltip>
20-
</p>
21-
</template>
11+
<p class="chain right" bottom v-if="$vuetify.breakpoint.smAndUp">
12+
<span class="label">You are viewing transactions for</span>
13+
<v-tooltip>
14+
<template v-slot:activator="{ on }">
15+
<span v-on="on" class="tag">X-Chain</span>
16+
</template>
17+
<span>The X-Chain acts as a decentralized platform for creating and trading smart digital assets. (Think X for eXchanging assets.)</span>
18+
</v-tooltip>
19+
</p>
2220
</div>
23-
<template v-if="assetsLoaded">
2421
<div class="list">
25-
<div class="table_headers recent_tx_rows">
26-
<p></p>
27-
<p>
28-
ID
29-
<Tooltip content="a transaction queries or modifies the state of a blockchain"></Tooltip>
30-
</p>
31-
<p>
32-
From
33-
<Tooltip content="address that sends transfer value"></Tooltip>
34-
</p>
35-
<p>
36-
To
37-
<Tooltip content="address that receives transfer value"></Tooltip>
38-
</p>
22+
<div class="table_headers recent_tx_rows">
23+
<p></p>
24+
<p>
25+
ID
26+
<Tooltip content="a transaction queries or modifies the state of a blockchain"></Tooltip>
27+
</p>
28+
<p>
29+
From
30+
<Tooltip content="address that sends transfer value"></Tooltip>
31+
</p>
32+
<p>
33+
To
34+
<Tooltip content="address that receives transfer value"></Tooltip>
35+
</p>
36+
</div>
37+
<transition-group name="fade" v-if="transactions.length > 0">
38+
<tx-row
39+
v-for="tx in transactions"
40+
:key="tx.id"
41+
class="recent_tx_rows"
42+
:transaction="tx"
43+
></tx-row>
44+
</transition-group>
45+
<div v-if="transactions.length === 0">
46+
<v-progress-circular :size="16" :width="2" color="#E84970" indeterminate key="1"></v-progress-circular>
47+
</div>
48+
</div>
49+
<div class="bottom">
50+
<router-link to="/tx" class="view_all">View All Transactions</router-link>
3951
</div>
40-
<transition-group name="fade">
41-
<tx-row
42-
v-for="tx in transactions"
43-
:key="tx.id"
44-
class="recent_tx_rows"
45-
:transaction="tx"
46-
></tx-row>
47-
</transition-group>
48-
</div>
49-
<div class="bottom">
50-
<router-link to="/tx" class="view_all">View All Transactions</router-link>
51-
</div>
52-
</template>
5352
</div>
5453
</template>
5554

5655
<script lang="ts">
57-
import { Vue, Component, Watch } from "vue-property-decorator";
56+
import { Vue, Component, Prop, Watch } from "vue-property-decorator";
5857
import Tooltip from "@/components/rows/Tooltip.vue";
5958
import TxRow from "@/components/rows/TxRow/TxRow.vue";
6059
import api from "@/axios";
@@ -68,34 +67,25 @@ import { ITransaction } from '@/js/ITransaction';
6867
})
6968
export default class RecentTransactions extends Vue {
7069
loading: boolean = false;
71-
transactions: ITransaction[] = [];
72-
73-
created() {
74-
this.updateTx();
75-
}
76-
77-
@Watch("assetsLoaded")
78-
onAssetsLoadedChanged(val: string, oldVal: string) {
79-
this.updateTx();
80-
}
81-
82-
updateTx() {
70+
71+
async updateTx() {
8372
let txNum = 8;
8473
this.loading = true;
8574
8675
if (this.assetsLoaded) {
8776
// TODO: support service for multiple chains
88-
api.get(`/x/transactions?sort=timestamp-desc&limit=${txNum}`).then(res => {
89-
const list = res.data.transactions;
90-
this.transactions = list;
91-
this.loading = false;
92-
});
77+
await this.$store.dispatch("getRecentTransactions");
78+
this.loading = false;
9379
}
9480
}
9581
9682
get assetsLoaded() {
9783
return this.$store.state.assetsLoaded;
9884
}
85+
86+
get transactions(): ITransaction[] {
87+
return this.$store.state.recentTransactions;
88+
}
9989
}
10090
</script>
10191

src/components/Home/TopInfo/MetaData.vue

Lines changed: 90 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,15 @@
9191
</template>
9292
<script lang="ts">
9393
import "reflect-metadata";
94-
import { Vue, Component } from "vue-property-decorator";
94+
import { Vue, Component, Watch } from "vue-property-decorator";
9595
9696
import axios from "@/axios";
9797
import { stringToBig } from "@/helper";
9898
import TooltipHeading from "../../misc/TooltipHeading.vue";
9999
import TooltipMeta from "../TopInfo/TooltipMeta.vue";
100100
import { AVAX_ID } from "@/store/index";
101+
import { Asset } from '@/js/Asset';
102+
import Big from "big.js";
101103
102104
@Component({
103105
components: {
@@ -106,14 +108,77 @@ import { AVAX_ID } from "@/store/index";
106108
}
107109
})
108110
export default class MetaData extends Vue {
111+
volumeCache: Big = Big(0);
112+
totalTransactionsCache: number = 0;
113+
109114
get assetsLoaded(): boolean {
110115
return this.$store.state.assetsLoaded;
111116
}
112117
118+
get assetAggregatesLoaded(): boolean {
119+
return this.$store.state.assetAggregatesLoaded;
120+
}
121+
113122
get subnetsLoaded(): boolean {
114123
return this.$store.state.Platform.subnetsLoaded;
115124
}
116125
126+
@Watch("avaxVolume")
127+
onAvaxVolumeChanged(val: string) {
128+
// console.log("CALLED FROM: @Watch(avaxVolume)")
129+
this.saveCacheAvax();
130+
}
131+
132+
@Watch("totalTransactions")
133+
ontotalTransactionsChanged(val: number) {
134+
// console.log("CALLED FROM: @Watch(totalTransactions)")
135+
this.saveCacheTotalTransactions();
136+
}
137+
138+
created() {
139+
// Get 24h volume cache
140+
// TODO: remove when API is enhanced
141+
let volumeCacheJSON = localStorage.getItem('avaxCache');
142+
let volumeCache = Big(0);
143+
if (volumeCacheJSON) {
144+
let cache = JSON.parse(volumeCacheJSON);
145+
volumeCache = Big(cache.volume_day);
146+
}
147+
this.volumeCache = volumeCache;
148+
149+
// Get totalTransactions cache
150+
// TODO: remove when API is enhanced
151+
let totalTransactionsCacheJSON = localStorage.getItem('totalTransactions');
152+
let totalTransactionsCache = 0;
153+
if (totalTransactionsCacheJSON) {
154+
let cache = JSON.parse(totalTransactionsCacheJSON);
155+
totalTransactionsCache = cache;
156+
}
157+
this.totalTransactionsCache = totalTransactionsCache;
158+
}
159+
160+
saveCacheAvax() {
161+
let asset = this.avax;
162+
if (asset) {
163+
let volume_day = asset.volume_day.toString();
164+
let txCount_day = asset.txCount_day;
165+
let cache = {
166+
volume_day, // AVAX volume
167+
txCount_day, // AVAX count
168+
};
169+
localStorage.setItem('avaxCache', JSON.stringify(cache));
170+
}
171+
}
172+
173+
saveCacheTotalTransactions() {
174+
let totalTransactions = this.totalTransactions;
175+
let cache = {
176+
totalTransactions // count across all assets
177+
}
178+
localStorage.setItem('totalTransactions', JSON.stringify(totalTransactions));
179+
}
180+
181+
// Data from Ortelius
117182
get tpmText(): string {
118183
let day = 60 * 24;
119184
let avg = this.totalTransactions / day;
@@ -126,6 +191,30 @@ export default class MetaData extends Vue {
126191
return avg > 1 ? avg.toFixed(0) : avg.toFixed(2);
127192
}
128193
194+
get assets() {
195+
return this.$store.state.assets;
196+
}
197+
198+
get avax(): Asset | undefined {
199+
return this.assets[AVAX_ID];
200+
}
201+
202+
get avaxVolume(): string {
203+
if (!this.avax) {
204+
return parseInt(this.volumeCache.toFixed(0)).toLocaleString();
205+
}
206+
return this.avax.isHistoryUpdated
207+
? parseInt(this.avax.volume_day.toFixed(0)).toLocaleString()
208+
: parseInt(this.volumeCache.toFixed(0)).toLocaleString();
209+
}
210+
211+
get totalTransactions(): number {
212+
return this.$store.state.assetAggregatesLoaded
213+
? this.$store.getters.totalTransactions
214+
: this.totalTransactionsCache;
215+
}
216+
217+
// Data from Avalanche-Go
129218
get totalStake(): string {
130219
let res = this.$store.getters["Platform/totalStake"];
131220
res = stringToBig(res.toString(), 9).toFixed(0);
@@ -135,18 +224,6 @@ export default class MetaData extends Vue {
135224
get validatorCount(): number {
136225
return this.$store.getters["Platform/totalValidators"];
137226
}
138-
139-
get avaxVolume(): string {
140-
let assets = this.$store.state.assets;
141-
let avax = assets[AVAX_ID];
142-
return !avax
143-
? (0).toLocaleString()
144-
: parseInt(avax.volume_day.toFixed(0)).toLocaleString();
145-
}
146-
147-
get totalTransactions(): number {
148-
return this.$store.getters.totalTransactions;
149-
}
150227
}
151228
152229
</script>

src/components/Home/TopInfo/TopAssets.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
></TooltipHeading>
99
</h2>
1010
</div>
11-
<div v-if="!assetsLoaded">
11+
<div v-if="!assetAggregatesLoaded">
1212
<v-progress-circular :size="16" :width="2" color="#E84970" indeterminate key="1"></v-progress-circular>
1313
</div>
1414
<div v-else>
@@ -65,6 +65,10 @@ export default class TopAssets extends Vue {
6565
return res.slice(0, 5);
6666
}
6767
68+
get assetAggregatesLoaded(): boolean {
69+
return this.$store.state.assetAggregatesLoaded;
70+
}
71+
6872
get assetsLoaded(): boolean {
6973
return this.$store.state.assetsLoaded;
7074
}

src/components/Home/TopInfo/TopInfo.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export default {
3636
}
3737
3838
> div:last-of-type {
39+
min-height: 256px;
3940
border: none;
4041
}
4142
}

src/js/Asset.ts

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { IAssetData_Ortelius } from "./IAsset";
33
import { profanities } from "@/js/Profanities";
44
import Big from "big.js";
55
import { stringToBig } from '@/helper';
6+
import store from '../store';
67

78
class Asset {
89
id: string;
@@ -12,9 +13,14 @@ class Asset {
1213
denomination: number;
1314
name: string;
1415
symbol: string;
16+
// aggregate data
1517
volume_day: Big;
1618
txCount_day: number;
19+
isHistoryUpdated: boolean;
20+
// FE metadata
1721
profane: boolean;
22+
// not in indexer
23+
isUnknown: boolean;
1824

1925
constructor(assetData: IAssetData_Ortelius, isUnknown: boolean) {
2026
this.id = assetData.id;
@@ -27,29 +33,34 @@ class Asset {
2733
this.symbol = assetData.symbol;
2834
this.volume_day = Big(0);
2935
this.txCount_day = 0;
36+
// aggregate data
37+
this.isHistoryUpdated = false;
38+
// not in indexer
39+
this.isUnknown = isUnknown;
40+
// FE metadata
3041
this.profane = false;
31-
if (!isUnknown) {
32-
this.updateVolumeHistory();
33-
}
3442
this.checkForProfanities(this.name);
3543
this.checkForProfanities(this.symbol);
3644
}
3745

3846
// Daily Volume
39-
private updateVolumeHistory(): void {
40-
let parent = this;
41-
let endDate = new Date();
42-
let startTime = Date.now() - (1000 * 60 * 60 * 24);
43-
let startDate = new Date(startTime);
47+
public updateVolumeHistory(): void {
48+
if (this.isUnknown === false) {
49+
let endDate = new Date();
50+
let startTime = Date.now() - (1000 * 60 * 60 * 24);
51+
let startDate = new Date(startTime);
4452

45-
// TODO: support service for multiple chains
46-
// TODO: declare interface
47-
api.get(`/x/transactions/aggregates?startTime=${startDate.toISOString()}&endTime=${endDate.toISOString()}&assetID=${this.id}`).then(res => {
48-
let txCount = res.data.aggregates.transactionCount || 0;
49-
let txVolume = res.data.aggregates.transactionVolume || "0";
50-
parent.volume_day = stringToBig(txVolume, parent.denomination);
51-
parent.txCount_day = txCount;
52-
});
53+
// TODO: support service for multiple chains
54+
// TODO: declare interface
55+
api.get(`/x/transactions/aggregates?startTime=${startDate.toISOString()}&endTime=${endDate.toISOString()}&assetID=${this.id}`).then(res => {
56+
let txCount = res.data.aggregates.transactionCount || 0;
57+
let txVolume = res.data.aggregates.transactionVolume || "0";
58+
this.volume_day = stringToBig(txVolume, this.denomination);
59+
this.txCount_day = txCount;
60+
this.isHistoryUpdated = true;
61+
store.dispatch("checkAssetAggregatesLoaded");
62+
});
63+
}
5364
}
5465

5566
private checkForProfanities(value: string): void {

0 commit comments

Comments
 (0)