Skip to content

Commit

Permalink
Add a EdgeAccount.createCurrencyWallets method
Browse files Browse the repository at this point in the history
  • Loading branch information
swansontec committed Dec 5, 2023
1 parent a191310 commit cfa18e5
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
24 changes: 24 additions & 0 deletions src/core/account/account-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
EdgeAccount,
EdgeActivationOptions,
EdgeActivationQuote,
EdgeCreateCurrencyWallet,
EdgeCreateCurrencyWalletOptions,
EdgeCurrencyConfig,
EdgeCurrencyWallet,
Expand Down Expand Up @@ -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<EdgeCurrencyWallet[]> {
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<EdgeCurrencyWallet> {
return await new Promise((resolve, reject) => {
const check = (): void => {
Expand Down
7 changes: 7 additions & 0 deletions src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1347,6 +1347,10 @@ export interface EdgeCreateCurrencyWalletOptions {
migratedFromWalletId?: string
}

export type EdgeCreateCurrencyWallet = EdgeCreateCurrencyWalletOptions & {
walletType: string
}

export interface EdgeCurrencyConfig {
readonly watch: Subscriber<EdgeCurrencyConfig>

Expand Down Expand Up @@ -1574,6 +1578,9 @@ export interface EdgeAccount {
walletType: string,
opts?: EdgeCreateCurrencyWalletOptions
) => Promise<EdgeCurrencyWallet>
readonly createCurrencyWallets: (
createWallets: EdgeCreateCurrencyWallet[]
) => Promise<EdgeCurrencyWallet[]>
readonly waitForCurrencyWallet: (
walletId: string
) => Promise<EdgeCurrencyWallet>
Expand Down

0 comments on commit cfa18e5

Please sign in to comment.