diff --git a/app/scripts/lib/snap-keyring/snap-keyring.test.ts b/app/scripts/lib/snap-keyring/snap-keyring.test.ts index 62b0c9a991a2..bfa8e124d3f0 100644 --- a/app/scripts/lib/snap-keyring/snap-keyring.test.ts +++ b/app/scripts/lib/snap-keyring/snap-keyring.test.ts @@ -171,7 +171,6 @@ describe('Snap Keyring Methods', () => { await showAccountNameSuggestionDialog( mockSnapId, - mockAccount.address, controllerMessenger, accountNameSuggestion, ); @@ -182,7 +181,6 @@ describe('Snap Keyring Methods', () => { origin: mockSnapId, type: SNAP_MANAGE_ACCOUNTS_CONFIRMATION_TYPES.showNameSnapAccount, requestData: { - address: mockAccount.address, snapSuggestedAccountName: accountNameSuggestion, }, }, @@ -229,7 +227,6 @@ describe('Snap Keyring Methods', () => { origin: mockSnapId, type: SNAP_MANAGE_ACCOUNTS_CONFIRMATION_TYPES.showNameSnapAccount, requestData: { - address: mockInternalAccount.address.toLowerCase(), snapSuggestedAccountName: '', }, }, @@ -294,7 +291,6 @@ describe('Snap Keyring Methods', () => { origin: mockSnapId, type: SNAP_MANAGE_ACCOUNTS_CONFIRMATION_TYPES.showNameSnapAccount, requestData: { - address: mockInternalAccount.address.toLowerCase(), // No user defined name snapSuggestedAccountName: '', }, @@ -355,7 +351,6 @@ describe('Snap Keyring Methods', () => { origin: mockSnapId, type: SNAP_MANAGE_ACCOUNTS_CONFIRMATION_TYPES.showNameSnapAccount, requestData: { - address: mockInternalAccount.address.toLowerCase(), snapSuggestedAccountName: mockNameSuggestion, }, }, @@ -428,7 +423,6 @@ describe('Snap Keyring Methods', () => { origin: mockSnapId, type: SNAP_MANAGE_ACCOUNTS_CONFIRMATION_TYPES.showNameSnapAccount, requestData: { - address: mockInternalAccount.address.toLowerCase(), snapSuggestedAccountName: mockNameSuggestion, }, }, @@ -492,7 +486,6 @@ describe('Snap Keyring Methods', () => { origin: mockSnapId, type: SNAP_MANAGE_ACCOUNTS_CONFIRMATION_TYPES.showNameSnapAccount, requestData: { - address: mockInternalAccount.address.toLowerCase(), snapSuggestedAccountName: mockNameSuggestion, }, }, diff --git a/app/scripts/lib/snap-keyring/snap-keyring.ts b/app/scripts/lib/snap-keyring/snap-keyring.ts index 6471fbe477b6..d707b0bb61c4 100644 --- a/app/scripts/lib/snap-keyring/snap-keyring.ts +++ b/app/scripts/lib/snap-keyring/snap-keyring.ts @@ -65,14 +65,12 @@ export async function showAccountCreationDialog( * Show the account name suggestion confirmation dialog for a given Snap. * * @param snapId - Snap ID to show the account name suggestion dialog for. - * @param address - The address of the new account. * @param controllerMessenger - The controller messenger instance. * @param accountNameSuggestion - Suggested name for the new account. * @returns The user's confirmation result. */ export async function showAccountNameSuggestionDialog( snapId: string, - address: string, controllerMessenger: SnapKeyringBuilderMessenger, accountNameSuggestion: string, ): Promise<{ success: boolean; name?: string }> { @@ -83,7 +81,6 @@ export async function showAccountNameSuggestionDialog( origin: snapId, type: SNAP_MANAGE_ACCOUNTS_CONFIRMATION_TYPES.showNameSnapAccount, requestData: { - address, snapSuggestedAccountName: accountNameSuggestion, }, }, @@ -227,7 +224,6 @@ export const snapKeyringBuilder = ( const accountNameConfirmationResult = await showAccountNameSuggestionDialog( snapId, - address, controllerMessenger, accountNameSuggestion, ); diff --git a/ui/components/multichain/create-btc-account/create-btc-account.stories.js b/ui/components/multichain/create-btc-account/create-btc-account.stories.js deleted file mode 100644 index 15f93f16ce26..000000000000 --- a/ui/components/multichain/create-btc-account/create-btc-account.stories.js +++ /dev/null @@ -1,15 +0,0 @@ -import React from 'react'; -import { MultichainNetworks } from '../../../../shared/constants/multichain/networks'; -import { CreateBtcAccount } from '.'; - -export default { - title: 'Components/Multichain/CreateBtcAccount', - component: CreateBtcAccount, - args: { - defaultAccountName: 'Bitcoin Account', - network: MultichainNetworks.BITCOIN, - }, -}; - -export const DefaultStory = (args) => ; -DefaultStory.storyName = 'Default'; diff --git a/ui/components/multichain/create-btc-account/create-btc-account.test.tsx b/ui/components/multichain/create-btc-account/create-btc-account.test.tsx deleted file mode 100644 index efc845b44469..000000000000 --- a/ui/components/multichain/create-btc-account/create-btc-account.test.tsx +++ /dev/null @@ -1,120 +0,0 @@ -/* eslint-disable jest/require-top-level-describe */ -import React from 'react'; -import { JsonRpcRequest } from '@metamask/utils'; -import { BtcAccountType, BtcMethod } from '@metamask/keyring-api'; -import messages from '../../../../app/_locales/en/messages.json'; -import { fireEvent, renderWithProvider, waitFor } from '../../../../test/jest'; -import configureStore from '../../../store/store'; -import mockState from '../../../../test/data/mock-state.json'; -import { MultichainNetworks } from '../../../../shared/constants/multichain/networks'; -import { CreateBtcAccount } from '.'; - -const ACCOUNT_NAME = 'Bitcoin Account'; - -const mockBtcAccount = { - type: BtcAccountType.P2wpkh, - id: '8a323a0b-9ff5-4ab6-95e0-d51ec7e09763', - address: 'bc1qwl8399fz829uqvqly9tcatgrgtwp3udnhxfq4k', - options: { - scope: MultichainNetworks.BITCOIN, - index: 0, - }, - methods: [BtcMethod.SendMany], -}; -const render = ( - props = { onActionComplete: jest.fn(), onCreateAccount: jest.fn() }, -) => { - const store = configureStore(mockState); - return renderWithProvider( - , - store, - ); -}; - -const mockBitcoinWalletSnapSend = jest.fn().mockReturnValue(mockBtcAccount); -const mockSetAccountLabel = jest.fn().mockReturnValue({ type: 'TYPE' }); - -jest.mock('../../../store/actions', () => ({ - forceUpdateMetamaskState: jest.fn(), - setAccountLabel: (address: string, label: string) => - mockSetAccountLabel(address, label), -})); - -jest.mock( - '../../../../app/scripts/lib/snap-keyring/bitcoin-wallet-snap', - () => ({ - BitcoinWalletSnapSender: jest.fn().mockImplementation(() => { - return { - send: (_request: JsonRpcRequest) => { - return mockBitcoinWalletSnapSend(); - }, - }; - }), - }), -); - -describe('CreateBtcAccount', () => { - afterEach(() => { - jest.clearAllMocks(); - }); - - it('displays account name input and suggests name', async () => { - const { getByPlaceholderText } = render(); - - await waitFor(() => - expect(getByPlaceholderText(ACCOUNT_NAME)).toBeInTheDocument(), - ); - }); - - it('fires onActionComplete when "Cancel" has been clicked', async () => { - const onActionComplete = jest.fn(); - const { getByText, getByPlaceholderText } = render({ - onActionComplete, - onCreateAccount: jest.fn(), - }); - - const input = await waitFor(() => getByPlaceholderText(ACCOUNT_NAME)); - const newAccountName = 'New Account Name'; - - fireEvent.change(input, { - target: { value: newAccountName }, - }); - fireEvent.click(getByText(messages.cancel.message)); - await waitFor(() => expect(onActionComplete).toHaveBeenCalled()); - }); - - it('fires onCreateAccount when "Add Account" has been clicked', async () => { - const onCreateAccount = jest.fn(); - const { getByText, getByPlaceholderText } = render({ - onActionComplete: jest.fn(), - onCreateAccount, - }); - - const input = await waitFor(() => getByPlaceholderText(ACCOUNT_NAME)); - const newAccountName = 'New Account Name'; - - fireEvent.change(input, { - target: { value: newAccountName }, - }); - fireEvent.click(getByText(messages.addAccount.message)); - - await waitFor(() => expect(onCreateAccount).toHaveBeenCalled()); - }); - - it(`doesn't allow duplicate account names`, async () => { - const { getByText, getByPlaceholderText } = render(); - - const input = await waitFor(() => getByPlaceholderText(ACCOUNT_NAME)); - const usedAccountName = - mockState.metamask.internalAccounts.accounts[ - '07c2cfec-36c9-46c4-8115-3836d3ac9047' - ].metadata.name; - - fireEvent.change(input, { - target: { value: usedAccountName }, - }); - - const submitButton = getByText(messages.addAccount.message); - expect(submitButton).toHaveAttribute('disabled'); - }); -}); diff --git a/ui/components/multichain/create-btc-account/create-btc-account.tsx b/ui/components/multichain/create-btc-account/create-btc-account.tsx deleted file mode 100644 index 9408841d36df..000000000000 --- a/ui/components/multichain/create-btc-account/create-btc-account.tsx +++ /dev/null @@ -1,42 +0,0 @@ -// TODO: remove when snap suggests account name during account creation event -import React from 'react'; -import { InternalAccount } from '@metamask/keyring-api'; -import { CreateAccount } from '..'; -import { isBtcTestnetAddress } from '../../../../shared/lib/multichain'; - -type CreateBtcAccountOptions = { - /** - * Callback called once the account has been created - */ - onActionComplete: (completed: boolean) => Promise; - /** - * Callback to create the account. - */ - onCreateAccount: (name: string) => Promise; - /** - * Address of the new account - */ - address: string; -}; - -export const CreateBtcAccount = ({ - onActionComplete, - onCreateAccount, - address, -}: CreateBtcAccountOptions) => { - const getNextAvailableAccountName = async (_accounts: InternalAccount[]) => { - if (isBtcTestnetAddress(address)) { - return 'Bitcoin Testnet Account'; - } - - return 'Bitcoin Account'; - }; - - return ( - - ); -}; diff --git a/ui/components/multichain/create-btc-account/index.ts b/ui/components/multichain/create-btc-account/index.ts deleted file mode 100644 index 99f761103277..000000000000 --- a/ui/components/multichain/create-btc-account/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { CreateBtcAccount } from './create-btc-account'; diff --git a/ui/components/multichain/create-named-snap-account/create-named-snap-account.test.tsx b/ui/components/multichain/create-named-snap-account/create-named-snap-account.test.tsx index 7007fb0529af..95b1cd4a971b 100644 --- a/ui/components/multichain/create-named-snap-account/create-named-snap-account.test.tsx +++ b/ui/components/multichain/create-named-snap-account/create-named-snap-account.test.tsx @@ -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', () => ({ @@ -61,7 +55,6 @@ const mockSnapAccount2 = { const render = ( props: CreateNamedSnapAccountProps = { onActionComplete: jest.fn().mockResolvedValue({ success: true }), - address: mockAccount.address, snapSuggestedAccountName: mockSnapSuggestedAccountName, }, ) => { @@ -105,7 +98,6 @@ describe('CreateNamedSnapAccount', () => { const onActionComplete = jest.fn(); const { getByText, getByPlaceholderText } = render({ onActionComplete, - address: mockAccount.address, snapSuggestedAccountName: mockSnapSuggestedAccountName, }); @@ -150,7 +142,6 @@ describe('CreateNamedSnapAccount', () => { const onActionComplete = jest.fn(); const { getByText, getByPlaceholderText } = render({ onActionComplete, - address: mockAccount.address, }); fireEvent.click(getByText(messages.addAccount.message)); @@ -170,7 +161,6 @@ describe('CreateNamedSnapAccount', () => { const onActionComplete = jest.fn(); const { getByText } = render({ onActionComplete, - address: mockAccount.address, snapSuggestedAccountName: mockSnapSuggestedAccountName, }); diff --git a/ui/components/multichain/create-named-snap-account/create-named-snap-account.tsx b/ui/components/multichain/create-named-snap-account/create-named-snap-account.tsx index 2004bcd9f3da..99a0ff7f457a 100644 --- a/ui/components/multichain/create-named-snap-account/create-named-snap-account.tsx +++ b/ui/components/multichain/create-named-snap-account/create-named-snap-account.tsx @@ -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 = { @@ -22,11 +18,6 @@ export type CreateNamedSnapAccountProps = { reject?: boolean, ) => Promise; - /** - * Address of the account to create - */ - address: string; - /** * Suggested account name from the snap */ @@ -35,17 +26,12 @@ export type CreateNamedSnapAccountProps = { export const CreateNamedSnapAccount: React.FC = ({ 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 }); @@ -81,23 +67,13 @@ export const CreateNamedSnapAccount: React.FC = ({ {t('addAccountToMetaMask')} - {isBtcAccount ? ( - - ) : ( - - )} + ); }; diff --git a/ui/components/multichain/index.js b/ui/components/multichain/index.js index 2c606081c861..4f4ca9468bac 100644 --- a/ui/components/multichain/index.js +++ b/ui/components/multichain/index.js @@ -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'; diff --git a/ui/pages/confirmations/confirmation/templates/create-named-snap-account.js b/ui/pages/confirmations/confirmation/templates/create-named-snap-account.js index 2aa7bc6adfcf..0b2b4aefbf40 100644 --- a/ui/pages/confirmations/confirmation/templates/create-named-snap-account.js +++ b/ui/pages/confirmations/confirmation/templates/create-named-snap-account.js @@ -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; const { trackEvent } = contexts; const trackSnapAccountEvent = (event) => { @@ -52,7 +52,6 @@ function getValues(pendingApproval, t, actions, _history, _data, contexts) { key: 'create-named-snap-account', props: { onActionComplete, - address, snapSuggestedAccountName, }, },