]> git.codecow.com Git - libnemo.git/commitdiff
Fix invalid iteration of single account object.
authorChris Duncan <chris@zoso.dev>
Mon, 8 Sep 2025 04:37:52 +0000 (21:37 -0700)
committerChris Duncan <chris@zoso.dev>
Mon, 8 Sep 2025 04:37:52 +0000 (21:37 -0700)
src/lib/wallet/accounts.ts

index d5331e289334322aba6c002c62ffc00b3c72f9c3..1939c408f0fe4eb62f51742a0500b401a2f8f658 100644 (file)
@@ -7,7 +7,9 @@ import { Vault } from '../vault'
 
 export async function _accounts (type: WalletType, accounts: Map<number, Account>, vault: Vault, index: number): Promise<Account>
 export async function _accounts (type: WalletType, accounts: Map<number, Account>, vault: Vault, from: number, to: number): Promise<Map<number, Account>>
-export async function _accounts (type: WalletType, accounts: Map<number, Account>, vault: Vault, from: unknown, to: unknown = from): Promise<Account | Map<number, Account>> {
+export async function _accounts (type: WalletType, accounts: Map<number, Account>, vault: Vault, from: unknown, to?: unknown): Promise<Account | Map<number, Account>> {
+       const isSingle = to === undefined
+       to ??= from
        if (typeof from !== 'number' || typeof to !== 'number') {
                throw new TypeError('Invalid account range', { cause: `${from}-${to}` })
        }
@@ -54,7 +56,7 @@ export async function _accounts (type: WalletType, accounts: Map<number, Account
                        accounts.set(a.index, a)
                }
        }
-       if (from === to) {
+       if (isSingle) {
                const account = output.get(from)
                if (account === undefined) {
                        throw new Error(`Failed to get account at index ${from}`)