return ''\r
}\r
\r
- abstract ckd (index: number): Promise<Account | null>\r
+ abstract ckd (index: number): Promise<Account>\r
\r
constructor (seed?: string, mnemonic?: Bip39Mnemonic, id?: string) {\r
if (this.constructor === Wallet) {\r
from = to\r
to = swap\r
}\r
- const accountQueue = Array(to + 1)\r
+ const accountQueue = []\r
for (let i = from; i <= to; i++) {\r
if (this.#accounts[i] == null) {\r
- accountQueue[i] = this.ckd(i)\r
+ accountQueue.push(new Promise(resolve => {\r
+ this.ckd(i).then(account => this.#accounts[i] = account).then(resolve)\r
+ }))\r
}\r
}\r
if (accountQueue.length > 0) {\r
- const results = await Promise.allSettled(accountQueue)\r
- for (let i = results.length - 1; i >= 0; i--) {\r
- const result = results[i] as PromiseFulfilledResult<Account>\r
- if (result?.value != null) {\r
- this.#accounts[i] = result.value\r
- }\r
- }\r
+ await Promise.allSettled(accountQueue)\r
}\r
return this.#accounts.slice(from, to + 1)\r
}\r
* @param {number} index - Index of the account\r
* @returns {Promise<Account>}\r
*/\r
- async ckd (index: number): Promise<Account | null> {\r
+ async ckd (index: number): Promise<Account> {\r
const { status, publicKey } = await this.ledger.account(index)\r
if (status === 'OK' && publicKey != null) {\r
return await Account.fromPublicKey(publicKey, index)\r
}\r
- return null\r
+ throw new Error(`Error getting Ledger account: ${status}`)\r
}\r
\r
/**\r