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(btc): use new snap account flow for Bitcoin accounts #26183

Merged
merged 3 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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

This file was deleted.

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion ui/components/multichain/create-btc-account/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,12 @@ import { fireEvent, renderWithProvider, waitFor } from '../../../../test/jest';
import configureStore from '../../../store/store';
import mockState from '../../../../test/data/mock-state.json';
import messages from '../../../../app/_locales/en/messages.json';
import { createMockInternalAccount } from '../../../../test/jest/mocks';
import { ETH_EOA_METHODS } from '../../../../shared/constants/eth-methods';
import {
CreateNamedSnapAccount,
CreateNamedSnapAccountProps,
} from './create-named-snap-account';

const mockAddress = '0x3f9658179a5c053bb2faaf7badbb95f6c9be0fa7';
const mockAccount = createMockInternalAccount({
address: mockAddress,
name: 'New account',
});
const mockSnapSuggestedAccountName = 'Suggested Account Name';

jest.mock('../../../store/actions', () => ({
Expand Down Expand Up @@ -61,7 +55,6 @@ const mockSnapAccount2 = {
const render = (
props: CreateNamedSnapAccountProps = {
onActionComplete: jest.fn().mockResolvedValue({ success: true }),
address: mockAccount.address,
snapSuggestedAccountName: mockSnapSuggestedAccountName,
},
) => {
Expand Down Expand Up @@ -105,7 +98,6 @@ describe('CreateNamedSnapAccount', () => {
const onActionComplete = jest.fn();
const { getByText, getByPlaceholderText } = render({
onActionComplete,
address: mockAccount.address,
snapSuggestedAccountName: mockSnapSuggestedAccountName,
});

Expand Down Expand Up @@ -150,7 +142,6 @@ describe('CreateNamedSnapAccount', () => {
const onActionComplete = jest.fn();
const { getByText, getByPlaceholderText } = render({
onActionComplete,
address: mockAccount.address,
});

fireEvent.click(getByText(messages.addAccount.message));
Expand All @@ -170,7 +161,6 @@ describe('CreateNamedSnapAccount', () => {
const onActionComplete = jest.fn();
const { getByText } = render({
onActionComplete,
address: mockAccount.address,
snapSuggestedAccountName: mockSnapSuggestedAccountName,
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import React, { useCallback, useMemo } from 'react';
import React, { useCallback } from 'react';
import { useSelector } from 'react-redux';
import { useHistory } from 'react-router-dom';
import { InternalAccount } from '@metamask/keyring-api';
import { KeyringTypes } from '@metamask/keyring-controller';
import { CreateAccount, CreateBtcAccount } from '..';
import { CreateAccount } from '..';
import { Box, ModalHeader } from '../../component-library';
import { useI18nContext } from '../../../hooks/useI18nContext';
import { getMostRecentOverviewPage } from '../../../ducks/history/history';
import {
isBtcMainnetAddress,
isBtcTestnetAddress,
} from '../../../../shared/lib/multichain';
import { getNextAvailableAccountName } from '../../../store/actions';

export type CreateNamedSnapAccountProps = {
Expand All @@ -22,11 +18,6 @@ export type CreateNamedSnapAccountProps = {
reject?: boolean,
) => Promise<void>;

/**
* Address of the account to create
*/
address: string;

/**
* Suggested account name from the snap
*/
Expand All @@ -35,17 +26,12 @@ export type CreateNamedSnapAccountProps = {

export const CreateNamedSnapAccount: React.FC<CreateNamedSnapAccountProps> = ({
onActionComplete,
address,
snapSuggestedAccountName,
}) => {
const t = useI18nContext();
const history = useHistory();

const mostRecentOverviewPage = useSelector(getMostRecentOverviewPage);
const isBtcAccount = useMemo(
() => isBtcMainnetAddress(address) || isBtcTestnetAddress(address),
[address],
);

const rejectAction = useCallback(async (completed: boolean) => {
await onActionComplete({ success: completed });
Expand Down Expand Up @@ -81,23 +67,13 @@ export const CreateNamedSnapAccount: React.FC<CreateNamedSnapAccountProps> = ({
<ModalHeader padding={4} onClose={onClose}>
{t('addAccountToMetaMask')}
</ModalHeader>
{isBtcAccount ? (
<CreateBtcAccount
// onActionComplete is called when a user rejects the action
// onCreateAccount will call onActionComplete if a user confirms the action
onActionComplete={rejectAction}
onCreateAccount={onCreateAccount}
address={address}
/>
) : (
<CreateAccount
// onActionComplete is called when a user rejects the action
// onCreateAccount will call onActionComplete if a user confirms the action
onActionComplete={rejectAction}
onCreateAccount={onCreateAccount}
getNextAvailableAccountName={getNextAccountName}
/>
)}
<CreateAccount
// onActionComplete is called when a user rejects the action
// onCreateAccount will call onActionComplete if a user confirms the action
onActionComplete={rejectAction}
onCreateAccount={onCreateAccount}
getNextAvailableAccountName={getNextAccountName}
/>
</Box>
);
};
1 change: 0 additions & 1 deletion ui/components/multichain/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export { ProductTour } from './product-tour-popover';
export { AccountDetails } from './account-details';
export { CreateAccount } from './create-account';
export { CreateEthAccount } from './create-eth-account';
export { CreateBtcAccount } from './create-btc-account';
export { ConnectedAccountsMenu } from './connected-accounts-menu';
export { ImportAccount } from './import-account';
export { ImportNftsModal } from './import-nfts-modal';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
*/
function getValues(pendingApproval, t, actions, _history, _data, contexts) {
const { origin: snapId, snapName, requestData } = pendingApproval;
const { address, snapSuggestedAccountName } = requestData;
const { snapSuggestedAccountName } = requestData;
ccharly marked this conversation as resolved.
Show resolved Hide resolved
const { trackEvent } = contexts;

const trackSnapAccountEvent = (event) => {
Expand Down Expand Up @@ -52,7 +52,6 @@ function getValues(pendingApproval, t, actions, _history, _data, contexts) {
key: 'create-named-snap-account',
props: {
onActionComplete,
address,
snapSuggestedAccountName,
},
},
Expand Down