From 5c380a5ea98cc5ed13edc00493709941890356c2 Mon Sep 17 00:00:00 2001 From: SIDANWhatever Date: Wed, 29 May 2024 16:19:28 +0800 Subject: [PATCH] feat: changing fetcher / submitter to be optional flag --- packages/module/src/wallet/app.service.ts | 23 ++++++++++++++++++---- packages/module/src/wallet/mesh.service.ts | 4 ++-- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/packages/module/src/wallet/app.service.ts b/packages/module/src/wallet/app.service.ts index 05c22fbc2..daafb05ef 100644 --- a/packages/module/src/wallet/app.service.ts +++ b/packages/module/src/wallet/app.service.ts @@ -20,8 +20,8 @@ const DEFAULT_PASSWORD = 'MARI0TIME'; export type CreateAppWalletOptions = { networkId: number; - fetcher: IFetcher; - submitter: ISubmitter; + fetcher?: IFetcher; + submitter?: ISubmitter; key: | { type: 'root'; @@ -39,8 +39,8 @@ export type CreateAppWalletOptions = { }; export class AppWallet implements IInitiator, ISigner, ISubmitter { - private readonly _fetcher: IFetcher; - private readonly _submitter: ISubmitter; + private readonly _fetcher?: IFetcher; + private readonly _submitter?: ISubmitter; private readonly _wallet: EmbeddedWallet; constructor(options: CreateAppWalletOptions) { @@ -99,6 +99,11 @@ export class AppWallet implements IInitiator, ISigner, ISubmitter { } async getUsedUTxOs(accountIndex = 0): Promise { + if (!this._fetcher) { + throw new Error( + '[AppWallet] Fetcher is required to fetch UTxOs. Please provide a fetcher.' + ); + } const account = this._wallet.getAccount(accountIndex, DEFAULT_PASSWORD); const utxos = await this._fetcher.fetchAddressUTxOs( account.enterpriseAddress @@ -128,6 +133,11 @@ export class AppWallet implements IInitiator, ISigner, ISubmitter { accountIndex = 0 ): Promise { try { + if (!this._fetcher) { + throw new Error( + '[AppWallet] Fetcher is required to fetch UTxOs. Please provide a fetcher.' + ); + } const account = this._wallet.getAccount(accountIndex, DEFAULT_PASSWORD); const utxos = await this._fetcher.fetchAddressUTxOs( account.enterpriseAddress @@ -169,6 +179,11 @@ export class AppWallet implements IInitiator, ISigner, ISubmitter { } submitTx(tx: string): Promise { + if (!this._submitter) { + throw new Error( + '[AppWallet] Submitter is required to submit transactions. Please provide a submitter.' + ); + } return this._submitter.submitTx(tx); } diff --git a/packages/module/src/wallet/mesh.service.ts b/packages/module/src/wallet/mesh.service.ts index 0a1bed02c..520991622 100644 --- a/packages/module/src/wallet/mesh.service.ts +++ b/packages/module/src/wallet/mesh.service.ts @@ -24,8 +24,8 @@ import { EmbeddedWallet, Transaction } from '..'; export type CreateMeshWalletOptions = { networkId: number; - fetcher: IFetcher; - submitter: ISubmitter; + fetcher?: IFetcher; + submitter?: ISubmitter; key: | { type: 'root';