From cfa18e5dd3418f6803a30142a145d30616440fd1 Mon Sep 17 00:00:00 2001 From: William Swanson Date: Fri, 24 Nov 2023 15:05:25 -0800 Subject: [PATCH] Add a `EdgeAccount.createCurrencyWallets` method --- CHANGELOG.md | 2 ++ src/core/account/account-api.ts | 24 ++++++++++++++++++++++++ src/types/types.ts | 7 +++++++ 3 files changed, 33 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 66f5a09ae..8f6fe5e55 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +- added: `EdgeAccount.createCurrencyWallets`, for creating multiple wallets at once. + ## 1.12.0 (2023-11-30) - added: Accept an `onNewTokens` callback from `EdgeCurrencyEngine`. diff --git a/src/core/account/account-api.ts b/src/core/account/account-api.ts index e29814fd0..8e4475feb 100644 --- a/src/core/account/account-api.ts +++ b/src/core/account/account-api.ts @@ -9,6 +9,7 @@ import { EdgeAccount, EdgeActivationOptions, EdgeActivationQuote, + EdgeCreateCurrencyWallet, EdgeCreateCurrencyWalletOptions, EdgeCurrencyConfig, EdgeCurrencyWallet, @@ -503,6 +504,29 @@ export function makeAccountApi(ai: ApiInput, accountId: string): EdgeAccount { return await finishWalletCreation(ai, accountId, walletInfo.id, opts) }, + async createCurrencyWallets( + createWallets: EdgeCreateCurrencyWallet[] + ): Promise { + const { login, loginTree } = accountState() + + const walletInfos = await Promise.all( + createWallets.map(async opts => { + return await makeCurrencyWalletKeys(ai, opts.walletType, opts) + }) + ) + await applyKit(ai, loginTree, makeKeysKit(ai, login, walletInfos)) + return await Promise.all( + walletInfos.map(async (info, i) => { + return await finishWalletCreation( + ai, + accountId, + info.id, + createWallets[i] + ) + }) + ) + }, + async waitForCurrencyWallet(walletId: string): Promise { return await new Promise((resolve, reject) => { const check = (): void => { diff --git a/src/types/types.ts b/src/types/types.ts index f3f9068dc..c3072e1fd 100644 --- a/src/types/types.ts +++ b/src/types/types.ts @@ -1347,6 +1347,10 @@ export interface EdgeCreateCurrencyWalletOptions { migratedFromWalletId?: string } +export type EdgeCreateCurrencyWallet = EdgeCreateCurrencyWalletOptions & { + walletType: string +} + export interface EdgeCurrencyConfig { readonly watch: Subscriber @@ -1574,6 +1578,9 @@ export interface EdgeAccount { walletType: string, opts?: EdgeCreateCurrencyWalletOptions ) => Promise + readonly createCurrencyWallets: ( + createWallets: EdgeCreateCurrencyWallet[] + ) => Promise readonly waitForCurrencyWallet: ( walletId: string ) => Promise