Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: changing fetcher / submitter to be optional flag #227

Merged
merged 1 commit into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@

export type CreateMeshWalletOptions = {
networkId: number;
fetcher: IFetcher;
submitter: ISubmitter;
fetcher?: IFetcher;
submitter?: ISubmitter;
key:
| {
type: 'root';
Expand Down Expand Up @@ -123,7 +123,7 @@
const assetId = asset.unit;
const amount = Number(asset.quantity);
if (assets.has(assetId)) {
const quantity = assets.get(assetId)!;

Check warning on line 126 in packages/module/src/wallet/mesh.service.ts

View workflow job for this annotation

GitHub Actions / build

Forbidden non-null assertion

Check warning on line 126 in packages/module/src/wallet/mesh.service.ts

View workflow job for this annotation

GitHub Actions / build

Forbidden non-null assertion
assets.set(assetId, quantity + amount);
} else {
assets.set(assetId, amount);
Expand Down
Loading