Skip to content

Commit 4944dbb

Browse files
authored
Merge pull request #1543 from input-output-hk/refactor/async-stores-factory
refactor(web-extension)!: make StoresFactory async
2 parents f56823d + 77e12de commit 4944dbb

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

packages/e2e/test/web-extension/extension/background/walletManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ const walletFactory: WalletFactory<Metadata, Metadata> = {
8686
};
8787

8888
const storesFactory: StoresFactory = {
89-
create: ({ name }) => storage.createPouchDbWalletStores(name, { logger })
89+
create: async ({ name }) => storage.createPouchDbWalletStores(name, { logger })
9090
};
9191

9292
const walletRepository = new WalletRepository<Metadata, Metadata>({

packages/web-extension/src/walletManager/walletManager.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ export class WalletManager<WalletMetadata extends { name: string }, AccountMetad
147147
this.#activeWalletProps = props;
148148

149149
const walletStoreId = getWalletStoreId(walletId, chainId, accountIndex);
150-
const stores = this.#getStores(walletStoreId);
150+
const stores = await this.#getStores(walletStoreId);
151151

152152
const witnesser = this.#buildWitnesser(activeWallet, walletId, chainId, accountIndex);
153153

@@ -202,10 +202,10 @@ export class WalletManager<WalletMetadata extends { name: string }, AccountMetad
202202
}
203203

204204
/** Gets store if wallet was activated previously or creates one when wallet is activated for the first time. */
205-
#getStores(walletStoreName: string): storage.WalletStores {
205+
async #getStores(walletStoreName: string): Promise<storage.WalletStores> {
206206
let stores = this.#walletStores.get(walletStoreName);
207207
if (!stores) {
208-
stores = this.#storesFactory.create({ name: walletStoreName });
208+
stores = await this.#storesFactory.create({ name: walletStoreName });
209209
this.#walletStores.set(walletStoreName, stores);
210210
}
211211
return stores;
@@ -237,7 +237,7 @@ export class WalletManager<WalletMetadata extends { name: string }, AccountMetad
237237
if (!storeIds || storeIds.length === 0) return;
238238

239239
for (const walletStoreId of storeIds) {
240-
const walletStores = this.#getStores(walletStoreId);
240+
const walletStores = await this.#getStores(walletStoreId);
241241

242242
this.#logger.debug(`Destroying wallet store ${walletStoreId}`);
243243

packages/web-extension/src/walletManager/walletManager.types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,5 +91,5 @@ export interface WalletFactory<WalletMetadata extends { name: string }, AccountM
9191
}
9292

9393
export interface StoresFactory {
94-
create: (props: { name: string }) => storage.WalletStores;
94+
create: (props: { name: string }) => Promise<storage.WalletStores>;
9595
}

packages/web-extension/test/walletManager/walletManager.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ describe('WalletManager', () => {
134134
runtime,
135135
signingCoordinatorApi,
136136
storesFactory: {
137-
create: (props) =>
137+
create: async (props) =>
138138
({
139139
destroy: jest.fn().mockReturnValue(
140140
from(

0 commit comments

Comments
 (0)