Skip to content
35 changes: 3 additions & 32 deletions app/actions/multiSrp/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import { KeyringTypes } from '@metamask/keyring-controller';
import ExtendedKeyringTypes from '../../constants/keyringTypes';
import Engine from '../../core/Engine';
import {
importNewSecretRecoveryPhrase,
createNewSecretRecoveryPhrase,
addNewHdAccount,
} from './';
import { importNewSecretRecoveryPhrase, addNewHdAccount } from './';
import { createMockInternalAccount } from '../../util/test/accountsControllerTestUtils';
import { TraceName, TraceOperation } from '../../util/trace';
import ReduxService from '../../core/redux/ReduxService';
Expand Down Expand Up @@ -103,6 +99,8 @@ jest.mock('../../core/Engine', () => ({
getKeyringsByType: () => mockGetKeyringsByType(),
withKeyring: (_selector: unknown, operation: (args: unknown) => void) =>
operation({ keyring: hdKeyring, metadata: { id: '1234' } }),
withKeyringV2: (_selector: unknown, operation: (args: unknown) => void) =>
operation({ keyring: hdKeyring, metadata: { id: '1234' } }),
},
AccountsController: {
getNextAvailableAccountName: jest.fn().mockReturnValue('Snap Account 1'),
Expand Down Expand Up @@ -474,33 +472,6 @@ describe('MultiSRP Actions', () => {
});
});

describe('createNewSecretRecoveryPhrase', () => {
it('creates new SRP', async () => {
mockAddNewKeyring.mockResolvedValue({
getAccounts: () => Promise.resolve([mockAddress]),
});

await createNewSecretRecoveryPhrase();

expect(mockAddNewKeyring).toHaveBeenCalledWith(
KeyringTypes.hd,
undefined,
);
expect(mockSetSelectedAddress).toHaveBeenCalledWith(mockAddress);
});

it('Does not set selected address or gets accounts on errors', async () => {
mockAddNewKeyring.mockRejectedValue(new Error('Test error'));

await expect(
async () => await createNewSecretRecoveryPhrase(),
).rejects.toThrow('Test error');

expect(mockGetAccounts).not.toHaveBeenCalled();
expect(mockSetSelectedAddress).not.toHaveBeenCalled();
});
});

describe('addNewHdAccount', () => {
it('adds a new HD account, sets the selected address and returns the account', async () => {
mockAddAccounts.mockReturnValue([mockAddress]);
Expand Down
18 changes: 1 addition & 17 deletions app/actions/multiSrp/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export async function importNewSecretRecoveryPhrase(
});
const entropySource = wallet.entropySource;

const [newAccountAddress] = await KeyringController.withKeyring(
const [newAccountAddress] = await KeyringController.withKeyringV2(
Comment thread
hmalik88 marked this conversation as resolved.
Outdated
{
id: entropySource,
},
Expand Down Expand Up @@ -143,22 +143,6 @@ export async function importNewSecretRecoveryPhrase(
return { address: newAccountAddress, discoveredAccountsCount };
}

export async function createNewSecretRecoveryPhrase() {
const { KeyringController } = Engine.context;
const newHdkeyring = await KeyringController.addNewKeyring(
ExtendedKeyringTypes.hd,
);

const [newAccountAddress] = await KeyringController.withKeyring(
{
id: newHdkeyring.id,
},
async ({ keyring }) => keyring.getAccounts(),
);

return Engine.setSelectedAddress(newAccountAddress);
}

export async function addNewHdAccount(
keyringId?: string,
name?: string,
Expand Down
2 changes: 1 addition & 1 deletion app/core/Authentication/Authentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1121,7 +1121,7 @@ class AuthenticationService {
);
const entropySource = wallet.entropySource;

const [newAccountAddress] = await KeyringController.withKeyring(
const [newAccountAddress] = await KeyringController.withKeyringV2(
Comment thread
hmalik88 marked this conversation as resolved.
Outdated
{ id: entropySource },
async ({ keyring }) => keyring.getAccounts(),
);
Expand Down
Loading