diff --git a/src/components/AccountLink.vue b/src/components/AccountLink.vue index ce4fa4d..8035dc7 100644 --- a/src/components/AccountLink.vue +++ b/src/components/AccountLink.vue @@ -13,9 +13,11 @@ v-if="noLink" class="text-monospace text-truncate" > - - + + + + {{ resolvedName }} { try { @@ -33,4 +52,19 @@ export const resolveDomainName = async (address: string, connex: Connex) => { } catch { return null } -} \ No newline at end of file +} + +export const resolveAddressByName = async (name: string, connex: Connex) => { + try { + const { decoded: { addresses } } = await connex.thor + .account(vet_domainResolver) + .method(getAddressesJsonAbi) + .cache([vet_domainResolver]) + .call([name]) + + return addresses[0] || null + } catch { + return null + } +} + diff --git a/src/views/Account.vue b/src/views/Account.vue index 8077676..2e29135 100644 --- a/src/views/Account.vue +++ b/src/views/Account.vue @@ -4,24 +4,16 @@ Account
-
- -
-
- {{ address|checksum }} - -
- {{ resolvedName }} -
-
- + +
import Vue from 'vue' import { genesisIdToNetwork } from '../utils' +import { resolveAddressByName } from '@/resolver' export default Vue.extend({ data: () => { @@ -68,20 +69,12 @@ export default Vue.extend({ } } } else if (/\./.test(str) && genesisIdToNetwork(this.$connex.thor.genesis.id) === 'main') { - try { - const { decoded: { addresses } } = await this.$connex.thor - .account(vetResolverUtilsAddress) - .method(getAddressesJsonAbi) - .call([str]) - - if (!addresses[0] || addresses[0] === '0x0000000000000000000000000000000000000000') { - throw new Error('Name not found') - } + const address = await resolveAddressByName(str, this.$connex) - return this.$router.replace({ name: 'account', params: { address: addresses[0] } }) - } catch (err) { - this.error = new Error('Name not found') + if (address && address !== '0x0000000000000000000000000000000000000000') { + return this.$router.replace({ name: 'account', params: { address: address } }) } + this.error = new Error('Name not found') } if (!this.error) { this.error = new Error(`No result for '${str}'`) @@ -93,25 +86,4 @@ export default Vue.extend({ } }) -const vetResolverUtilsAddress = '0xA11413086e163e41901bb81fdc5617c975Fa5a1A' -const getAddressesJsonAbi = { - "inputs": [ - { - "internalType": "string[]", - "name": "names", - "type": "string[]" - } - ], - "name": "getAddresses", - "outputs": [ - { - "internalType": "address[]", - "name": "addresses", - "type": "address[]" - } - ], - "stateMutability": "view", - "type": "function" -} - \ No newline at end of file