Skip to content

Commit

Permalink
use eth address to fetch tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
buberdds committed Oct 11, 2024
1 parent f1f6e8d commit f89a7a4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 66 deletions.
79 changes: 17 additions & 62 deletions src/app/pages/TokenDashboardPage/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@ import { SearchScope } from '../../../types/searchScope'
import { useSearchParamsPagination } from '../../components/Table/useSearchParamsPagination'
import { NUMBER_OF_ITEMS_ON_SEPARATE_PAGE } from '../../config'
import { useComprehensiveSearchParamsPagination } from '../../components/Table/useComprehensiveSearchParamsPagination'
import { getOasisAddressOrNull } from '../../utils/helpers'

export const useTokenInfo = (scope: SearchScope, address: string, enabled = true) => {
const { network, layer } = scope
if (layer === Layer.consensus) {
// There can be no ERC-20 or ERC-721 tokens on consensus
throw AppErrors.UnsupportedLayer
}
const query = useGetRuntimeEvmTokensAddress(network, layer, address!, {
const query = useGetRuntimeEvmTokensAddress(network, layer, address, {
query: { enabled },
})
const token = query.data?.data
Expand All @@ -38,19 +37,14 @@ export const useTokenInfo = (scope: SearchScope, address: string, enabled = true
}

export const useTokenTransfers = (scope: SearchScope, params: { address: string }) => {
const oasisAddress = getOasisAddressOrNull(params.address)
return _useTokenTransfers(scope, oasisAddress ? { rel: oasisAddress } : undefined)
return _useTokenTransfers(scope, { rel: params.address })
}

export const useNFTInstanceTransfers = (
scope: SearchScope,
params: { nft_id: string; contract_address: string },
) => {
const oasisAddress = getOasisAddressOrNull(params.contract_address)
return _useTokenTransfers(
scope,
oasisAddress ? { nft_id: params.nft_id, contract_address: oasisAddress } : undefined,
)
return _useTokenTransfers(scope, { nft_id: params.nft_id, contract_address: params.contract_address })
}

export const _useTokenTransfers = (scope: SearchScope, params: undefined | GetRuntimeEventsParams) => {
Expand Down Expand Up @@ -109,21 +103,10 @@ export const useTokenHolders = (scope: SearchScope, address: string) => {
// There are no token holders on the consensus layer.
}

const oasisAddress = getOasisAddressOrNull(address)
const query = useGetRuntimeEvmTokensAddressHolders(
network,
layer,
oasisAddress!,
{
limit: NUMBER_OF_ITEMS_ON_SEPARATE_PAGE,
offset: offset,
},
{
query: {
enabled: !!oasisAddress,
},
},
)
const query = useGetRuntimeEvmTokensAddressHolders(network, layer, address, {
limit: NUMBER_OF_ITEMS_ON_SEPARATE_PAGE,
offset: offset,
})

const { isFetched, isLoading, data } = query

Expand Down Expand Up @@ -157,21 +140,10 @@ export const useTokenInventory = (scope: SearchScope, address: string) => {
throw AppErrors.UnsupportedLayer
// There are no tokens on the consensus layer.
}
const oasisAddress = getOasisAddressOrNull(address)
const query = useGetRuntimeEvmTokensAddressNfts(
network,
layer,
oasisAddress!,
{
limit: NUMBER_OF_INVENTORY_ITEMS,
offset: offset,
},
{
query: {
enabled: !!oasisAddress,
},
},
)
const query = useGetRuntimeEvmTokensAddressNfts(network, layer, address, {
limit: NUMBER_OF_INVENTORY_ITEMS,
offset: offset,
})
const { isFetched, isLoading, data } = query
const inventory = data?.data.evm_nfts

Expand Down Expand Up @@ -204,23 +176,11 @@ export const useAccountTokenInventory = (scope: SearchScope, address: string, to
// There are no tokens on the consensus layer.
}

const oasisAddress = getOasisAddressOrNull(address)
const oasisTokenAddress = getOasisAddressOrNull(tokenAddress)
const query = useGetRuntimeAccountsAddressNfts(
network,
layer,
oasisAddress!,
{
limit: NUMBER_OF_INVENTORY_ITEMS,
offset: offset,
token_address: oasisTokenAddress!,
},
{
query: {
enabled: !!oasisAddress && !!oasisTokenAddress,
},
},
)
const query = useGetRuntimeAccountsAddressNfts(network, layer, address, {
limit: NUMBER_OF_INVENTORY_ITEMS,
offset: offset,
token_address: tokenAddress,
})
const { isFetched, isLoading, data } = query
const inventory = data?.data.evm_nfts

Expand Down Expand Up @@ -250,12 +210,7 @@ export const useNFTInstance = (scope: SearchScope, address: string, id: string)
throw AppErrors.UnsupportedLayer
// There are no tokens on the consensus layer.
}
const oasisAddress = getOasisAddressOrNull(address)
const query = useGetRuntimeEvmTokensAddressNftsId(network, layer, oasisAddress!, id, {
query: {
enabled: !!oasisAddress,
},
})
const query = useGetRuntimeEvmTokensAddressNftsId(network, layer, address, id)

const { data, isError, isFetched, isLoading } = query
if (isError) {
Expand Down
6 changes: 2 additions & 4 deletions src/oasis-nexus/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -807,13 +807,11 @@ export const useGetRuntimeEvmTokensAddress: typeof generated.useGetRuntimeEvmTok
address,
options,
) => {
const oasisAddress = getOasisAddressOrNull(address)

return generated.useGetRuntimeEvmTokensAddress(network, runtime, oasisAddress!, {
return generated.useGetRuntimeEvmTokensAddress(network, runtime, address, {
...options,
query: {
...(options?.query ?? {}),
enabled: !!oasisAddress && (options?.query?.enabled ?? true),
enabled: options?.query?.enabled ?? true,
},
request: {
...options?.request,
Expand Down

0 comments on commit f89a7a4

Please sign in to comment.