From 87f41932e75ee6733f6b99d78395891d8e8008af Mon Sep 17 00:00:00 2001 From: Carlos Garcia Ortiz karliatto Date: Tue, 10 Dec 2024 07:29:14 +0100 Subject: [PATCH] chore(connect): use resolveAfter from @trezor/utilsf --- packages/connect/src/api/composeTransaction.ts | 2 +- packages/connect/src/api/getAccountInfo.ts | 3 ++- packages/connect/src/device/DeviceList.ts | 2 +- packages/connect/src/utils/promiseUtils.ts | 13 ------------- 4 files changed, 4 insertions(+), 16 deletions(-) delete mode 100644 packages/connect/src/utils/promiseUtils.ts diff --git a/packages/connect/src/api/composeTransaction.ts b/packages/connect/src/api/composeTransaction.ts index f72749c222d..818e6b65b1a 100644 --- a/packages/connect/src/api/composeTransaction.ts +++ b/packages/connect/src/api/composeTransaction.ts @@ -1,6 +1,7 @@ // origin: https://github.com/trezor/connect/blob/develop/src/js/core/methods/ComposeTransaction.js import { BigNumber } from '@trezor/utils/src/bigNumber'; +import { resolveAfter } from '@trezor/utils/src/resolveAfter'; import type { ComposeOutput, TransactionInputOutputSortingStrategy } from '@trezor/utxo-lib'; import { AbstractMethod } from '../core/AbstractMethod'; @@ -9,7 +10,6 @@ import { UI, createUiMessage } from '../events'; import { Discovery } from './common/Discovery'; import { validateParams, getFirmwareRange } from './common/paramsValidator'; import * as pathUtils from '../utils/pathUtils'; -import { resolveAfter } from '../utils/promiseUtils'; import { formatAmount } from '../utils/formatUtils'; import { getBitcoinNetwork, fixCoinInfoNetwork } from '../data/coinInfo'; import { isBackendSupported, initBlockchain } from '../backend/BlockchainLink'; diff --git a/packages/connect/src/api/getAccountInfo.ts b/packages/connect/src/api/getAccountInfo.ts index b317bb6c7b2..099117af617 100644 --- a/packages/connect/src/api/getAccountInfo.ts +++ b/packages/connect/src/api/getAccountInfo.ts @@ -1,11 +1,12 @@ // origin: https://github.com/trezor/connect/blob/develop/src/js/core/methods/GetAccountInfo.js +import { resolveAfter } from '@trezor/utils/src/resolveAfter'; + import { AbstractMethod, MethodReturnType, DEFAULT_FIRMWARE_RANGE } from '../core/AbstractMethod'; import { Discovery } from './common/Discovery'; import { validateParams, getFirmwareRange } from './common/paramsValidator'; import { validatePath, getSerializedPath } from '../utils/pathUtils'; import { getAccountLabel, isUtxoBased } from '../utils/accountUtils'; -import { resolveAfter } from '../utils/promiseUtils'; import { getCoinInfo } from '../data/coinInfo'; import { PROTO, ERRORS } from '../constants'; import { UI, createUiMessage } from '../events'; diff --git a/packages/connect/src/device/DeviceList.ts b/packages/connect/src/device/DeviceList.ts index 81e8e34bd7a..aca31c954dd 100644 --- a/packages/connect/src/device/DeviceList.ts +++ b/packages/connect/src/device/DeviceList.ts @@ -11,6 +11,7 @@ import { isTransportInstance, } from '@trezor/transport'; import { Descriptor, PathPublic } from '@trezor/transport/src/types'; +import { resolveAfter } from '@trezor/utils/src/resolveAfter'; import { ERRORS } from '../constants'; import { DEVICE, TransportInfo } from '../events'; @@ -23,7 +24,6 @@ import { } from '../types'; import { getBridgeInfo } from '../data/transportInfo'; import { initLog } from '../utils/debug'; -import { resolveAfter } from '../utils/promiseUtils'; import { typedObjectKeys } from '../types/utils'; // custom log diff --git a/packages/connect/src/utils/promiseUtils.ts b/packages/connect/src/utils/promiseUtils.ts deleted file mode 100644 index 9361ecdc93b..00000000000 --- a/packages/connect/src/utils/promiseUtils.ts +++ /dev/null @@ -1,13 +0,0 @@ -// origin: https://github.com/trezor/connect/blob/develop/src/js/utils/promiseUtils.js - -import { createDeferred } from '@trezor/utils'; - -export const resolveAfter = (msec: number, value?: T) => { - const { promise, reject, resolve } = createDeferred(); - const timeout = setTimeout(resolve, msec, value); - - return { - promise: promise.finally(() => clearTimeout(timeout)), - reject, - }; -};