checking pubkey lack prefix
This commit is contained in:
parent
084e0d65db
commit
3bb6a57640
@ -15,7 +15,11 @@ function calculateValue(value: any) {
|
||||
if (!value) return;
|
||||
|
||||
if (value instanceof Uint8Array) {
|
||||
return formatter.formatDecimalToPercent(fromAscii(value), 1e18);
|
||||
try {
|
||||
return formatter.formatDecimalToPercent(fromAscii(value), 1e18);
|
||||
} catch {
|
||||
return '-';
|
||||
}
|
||||
}
|
||||
|
||||
if (Array.isArray(value)) {
|
||||
|
||||
@ -61,7 +61,12 @@ export const decodeKey = (value: Any): Key => {
|
||||
export function consensusPubkeyToKey(consensusPubkey?: Any) {
|
||||
if (!consensusPubkey) return;
|
||||
if (consensusPubkey.typeUrl === '/cosmos.crypto.ed25519.PubKey') {
|
||||
return Ed25519PubKey.decode(consensusPubkey.value).key;
|
||||
const value =
|
||||
// fix trim 0a20 at beginning of buffer
|
||||
consensusPubkey.value.length === 32
|
||||
? new Uint8Array([10, 32, ...consensusPubkey.value])
|
||||
: consensusPubkey.value;
|
||||
return Ed25519PubKey.decode(value).key;
|
||||
}
|
||||
if (consensusPubkey.typeUrl === '/cosmos.crypto.secp256k1.PubKey') {
|
||||
return Secp256k1PubKey.decode(consensusPubkey.value).key;
|
||||
@ -69,6 +74,7 @@ export function consensusPubkeyToKey(consensusPubkey?: Any) {
|
||||
}
|
||||
|
||||
export function consensusPubkeyToHexAddress(consensusPubkey?: Any) {
|
||||
console.log('consensusPubkey', consensusPubkey);
|
||||
const pubkey = consensusPubkeyToKey(consensusPubkey);
|
||||
if (!pubkey) return '';
|
||||
if (consensusPubkey?.typeUrl === '/cosmos.crypto.ed25519.PubKey') {
|
||||
|
||||
@ -292,12 +292,7 @@ loadAvatars();
|
||||
</span>
|
||||
<span>
|
||||
<div class="font-bold">
|
||||
{{
|
||||
format.percent(
|
||||
slashing.slashFractionDoubleSign &&
|
||||
fromAscii(slashing.slashFractionDoubleSign)
|
||||
)
|
||||
}}
|
||||
{{ format.percent(slashing.slashFractionDoubleSign) }}
|
||||
</div>
|
||||
<div class="text-xs">{{ $t('staking.double_sign_slashing') }}</div>
|
||||
</span>
|
||||
@ -315,12 +310,7 @@ loadAvatars();
|
||||
</span>
|
||||
<span>
|
||||
<div class="font-bold">
|
||||
{{
|
||||
format.percent(
|
||||
slashing.slashFractionDowntime &&
|
||||
fromAscii(slashing.slashFractionDowntime)
|
||||
)
|
||||
}}
|
||||
{{ format.percent(slashing.slashFractionDowntime) }}
|
||||
</div>
|
||||
<div class="text-xs">{{ $t('staking.downtime_slashing') }}</div>
|
||||
</span>
|
||||
|
||||
@ -313,10 +313,7 @@ function fetchAllKeyRotation() {
|
||||
:data-tip="`Window size: ${slashingParam.signedBlocksWindow}`"
|
||||
><span class="ml-2 btn btn-error btn-xs">{{
|
||||
slashingParam.minSignedPerWindow &&
|
||||
format.percent(
|
||||
fromAscii(slashingParam.minSignedPerWindow),
|
||||
1e18
|
||||
)
|
||||
format.percent(slashingParam.minSignedPerWindow, 1e18)
|
||||
}}</span>
|
||||
</span>
|
||||
</td>
|
||||
|
||||
@ -8,7 +8,13 @@ import updateLocale from 'dayjs/plugin/updateLocale';
|
||||
import utc from 'dayjs/plugin/utc';
|
||||
import localeData from 'dayjs/plugin/localeData';
|
||||
import { useStakingStore } from './useStakingStore';
|
||||
import { fromBase64, fromBech32, fromHex, toHex } from '@cosmjs/encoding';
|
||||
import {
|
||||
fromAscii,
|
||||
fromBase64,
|
||||
fromBech32,
|
||||
fromHex,
|
||||
toHex,
|
||||
} from '@cosmjs/encoding';
|
||||
import { consensusPubkeyToHexAddress, get } from '@/libs';
|
||||
import { useBankStore } from './useBankStore';
|
||||
// import type { Coin, DenomTrace } from '@/types';
|
||||
@ -347,9 +353,19 @@ export const useFormatter = defineStore('formatter', {
|
||||
if (!rate) return '-';
|
||||
return this.percent(rate, divideDecimal);
|
||||
},
|
||||
percent(decimal?: string | number, divideDecimal?: number) {
|
||||
let decimalFormat = numeral(decimal);
|
||||
if (!decimalFormat) return '-';
|
||||
percent(decimal?: string | number | Uint8Array, divideDecimal?: number) {
|
||||
if (!decimal) return '-';
|
||||
let decimalFormat;
|
||||
if (decimal instanceof Uint8Array) {
|
||||
try {
|
||||
decimalFormat = numeral(fromAscii(decimal));
|
||||
} catch {
|
||||
return '-';
|
||||
}
|
||||
} else {
|
||||
decimalFormat = numeral(decimal);
|
||||
}
|
||||
if (!decimalFormat || !decimalFormat.value()) return '-';
|
||||
if (divideDecimal) {
|
||||
decimalFormat = decimalFormat.divide(divideDecimal);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user