From 441d808b721560140dc384df2cbf8456afcd7275 Mon Sep 17 00:00:00 2001 From: John Peterson Date: Thu, 16 May 2024 11:07:05 -0700 Subject: [PATCH] delay util --- src/coinbase/transfer.ts | 3 ++- src/coinbase/utils.ts | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/coinbase/transfer.ts b/src/coinbase/transfer.ts index 3f9e5397..79e4687d 100644 --- a/src/coinbase/transfer.ts +++ b/src/coinbase/transfer.ts @@ -3,6 +3,7 @@ import { Coinbase } from "./coinbase"; import { Transfer as TransferModel } from "../client/api"; import { ethers } from "ethers"; import { InternalError, InvalidUnsignedPayload } from "./errors"; +import { delay } from "./utils"; /** * The Transfer API client types. @@ -218,7 +219,7 @@ export class Transfer { if (status === TransferStatus.COMPLETE || status === TransferStatus.FAILED) { return this; } - await new Promise(resolve => setTimeout(resolve, intervalSeconds * 1000)); + await delay(intervalSeconds); } throw new Error("Transfer timed out"); } diff --git a/src/coinbase/utils.ts b/src/coinbase/utils.ts index b45ab341..f647b8c1 100644 --- a/src/coinbase/utils.ts +++ b/src/coinbase/utils.ts @@ -70,3 +70,13 @@ export const registerAxiosInterceptors = ( export const convertStringToHex = (key: Uint8Array): string => { return Buffer.from(key).toString("hex"); }; + +/** + * Delays the execution of the function by the specified number of seconds. + * + * @param seconds - The number of seconds to delay the execution. + * @returns A promise that resolves after the specified number of seconds. + */ +export async function delay(seconds: number): Promise { + return new Promise(resolve => setTimeout(resolve, seconds * 1000)); +}