Skip to content

Commit d16e840

Browse files
authored
Merge pull request #1903 from oasisprotocol/lw/pontusx-acc-get
Get pontusX account metadata by oasis address instead of hex address
2 parents d11c1be + 066521c commit d16e840

File tree

5 files changed

+15
-13
lines changed

5 files changed

+15
-13
lines changed

.changelog/1903.trivial.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Get pontusX account metadata by oasis address instead of hex address

src/app/data/named-accounts.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { Network } from '../../types/network'
2-
import { Account, Layer, Runtime, RuntimeAccount } from '../../oasis-nexus/api'
2+
import { Account, Address, Layer, Runtime, RuntimeAccount } from '../../oasis-nexus/api'
33

44
export type AccountMetadataSource = 'OasisRegistry' | 'DeltaDaoRegistry' | 'SelfProfessed'
55

66
export type AccountMetadata = {
7-
address: string
7+
address: Address
88
name?: string
99
description?: string
1010
source: AccountMetadataSource
@@ -16,7 +16,7 @@ export type AccountMetadataInfo = {
1616
isError: boolean
1717
}
1818

19-
export type AccountMap = Map<string, AccountMetadata>
19+
export type AccountMap = Map<Address, AccountMetadata>
2020

2121
export type AccountData = {
2222
map: AccountMap
@@ -26,19 +26,19 @@ export type AccountData = {
2626
export type AccountNameSearchMatch = {
2727
network: Network
2828
layer: Layer
29-
address: string
29+
address: Address
3030
}
3131

3232
export type AccountNameSearchRuntimeMatch = {
3333
network: Network
3434
layer: Runtime
35-
address: string
35+
address: Address
3636
}
3737

3838
export type AccountNameSearchConsensusMatch = {
3939
network: Network
4040
layer: typeof Layer.consensus
41-
address: string
41+
address: Address
4242
}
4343

4444
export type AccountNameSearchResults = {

src/app/data/oasis-account-names.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
} from './named-accounts'
1919
import { hasTextMatch } from '../components/HighlightedText/text-matching'
2020
import * as externalLinks from '../utils/externalLinks'
21+
import { getOasisAddress } from '../utils/helpers'
2122

2223
const dataSources: Record<Network, Partial<Record<Layer, string>>> = {
2324
[Network.mainnet]: {
@@ -51,7 +52,7 @@ const getOasisAccountsMetadata = async (network: Network, layer: Layer): Promise
5152
Array.from(response.data).forEach((entry: any) => {
5253
const metadata: AccountMetadata = {
5354
source: 'OasisRegistry',
54-
address: entry.Address,
55+
address: getOasisAddress(entry.Address),
5556
name: entry.Name,
5657
description: entry.Description,
5758
}
@@ -79,15 +80,15 @@ const useOasisAccountsMetadata = (
7980
export const useOasisAccountMetadata = (
8081
network: Network,
8182
layer: Layer,
82-
address: string,
83+
oasisAddress: string,
8384
queryOptions: UseQueryOptions<AccountData, unknown, AccountData, string[]>,
8485
): AccountMetadataInfo => {
8586
const { isLoading, isError, error, data: allData } = useOasisAccountsMetadata(network, layer, queryOptions)
8687
if (isError) {
8788
console.log('Failed to load Oasis account metadata', error)
8889
}
8990
return {
90-
metadata: allData?.map.get(address),
91+
metadata: allData?.map.get(oasisAddress),
9192
isLoading,
9293
isError,
9394
}

src/app/data/pontusx-account-names.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const getPontusXAccountsMetadata = async (): Promise<PontusXAccountsMetadata> =>
3030
address: getOasisAddress(evmAddress),
3131
name: name as string,
3232
}
33-
map.set(evmAddress.toLowerCase(), account)
33+
map.set(account.address, account)
3434
list.push(account)
3535
})
3636
return {
@@ -49,15 +49,15 @@ export const usePontusXAccountsMetadata = (
4949
}
5050

5151
export const usePontusXAccountMetadata = (
52-
address: string,
52+
oasisAddress: string,
5353
queryOptions: UseQueryOptions<PontusXAccountsMetadata, unknown, PontusXAccountsMetadata, string[]>,
5454
): AccountMetadataInfo => {
5555
const { isLoading, isError, error, data: allData } = usePontusXAccountsMetadata(queryOptions)
5656
if (isError) {
5757
console.log('Failed to load Pontus-X account names', error)
5858
}
5959
return {
60-
metadata: allData?.map.get(address.toLowerCase()),
60+
metadata: allData?.map.get(oasisAddress),
6161
isLoading,
6262
isError,
6363
}

src/app/hooks/useAccountMetadata.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { useTokenInfo } from '../pages/TokenDashboardPage/hook'
1818
export const useAccountMetadata = (scope: SearchScope, address: string): AccountMetadataInfo => {
1919
// Look up metadata specified by us
2020
const isPontusX = scope.layer === Layer.pontusxtest || scope.layer === Layer.pontusxdev
21-
const pontusXData = usePontusXAccountMetadata(address, {
21+
const pontusXData = usePontusXAccountMetadata(getOasisAddress(address), {
2222
enabled: isPontusX,
2323
useErrorBoundary: false,
2424
})

0 commit comments

Comments
 (0)