From b5c9c79811d3f7e2b599abeb698b3acba26c7727 Mon Sep 17 00:00:00 2001 From: kyranjamie Date: Sun, 5 May 2024 17:27:55 +0200 Subject: [PATCH] fix: change default to pulling 10 keys --- .../request-bitcoin-keys.utils.ts | 14 +++++++++++--- .../ledger-request-stacks-keys.tsx | 9 +++++++-- .../request-stacks-keys.utils.ts | 5 +++-- .../request-keys/use-request-ledger-keys.ts | 2 ++ 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/app/features/ledger/flows/request-bitcoin-keys/request-bitcoin-keys.utils.ts b/src/app/features/ledger/flows/request-bitcoin-keys/request-bitcoin-keys.utils.ts index a54c6adc53f..f99c612906f 100644 --- a/src/app/features/ledger/flows/request-bitcoin-keys/request-bitcoin-keys.utils.ts +++ b/src/app/features/ledger/flows/request-bitcoin-keys/request-bitcoin-keys.utils.ts @@ -6,6 +6,7 @@ import { getTaprootAccountDerivationPath } from '@shared/crypto/bitcoin/p2tr-add import { getNativeSegwitAccountDerivationPath } from '@shared/crypto/bitcoin/p2wpkh-address-gen'; import { delay } from '@shared/utils'; +import { defaultNumberOfKeysToPullFromLedgerDevice } from '../../generic-flows/request-keys/use-request-ledger-keys'; import { WalletPolicyDetails, createNativeSegwitDefaultWalletPolicy, @@ -55,10 +56,13 @@ interface PullBitcoinKeysFromLedgerDeviceArgs { } export function pullBitcoinKeysFromLedgerDevice(bitcoinApp: BitcoinApp, targetId = '') { return async ({ onRequestKey, network }: PullBitcoinKeysFromLedgerDeviceArgs) => { - const amountOfKeysToExtractFromDevice = 5; const fingerprint = await bitcoinApp.getMasterFingerprint(); const keys: { id: string; path: string; policy: string; targetId: string }[] = []; - for (let accountIndex = 0; accountIndex < amountOfKeysToExtractFromDevice; accountIndex++) { + for ( + let accountIndex = 0; + accountIndex < defaultNumberOfKeysToPullFromLedgerDevice; + accountIndex++ + ) { onRequestKey?.(accountIndex); const { path, policy } = await getNativeSegwitExtendedPublicKey({ bitcoinApp, @@ -68,7 +72,11 @@ export function pullBitcoinKeysFromLedgerDevice(bitcoinApp: BitcoinApp, targetId }); keys.push({ id: createWalletIdDecoratedPath(path, 'default'), path, policy, targetId }); } - for (let accountIndex = 0; accountIndex < amountOfKeysToExtractFromDevice; accountIndex++) { + for ( + let accountIndex = 0; + accountIndex < defaultNumberOfKeysToPullFromLedgerDevice; + accountIndex++ + ) { onRequestKey?.(accountIndex + 5); const { path, policy } = await getTaprootExtendedPublicKey({ bitcoinApp, diff --git a/src/app/features/ledger/flows/request-stacks-keys/ledger-request-stacks-keys.tsx b/src/app/features/ledger/flows/request-stacks-keys/ledger-request-stacks-keys.tsx index b746bab2eee..c6162a6740d 100644 --- a/src/app/features/ledger/flows/request-stacks-keys/ledger-request-stacks-keys.tsx +++ b/src/app/features/ledger/flows/request-stacks-keys/ledger-request-stacks-keys.tsx @@ -9,7 +9,10 @@ import { defaultWalletKeyId } from '@shared/utils'; import { ledgerRequestKeysRoutes } from '@app/features/ledger/generic-flows/request-keys/ledger-request-keys-route-generator'; import { LedgerRequestKeysContext } from '@app/features/ledger/generic-flows/request-keys/ledger-request-keys.context'; import { RequestKeysFlow } from '@app/features/ledger/generic-flows/request-keys/request-keys-flow'; -import { useRequestLedgerKeys } from '@app/features/ledger/generic-flows/request-keys/use-request-ledger-keys'; +import { + defaultNumberOfKeysToPullFromLedgerDevice, + useRequestLedgerKeys, +} from '@app/features/ledger/generic-flows/request-keys/use-request-ledger-keys'; import { useLedgerNavigate } from '@app/features/ledger/hooks/use-ledger-navigate'; import { connectLedgerStacksApp, @@ -42,7 +45,9 @@ function LedgerRequestStacksKeys() { async pullKeysFromDevice(app) { const resp = await pullStacksKeysFromLedgerDevice(app)({ onRequestKey(accountIndex) { - ledgerNavigate.toDeviceBusyStep(`Requesting STX addresses (${accountIndex + 1}…5)`); + ledgerNavigate.toDeviceBusyStep( + `Requesting STX addresses (${accountIndex + 1}…${defaultNumberOfKeysToPullFromLedgerDevice})` + ); }, }); if (resp.status === 'failure') { diff --git a/src/app/features/ledger/flows/request-stacks-keys/request-stacks-keys.utils.ts b/src/app/features/ledger/flows/request-stacks-keys/request-stacks-keys.utils.ts index 76b4a021991..b0ca692824e 100644 --- a/src/app/features/ledger/flows/request-stacks-keys/request-stacks-keys.utils.ts +++ b/src/app/features/ledger/flows/request-stacks-keys/request-stacks-keys.utils.ts @@ -8,6 +8,7 @@ import { } from '@shared/crypto/stacks/stacks.utils'; import { delay } from '@shared/utils'; +import { defaultNumberOfKeysToPullFromLedgerDevice } from '../../generic-flows/request-keys/use-request-ledger-keys'; import { StacksAppKeysResponseItem, requestPublicKeyForStxAccount, @@ -45,8 +46,8 @@ export function pullStacksKeysFromLedgerDevice(stacksApp: StacksApp) { onRequestKey, }: PullStacksKeysFromLedgerDeviceArgs): PullStacksKeysFromLedgerResponse => { const publicKeys = []; - const amountOfKeysToExtractFromDevice = 5; - for (let index = 0; index < amountOfKeysToExtractFromDevice; index++) { + + for (let index = 0; index < defaultNumberOfKeysToPullFromLedgerDevice; index++) { if (onRequestKey) onRequestKey(index); const stxPublicKeyResp = await requestPublicKeyForStxAccount(stacksApp)(index); const dataPublicKeyResp = await requestPublicKeyForIdentityAccount(stacksApp)(index); diff --git a/src/app/features/ledger/generic-flows/request-keys/use-request-ledger-keys.ts b/src/app/features/ledger/generic-flows/request-keys/use-request-ledger-keys.ts index f1f854542ad..4e67ae967fa 100644 --- a/src/app/features/ledger/generic-flows/request-keys/use-request-ledger-keys.ts +++ b/src/app/features/ledger/generic-flows/request-keys/use-request-ledger-keys.ts @@ -16,6 +16,8 @@ import { } from '../../utils/generic-ledger-utils'; import { StacksAppVersion } from '../../utils/stacks-ledger-utils'; +export const defaultNumberOfKeysToPullFromLedgerDevice = 10; + interface UseRequestLedgerKeysArgs { chain: SupportedBlockchains; isAppOpen({ name }: { name: string }): boolean;