forked from LaconicNetwork/cosmos-explorer
finish tx detail
This commit is contained in:
@@ -7,9 +7,9 @@ import type { Coin } from "@/types";
|
||||
export const useBankStore = defineStore('bankstore', {
|
||||
state: () => {
|
||||
return {
|
||||
supply: {} as Coin[],
|
||||
supply: {} as Coin,
|
||||
balances: {} as Record<string, Coin[]>,
|
||||
totalSupply: {supply: []} ,
|
||||
totalSupply: {supply: [] as Coin[]} ,
|
||||
}
|
||||
},
|
||||
getters: {
|
||||
@@ -26,7 +26,7 @@ export const useBankStore = defineStore('bankstore', {
|
||||
this.supply = {} as Coin
|
||||
const denom = this.staking.params.bondDenom || this.blockchain.current?.assets[0].base
|
||||
if(denom) {
|
||||
this.blockchain.rpc.supplyOf(denom).then(res => {
|
||||
this.blockchain.rpc.getBankSupplyByDenom(denom).then(res => {
|
||||
if(res.amount) this.supply = res.amount
|
||||
})
|
||||
}
|
||||
@@ -38,7 +38,7 @@ export const useBankStore = defineStore('bankstore', {
|
||||
// return response
|
||||
// },
|
||||
async fetchSupply(denom: string) {
|
||||
return this.blockchain.rpc.supplyOf( denom )
|
||||
return this.blockchain.rpc.getBankSupplyByDenom( denom )
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
+10
-11
@@ -1,15 +1,14 @@
|
||||
import { defineStore } from "pinia";
|
||||
import { useBlockchain } from "@/stores";
|
||||
import dayjs from "dayjs";
|
||||
|
||||
import type { BlockResponse } from "@cosmjs/tendermint-rpc";
|
||||
import type { Block } from "@/types";
|
||||
|
||||
export const useBaseStore = defineStore('baseStore', {
|
||||
state: () => {
|
||||
return {
|
||||
earlest: {} as BlockResponse,
|
||||
latest: {} as BlockResponse,
|
||||
recents: [] as BlockResponse[]
|
||||
earlest: {} as Block,
|
||||
latest: {} as Block,
|
||||
recents: [] as Block[]
|
||||
}
|
||||
},
|
||||
getters: {
|
||||
@@ -34,8 +33,8 @@ export const useBaseStore = defineStore('baseStore', {
|
||||
this.recents = []
|
||||
},
|
||||
async fetchLatest() {
|
||||
this.latest = await this.blockchain.rpc.block()
|
||||
if(!this.earlest || this.earlest.block?.header?.chainId != this.latest.block?.header?.chainId) {
|
||||
this.latest = await this.blockchain.rpc.getBaseBlockLatest()
|
||||
if(!this.earlest || this.earlest.block?.header?.chain_id != this.latest.block?.header?.chain_id) {
|
||||
//reset earlest and recents
|
||||
this.earlest = this.latest
|
||||
this.recents = []
|
||||
@@ -48,16 +47,16 @@ export const useBaseStore = defineStore('baseStore', {
|
||||
},
|
||||
|
||||
async fetchValidatorByHeight(height?: number, offset = 0) {
|
||||
return this.blockchain.rpc.validatorsAtHeight(height)
|
||||
return this.blockchain.rpc.getBaseValidatorsetAt(String(height))
|
||||
},
|
||||
async fetchLatestValidators(offset = 0) {
|
||||
return this.blockchain.rpc.validatorsAtHeight()
|
||||
return this.blockchain.rpc.getBaseValidatorsetLatest()
|
||||
},
|
||||
async fetchBlock(height?: number) {
|
||||
return this.blockchain.rpc.block(height)
|
||||
return this.blockchain.rpc.getBaseBlockAt(String(height))
|
||||
},
|
||||
async fetchAbciInfo() {
|
||||
return this.blockchain.rpc.abciInfo()
|
||||
return this.blockchain.rpc.getBaseNodeInfo()
|
||||
}
|
||||
// async fetchNodeInfo() {
|
||||
// return this.blockchain.rpc.no()
|
||||
|
||||
+10
-14
@@ -2,12 +2,8 @@ import { defineStore } from "pinia";
|
||||
import { useDashboard, type ChainConfig, type Endpoint, EndpointType } from "./useDashboard";
|
||||
import type { VerticalNavItems } from '@/@layouts/types'
|
||||
import { useRouter } from "vue-router";
|
||||
import { useStakingStore } from "./useStakingStore";
|
||||
import { useBankStore } from "./useBankStore";
|
||||
import { useBaseStore } from "./useBaseStore";
|
||||
import { useGovStore } from "./useGovStore";
|
||||
import { ref } from "vue";
|
||||
import { useMintStore } from "./useMintStore";
|
||||
import { CosmosRestClient } from "@/libs/client";
|
||||
import { useBankStore, useBaseStore, useGovStore, useMintStore, useStakingStore } from ".";
|
||||
import { useBlockModule } from "@/modules/[chain]/block/block";
|
||||
|
||||
export const useBlockchain = defineStore("blockchain", {
|
||||
@@ -95,16 +91,16 @@ export const useBlockchain = defineStore("blockchain", {
|
||||
actions: {
|
||||
async initial() {
|
||||
await this.randomSetupEndpoint()
|
||||
// await useStakingStore().init()
|
||||
// useBankStore().initial()
|
||||
// useBaseStore().initial()
|
||||
// useGovStore().initial()
|
||||
// useMintStore().initial()
|
||||
// useBlockModule().initial()
|
||||
await useStakingStore().init()
|
||||
useBankStore().initial()
|
||||
useBaseStore().initial()
|
||||
useGovStore().initial()
|
||||
useMintStore().initial()
|
||||
useBlockModule().initial()
|
||||
},
|
||||
|
||||
async randomSetupEndpoint() {
|
||||
const all = this.current?.endpoints?.rpc
|
||||
const all = this.current?.endpoints?.rest
|
||||
if(all) {
|
||||
const rn = Math.random()
|
||||
const endpoint = all[Math.floor(rn * all.length)]
|
||||
@@ -115,7 +111,7 @@ export const useBlockchain = defineStore("blockchain", {
|
||||
async setRestEndpoint(endpoint: Endpoint) {
|
||||
this.connErr = ''
|
||||
this.endpoint = endpoint
|
||||
// this.rpc = new RPCClient(endpoint.address)
|
||||
this.rpc = new CosmosRestClient(endpoint.address)
|
||||
// console.log(this.rpc.endpoint)
|
||||
},
|
||||
setCurrent(name: string) {
|
||||
|
||||
@@ -13,7 +13,7 @@ export const useDistributionStore = defineStore('distributionStore', {
|
||||
},
|
||||
actions: {
|
||||
async fetchCommunityPool() {
|
||||
return this.blockchain.rpc.communityPool()
|
||||
return this.blockchain.rpc.getDistributionCommunityPool()
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -8,7 +8,7 @@ import updateLocale from 'dayjs/plugin/updateLocale'
|
||||
import utc from 'dayjs/plugin/utc'
|
||||
import localeData from 'dayjs/plugin/localeData'
|
||||
import { useStakingStore } from "./useStakingStore";
|
||||
import { toHex } from "@cosmjs/encoding";
|
||||
import { fromBase64, toHex } from "@cosmjs/encoding";
|
||||
import { consensusPubkeyToHexAddress } from "@/libs";
|
||||
|
||||
dayjs.extend(localeData)
|
||||
@@ -90,9 +90,9 @@ export const useFormatter = defineStore('formatter', {
|
||||
}
|
||||
return '-'
|
||||
},
|
||||
validator(address: Uint8Array) {
|
||||
const txt = toHex(address).toUpperCase()
|
||||
const validator = this.staking.validators.find(x => consensusPubkeyToHexAddress(x.consensusPubkey) === txt)
|
||||
validator(address: string) {
|
||||
const txt = toHex(fromBase64(address)).toUpperCase()
|
||||
const validator = this.staking.validators.find(x => consensusPubkeyToHexAddress(x.consensus_pubkey) === txt)
|
||||
return validator?.description?.moniker
|
||||
},
|
||||
calculatePercent(input?: string, total?: string|number ) {
|
||||
@@ -103,10 +103,8 @@ export const useFormatter = defineStore('formatter', {
|
||||
formatDecimalToPercent(decimal: string) {
|
||||
return numeral(decimal).format('0.[00]%')
|
||||
},
|
||||
formatCommissionRate(v?: string) {
|
||||
console.log(v)
|
||||
if(!v) return '-'
|
||||
const rate = Number(v) / Number("1000000000000000000")
|
||||
formatCommissionRate(rate?: string) {
|
||||
if(!rate) return '-'
|
||||
return this.percent(rate)
|
||||
},
|
||||
percent(decimal?: string|number) {
|
||||
@@ -134,10 +132,10 @@ export const useFormatter = defineStore('formatter', {
|
||||
}
|
||||
return dayjs(time).format('YYYY-MM-DD HH:mm:ss')
|
||||
},
|
||||
messages(msgs: {typeUrl: string}[]) {
|
||||
messages(msgs: {"@type": string}[]) {
|
||||
if(msgs) {
|
||||
const sum: Record<string, number> = msgs.map(msg => {
|
||||
return msg.typeUrl.substring(msg.typeUrl.lastIndexOf('.') + 1).replace('Msg', '')
|
||||
return msg["@type"].substring(msg["@type"].lastIndexOf('.') + 1).replace('Msg', '')
|
||||
}).reduce((s, c) => {
|
||||
const sh: Record<string, number> = s
|
||||
if (sh[c]) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { defineStore } from "pinia";
|
||||
import { useBlockchain } from "./useBlockchain";
|
||||
import type { PageRequest } from "@/types";
|
||||
|
||||
export const useGovStore = defineStore('govStore', {
|
||||
state: () => {
|
||||
@@ -20,24 +21,17 @@ export const useGovStore = defineStore('govStore', {
|
||||
initial() {
|
||||
this.fetchParams()
|
||||
},
|
||||
async fetchProposals( proposalStatus: ProposalStatus, pagination?: PageRequest ) {
|
||||
const param = {
|
||||
proposalStatus,
|
||||
voter: '',
|
||||
depositor: '',
|
||||
pagination,
|
||||
}
|
||||
const proposals = await this.blockchain.rpc.proposals(proposalStatus, '', '')
|
||||
console.log(proposals)
|
||||
async fetchProposals( status: string, pagination?: PageRequest ) {
|
||||
const proposals = await this.blockchain.rpc.getGovProposals(status)
|
||||
return proposals
|
||||
},
|
||||
async fetchParams() {
|
||||
// this.blockchain.rpc.govParam().then(x => {
|
||||
// this.blockchain.rpc.getGovParamsDeposit().then(x => {
|
||||
// this.params.deposit = x.deposit
|
||||
// })
|
||||
},
|
||||
async fetchTally(proposalId: number) {
|
||||
return this.blockchain.rpc.tally(proposalId)
|
||||
async fetchTally(proposalId: string) {
|
||||
return this.blockchain.rpc.getGovProposalTally(proposalId)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -17,7 +17,7 @@ export const useMintStore = defineStore('mintStore', {
|
||||
this.fetchInflation()
|
||||
},
|
||||
async fetchInflation() {
|
||||
this.blockchain.rpc.inflation().then(x => {
|
||||
this.blockchain.rpc.getMintInflation().then(x => {
|
||||
this.inflation = x.inflation
|
||||
}).catch(() => {
|
||||
this.inflation = "0"
|
||||
|
||||
@@ -2,18 +2,30 @@ import { defineStore } from "pinia";
|
||||
import { useBlockchain } from "./useBlockchain";
|
||||
|
||||
import { get } from "@/libs/http";
|
||||
import type { StakingParam, StakingPool, Validator } from "@/types";
|
||||
|
||||
export const useStakingStore = defineStore('stakingStore', {
|
||||
state: () => {
|
||||
return {
|
||||
validators: [] as Validator[],
|
||||
params: {} as QueryParamsResponse,
|
||||
pool: {} as Pool | undefined,
|
||||
params: {} as {
|
||||
"unbonding_time": string,
|
||||
"max_validators": number,
|
||||
"max_entries": number,
|
||||
"historical_entries": number,
|
||||
"bond_denom": string,
|
||||
"min_commission_rate": string,
|
||||
"min_self_delegation": string
|
||||
},
|
||||
pool: {} as {
|
||||
bonded_tokens: string,
|
||||
not_bonded_tokens: string,
|
||||
},
|
||||
}
|
||||
},
|
||||
getters: {
|
||||
totalPower(): number {
|
||||
const sum = (s:number, e: Validator) => { return s + parseInt(e.delegatorShares) }
|
||||
const sum = (s:number, e: Validator) => { return s + parseInt(e.delegator_shares) }
|
||||
return this.validators ? this.validators.reduce(sum, 0): 0
|
||||
},
|
||||
blockchain() {
|
||||
@@ -31,12 +43,13 @@ export const useStakingStore = defineStore('stakingStore', {
|
||||
return get(`https://keybase.io/_/api/1.0/user/lookup.json?key_suffix=${identity}&fields=pictures`)
|
||||
},
|
||||
async fetchParams() {
|
||||
const response = await this.blockchain.rpc.stakingParams()
|
||||
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.stakingPool()
|
||||
const response = await this.blockchain.rpc.getStakingPool()
|
||||
response.pool.bonded_tokens
|
||||
this.pool = response.pool
|
||||
},
|
||||
async fetchAcitveValdiators() {
|
||||
@@ -46,14 +59,14 @@ export const useStakingStore = defineStore('stakingStore', {
|
||||
return this.fetchValidators('BOND_STATUS_UNBONDED')
|
||||
},
|
||||
async fetchValidator(validatorAddr: string) {
|
||||
return this.blockchain.rpc.validator(validatorAddr)
|
||||
return this.blockchain.rpc.getStakingValidator(validatorAddr)
|
||||
},
|
||||
async fetchValidatorDelegation(validatorAddr: string, delegatorAddr: string) {
|
||||
return (await this.blockchain.rpc.validatorDelegation(validatorAddr, delegatorAddr)).delegationResponse
|
||||
return await this.blockchain.rpc.getStakingValidatorsDelegationsDelegator(validatorAddr, delegatorAddr)
|
||||
},
|
||||
async fetchValidators(status: string) {
|
||||
return this.blockchain.rpc.validators(status, undefined).then(res => {
|
||||
const vals = res.validators.sort((a, b) => (Number(b.delegatorShares) - Number(a.delegatorShares)))
|
||||
return this.blockchain.rpc.getStakingValidators(status).then(res => {
|
||||
const vals = res.validators.sort((a, b) => (Number(b.delegator_shares) - Number(a.delegator_shares)))
|
||||
if(status==='BOND_STATUS_BONDED') {
|
||||
this.validators = vals
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user