Skip to content

Commit

Permalink
docs: add assets and add asset to api (#587)
Browse files Browse the repository at this point in the history
close #586
  • Loading branch information
matt-user authored Feb 23, 2023
1 parent 6cad6a3 commit 4573dd7
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .changeset/healthy-ligers-press.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
Original file line number Diff line number Diff line change
Expand Up @@ -307,10 +307,10 @@ export class BackgroundService {
Pages.requestAddAsset(),
this.communicationProtocol
);
const signedMessage = await popupService.addAsset({
const asset = await popupService.addAsset({
...input,
origin,
});
return signedMessage;
return asset;
}
}
14 changes: 14 additions & 0 deletions packages/docs/docs/api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@ Return the current account being used in the wallet application.

<CodeImport file="../../sdk/src/Fuel.test.ts" testCase="currentAccount" />

### List Assets

`async assets(): Promise<Array<Asset>>`<br />
Return the list of assets in the current wallet.

<CodeImport file="../../sdk/src/Fuel.test.ts" testCase="assets" />

### Add Asset

`async addAsset(asset: Asset): Promise<Asset>`<br />
Add an asset to the wallet.

<CodeImport file="../../sdk/src/Fuel.test.ts" testCase="addAsset" />

### Request signature message

`async signMessage(address: string, message: string): Promise<string>`<br />
Expand Down
11 changes: 11 additions & 0 deletions packages/sdk/src/Fuel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ describe('Fuel', () => {
expect(currentAccount).toEqual(userWallet.address.toAddress());
});

test('assets', async () => {
const assets = await fuel.assets();
expect(assets.length).toEqual(0);
});

test('addAsset', async () => {
const asset = { assetId: NativeAssetId };
const addedAsset = await fuel.addAsset(asset);
expect({ ...addedAsset }).toEqual(asset);
});

test('signMessage', async () => {
const accounts = await fuel.accounts();
const account = accounts[0];
Expand Down
14 changes: 14 additions & 0 deletions packages/sdk/src/__mock__/Fuel.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any */

import { FuelWalletEvents, PAGE_SCRIPT_NAME } from '@fuel-wallet/types';
import type { Asset } from '@fuel-wallet/types';
import EventEmitter from 'events';
import { transactionRequestify, Wallet } from 'fuels';
import type { JSONRPCResponse } from 'json-rpc-2.0';
Expand Down Expand Up @@ -28,6 +29,8 @@ export class MockConnection extends BaseConnection {
this.signMessage,
this.sendTransaction,
this.currentAccount,
this.assets,
this.addAsset,
]);
}

Expand Down Expand Up @@ -96,6 +99,17 @@ export class MockConnection extends BaseConnection {
fuel.emit(FuelWalletEvents.currentAccount, account);
return account;
}

async assets() {
const assets = await userWallet.getBalances();
return assets;
}

async addAsset({ asset }: { asset: Asset }): Promise<Asset> {
const addedAsset: Asset = asset;
fuel.emit(FuelWalletEvents.assets, addedAsset);
return addedAsset;
}
}

global.window = {
Expand Down

0 comments on commit 4573dd7

Please sign in to comment.