Skip to content

Commit

Permalink
Also search for Pontus-X names on Sapphire
Browse files Browse the repository at this point in the history
  • Loading branch information
csillag committed Jan 22, 2025
1 parent 4f678a9 commit ba68600
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/app/data/pontusx-account-names.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ type PontusXAccountsMetadata = {
list: AccountMetadata[]
}

export const pontusXLayers: Layer[] = [Layer.pontusxtest, Layer.pontusxdev, Layer.sapphire]

const getPontusXAccountsMetadata = async (): Promise<PontusXAccountsMetadata> => {
const response = await axios.get(DATA_SOURCE_URL)
if (response.status !== 200) throw new Error("Couldn't load names")
Expand Down
15 changes: 10 additions & 5 deletions src/app/hooks/useAccountMetadata.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { SearchScope } from '../../types/searchScope'
import { Layer } from '../../oasis-nexus/api'
import { usePontusXAccountMetadata, useSearchForPontusXAccountsByName } from '../data/pontusx-account-names'
import {
pontusXLayers,
usePontusXAccountMetadata,
useSearchForPontusXAccountsByName,
} from '../data/pontusx-account-names'
import { AccountMetadataInfo, AccountNameSearchResults } from '../data/named-accounts'
import { useOasisAccountMetadata, useSearchForOasisAccountsByName } from '../data/oasis-account-names'
import { getOasisAddress } from '../utils/helpers'
Expand All @@ -15,7 +19,7 @@ import { isLocalnet } from '../utils/route-utils'
* Doesn't throw if it fails.
*/
export const useAccountMetadata = (scope: SearchScope, address: string): AccountMetadataInfo => {
const isPontusX = scope.layer === Layer.pontusxtest || scope.layer === Layer.pontusxdev
const isPontusX = pontusXLayers.includes(scope.layer)
const pontusXData = usePontusXAccountMetadata(address, {
enabled: isPontusX,
useErrorBoundary: false,
Expand All @@ -24,21 +28,22 @@ export const useAccountMetadata = (scope: SearchScope, address: string): Account
enabled: !isPontusX && !isLocalnet(scope.network),
useErrorBoundary: false,
})
return isPontusX ? pontusXData : oasisData
return isPontusX ? (pontusXData?.metadata ? pontusXData : oasisData) : oasisData
}

/** Doesn't throw if it fails. */
export const useSearchForAccountsByName = (
scope: SearchScope,
nameFragment = '',
): AccountNameSearchResults => {
const isPontusX = scope.layer === Layer.pontusxtest || scope.layer === Layer.pontusxdev
const isPontusX = pontusXLayers.includes(scope.layer)
const isValidPontusXSearch = isPontusX && !!nameFragment
const pontusXResults = useSearchForPontusXAccountsByName(scope.network, nameFragment, {
enabled: isValidPontusXSearch,
useErrorBoundary: false,
})
const isValidOasisSearch = !isPontusX && !!nameFragment
const isValidOasisSearch =
!(scope.layer === Layer.pontusxdev || scope.layer === Layer.pontusxtest) && !!nameFragment
const oasisResults = useSearchForOasisAccountsByName(scope.network, scope.layer, nameFragment, {
enabled: isValidOasisSearch,
useErrorBoundary: false,
Expand Down

0 comments on commit ba68600

Please sign in to comment.