Skip to content

Commit

Permalink
Merge branch 'develop' into 17191/onboarding-unit-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tmashuang authored Feb 3, 2023
2 parents 08f4a0a + 31897b5 commit 4cbf137
Show file tree
Hide file tree
Showing 33 changed files with 1,746 additions and 902 deletions.
1 change: 0 additions & 1 deletion development/states/navigate-txs.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"appState": {
"shouldClose": false,
"menuOpen": false,
"modal": {
"open": false,
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@
"@types/react": "^16.9.53",
"@types/react-dom": "^17.0.11",
"@types/remote-redux-devtools": "^0.5.5",
"@types/w3c-web-hid": "^1.0.3",
"@types/watchify": "^3.11.1",
"@types/yargs": "^17.0.8",
"@typescript-eslint/eslint-plugin": "^5.30.7",
Expand Down
12 changes: 12 additions & 0 deletions types/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// In order for variables to be considered on the global scope they must be
// declared using var and not const or let, which is why this rule is disabled
/* eslint-disable no-var */

declare class Platform {
openTab: (opts: { url: string }) => void;

closeCurrentWindow: () => void;
}
export declare global {
var platform: Platform;
}
28 changes: 19 additions & 9 deletions ui/components/app/approve-content-card/approve-content-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export default function ApproveContentCard({
data,
userAcknowledgedGasMissing,
renderSimulationFailureWarning,
useCurrencyRateCheck,
}) {
const t = useContext(I18nContext);

Expand Down Expand Up @@ -163,15 +164,20 @@ export default function ApproveContentCard({
alignItems={AlignItems.flexEnd}
textAlign={TEXT_ALIGN.RIGHT}
>
<Box>
<Typography
variant={TypographyVariant.H4}
fontWeight={FONT_WEIGHT.BOLD}
color={TextColor.textDefault}
>
{formatCurrency(fiatTransactionTotal, currentCurrency)}
</Typography>
</Box>
{useCurrencyRateCheck && (
<Box>
<Typography
variant={TypographyVariant.H4}
fontWeight={FONT_WEIGHT.BOLD}
color={TextColor.TEXT_DEFAULT}
>
{formatCurrency(
fiatTransactionTotal,
currentCurrency,
)}
</Typography>
</Box>
)}
<Box>
<Typography
variant={TypographyVariant.H6}
Expand Down Expand Up @@ -320,4 +326,8 @@ ApproveContentCard.propTypes = {
* Render simulation failure warning
*/
renderSimulationFailureWarning: PropTypes.bool,
/**
* Fiat conversion control
*/
useCurrencyRateCheck: PropTypes.bool,
};
2 changes: 1 addition & 1 deletion ui/components/app/gas-timing/gas-timing.component.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import mockState from '../../../../test/data/mock-state.json';

import GasTiming from '.';

jest.mock('../../../store/actions.js', () => ({
jest.mock('../../../store/actions.ts', () => ({
getGasFeeTimeEstimate: jest.fn().mockImplementation(() => Promise.resolve()),
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jest.mock('react-router-dom', () => {
};
});

jest.mock('../../../store/actions.js', () => ({
jest.mock('../../../store/actions.ts', () => ({
detectNewTokens: jest.fn(),
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import AccountDetailsModal from '.';

const mockShowModal = jest.fn();

jest.mock('../../../../store/actions.js', () => {
jest.mock('../../../../store/actions.ts', () => {
return {
showModal: () => mockShowModal,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const mockCreateCancelTransaction = jest.fn();
const mockShowModal = jest.fn();
const mockHideModal = jest.fn();

jest.mock('../../../../store/actions.js', () => {
jest.mock('../../../../store/actions.ts', () => {
return {
createCancelTransaction: () => mockCreateCancelTransaction,
showModal: () => mockShowModal,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { renderWithProvider } from '../../../../test/lib/render-helpers';
import mockState from '../../../../test/data/mock-state.json';
import TransactionListItemDetails from '.';

jest.mock('../../../store/actions.js', () => ({
jest.mock('../../../store/actions.ts', () => ({
tryReverseResolveAddress: () => jest.fn(),
getGasFeeEstimatesAndStartPolling: jest.fn().mockResolvedValue(),
addPollingTokenToAppState: jest.fn(),
Expand Down
12 changes: 6 additions & 6 deletions ui/ducks/app/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('App State', () => {
it('opens alert', () => {
const state = reduceApp(metamaskState, {
type: actions.ALERT_OPEN,
value: 'test message',
payload: 'test message',
});

expect(state.alertOpen).toStrictEqual(true);
Expand Down Expand Up @@ -243,7 +243,7 @@ describe('App State', () => {
};
const state = reduceApp(metamaskState, {
type: actions.SET_HARDWARE_WALLET_DEFAULT_HD_PATH,
value: {
payload: {
device: HardwareDeviceNames.ledger,
path: "m/44'/60'/0'",
},
Expand All @@ -255,7 +255,7 @@ describe('App State', () => {
it('shows loading message', () => {
const state = reduceApp(metamaskState, {
type: actions.SHOW_LOADING,
value: 'loading',
payload: 'loading',
});

expect(state.isLoading).toStrictEqual(true);
Expand All @@ -276,7 +276,7 @@ describe('App State', () => {
it('displays warning', () => {
const state = reduceApp(metamaskState, {
type: actions.DISPLAY_WARNING,
value: 'warning',
payload: 'warning',
});

expect(state.isLoading).toStrictEqual(false);
Expand All @@ -296,7 +296,7 @@ describe('App State', () => {
it('shows private key', () => {
const state = reduceApp(metamaskState, {
type: actions.SHOW_PRIVATE_KEY,
value: 'private key',
payload: 'private key',
});

expect(state.accountDetail.privateKey).toStrictEqual('private key');
Expand All @@ -305,7 +305,7 @@ describe('App State', () => {
it('set mouse user state', () => {
const state = reduceApp(metamaskState, {
type: actions.SET_MOUSE_USER_STATE,
value: true,
payload: true,
});

expect(state.isMouseUser).toStrictEqual(true);
Expand Down
49 changes: 12 additions & 37 deletions ui/ducks/app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export default function reduceApp(
return {
...appState,
alertOpen: true,
alertMessage: action.value,
alertMessage: action.payload,
};

case actionConstants.ALERT_CLOSE:
Expand Down Expand Up @@ -263,27 +263,10 @@ export default function reduceApp(
};

case actionConstants.COMPLETED_TX:
if (action.value.unconfirmedActionsCount > 0) {
return {
...appState,
txId: null,
warning: null,
};
}
return {
...appState,
// indicate notification should close
shouldClose: true,
warning: null,
txId: null,
accountDetail: {
subview: 'transactions',
},
};

case actionConstants.TRANSACTION_ERROR:
return {
...appState,
};

case actionConstants.UNLOCK_FAILED:
Expand All @@ -299,7 +282,7 @@ export default function reduceApp(
};

case actionConstants.SET_HARDWARE_WALLET_DEFAULT_HD_PATH: {
const { device, path } = action.value;
const { device, path } = action.payload;
const newDefaults = { ...appState.defaultHdPaths } as any;
newDefaults[device] = path;

Expand All @@ -313,7 +296,7 @@ export default function reduceApp(
return {
...appState,
isLoading: true,
loadingMessage: action.value,
loadingMessage: action.payload,
};

case actionConstants.HIDE_LOADING:
Expand All @@ -325,7 +308,7 @@ export default function reduceApp(
case actionConstants.DISPLAY_WARNING:
return {
...appState,
warning: action.value,
warning: action.payload,
isLoading: false,
};

Expand All @@ -339,46 +322,44 @@ export default function reduceApp(
return {
...appState,
accountDetail: {
subview: 'export',
accountExport: 'completed',
privateKey: action.value,
privateKey: action.payload,
},
};

case actionConstants.SET_MOUSE_USER_STATE:
return {
...appState,
isMouseUser: action.value,
isMouseUser: action.payload,
};

case actionConstants.SET_SELECTED_SETTINGS_RPC_URL:
return {
...appState,
networksTabSelectedRpcUrl: action.value,
networksTabSelectedRpcUrl: action.payload,
};

case actionConstants.SET_NEW_NETWORK_ADDED:
return {
...appState,
newNetworkAdded: action.value,
newNetworkAdded: action.payload,
};

case actionConstants.SET_NEW_TOKENS_IMPORTED:
return {
...appState,
newTokensImported: action.value,
newTokensImported: action.payload,
};

case actionConstants.SET_NEW_COLLECTIBLE_ADDED_MESSAGE:
return {
...appState,
newCollectibleAddedMessage: action.value,
newCollectibleAddedMessage: action.payload,
};

case actionConstants.SET_REMOVE_COLLECTIBLE_MESSAGE:
return {
...appState,
removeCollectibleMessage: action.value,
removeCollectibleMessage: action.payload,
};

case actionConstants.PORTFOLIO_TOOLTIP_WAS_SHOWN_IN_THIS_SESSION:
Expand All @@ -396,13 +377,7 @@ export default function reduceApp(
case actionConstants.SET_OPEN_METAMASK_TAB_IDS:
return {
...appState,
openMetaMaskTabs: action.value,
};

case actionConstants.SET_CURRENT_WINDOW_TAB:
return {
...appState,
currentWindowTab: action.value,
openMetaMaskTabs: action.payload,
};

case actionConstants.HIDE_WHATS_NEW_POPUP:
Expand Down
6 changes: 3 additions & 3 deletions ui/ducks/locale/locale.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import * as actionConstants from '../../store/actionConstants';

export default function reduceLocaleMessages(state = {}, { type, value }) {
export default function reduceLocaleMessages(state = {}, { type, payload }) {
switch (type) {
case actionConstants.SET_CURRENT_LOCALE:
return {
...state,
current: value.messages,
currentLocale: value.locale,
current: payload.messages,
currentLocale: payload.locale,
};
default:
return state;
Expand Down
2 changes: 1 addition & 1 deletion ui/ducks/metamask/metamask.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export default function reduceMetamask(state = initialState, action) {
case actionConstants.SET_NEXT_NONCE: {
return {
...metamaskState,
nextNonce: action.value,
nextNonce: action.payload,
};
}

Expand Down
2 changes: 2 additions & 0 deletions ui/ducks/send/send.js
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,8 @@ export const computeEstimatedGasLimit = createAsyncThunk(
* the send slice. It returns the values that might change from this action and
* those values are written to the slice in the `initializeSendState.fulfilled`
* action handler.
*
* @type {import('@reduxjs/toolkit').AsyncThunk<any, { chainHasChanged: boolean }, {}>}
*/
export const initializeSendState = createAsyncThunk(
'send/initializeSendState',
Expand Down
4 changes: 2 additions & 2 deletions ui/ducks/send/send.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2308,7 +2308,7 @@ describe('Send Slice', () => {
},
};

jest.mock('../../store/actions.js');
jest.mock('../../store/actions.ts');

const store = mockStore(tokenTransferTxState);

Expand Down Expand Up @@ -2345,7 +2345,7 @@ describe('Send Slice', () => {
},
};

jest.mock('../../store/actions.js');
jest.mock('../../store/actions.ts');

const store = mockStore(editStageSignTxState);

Expand Down
2 changes: 1 addition & 1 deletion ui/ducks/swaps/swaps.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import swapsReducer, * as swaps from './swaps';

const middleware = [thunk];

jest.mock('../../store/actions.js', () => ({
jest.mock('../../store/actions.ts', () => ({
setSwapsLiveness: jest.fn(),
setSwapsFeatureFlags: jest.fn(),
fetchSmartTransactionsLiveness: jest.fn(),
Expand Down
4 changes: 2 additions & 2 deletions ui/helpers/utils/tx-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export default function txHelper(
decryptMsgs: Record<string, any> | null,
encryptionPublicKeyMsgs: Record<string, any> | null,
typedMessages: Record<string, any> | null,
network: string,
chainId: string,
network?: string,
chainId?: string,
): Record<string, any> {
log.debug('tx-helper called with params:');
log.debug({
Expand Down
Loading

0 comments on commit 4cbf137

Please sign in to comment.