Skip to content

Commit

Permalink
responding to Monte's review
Browse files Browse the repository at this point in the history
  • Loading branch information
HowardBraham committed Feb 16, 2023
1 parent c359e8f commit 36be5bc
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 25 deletions.
6 changes: 6 additions & 0 deletions app/_locales/en/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 20 additions & 19 deletions ui/pages/create-account/import-account/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ export default function NewAccountImportForm() {
const [type, setType] = useState(menuItems[0]);

function importAccount(strategy, importArgs) {
dispatch(actions.importNewAccount(strategy, importArgs))
const loadingMessage = getLoadingMessage(strategy);

dispatch(actions.importNewAccount(strategy, importArgs, loadingMessage))
.then(({ selectedAddress }) => {
if (selectedAddress) {
trackImportEvent(strategy, true);
Expand Down Expand Up @@ -67,6 +69,22 @@ export default function NewAccountImportForm() {
});
}

function getLoadingMessage(strategy) {
if (strategy === 'JSON File') {
return (
<Text width={BLOCK_SIZES.THREE_FOURTHS} fontWeight={FONT_WEIGHT.BOLD}>
<br />
{t('importAccountJsonLoading1')}
<br />
<br />
{t('importAccountJsonLoading2')}
</Text>
);
}

return '';
}

/**
* @param {string} message - an Error/Warning message caught in importAccount()
* This function receives a message that is a string like:
Expand All @@ -92,9 +110,8 @@ export default function NewAccountImportForm() {
case menuItems[0]:
return <PrivateKeyImportView importAccountFunc={importAccount} />;
case menuItems[1]:
return <JsonImportView importAccountFunc={importAccount} />;
default:
return null;
return <JsonImportView importAccountFunc={importAccount} />;
}
}

Expand Down Expand Up @@ -141,19 +158,3 @@ export function moreInfoLink() {
url: ZENDESK_URLS.IMPORTED_ACCOUNTS,
});
}

export function getLoadingMessage(strategy) {
if (strategy === 'JSON File') {
return (
<Text width={BLOCK_SIZES.THREE_FOURTHS} fontWeight={FONT_WEIGHT.BOLD}>
<br />
Expect this JSON import to take a few minutes and freeze MetaMask.
<br />
<br />
We apologize, and we will make it faster in the future.
</Text>
);
}

return '';
}
10 changes: 6 additions & 4 deletions ui/store/actions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,11 @@ describe('Actions', () => {
_setBackgroundConnection(background);

await store.dispatch(
actions.importNewAccount('Private Key', [
'c87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3',
]),
actions.importNewAccount(
'Private Key',
['c87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3'],
'',
),
);
expect(importAccountWithStrategy.callCount).toStrictEqual(1);
});
Expand All @@ -369,7 +371,7 @@ describe('Actions', () => {
const expectedActions = [
{
type: 'SHOW_LOADING_INDICATION',
payload: '',
payload: undefined,
},
{ type: 'HIDE_LOADING_INDICATION' },
];
Expand Down
4 changes: 2 additions & 2 deletions ui/store/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ import { TransactionMeta } from '../../app/scripts/controllers/incoming-transact
import { TxParams } from '../../app/scripts/controllers/transactions/tx-state-manager';
import { CustomGasSettings } from '../../app/scripts/controllers/transactions';
import { ThemeType } from '../../shared/constants/preferences';
import { getLoadingMessage } from '../pages/create-account/import-account';
import * as actionConstants from './actionConstants';
import {
generateActionId,
Expand Down Expand Up @@ -405,6 +404,7 @@ export function removeAccount(
export function importNewAccount(
strategy: string,
args: any[],
loadingMessage: ReactFragment,
): ThunkAction<
Promise<MetaMaskReduxState['metamask']>,
MetaMaskReduxState,
Expand All @@ -414,7 +414,7 @@ export function importNewAccount(
return async (dispatch: MetaMaskReduxDispatch) => {
let newState;

dispatch(showLoadingIndication(getLoadingMessage(strategy)));
dispatch(showLoadingIndication(loadingMessage));

try {
log.debug(`background.importAccountWithStrategy`);
Expand Down

0 comments on commit 36be5bc

Please sign in to comment.