From ccf519154edac843b5a396be2aa4abc822807651 Mon Sep 17 00:00:00 2001 From: liangping <18786721@qq.com> Date: Fri, 6 May 2022 15:27:33 +0800 Subject: [PATCH] show eth address on evm chains --- src/libs/utils.js | 8 ++++++-- src/views/WalletAccountDetail.vue | 9 ++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/libs/utils.js b/src/libs/utils.js index 3c852d09..84f085df 100644 --- a/src/libs/utils.js +++ b/src/libs/utils.js @@ -1,5 +1,5 @@ import { - Bech32, fromBase64, fromHex, toHex, + Bech32, fromBase64, fromBech32, fromHex, toHex, } from '@cosmjs/encoding' import { sha256, stringToPath } from '@cosmjs/crypto' // ledger @@ -169,12 +169,16 @@ export function consensusPubkeyToHexAddress(consensusPubkey) { } raw = sha256(fromBase64(consensusPubkey.value)) } else { - raw = sha256(fromHex(toHex(Bech32.decode(consensusPubkey).data).toUpperCase().replace('1624DE6420', ''))) + raw = sha256(fromHex(toHex(fromBech32(consensusPubkey).data).toUpperCase().replace('1624DE6420', ''))) } const address = toHex(raw).slice(0, 40).toUpperCase() return address } +export function toETHAddress(cosmosAddress) { + return `0x${toHex(fromBech32(cosmosAddress).data)}` +} + function toSignAddress(addr) { const { data } = addressDecode(addr) return addressEnCode('cosmos', data) diff --git a/src/views/WalletAccountDetail.vue b/src/views/WalletAccountDetail.vue index a2f75398..0242a0a4 100644 --- a/src/views/WalletAccountDetail.vue +++ b/src/views/WalletAccountDetail.vue @@ -30,6 +30,7 @@ /> {{ address }} + - {{ ethaddress() }} @@ -426,7 +427,7 @@ import VueQr from 'vue-qr' import chainAPI from '@/libs/fetch' import { formatToken, formatTokenAmount, formatTokenDenom, getStakingValidatorOperator, percent, tokenFormatter, toDay, - toDuration, abbrMessage, abbrAddress, getUserCurrency, getUserCurrencySign, numberWithCommas, + toDuration, abbrMessage, abbrAddress, getUserCurrency, getUserCurrencySign, numberWithCommas, toETHAddress, } from '@/libs/utils' import OperationModal from '@/views/components/OperationModal/index.vue' import ObjectFieldComponent from './ObjectFieldComponent.vue' @@ -627,6 +628,9 @@ export default { denoms() { return this.$store.state.chains.denoms }, + isEthAddr() { + return JSON.stringify(this.account).indexOf('PubKeyEthSecp256k1') > 0 + }, }, created() { this.$http.getAuthAccount(this.address).then(acc => { @@ -730,6 +734,9 @@ export default { }) }) }, + ethaddress() { + return toETHAddress(this.address) + }, }, }