Skip to content

Commit

Permalink
Merge branch 'develop' into rm-enzyme
Browse files Browse the repository at this point in the history
  • Loading branch information
tmashuang authored Nov 8, 2022
2 parents 1cece26 + 02088e4 commit 7b1465b
Show file tree
Hide file tree
Showing 12 changed files with 126 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,7 @@ jobs:

test-e2e-chrome:
executor: node-browsers
parallelism: 8
steps:
- checkout
- run:
Expand Down Expand Up @@ -543,6 +544,7 @@ jobs:

test-e2e-chrome-mv3:
executor: node-browsers
parallelism: 8
steps:
- checkout
- run:
Expand Down Expand Up @@ -570,6 +572,7 @@ jobs:

test-e2e-firefox-snaps:
executor: node-browsers
parallelism: 2
steps:
- checkout
- run:
Expand Down Expand Up @@ -597,6 +600,7 @@ jobs:

test-e2e-chrome-snaps:
executor: node-browsers
parallelism: 2
steps:
- checkout
- run:
Expand Down Expand Up @@ -624,6 +628,7 @@ jobs:

test-e2e-firefox:
executor: node-browsers-medium-plus
parallelism: 8
steps:
- checkout
- run:
Expand Down
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.

12 changes: 12 additions & 0 deletions app/scripts/controllers/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export default class PreferencesController {
? LEDGER_TRANSPORT_TYPES.WEBHID
: LEDGER_TRANSPORT_TYPES.U2F,
theme: 'light',
improvedTokenAllowanceEnabled: false,
...opts.initState,
};

Expand Down Expand Up @@ -187,6 +188,17 @@ export default class PreferencesController {
this.store.updateState({ theme: val });
}

/**
* Setter for the `improvedTokenAllowanceEnabled` property
*
* @param improvedTokenAllowanceEnabled
*/
setImprovedTokenAllowanceEnabled(improvedTokenAllowanceEnabled) {
this.store.updateState({
improvedTokenAllowanceEnabled,
});
}

