Skip to content

Commit e7f4d24

Browse files
authored
feat: support bitcoin (#15263)
## **Description** Bump Bitcoin Snap version. [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/32471?quickstart=1) ## **Related issues** Fixes: https://consensyssoftware.atlassian.net/browse/NNT-338 ## **Manual testing steps** 1. Install MM Flask 2. Create Bitcoin account ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.
1 parent 905030c commit e7f4d24

File tree

4 files changed

+44
-5
lines changed

4 files changed

+44
-5
lines changed

app/core/SnapKeyring/MultichainWalletSnapClient.test.ts

+28
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import Engine from '../Engine';
1111
import { Sender } from '@metamask/keyring-snap-client';
1212
import { SnapKeyring } from '@metamask/eth-snap-keyring';
1313
import { BtcScope, SolScope } from '@metamask/keyring-api';
14+
import { BITCOIN_WALLET_SNAP_ID } from './BitcoinWalletSnap';
1415

1516
jest.mock('../Engine', () => ({
1617
controllerMessenger: {
@@ -292,6 +293,33 @@ describe('Wallet Client Implementations', () => {
292293
const bitcoinClient = new BitcoinWalletSnapClient(mockSnapKeyringOptions);
293294
expect(bitcoinClient.getScope()).toEqual(BtcScope.Mainnet);
294295
});
296+
297+
it('adds synchronize parameter to createAccount', async () => {
298+
const mockOptions = {
299+
scope: BtcScope.Mainnet,
300+
accountNameSuggestion: 'Bitcoin Account 1',
301+
entropySource: 'test-entropy',
302+
};
303+
304+
const mockKeyring = {
305+
createAccount: jest.fn(),
306+
};
307+
308+
(Engine.controllerMessenger.call as jest.Mock).mockImplementationOnce(
309+
async (_, __, callback) => {
310+
await callback({ keyring: mockKeyring });
311+
},
312+
);
313+
314+
const bitcoinClient = new BitcoinWalletSnapClient(mockSnapKeyringOptions);
315+
await bitcoinClient.createAccount(mockOptions);
316+
317+
expect(mockKeyring.createAccount).toHaveBeenCalledWith(
318+
BITCOIN_WALLET_SNAP_ID,
319+
{ ...mockOptions, synchronize: true },
320+
mockSnapKeyringOptions,
321+
);
322+
});
295323
});
296324

297325
describe('SolanaWalletSnapClient', () => {

app/core/SnapKeyring/MultichainWalletSnapClient.ts

+11
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export const WALLET_SNAP_MAP = {
3838

3939
export interface MultichainWalletSnapOptions {
4040
scope: CaipChainId;
41+
synchronize?: boolean;
4142
///: BEGIN:ONLY_INCLUDE_IF(multi-srp)
4243
entropySource?: string;
4344
accountNameSuggestion?: string;
@@ -253,6 +254,16 @@ export class BitcoinWalletSnapClient extends MultichainWalletSnapClient {
253254
protected getSnapSender(): Sender {
254255
return new BitcoinWalletSnapSender();
255256
}
257+
258+
async createAccount(
259+
options: MultichainWalletSnapOptions,
260+
snapKeyringOptions?: SnapKeyringOptions,
261+
) {
262+
return super.createAccount(
263+
{ ...options, synchronize: true },
264+
snapKeyringOptions,
265+
);
266+
}
256267
}
257268

258269
export class SolanaWalletSnapClient extends MultichainWalletSnapClient {

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@
165165
"@metamask/approval-controller": "^7.1.3",
166166
"@metamask/assets-controllers": "^61.0.0",
167167
"@metamask/base-controller": "^8.0.0",
168-
"@metamask/bitcoin-wallet-snap": "^0.9.0",
168+
"@metamask/bitcoin-wallet-snap": "^0.12.1",
169169
"@metamask/bridge-controller": "^21.0.0",
170170
"@metamask/bridge-status-controller": "^18.0.0",
171171
"@metamask/chain-agnostic-permission": "^0.3.0",

yarn.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -4765,10 +4765,10 @@
47654765
"@metamask/utils" "^11.2.0"
47664766
immer "^9.0.6"
47674767

4768-
"@metamask/bitcoin-wallet-snap@^0.9.0":
4769-
version "0.9.0"
4770-
resolved "https://registry.yarnpkg.com/@metamask/bitcoin-wallet-snap/-/bitcoin-wallet-snap-0.9.0.tgz#47014c75c1e1ed84fef57177901f458fd2b6510a"
4771-
integrity sha512-983twhfOfSCQljT+eV8JLcV0bqGVMObXnEy8TOFAkwwRW2I1ZsVRAfylbGiSwxlhxLntcpLqVu0Sj29xNyA06Q==
4768+
"@metamask/bitcoin-wallet-snap@^0.12.1":
4769+
version "0.12.1"
4770+
resolved "https://registry.yarnpkg.com/@metamask/bitcoin-wallet-snap/-/bitcoin-wallet-snap-0.12.1.tgz#2b60ac613992e97302a9898b3d4030395b2b2123"
4771+
integrity sha512-8gsN7a5OyRMg6c0jw0tDrqePHjFv9uHi36eL2PdTMUYU9J3dL/t9cOWe/3RPSwu7tw/tMNXyM4mzwZvq7Kxs2Q==
47724772

47734773
"@metamask/bridge-controller@^21.0.0":
47744774
version "21.0.0"

0 commit comments

Comments
 (0)