forked from cerc-io/cosmos-explorer
fix rewards amount
This commit is contained in:
parent
c37c4cbc8d
commit
2885415630
@ -73,7 +73,13 @@ export interface RequestRegistry extends AbstractRegistry {
|
||||
}>;
|
||||
distribution_validator_slashes: Request<PaginatedSlashes>;
|
||||
distribution_community_pool: Request<{ pool: Coin[] }>;
|
||||
distribution_delegator_rewards: Request<any>;
|
||||
distribution_delegator_rewards: Request<{
|
||||
rewards: {
|
||||
validator_address: string,
|
||||
reward: Coin[]
|
||||
}[],
|
||||
total: Coin[]
|
||||
}>;
|
||||
|
||||
mint_inflation: Request<{ inflation: string }>;
|
||||
mint_params: Request<{
|
||||
|
@ -1,10 +1,17 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import { useBlockchain } from './useBlockchain';
|
||||
import { fromBech32, toBech32 } from '@cosmjs/encoding';
|
||||
import type { Delegation, Coin, UnbondingResponses, DelegatorRewards } from '@/types';
|
||||
import { useStakingStore } from './useStakingStore';
|
||||
|
||||
export const useWalletStore = defineStore('walletStore', {
|
||||
state: () => {
|
||||
return {};
|
||||
return {
|
||||
balances: [] as Coin[],
|
||||
delegations: [] as Delegation[],
|
||||
unbonding: [] as UnbondingResponses[],
|
||||
rewards: {} as DelegatorRewards,
|
||||
};
|
||||
},
|
||||
getters: {
|
||||
blockchain() {
|
||||
@ -17,13 +24,63 @@ export const useWalletStore = defineStore('walletStore', {
|
||||
const connected = JSON.parse(localStorage.getItem(key)||"{}")
|
||||
return connected
|
||||
},
|
||||
balanceOfStakingToken(): Coin {
|
||||
const stakingStore = useStakingStore()
|
||||
return this.balances.find( x => x.denom === stakingStore.params.bond_denom) || {amount: "0", denom: stakingStore.params.bond_denom}
|
||||
},
|
||||
stakingAmount() {
|
||||
let amt = 0
|
||||
let denom = ''
|
||||
this.delegations.forEach((i) => {
|
||||
amt += Number(i.balance.amount)
|
||||
denom = i.balance.denom
|
||||
})
|
||||
return {amount: String(amt), denom}
|
||||
},
|
||||
rewardAmount() {
|
||||
|
||||
const stakingStore = useStakingStore()
|
||||
const reward = this.rewards.total?.find(x => x.denom === stakingStore.params.bond_denom)
|
||||
return reward || {amount: "0", denom: stakingStore.params.bond_denom}
|
||||
},
|
||||
unbondingAmount() {
|
||||
let amt = 0
|
||||
let denom = ''
|
||||
this.unbonding.forEach((i) => {
|
||||
i.entries.forEach(e => {
|
||||
amt += Number(e.balance)
|
||||
})
|
||||
})
|
||||
|
||||
const stakingStore = useStakingStore()
|
||||
return {amount: String(amt), denom: stakingStore.params.bond_denom}
|
||||
},
|
||||
currentAddress() {
|
||||
const {prefix, data} = fromBech32(this.connectedWallet.cosmosAddress);
|
||||
const chainStore = useBlockchain()
|
||||
return toBech32(chainStore.current?.bech32Prefix || prefix, data)
|
||||
if(this.connectedWallet.cosmosAddress) {
|
||||
const {prefix, data} = fromBech32(this.connectedWallet.cosmosAddress);
|
||||
const chainStore = useBlockchain()
|
||||
return toBech32(chainStore.current?.bech32Prefix || prefix, data)
|
||||
} else {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
async loadMyAsset() {
|
||||
if(!this.currentAddress) return
|
||||
this.blockchain.rpc.getBankBalances(this.currentAddress).then(x => {
|
||||
this.balances = x.balances
|
||||
})
|
||||
this.blockchain.rpc.getStakingDelegations(this.currentAddress).then(x => {
|
||||
this.delegations = x.delegation_responses
|
||||
})
|
||||
this.blockchain.rpc.getStakingDelegatorUnbonding(this.currentAddress).then(x => {
|
||||
this.unbonding = x.unbonding_responses
|
||||
})
|
||||
this.blockchain.rpc.getDistributionDelegatorRewards(this.currentAddress).then(x => {
|
||||
this.rewards = x
|
||||
})
|
||||
},
|
||||
myBalance() {
|
||||
return this.blockchain.rpc.getBankBalances(this.currentAddress)
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user