Skip to content

Commit

Permalink
feat: changing fetcher / submitter to be optional flag
Browse files Browse the repository at this point in the history
  • Loading branch information
HinsonSIDAN committed May 29, 2024
1 parent aa5e425 commit 5c380a5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
23 changes: 19 additions & 4 deletions packages/module/src/wallet/app.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ const DEFAULT_PASSWORD = 'MARI0TIME';

export type CreateAppWalletOptions = {
networkId: number;
fetcher: IFetcher;
submitter: ISubmitter;
fetcher?: IFetcher;
submitter?: ISubmitter;
key:
| {
type: 'root';
Expand All @@ -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) {
Expand Down Expand Up @@ -99,6 +99,11 @@ export class AppWallet implements IInitiator, ISigner, ISubmitter {
}

async getUsedUTxOs(accountIndex = 0): Promise<TransactionUnspentOutput[]> {
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
Expand Down Expand Up @@ -128,6 +133,11 @@ export class AppWallet implements IInitiator, ISigner, ISubmitter {
accountIndex = 0
): Promise<string> {
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
Expand Down Expand Up @@ -169,6 +179,11 @@ export class AppWallet implements IInitiator, ISigner, ISubmitter {
}

submitTx(tx: string): Promise<string> {
if (!this._submitter) {
throw new Error(
'[AppWallet] Submitter is required to submit transactions. Please provide a submitter.'
);
}
return this._submitter.submitTx(tx);
}

Expand Down
4 changes: 2 additions & 2 deletions packages/module/src/wallet/mesh.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import { EmbeddedWallet, Transaction } from '..';

export type CreateMeshWalletOptions = {
networkId: number;
fetcher: IFetcher;
submitter: ISubmitter;
fetcher?: IFetcher;
submitter?: ISubmitter;
key:
| {
type: 'root';
Expand Down

0 comments on commit 5c380a5

Please sign in to comment.