Skip to content

Commit ac94cb6

Browse files
committed
move function to snap-utils and add JSDocs
1 parent b1ab222 commit ac94cb6

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
@@ -456,14 +456,24 @@ export class SnapInterfaceController extends BaseController<
456456
);
457457
}
458458

459+
/**
460+
* Get the selected account in the client.
461+
*
462+
* @returns The selected account.
463+
*/
459464
#getSelectedAccount() {
460465
return this.messagingSystem.call(
461466
'AccountsController:getSelectedMultichainAccount',
462467
);
463468
}
464469

470+
/**
471+
* Set the selected account in the client.
472+
*
473+
* @param accountId - The account id.
474+
*/
465475
#setSelectedAccount(accountId: string) {
466-
return this.messagingSystem.call(
476+
this.messagingSystem.call(
467477
'AccountsController:setSelectedAccount',
468478
accountId,
469479
);

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)