Skip to content

Commit

Permalink
Add the validation of the accountAddressOrAddresses parameter;
Browse files Browse the repository at this point in the history
Fix typos
  • Loading branch information
skubarenko committed Mar 20, 2024
1 parent a485de3 commit 744376d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ export class DefaultDataProvider implements TransfersBridgeDataProvider, Balance
async getAccountTokenTransfers(accountAddresses: readonly string[]): Promise<BridgeTokenTransfer[]>;
async getAccountTokenTransfers(accountAddress: string, fetchOptions: TransfersFetchOptions): Promise<BridgeTokenTransfer[]>;
async getAccountTokenTransfers(accountAddresses: readonly string[], fetchOptions: TransfersFetchOptions): Promise<BridgeTokenTransfer[]>;
async getAccountTokenTransfers(accountAddressOfAddresses: string | readonly string[], fetchOptions?: TransfersFetchOptions): Promise<BridgeTokenTransfer[]>;
async getAccountTokenTransfers(accountAddressOfAddresses: string | readonly string[], fetchOptions?: TransfersFetchOptions): Promise<BridgeTokenTransfer[]> {
return this.dipDupBridgeDataProvider.getAccountTokenTransfers(accountAddressOfAddresses, fetchOptions);
async getAccountTokenTransfers(accountAddressOrAddresses: string | readonly string[], fetchOptions?: TransfersFetchOptions): Promise<BridgeTokenTransfer[]>;
async getAccountTokenTransfers(accountAddressOrAddresses: string | readonly string[], fetchOptions?: TransfersFetchOptions): Promise<BridgeTokenTransfer[]> {
return this.dipDupBridgeDataProvider.getAccountTokenTransfers(accountAddressOrAddresses, fetchOptions);
}

async getOperationTokenTransfers(operationHash: string): Promise<BridgeTokenTransfer[]>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,11 @@ export class DipDupBridgeDataProvider extends RemoteService implements Transfers
async getAccountTokenTransfers(accountAddresses: readonly string[]): Promise<BridgeTokenTransfer[]>;
async getAccountTokenTransfers(accountAddress: string, fetchOptions: TransfersFetchOptions): Promise<BridgeTokenTransfer[]>;
async getAccountTokenTransfers(accountAddresses: readonly string[], fetchOptions: TransfersFetchOptions): Promise<BridgeTokenTransfer[]>;
async getAccountTokenTransfers(accountAddressOfAddresses: string | readonly string[], fetchOptions?: TransfersFetchOptions): Promise<BridgeTokenTransfer[]>;
async getAccountTokenTransfers(accountAddressOfAddresses: string | readonly string[], fetchOptions?: TransfersFetchOptions): Promise<BridgeTokenTransfer[]> {
return this.getTokenTransfersInternal(accountAddressOfAddresses, fetchOptions);
async getAccountTokenTransfers(accountAddressOrAddresses: string | readonly string[], fetchOptions?: TransfersFetchOptions): Promise<BridgeTokenTransfer[]>;
async getAccountTokenTransfers(accountAddressOrAddresses: string | readonly string[], fetchOptions?: TransfersFetchOptions): Promise<BridgeTokenTransfer[]> {
return this.validateAccountAddressOrAddresses(accountAddressOrAddresses)
? this.getTokenTransfersInternal(accountAddressOrAddresses, fetchOptions)
: [];
}

async getOperationTokenTransfers(operationHash: string): Promise<BridgeTokenTransfer[]>;
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}

Expand Down Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface TransfersBridgeDataProvider {
getAccountTokenTransfers(accountAddresses: readonly string[]): Promise<BridgeTokenTransfer[]>;
getAccountTokenTransfers(accountAddress: string, fetchOptions: TransfersFetchOptions): Promise<BridgeTokenTransfer[]>;
getAccountTokenTransfers(accountAddresses: readonly string[], fetchOptions: TransfersFetchOptions): Promise<BridgeTokenTransfer[]>;
getAccountTokenTransfers(accountAddressOfAddresses: string | readonly string[], fetchOptions?: TransfersFetchOptions): Promise<BridgeTokenTransfer[]>;
getAccountTokenTransfers(accountAddressOrAddresses: string | readonly string[], fetchOptions?: TransfersFetchOptions): Promise<BridgeTokenTransfer[]>;

getOperationTokenTransfers(operationHash: string): Promise<BridgeTokenTransfer[]>;
getOperationTokenTransfers(tokenTransfer: BridgeTokenTransfer): Promise<BridgeTokenTransfer[]>;
Expand Down
6 changes: 3 additions & 3 deletions src/tokenBridge/tokenBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,10 +453,10 @@ export class TokenBridge<
protected getAccountTokenTransfers(accountAddresses: readonly string[]): Promise<BridgeTokenTransfer[]>;
protected getAccountTokenTransfers(accountAddress: string, fetchOptions: TransfersFetchOptions): Promise<BridgeTokenTransfer[]>;
protected getAccountTokenTransfers(accountAddresses: readonly string[], fetchOptions: TransfersFetchOptions): Promise<BridgeTokenTransfer[]>;
protected getAccountTokenTransfers(accountAddressOfAddresses: string | readonly string[], fetchOptions?: TransfersFetchOptions): Promise<BridgeTokenTransfer[]>;
protected getAccountTokenTransfers(accountAddressOfAddresses: string | readonly string[], fetchOptions?: TransfersFetchOptions): Promise<BridgeTokenTransfer[]> {
protected getAccountTokenTransfers(accountAddressOrAddresses: string | readonly string[], fetchOptions?: TransfersFetchOptions): Promise<BridgeTokenTransfer[]>;
protected getAccountTokenTransfers(accountAddressOrAddresses: string | readonly string[], fetchOptions?: TransfersFetchOptions): Promise<BridgeTokenTransfer[]> {
return this.bridgeComponents.transfersBridgeDataProvider
.getAccountTokenTransfers(accountAddressOfAddresses, fetchOptions);
.getAccountTokenTransfers(accountAddressOrAddresses, fetchOptions);
}

protected getOperationTokenTransfers(operationHash: string): Promise<BridgeTokenTransfer[]>;
Expand Down

0 comments on commit 744376d

Please sign in to comment.