diff --git a/.changeset/healthy-ligers-press.md b/.changeset/healthy-ligers-press.md new file mode 100644 index 000000000..a845151cc --- /dev/null +++ b/.changeset/healthy-ligers-press.md @@ -0,0 +1,2 @@ +--- +--- diff --git a/packages/app/src/systems/CRX/background/services/BackgroundService.ts b/packages/app/src/systems/CRX/background/services/BackgroundService.ts index 608dee670..b9d3c6464 100644 --- a/packages/app/src/systems/CRX/background/services/BackgroundService.ts +++ b/packages/app/src/systems/CRX/background/services/BackgroundService.ts @@ -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; } } diff --git a/packages/docs/docs/api.mdx b/packages/docs/docs/api.mdx index ff0d86ba4..bfb9d47f1 100644 --- a/packages/docs/docs/api.mdx +++ b/packages/docs/docs/api.mdx @@ -41,6 +41,20 @@ Return the current account being used in the wallet application. +### List Assets + +`async assets(): Promise>`
+Return the list of assets in the current wallet. + + + +### Add Asset + +`async addAsset(asset: Asset): Promise`
+Add an asset to the wallet. + + + ### Request signature message `async signMessage(address: string, message: string): Promise`
diff --git a/packages/sdk/src/Fuel.test.ts b/packages/sdk/src/Fuel.test.ts index acfa0fc41..e2488e1bf 100644 --- a/packages/sdk/src/Fuel.test.ts +++ b/packages/sdk/src/Fuel.test.ts @@ -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]; diff --git a/packages/sdk/src/__mock__/Fuel.ts b/packages/sdk/src/__mock__/Fuel.ts index 9e76b7ec2..edeb55256 100644 --- a/packages/sdk/src/__mock__/Fuel.ts +++ b/packages/sdk/src/__mock__/Fuel.ts @@ -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'; @@ -28,6 +29,8 @@ export class MockConnection extends BaseConnection { this.signMessage, this.sendTransaction, this.currentAccount, + this.assets, + this.addAsset, ]); } @@ -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 { + const addedAsset: Asset = asset; + fuel.emit(FuelWalletEvents.assets, addedAsset); + return addedAsset; + } } global.window = {