/**
* Add new methodData to state, to avoid requesting this information again through Infura
*
Expand Down
4 changes: 4 additions & 0 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -1629,6 +1629,10 @@ export default class MetamaskController extends EventEmitter {
preferencesController,
),
setTheme: preferencesController.setTheme.bind(preferencesController),
setImprovedTokenAllowanceEnabled:
preferencesController.setImprovedTokenAllowanceEnabled.bind(
preferencesController,
),
// AssetsContractController
getTokenStandardAndDetails: this.getTokenStandardAndDetails.bind(this),

Expand Down
17 changes: 16 additions & 1 deletion test/e2e/run-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ const getTestPathsForTestDir = async (testDir) => {
return testPaths;
};

function chunk(array, chunkSize) {
const result = [];
for (let i = 0; i < array.length; i += chunkSize) {
result.push(array.slice(i, i + chunkSize));
}
return result;
}

async function main() {
const { argv } = yargs(hideBin(process.argv))
.usage(
Expand Down Expand Up @@ -66,7 +74,14 @@ async function main() {
args.push('--retries', retries);
}

for (const testPath of testPaths) {
// For running E2Es in parallel in CI
const currentChunkIndex = process.env.CIRCLE_NODE_INDEX ?? 0;
const totalChunks = process.env.CIRCLE_NODE_TOTAL ?? 1;
const chunkSize = Math.ceil(testPaths.length / totalChunks);
const chunks = chunk(testPaths, chunkSize);
const currentChunk = chunks[currentChunkIndex];

for (const testPath of currentChunk) {
await runInShell('node', [...args, testPath]);
}
}
Expand Down
7 changes: 7 additions & 0 deletions ui/helpers/constants/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,4 +329,11 @@ export const SETTINGS_CONSTANTS = [
route: `${ADVANCED_ROUTE}#restore-userdata`,
icon: 'fas fa-upload',
},
{
tabMessage: (t) => t('experimental'),
sectionMessage: (t) => t('improvedTokenAllowance'),
descriptionMessage: (t) => t('improvedTokenAllowanceDescription'),
route: `${EXPERIMENTAL_ROUTE}#improved-token-allowance`,
icon: 'fa fa-flask',
},
];
2 changes: 1 addition & 1 deletion ui/helpers/utils/settings-search.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ describe('Settings Search Utils', () => {

it('should get good experimental section number', () => {
expect(getNumberOfSettingsInSection(t, t('experimental'))).toStrictEqual(
1,
2,
);
});

Expand Down
7 changes: 6 additions & 1 deletion ui/pages/confirm-approve/confirm-approve.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
getIsMultiLayerFeeNetwork,
checkNetworkAndAccountSupports1559,
getEIP1559V2Enabled,
getIsImprovedTokenAllowanceEnabled,
} from '../../selectors';
import { useApproveTransaction } from '../../hooks/useApproveTransaction';
import AdvancedGasFeePopover from '../../components/app/advanced-gas-fee-popover';
Expand Down Expand Up @@ -87,6 +88,10 @@ export default function ConfirmApprove({
const eip1559V2Enabled = useSelector(getEIP1559V2Enabled);
const supportsEIP1559V2 = eip1559V2Enabled && networkAndAccountSupports1559;

const improvedTokenAllowanceEnabled = useSelector(
getIsImprovedTokenAllowanceEnabled,
);

const previousTokenAmount = useRef(tokenAmount);
const {
approveTransaction,
Expand Down Expand Up @@ -161,7 +166,7 @@ export default function ConfirmApprove({
if (tokenSymbol === undefined && assetName === undefined) {
return <Loading />;
}
if (process.env.TOKEN_ALLOWANCE_IMPROVEMENTS && assetStandard === ERC20) {
if (improvedTokenAllowanceEnabled && assetStandard === ERC20) {
return (
<GasFeeContextProvider transaction={transaction}>
<TransactionModalContextProvider>
Expand Down
40 changes: 40 additions & 0 deletions ui/pages/settings/experimental-tab/experimental-tab.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export default class ExperimentalTab extends PureComponent {
openSeaEnabled: PropTypes.bool,
eip1559V2Enabled: PropTypes.bool,
setEIP1559V2Enabled: PropTypes.func,
improvedTokenAllowanceEnabled: PropTypes.bool,
setImprovedTokenAllowanceEnabled: PropTypes.func,
};

settingsRefs = Array(
Expand Down Expand Up @@ -190,9 +192,47 @@ export default class ExperimentalTab extends PureComponent {
);
}

renderImprovedTokenAllowanceToggle() {
const { t } = this.context;
const { improvedTokenAllowanceEnabled, setImprovedTokenAllowanceEnabled } =
this.props;

return (
<div ref={this.settingsRefs[1]} className="settings-page__content-row">
<div className="settings-page__content-item">
<span>{t('improvedTokenAllowance')}</span>
<div className="settings-page__content-description">
{t('improvedTokenAllowanceDescription')}
</div>
</div>
<div className="settings-page__content-item">
<div className="settings-page__content-item-col">
<ToggleButton
value={improvedTokenAllowanceEnabled}
onToggle={(value) => {
this.context.trackEvent({
category: EVENT.CATEGORIES.SETTINGS,
event: 'Enabled/Disable ImprovedTokenAllowance',
properties: {
action: 'Enabled/Disable ImprovedTokenAllowance',
legacy_event: true,
},
});
setImprovedTokenAllowanceEnabled(!value);
}}
offLabel={t('off')}
onLabel={t('on')}
/>
</div>
</div>
</div>
);
}

render() {
return (
<div className="settings-page__body">
{this.renderImprovedTokenAllowanceToggle()}
{this.renderOpenSeaEnabledToggle()}
{this.renderCollectibleDetectionToggle()}
{this.renderEIP1559V2EnabledToggle()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import {
setUseCollectibleDetection,
setOpenSeaEnabled,
setEIP1559V2Enabled,
setImprovedTokenAllowanceEnabled,
} from '../../../store/actions';
import {
getUseCollectibleDetection,
getOpenSeaEnabled,
getEIP1559V2Enabled,
getIsImprovedTokenAllowanceEnabled,
} from '../../../selectors';
import ExperimentalTab from './experimental-tab.component';

Expand All @@ -18,6 +20,7 @@ const mapStateToProps = (state) => {
useCollectibleDetection: getUseCollectibleDetection(state),
openSeaEnabled: getOpenSeaEnabled(state),
eip1559V2Enabled: getEIP1559V2Enabled(state),
improvedTokenAllowanceEnabled: getIsImprovedTokenAllowanceEnabled(state),
};
};

Expand All @@ -27,6 +30,8 @@ const mapDispatchToProps = (dispatch) => {
dispatch(setUseCollectibleDetection(val)),
setOpenSeaEnabled: (val) => dispatch(setOpenSeaEnabled(val)),
setEIP1559V2Enabled: (val) => dispatch(setEIP1559V2Enabled(val)),
setImprovedTokenAllowanceEnabled: (val) =>
dispatch(setImprovedTokenAllowanceEnabled(val)),
};
};

Expand Down
10 changes: 10 additions & 0 deletions ui/selectors/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -1254,6 +1254,16 @@ export function getIstokenDetectionInactiveOnNonMainnetSupportedNetwork(state) {
return isDynamicTokenListAvailable && !useTokenDetection && !isMainnet;
}

/**
* To get the `improvedTokenAllowanceEnabled` value which determines whether we use the improved token allowance
*
* @param {*} state
* @returns Boolean
*/
export function getIsImprovedTokenAllowanceEnabled(state) {
return state.metamask.improvedTokenAllowanceEnabled;
}

export function getIsCustomNetwork(state) {
const chainId = getCurrentChainId(state);

Expand Down
14 changes: 14 additions & 0 deletions ui/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3789,6 +3789,20 @@ export function setEnableEIP1559V2NoticeDismissed() {
return submitRequestToBackground('setEnableEIP1559V2NoticeDismissed', [true]);
}

export function setImprovedTokenAllowanceEnabled(
improvedTokenAllowanceEnabled,
) {
return async () => {
try {
await submitRequestToBackground('setImprovedTokenAllowanceEnabled', [
improvedTokenAllowanceEnabled,
]);
} catch (error) {
log.error(error);
}
};
}

export function setFirstTimeUsedNetwork(chainId) {
return submitRequestToBackground('setFirstTimeUsedNetwork', [chainId]);
}
Expand Down

0 comments on commit 7b1465b

Please sign in to comment.