Merge pull request #380 from alisaweb3/v3-single

Timeline, Wallet Drapdown,Validator Detail,Governance Progress
This commit is contained in:
ping
2023-05-15 14:07:19 +08:00
committed by GitHub
34 changed files with 755 additions and 1016 deletions
+12 -8
View File
@@ -33,11 +33,11 @@ export const useBaseStore = defineStore('baseStore', {
return useBlockchain();
},
txsInRecents() {
const txs = [] as { height: string, hash: string; tx: DecodedTxRaw }[];
const txs = [] as { height: string; hash: string; tx: DecodedTxRaw }[];
this.recents.forEach((b) =>
b.block?.data?.txs.forEach((tx: string) => {
if (tx) {
const raw = fromBase64(tx)
const raw = fromBase64(tx);
try {
txs.push({
height: b.block.header.height,
@@ -45,7 +45,7 @@ export const useBaseStore = defineStore('baseStore', {
tx: decodeTxRaw(raw),
});
} catch (e) {
console.error(e)
console.error(e);
}
}
})
@@ -61,18 +61,22 @@ export const useBaseStore = defineStore('baseStore', {
this.recents = [];
},
async fetchLatest() {
this.latest = await this.blockchain.rpc.getBaseBlockLatest();
this.latest = await this.blockchain.rpc?.getBaseBlockLatest();
if (
!this.earlest ||
this.earlest.block?.header?.chain_id !=
this.latest.block?.header?.chain_id
this.earlest?.block?.header?.chain_id !=
this.latest?.block?.header?.chain_id
) {
//reset earlest and recents
this.earlest = this.latest;
this.recents = [];
}
//check if the block exists in recents
if(this.recents.findIndex(x => x.block_id.hash === this.latest.block_id.hash) === -1 ) {
if (
this.recents.findIndex(
(x) => x?.block_id?.hash === this.latest?.block_id?.hash
) === -1
) {
if (this.recents.length >= 50) {
this.recents.pop();
}
@@ -87,7 +91,7 @@ export const useBaseStore = defineStore('baseStore', {
async fetchLatestValidators(offset = 0) {
return this.blockchain.rpc.getBaseValidatorsetLatest(offset);
},
async fetchBlock(height?: number|string) {
async fetchBlock(height?: number | string) {
return this.blockchain.rpc.getBaseBlockAt(String(height));
},
async fetchAbciInfo() {
+1 -1
View File
@@ -12,7 +12,7 @@ export const useDistributionStore = defineStore('distributionStore', {
},
actions: {
async fetchCommunityPool() {
return this.blockchain.rpc.getDistributionCommunityPool();
return this.blockchain.rpc?.getDistributionCommunityPool();
},
},
});
+13 -12
View File
@@ -54,8 +54,8 @@ export const useFormatter = defineStore('formatter', {
return useBankStore();
},
dashboard() {
return useDashboard()
}
return useDashboard();
},
},
actions: {
async fetchDenomTrace(denom: string) {
@@ -69,9 +69,9 @@ export const useFormatter = defineStore('formatter', {
return trace;
},
priceInfo(denom: string) {
const id = this.dashboard.coingecko[denom]?.coinId
const prices = this.dashboard.prices[id]
return prices
const id = this.dashboard.coingecko[denom]?.coinId;
const prices = this.dashboard.prices[id];
return prices;
},
priceColor(denom: string, currency = "usd") {
const change = this.priceChanges(denom, currency)
@@ -86,11 +86,11 @@ export const useFormatter = defineStore('formatter', {
},
price(denom: string, currency = "usd") {
const info = this.priceInfo(denom);
return info? info[currency]||0 : 0
return info ? info[currency] || 0 : 0;
},
priceChanges(denom: string, currency="usd"): number {
priceChanges(denom: string, currency = 'usd'): number {
const info = this.priceInfo(denom);
return info? info[`${currency}_24h_change`]||0 : 0
return info ? info[`${currency}_24h_change`] || 0 : 0;
},
showChanges(v: number) {
return v!==0 ? numeral(v).format("+0,0.[00]"): ""
@@ -103,7 +103,8 @@ export const useFormatter = defineStore('formatter', {
// find the symbol,
const symbol = this.dashboard.coingecko[token.denom]?.symbol || ""
// convert denomation to to symbol
const exponent = this.dashboard.coingecko[symbol.toLowerCase()]?.exponent || 0
const exponent =
this.dashboard.coingecko[symbol.toLowerCase()]?.exponent || 0;
// cacualte amount of symbol
const amount = Number(token.amount) / (10 ** exponent)
const value = amount * this.price(token.denom)
@@ -131,7 +132,7 @@ export const useFormatter = defineStore('formatter', {
fmt = '0.0a',
mode = 'local'
): string {
if (token && token.amount) {
if (token && token.amount && token?.denom) {
let amount = Number(token.amount);
let denom = token.denom;
@@ -241,11 +242,11 @@ export const useFormatter = defineStore('formatter', {
}
return dayjs(time).format('YYYY-MM-DD HH:mm:ss');
},
messages(msgs: { '@type'?: string, typeUrl?: string }[]) {
messages(msgs: { '@type'?: string; typeUrl?: string }[]) {
if (msgs) {
const sum: Record<string, number> = msgs
.map((msg) => {
const msgType = msg['@type'] || msg.typeUrl || 'unknown'
const msgType = msg['@type'] || msg.typeUrl || 'unknown';
return msgType
.substring(msgType.lastIndexOf('.') + 1)
.replace('Msg', '');
+2 -2
View File
@@ -31,10 +31,10 @@ export const useGovStore = defineStore('govStore', {
if (!this.loading[status]) {
this.loading[status] = LoadingStatus.Loading;
const proposals = reactive(
await this.blockchain.rpc.getGovProposals(status)
await this.blockchain.rpc?.getGovProposals(status)
);
if (status === '2') {
proposals.proposals.forEach(async (x1) => {
proposals?.proposals?.forEach(async (x1) => {
await this.fetchTally(x1.proposal_id).then((res) => {
x1.final_tally_result = res?.tally;
});
+8 -6
View File
@@ -17,14 +17,16 @@ export const useMintStore = defineStore('mintStore', {
this.fetchInflation();
},
async fetchInflation() {
this.blockchain.rpc
.getMintInflation()
.then((x) => {
this.inflation = x.inflation;
})
.catch(() => {
try {
const res = await this.blockchain?.rpc?.getMintInflation().catch(() => {
this.inflation = '0';
});
if (res) {
this.inflation = res.inflation;
}
} catch (e) {
console.log(e);
}
},
},
});
+11 -11
View File
@@ -203,19 +203,19 @@ export const useParamStore = defineStore('paramstore', {
console.log('handleAbciInfo', this.nodeVersion.items);
},
async getBaseTendermintBlockLatest() {
return await this.blockchain.rpc.getBaseBlockLatest();
return await this.blockchain.rpc?.getBaseBlockLatest();
},
async getMintParam() {
return await this.blockchain.rpc.getMintParam();
return await this.blockchain.rpc?.getMintParam();
},
async getStakingParams() {
return await this.blockchain.rpc.getStakingParams();
return await this.blockchain.rpc?.getStakingParams();
},
async getStakingPool() {
return await this.blockchain.rpc.getStakingPool();
return await this.blockchain.rpc?.getStakingPool();
},
async getBankTotal(denom: string) {
return await this.blockchain.rpc.getBankSupplyByDenom(denom);
return await this.blockchain.rpc?.getBankSupplyByDenom(denom);
// if (compareVersions(this.config.sdk_version, '0.46.2') > 0) {
// return this.get(`/cosmos/bank/v1beta1/supply/by_denom?denom=${denom}`).then(data => commonProcess(data).amount)
// }
@@ -225,22 +225,22 @@ export const useParamStore = defineStore('paramstore', {
// return this.get(`/cosmos/bank/v1beta1/supply/${denom}`).then(data => commonProcess(data).amount)
},
async getSlashingParams() {
return await this.blockchain.rpc.getSlashingParams();
return await this.blockchain.rpc?.getSlashingParams();
},
async getDistributionParams() {
return await this.blockchain.rpc.getDistributionParams();
return await this.blockchain.rpc?.getDistributionParams();
},
async getGovParamsVoting() {
return await this.blockchain.rpc.getGovParamsVoting();
return await this.blockchain.rpc?.getGovParamsVoting();
},
async getGovParamsDeposit() {
return await this.blockchain.rpc.getGovParamsDeposit();
return await this.blockchain.rpc?.getGovParamsDeposit();
},
async getGovParamsTally() {
return await this.blockchain.rpc.getGovParamsTally();
return await this.blockchain.rpc?.getGovParamsTally();
},
async fetchAbciInfo() {
return this.blockchain.rpc.getBaseNodeInfo();
return this.blockchain.rpc?.getBaseNodeInfo();
},
},
});
+9 -7
View File
@@ -47,14 +47,16 @@ export const useStakingStore = defineStore('stakingStore', {
);
},
async fetchParams() {
const response = await this.blockchain.rpc.getStakingParams();
if (response.params) this.params = response.params;
const response = await this.blockchain.rpc?.getStakingParams();
if (response?.params) this.params = response.params;
return this.params;
},
async fetchPool() {
const response = await this.blockchain.rpc.getStakingPool();
response.pool.bonded_tokens;
this.pool = response.pool;
const response = await this.blockchain.rpc?.getStakingPool();
if (response) {
response.pool.bonded_tokens;
this.pool = response.pool;
}
},
async fetchAcitveValdiators() {
return this.fetchValidators('BOND_STATUS_BONDED');
@@ -69,13 +71,13 @@ export const useStakingStore = defineStore('stakingStore', {
validatorAddr: string,
delegatorAddr: string
) {
return await this.blockchain.rpc.getStakingValidatorsDelegationsDelegator(
return await this.blockchain.rpc?.getStakingValidatorsDelegationsDelegator(
validatorAddr,
delegatorAddr
);
},
async fetchValidators(status: string) {
return this.blockchain.rpc.getStakingValidators(status).then((res) => {
return this.blockchain.rpc?.getStakingValidators(status).then((res) => {
const vals = res.validators.sort(
(a, b) => Number(b.delegator_shares) - Number(a.delegator_shares)
);