Skip to content

Commit

Permalink
force _findLastUsedIndex to return -1 if no index is found
Browse files Browse the repository at this point in the history
  • Loading branch information
alejoacosta74 committed Oct 24, 2024
1 parent 79cba8a commit 5ef0637
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/wallet/qi-hdwallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
}

/**
Expand Down

0 comments on commit 5ef0637

Please sign in to comment.