Skip to content

Commit

Permalink
feat: add entropySource to non-evm accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrykLucka committed Feb 25, 2025
1 parent b551e58 commit ccfc68d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
16 changes: 8 additions & 8 deletions ui/components/multichain/account-list-menu/account-list-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,12 @@ export const AccountListMenu = ({
///: BEGIN:ONLY_INCLUDE_IF(build-flask)
const { pathname } = useLocation();
///: END:ONLY_INCLUDE_IF
const [searchQuery, setSearchQuery] = useState('');
const [actionMode, setActionMode] = useState(ACTION_MODES.LIST);
///: BEGIN:ONLY_INCLUDE_IF(multi-srp)
const primaryKeyringId = useSelector(getMetaMaskKeyrings)[0]?.fingerprint;
const [selectedKeyringId, setSelectedKeyringId] = useState(primaryKeyringId);
///: END:ONLY_INCLUDE_IF
const hiddenAddresses = useSelector(getHiddenAccountsList);
const updatedAccountsList = useSelector(getUpdatedAndSortedAccounts);
const filteredUpdatedAccountList = useMemo(
Expand Down Expand Up @@ -300,7 +306,7 @@ export const AccountListMenu = ({
history.push(CONFIRMATION_V_NEXT_ROUTE);
}

await bitcoinWalletSnapClient.createAccount(network);
await bitcoinWalletSnapClient.createAccount(network, selectedKeyringId);
};
///: END:ONLY_INCLUDE_IF

Expand All @@ -310,13 +316,6 @@ export const AccountListMenu = ({
WalletClientType.Solana,
);
///: END:ONLY_INCLUDE_IF
///: BEGIN:ONLY_INCLUDE_IF(multi-srp)
const primaryKeyringId = useSelector(getMetaMaskKeyrings)[0]?.id;
const [selectedKeyringId, setSelectedKeyringId] = useState(primaryKeyringId);
///: END:ONLY_INCLUDE_IF

const [searchQuery, setSearchQuery] = useState('');
const [actionMode, setActionMode] = useState(ACTION_MODES.LIST);

let searchResults: MergedInternalAccount[] = filteredUpdatedAccountList;
if (searchQuery) {
Expand Down Expand Up @@ -561,6 +560,7 @@ export const AccountListMenu = ({

await solanaWalletSnapClient.createAccount(
MultichainNetworks.SOLANA,
selectedKeyringId,
);
}}
data-testid="multichain-account-menu-popover-add-solana-account"
Expand Down
13 changes: 11 additions & 2 deletions ui/hooks/accounts/useMultichainWalletSnapClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,21 @@ describe('useMultichainWalletSnapClient', () => {

mockHandleSnapRequest.mockResolvedValue(mockAccount);

await multichainWalletSnapClient.createAccount(network);
await multichainWalletSnapClient.createAccount(
network,
'test-entropy-source',
);
expect(mockHandleSnapRequest).toHaveBeenCalledWith({
origin: 'metamask',
snapId,
handler: HandlerType.OnKeyringRequest,
request: expect.any(Object),
request: expect.objectContaining({
params: expect.objectContaining({
options: expect.objectContaining({
entropySource: 'test-entropy-source',
}),
}),
}),
});
});

Expand Down
15 changes: 11 additions & 4 deletions ui/hooks/accounts/useMultichainWalletSnapClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,18 @@ export class MultichainWalletSnapClient {
this.#client = new KeyringClient(new MultichainWalletSnapSender(snapId));
}

async createAccount(scope: CaipChainId) {
async createAccount(scope: CaipChainId, entropySource?: string) {
// This will trigger the Snap account creation flow (+ account renaming)
const account = await this.#client.createAccount({
scope,
});
const account = await this.#client.createAccount(
entropySource
? ({
scope,
entropySource,
} as Record<string, string>)
: {
scope,
},
);

// NOTE: The account's balance is going to be tracked automatically on when the new account
// will be added to the Snap bridge keyring (see `MultichainBalancesController:#handleOnAccountAdded`).
Expand Down

0 comments on commit ccfc68d

Please sign in to comment.