Skip to content

Commit

Permalink
Merge branch 'master' into feat-support-solo
Browse files Browse the repository at this point in the history
  • Loading branch information
akanoce committed Mar 12, 2024
2 parents fbe8341 + 750d2af commit 8af1433
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 4 deletions.
47 changes: 44 additions & 3 deletions src/components/AccountLink.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
>
<template v-if="abbr">{{ address | abbr }}</template>
<template v-else>{{ address | checksum }}</template>
<template v-if="vetName"> ({{ vetName }})</template>
</span>
<router-link
class="text-monospace text-truncate"
v-else
:to="{ name: 'account', params: { address: address, net: $net } }"
>
<template v-if="abbr">{{ address | abbr }}</template>
<template v-else>{{ address | checksum }}</template>
<template v-if="abbr">{{ (vetName || address) | abbr }}</template>
<template v-else>{{ (vetName || address | checksum) }}</template>
</router-link>
</div>
<span
Expand All @@ -33,6 +34,7 @@
<script lang="ts">
import Vue from "vue"
import { address } from "thor-devkit"
import { genesisIdToNetwork } from '../utils'
export default Vue.extend({
props: {
Expand All @@ -41,10 +43,49 @@ export default Vue.extend({
icon: Boolean,
noLink: Boolean
},
asyncComputed: {
async vetName(): Promise<string | null> {
if (genesisIdToNetwork(this.$connex.thor.genesis.id) !== 'main') {
return null
}
try {
const { decoded: { names } } = await this.$connex.thor
.account(vetResolverUtilsAddress)
.method(getNamesJsonAbi)
.call([this.address])
return names[0] || null
} catch {
return null
}
}
},
computed: {
isValid(): boolean {
return address.test(this.address);
}
}
})
</script>
const vetResolverUtilsAddress = '0xA11413086e163e41901bb81fdc5617c975Fa5a1A'
const getNamesJsonAbi = {
"inputs": [
{
"internalType": "address[]",
"name": "addresses",
"type": "address[]"
}
],
"name": "getNames",
"outputs": [
{
"internalType": "string[]",
"name": "names",
"type": "string[]"
}
],
"stateMutability": "view",
"type": "function"
}
</script>
39 changes: 38 additions & 1 deletion src/views/Search.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
</template>
<script lang="ts">
import Vue from 'vue'
import { genesisIdToNetwork } from '../utils'
export default Vue.extend({
data: () => {
Expand Down Expand Up @@ -66,6 +67,21 @@ export default Vue.extend({
this.error = err as Error
}
}
} 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')
}
return this.$router.replace({ name: 'account', params: { address: addresses[0] } })
} catch (err) {
this.error = new Error('Name not found')
}
}
if (!this.error) {
this.error = new Error(`No result for '${str}'`)
Expand All @@ -76,5 +92,26 @@ export default Vue.extend({
this.reload()
}
})
</script>
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"
}
</script>

0 comments on commit 8af1433

Please sign in to comment.