diff --git a/src/bridgeDataProviders/defaultDataProvider/defaultDataProvider.ts b/src/bridgeDataProviders/defaultDataProvider/defaultDataProvider.ts index cd5de93..3b0d618 100644 --- a/src/bridgeDataProviders/defaultDataProvider/defaultDataProvider.ts +++ b/src/bridgeDataProviders/defaultDataProvider/defaultDataProvider.ts @@ -63,9 +63,9 @@ export class DefaultDataProvider implements TransfersBridgeDataProvider, Balance async getAccountTokenTransfers(accountAddresses: readonly string[]): Promise; async getAccountTokenTransfers(accountAddress: string, fetchOptions: TransfersFetchOptions): Promise; async getAccountTokenTransfers(accountAddresses: readonly string[], fetchOptions: TransfersFetchOptions): Promise; - async getAccountTokenTransfers(accountAddressOfAddresses: string | readonly string[], fetchOptions?: TransfersFetchOptions): Promise; - async getAccountTokenTransfers(accountAddressOfAddresses: string | readonly string[], fetchOptions?: TransfersFetchOptions): Promise { - return this.dipDupBridgeDataProvider.getAccountTokenTransfers(accountAddressOfAddresses, fetchOptions); + async getAccountTokenTransfers(accountAddressOrAddresses: string | readonly string[], fetchOptions?: TransfersFetchOptions): Promise; + async getAccountTokenTransfers(accountAddressOrAddresses: string | readonly string[], fetchOptions?: TransfersFetchOptions): Promise { + return this.dipDupBridgeDataProvider.getAccountTokenTransfers(accountAddressOrAddresses, fetchOptions); } async getOperationTokenTransfers(operationHash: string): Promise; diff --git a/src/bridgeDataProviders/dipDupBridgeDataProvider/dipDupBridgeDataProvider.ts b/src/bridgeDataProviders/dipDupBridgeDataProvider/dipDupBridgeDataProvider.ts index 3aadfc1..5a07f4d 100644 --- a/src/bridgeDataProviders/dipDupBridgeDataProvider/dipDupBridgeDataProvider.ts +++ b/src/bridgeDataProviders/dipDupBridgeDataProvider/dipDupBridgeDataProvider.ts @@ -93,9 +93,11 @@ export class DipDupBridgeDataProvider extends RemoteService implements Transfers async getAccountTokenTransfers(accountAddresses: readonly string[]): Promise; async getAccountTokenTransfers(accountAddress: string, fetchOptions: TransfersFetchOptions): Promise; async getAccountTokenTransfers(accountAddresses: readonly string[], fetchOptions: TransfersFetchOptions): Promise; - async getAccountTokenTransfers(accountAddressOfAddresses: string | readonly string[], fetchOptions?: TransfersFetchOptions): Promise; - async getAccountTokenTransfers(accountAddressOfAddresses: string | readonly string[], fetchOptions?: TransfersFetchOptions): Promise { - return this.getTokenTransfersInternal(accountAddressOfAddresses, fetchOptions); + async getAccountTokenTransfers(accountAddressOrAddresses: string | readonly string[], fetchOptions?: TransfersFetchOptions): Promise; + async getAccountTokenTransfers(accountAddressOrAddresses: string | readonly string[], fetchOptions?: TransfersFetchOptions): Promise { + return this.validateAccountAddressOrAddresses(accountAddressOrAddresses) + ? this.getTokenTransfersInternal(accountAddressOrAddresses, fetchOptions) + : []; } async getOperationTokenTransfers(operationHash: string): Promise; @@ -162,6 +164,9 @@ export class DipDupBridgeDataProvider extends RemoteService implements Transfers subscribeToAccountTokenTransfers(accountAddresses: readonly string[]): void; subscribeToAccountTokenTransfers(accountAddressOrAddresses: string | readonly string[]): void; subscribeToAccountTokenTransfers(accountAddressOrAddresses: string | readonly string[]): void { + if (!this.validateAccountAddressOrAddresses(accountAddressOrAddresses)) + return; + this.startDipDupWebSocketClientIfNeeded(); this.subscribeToTokenTransfersInternal(accountAddressOrAddresses); } @@ -170,6 +175,9 @@ export class DipDupBridgeDataProvider extends RemoteService implements Transfers unsubscribeFromAccountTokenTransfers(accountAddresses: readonly string[]): void; unsubscribeFromAccountTokenTransfers(accountAddressOrAddresses: string | readonly string[]): void; unsubscribeFromAccountTokenTransfers(accountAddressOrAddresses: string | readonly string[]): void { + if (!this.validateAccountAddressOrAddresses(accountAddressOrAddresses)) + return; + this.unsubscribeFromTokenTransfersInternal(accountAddressOrAddresses); } @@ -480,6 +488,11 @@ export class DipDupBridgeDataProvider extends RemoteService implements Transfers return [previousSubscribedAddressesSize, updatedSubscribedAddressesSize]; } + private validateAccountAddressOrAddresses(accountAddressOrAddresses: unknown): accountAddressOrAddresses is string | readonly string[] { + return !!((guards.isReadonlyArray(accountAddressOrAddresses) && accountAddressOrAddresses.length) + || (typeof accountAddressOrAddresses === 'string' && accountAddressOrAddresses)); + } + private getPreparedOffsetParameter(offsetOrFetchOptions: number | undefined | null | BalancesFetchOptions): number { const offset = typeof offsetOrFetchOptions === 'number' ? offsetOrFetchOptions : offsetOrFetchOptions?.offset; diff --git a/src/bridgeDataProviders/transfersBridgeDataProvider/transfersBridgeDataProvider.ts b/src/bridgeDataProviders/transfersBridgeDataProvider/transfersBridgeDataProvider.ts index 3ad016f..3e8445b 100644 --- a/src/bridgeDataProviders/transfersBridgeDataProvider/transfersBridgeDataProvider.ts +++ b/src/bridgeDataProviders/transfersBridgeDataProvider/transfersBridgeDataProvider.ts @@ -20,7 +20,7 @@ export interface TransfersBridgeDataProvider { getAccountTokenTransfers(accountAddresses: readonly string[]): Promise; getAccountTokenTransfers(accountAddress: string, fetchOptions: TransfersFetchOptions): Promise; getAccountTokenTransfers(accountAddresses: readonly string[], fetchOptions: TransfersFetchOptions): Promise; - getAccountTokenTransfers(accountAddressOfAddresses: string | readonly string[], fetchOptions?: TransfersFetchOptions): Promise; + getAccountTokenTransfers(accountAddressOrAddresses: string | readonly string[], fetchOptions?: TransfersFetchOptions): Promise; getOperationTokenTransfers(operationHash: string): Promise; getOperationTokenTransfers(tokenTransfer: BridgeTokenTransfer): Promise; diff --git a/src/tokenBridge/tokenBridge.ts b/src/tokenBridge/tokenBridge.ts index 3e68b70..5cf7178 100644 --- a/src/tokenBridge/tokenBridge.ts +++ b/src/tokenBridge/tokenBridge.ts @@ -453,10 +453,10 @@ export class TokenBridge< protected getAccountTokenTransfers(accountAddresses: readonly string[]): Promise; protected getAccountTokenTransfers(accountAddress: string, fetchOptions: TransfersFetchOptions): Promise; protected getAccountTokenTransfers(accountAddresses: readonly string[], fetchOptions: TransfersFetchOptions): Promise; - protected getAccountTokenTransfers(accountAddressOfAddresses: string | readonly string[], fetchOptions?: TransfersFetchOptions): Promise; - protected getAccountTokenTransfers(accountAddressOfAddresses: string | readonly string[], fetchOptions?: TransfersFetchOptions): Promise { + protected getAccountTokenTransfers(accountAddressOrAddresses: string | readonly string[], fetchOptions?: TransfersFetchOptions): Promise; + protected getAccountTokenTransfers(accountAddressOrAddresses: string | readonly string[], fetchOptions?: TransfersFetchOptions): Promise { return this.bridgeComponents.transfersBridgeDataProvider - .getAccountTokenTransfers(accountAddressOfAddresses, fetchOptions); + .getAccountTokenTransfers(accountAddressOrAddresses, fetchOptions); } protected getOperationTokenTransfers(operationHash: string): Promise;