Skip to content

Commit

Permalink
fixup! Refactor useTokenTransfers function signature
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaw3d committed Jan 24, 2024
1 parent 718e8cb commit 782668d
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/app/pages/TokenDashboardPage/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,25 @@ export const useTokenInfo = (scope: SearchScope, address: string, enabled = true

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

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

export const _useTokenTransfers = (scope: SearchScope, params: GetRuntimeEventsParams) => {
export const _useTokenTransfers = (scope: SearchScope, params: undefined | GetRuntimeEventsParams) => {
if (params && Object.values(params).some(value => value === undefined || value === null)) {
throw new Error('Must set params=undefined while some values are unavailable')
}

const { network, layer } = scope
const pagination = useComprehensiveSearchParamsPagination<RuntimeEvent, RuntimeEventList>({
paramName: 'page',
Expand All @@ -73,7 +80,7 @@ export const _useTokenTransfers = (scope: SearchScope, params: GetRuntimeEventsP
},
{
query: {
enabled: !!params.rel || (!!params.contract_address && !!params.nft_id),
enabled: !!params,
},
},
)
Expand Down

0 comments on commit 782668d

Please sign in to comment.