Skip to content

Commit 82f0c38

Browse files
committed
move function to snap-utils and add JSDocs
1 parent 446feb2 commit 82f0c38

File tree

6 files changed

+47
-15
lines changed

6 files changed

+47
-15
lines changed

packages/snaps-controllers/src/interface/SnapInterfaceController.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,14 +467,24 @@ export class SnapInterfaceController extends BaseController<
467467
);
468468
}
469469

470+
/**
471+
* Get the selected account in the client.
472+
*
473+
* @returns The selected account.
474+
*/
470475
#getSelectedAccount() {
471476
return this.messagingSystem.call(
472477
'AccountsController:getSelectedMultichainAccount',
473478
);
474479
}
475480

481+
/**
482+
* Set the selected account in the client.
483+
*
484+
* @param accountId - The account id.
485+
*/
476486
#setSelectedAccount(accountId: string) {
477-
return this.messagingSystem.call(
487+
this.messagingSystem.call(
478488
'AccountsController:setSelectedAccount',
479489
accountId,
480490
);

packages/snaps-controllers/src/interface/utils.test.tsx

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,20 +74,6 @@ describe('assertNameIsUnique', () => {
7474
});
7575
});
7676

77-
describe('createAddressList', () => {
78-
it('creates an address list from an account', () => {
79-
const result = createAddressList(
80-
'0x1234567890123456789012345678901234567890',
81-
['eip155:1', 'eip155:2'],
82-
);
83-
84-
expect(result).toStrictEqual([
85-
'eip155:1:0x1234567890123456789012345678901234567890',
86-
'eip155:2:0x1234567890123456789012345678901234567890',
87-
]);
88-
});
89-
});
90-
9177
describe('constructState', () => {
9278
const elementDataGetters = {
9379
getAssetsState: jest.fn(),

packages/snaps-controllers/src/interface/utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import type {
2727
import { isJSXElementUnsafe } from '@metamask/snaps-sdk/jsx';
2828
import type { InternalAccount } from '@metamask/snaps-utils';
2929
import {
30+
createAddressList,
3031
getJsonSizeUnsafe,
3132
getJsxChildren,
3233
getJsxElementFromComponent,
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { createAddressList } from './address';
2+
3+
describe('createAddressList', () => {
4+
it('creates an address list from an account', () => {
5+
const result = createAddressList(
6+
'0x1234567890123456789012345678901234567890',
7+
['eip155:1', 'eip155:2'],
8+
);
9+
10+
expect(result).toStrictEqual([
11+
'eip155:1:0x1234567890123456789012345678901234567890',
12+
'eip155:2:0x1234567890123456789012345678901234567890',
13+
]);
14+
});
15+
});
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import type { CaipAccountId, CaipChainId } from '@metamask/utils';
2+
import { parseCaipChainId, toCaipAccountId } from '@metamask/utils';
3+
4+
/**
5+
* Create a list of CAIP account IDs from an address and a list of scopes.
6+
*
7+
* @param address - The address to create the account IDs from.
8+
* @param scopes - The scopes to create the account IDs from.
9+
* @returns The list of CAIP account IDs.
10+
*/
11+
export function createAddressList(
12+
address: string,
13+
scopes: CaipChainId[],
14+
): CaipAccountId[] {
15+
return scopes.map((scope) => {
16+
const { namespace, reference } = parseCaipChainId(scope);
17+
return toCaipAccountId(namespace, reference, address);
18+
});
19+
}

packages/snaps-utils/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export type * from './account';
2+
export * from './address';
23
export * from './array';
34
export * from './auxiliary-files';
45
export * from './base64';

0 commit comments

Comments
 (0)