Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add entropySource to non-evm accounts #30549

Draft
wants to merge 1 commit into
base: multi-srp-mvp-2
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading