From 782668d39bd6e10129f4dba5222ac2b0c1054246 Mon Sep 17 00:00:00 2001 From: lukaw3d Date: Wed, 24 Jan 2024 22:11:59 +0100 Subject: [PATCH] fixup! Refactor useTokenTransfers function signature --- src/app/pages/TokenDashboardPage/hook.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/app/pages/TokenDashboardPage/hook.ts b/src/app/pages/TokenDashboardPage/hook.ts index 193ffb4f12..b341629d60 100644 --- a/src/app/pages/TokenDashboardPage/hook.ts +++ b/src/app/pages/TokenDashboardPage/hook.ts @@ -39,7 +39,7 @@ 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 = ( @@ -47,10 +47,17 @@ export const useNFTInstanceTransfers = ( 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({ paramName: 'page', @@ -73,7 +80,7 @@ export const _useTokenTransfers = (scope: SearchScope, params: GetRuntimeEventsP }, { query: { - enabled: !!params.rel || (!!params.contract_address && !!params.nft_id), + enabled: !!params, }, }, )