fix staking for nomic
This commit is contained in:
parent
07d9e8e826
commit
ebf30b670c
@ -1,13 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
useBlockchain,
|
||||
useFormatter,
|
||||
useMintStore,
|
||||
useStakingStore,
|
||||
useTxDialog,
|
||||
} from '@/stores';
|
||||
import { onMounted, computed, ref } from 'vue';
|
||||
import { Icon } from '@iconify/vue';
|
||||
import { decodeProto } from '@/components/dynamic';
|
||||
import PaginationBar from '@/components/PaginationBar.vue';
|
||||
import CommissionRate from '@/components/ValidatorCommissionRate.vue';
|
||||
import {
|
||||
consensusPubkeyToHexAddress,
|
||||
@ -15,27 +8,26 @@ import {
|
||||
pubKeyToValcons,
|
||||
valoperToPrefix,
|
||||
} from '@/libs';
|
||||
import type { ExtraTxResponse, ExtraTxSearchResponse } from '@/libs/client';
|
||||
import { stringToUint8Array } from '@/libs/utils';
|
||||
import {
|
||||
PageRequest,
|
||||
type Coin,
|
||||
type Delegation,
|
||||
type PaginatedDelegations,
|
||||
type PaginatedTxs,
|
||||
} from '@/types';
|
||||
import PaginationBar from '@/components/PaginationBar.vue';
|
||||
import { fromAscii, fromBase64, toHex, toBase64 } from '@cosmjs/encoding';
|
||||
import { stringToUint8Array, uint8ArrayToString } from '@/libs/utils';
|
||||
import type { TxSearchResponse } from '@cosmjs/tendermint-rpc';
|
||||
import { fromTimestamp } from 'cosmjs-types/helpers';
|
||||
useBlockchain,
|
||||
useFormatter,
|
||||
useMintStore,
|
||||
useStakingStore,
|
||||
useTxDialog,
|
||||
} from '@/stores';
|
||||
import { PageRequest, type Coin } from '@/types';
|
||||
import { fromAscii, toBase64, toHex } from '@cosmjs/encoding';
|
||||
import type { Event } from '@cosmjs/tendermint-rpc';
|
||||
import { Icon } from '@iconify/vue';
|
||||
import type { QueryValidatorDelegationsResponse } from 'cosmjs-types/cosmos/staking/v1beta1/query';
|
||||
import type {
|
||||
DelegationResponse,
|
||||
Validator,
|
||||
} from 'cosmjs-types/cosmos/staking/v1beta1/staking';
|
||||
import type { QueryValidatorDelegationsResponse } from 'cosmjs-types/cosmos/staking/v1beta1/query';
|
||||
import type { ExtraTxResponse, ExtraTxSearchResponse } from '@/libs/client';
|
||||
import type { Event } from '@cosmjs/tendermint-rpc';
|
||||
import type { Any } from 'cosmjs-types/google/protobuf/any';
|
||||
import { decodeProto } from '@/components/dynamic';
|
||||
import { fromTimestamp } from 'cosmjs-types/helpers';
|
||||
import { computed, onMounted, ref } from 'vue';
|
||||
|
||||
const props = defineProps(['validator', 'chain']);
|
||||
|
||||
|
||||
@ -79,7 +79,6 @@ async function fetchChange() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const changes = computed(() => {
|
||||
const changes = {} as Record<string, number>;
|
||||
Object.keys(latest.value).forEach((k) => {
|
||||
@ -104,13 +103,18 @@ const decodeKey = (value: Any): Key => {
|
||||
'@type': value.typeUrl,
|
||||
key: '',
|
||||
};
|
||||
switch (value.typeUrl) {
|
||||
case '/cosmos.crypto.ed25519.PubKey':
|
||||
key.key = toBase64(Ed25519PubKey.decode(value.value).key);
|
||||
break;
|
||||
default:
|
||||
key.key = toBase64(Secp256k1PubKey.decode(value.value).key);
|
||||
break;
|
||||
try {
|
||||
switch (value.typeUrl) {
|
||||
case '/cosmos.crypto.ed25519.PubKey':
|
||||
key.key = toBase64(Ed25519PubKey.decode(value.value).key);
|
||||
break;
|
||||
default:
|
||||
key.key = toBase64(Secp256k1PubKey.decode(value.value).key);
|
||||
break;
|
||||
}
|
||||
} catch {
|
||||
// already decoded
|
||||
key.key = toBase64(value.value);
|
||||
}
|
||||
return key;
|
||||
};
|
||||
@ -248,12 +252,12 @@ const logo = (identity?: string) => {
|
||||
: `https://s3.amazonaws.com/keybase_processed_uploads/${url}`;
|
||||
};
|
||||
|
||||
let height_in_24h = ref(0)
|
||||
let height_in_24h = ref(0);
|
||||
base.$subscribe((_, s) => {
|
||||
if (Number(s.earlest.block.header.height) !== height_in_24h.value) {
|
||||
height_in_24h.value = Number(s.earlest.block.header.height);
|
||||
fetchChange();
|
||||
}
|
||||
if (Number(s.earlest.block.header.height) !== height_in_24h.value) {
|
||||
height_in_24h.value = Number(s.earlest.block.header.height);
|
||||
fetchChange();
|
||||
}
|
||||
});
|
||||
|
||||
loadAvatars();
|
||||
|
||||
@ -19,10 +19,11 @@ import {
|
||||
import { useBaseStore } from './useBaseStore';
|
||||
import type { BondStatusString } from '@cosmjs/stargate/build/modules/staking/queries';
|
||||
import type { Duration } from 'cosmjs-types/google/protobuf/duration';
|
||||
import type {
|
||||
Pool,
|
||||
Validator,
|
||||
Params,
|
||||
import {
|
||||
type Pool,
|
||||
type Validator,
|
||||
type Params,
|
||||
bondStatusToJSON,
|
||||
} from 'cosmjs-types/cosmos/staking/v1beta1/staking';
|
||||
import type { Any } from 'cosmjs-types/google/protobuf/any';
|
||||
import type { JsonObject } from '@cosmjs/cosmwasm-stargate';
|
||||
@ -159,34 +160,26 @@ export const useStakingStore = defineStore('stakingStore', {
|
||||
}
|
||||
},
|
||||
async fetchValidators(status: BondStatusString) {
|
||||
let client;
|
||||
if (this.blockchain.isConsumerChain) {
|
||||
if (
|
||||
this.blockchain.current?.providerChain.api &&
|
||||
this.blockchain.current.providerChain.api.length > 0
|
||||
) {
|
||||
const client = CosmosRestClient.newDefault(
|
||||
client = CosmosRestClient.newDefault(
|
||||
this.blockchain.current.providerChain.api[0].address
|
||||
);
|
||||
// provider validators
|
||||
const validatorsRes = await client.getStakingValidators(status);
|
||||
if (!validatorsRes) return [];
|
||||
const proVals = validatorsRes.validators.sort(
|
||||
(a, b) => Number(b.delegatorShares) - Number(a.delegatorShares)
|
||||
);
|
||||
if (status === 'BOND_STATUS_BONDED') {
|
||||
this.validators = proVals;
|
||||
}
|
||||
|
||||
return proVals;
|
||||
}
|
||||
} else {
|
||||
client = this.blockchain.rpc;
|
||||
}
|
||||
const validatorsRes = await this.blockchain.rpc?.getStakingValidators(
|
||||
status
|
||||
);
|
||||
|
||||
// provider validators
|
||||
const validatorsRes = await client?.getStakingValidators(status);
|
||||
if (!validatorsRes) return [];
|
||||
const vals = validatorsRes.validators.sort(
|
||||
(a, b) => Number(b.delegatorShares) - Number(a.delegatorShares)
|
||||
);
|
||||
const vals = validatorsRes.validators
|
||||
.filter((v) => bondStatusToJSON(v.status) === status)
|
||||
.sort((a, b) => Number(b.delegatorShares) - Number(a.delegatorShares));
|
||||
if (status === 'BOND_STATUS_BONDED') {
|
||||
this.validators = vals;
|
||||
}
|
||||
|
||||
@ -51,4 +51,8 @@ html[data-theme='dark'] {
|
||||
.slide-up-leave-to {
|
||||
opacity: 0;
|
||||
transform: translateY(-calc(15%));
|
||||
}
|
||||
|
||||
.table :where(th, td) {
|
||||
word-break: break-word;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user