From 5ef0637bbd95562593a5f8a20629df6fdc0e4374 Mon Sep 17 00:00:00 2001 From: Alejo Acosta Date: Thu, 24 Oct 2024 10:38:20 -0300 Subject: [PATCH] force _findLastUsedIndex to return -1 if no index is found --- src/wallet/qi-hdwallet.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wallet/qi-hdwallet.ts b/src/wallet/qi-hdwallet.ts index c41f0f64..1f10c232 100644 --- a/src/wallet/qi-hdwallet.ts +++ b/src/wallet/qi-hdwallet.ts @@ -218,7 +218,7 @@ export class QiHDWallet extends AbstractHDWallet { } /** - * Finds the last used index in an array of QiAddressInfo objects. + * Finds the last used index in an array of QiAddressInfo objects. If no index is found, returns -1. * * @param {QiAddressInfo[]} addresses - The array of QiAddressInfo objects. * @returns {number} The last used index. @@ -227,7 +227,7 @@ export class QiHDWallet extends AbstractHDWallet { const filteredAddresses = addresses?.filter( (addressInfo) => addressInfo.account === account && addressInfo.zone === zone, ); - return filteredAddresses?.reduce((maxIndex, addressInfo) => Math.max(maxIndex, addressInfo.index), -1) || 0; + return filteredAddresses?.reduce((maxIndex, addressInfo) => Math.max(maxIndex, addressInfo.index), -1) || -1; } /**