Add improved token allowance experience toggle (#16291)

feature/default_network_editable
Filip Sekulic 2 years ago committed by GitHub
parent e7d6684aa7
commit f3efe5a0bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      app/_locales/en/messages.json
  2. 12
      app/scripts/controllers/preferences.js
  3. 4
      app/scripts/metamask-controller.js
  4. 7
      ui/helpers/constants/settings.js
  5. 2
      ui/helpers/utils/settings-search.test.js
  6. 7
      ui/pages/confirm-approve/confirm-approve.js
  7. 40
      ui/pages/settings/experimental-tab/experimental-tab.component.js
  8. 5
      ui/pages/settings/experimental-tab/experimental-tab.container.js
  9. 10
      ui/selectors/selectors.js
  10. 14
      ui/store/actions.js

@ -1685,6 +1685,12 @@
"message": "Imported", "message": "Imported",
"description": "status showing that an account has been fully loaded into the keyring" "description": "status showing that an account has been fully loaded into the keyring"
}, },
"improvedTokenAllowance": {
"message": "Improved token allowance experience"
},
"improvedTokenAllowanceDescription": {
"message": "Turn this on to go through the improved token allowance experience whenever a dapp requests an ERC20 approve"
},
"inYourSettings": { "inYourSettings": {
"message": "in your Settings" "message": "in your Settings"
}, },

@ -69,6 +69,7 @@ export default class PreferencesController {
? LEDGER_TRANSPORT_TYPES.WEBHID ? LEDGER_TRANSPORT_TYPES.WEBHID
: LEDGER_TRANSPORT_TYPES.U2F, : LEDGER_TRANSPORT_TYPES.U2F,
theme: 'light', theme: 'light',
improvedTokenAllowanceEnabled: false,
...opts.initState, ...opts.initState,
}; };
@ -187,6 +188,17 @@ export default class PreferencesController {
this.store.updateState({ theme: val }); 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 * Add new methodData to state, to avoid requesting this information again through Infura
* *

@ -1629,6 +1629,10 @@ export default class MetamaskController extends EventEmitter {
preferencesController, preferencesController,
), ),
setTheme: preferencesController.setTheme.bind(preferencesController), setTheme: preferencesController.setTheme.bind(preferencesController),
setImprovedTokenAllowanceEnabled:
preferencesController.setImprovedTokenAllowanceEnabled.bind(
preferencesController,
),
// AssetsContractController // AssetsContractController
getTokenStandardAndDetails: this.getTokenStandardAndDetails.bind(this), getTokenStandardAndDetails: this.getTokenStandardAndDetails.bind(this),

@ -329,4 +329,11 @@ export const SETTINGS_CONSTANTS = [
route: `${ADVANCED_ROUTE}#restore-userdata`, route: `${ADVANCED_ROUTE}#restore-userdata`,
icon: 'fas fa-upload', 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',
},
]; ];

@ -182,7 +182,7 @@ describe('Settings Search Utils', () => {
it('should get good experimental section number', () => { it('should get good experimental section number', () => {
expect(getNumberOfSettingsInSection(t, t('experimental'))).toStrictEqual( expect(getNumberOfSettingsInSection(t, t('experimental'))).toStrictEqual(
1, 2,
); );
}); });

@ -27,6 +27,7 @@ import {
getIsMultiLayerFeeNetwork, getIsMultiLayerFeeNetwork,
checkNetworkAndAccountSupports1559, checkNetworkAndAccountSupports1559,
getEIP1559V2Enabled, getEIP1559V2Enabled,
getIsImprovedTokenAllowanceEnabled,
} from '../../selectors'; } from '../../selectors';
import { useApproveTransaction } from '../../hooks/useApproveTransaction'; import { useApproveTransaction } from '../../hooks/useApproveTransaction';
import AdvancedGasFeePopover from '../../components/app/advanced-gas-fee-popover'; import AdvancedGasFeePopover from '../../components/app/advanced-gas-fee-popover';
@ -87,6 +88,10 @@ export default function ConfirmApprove({
const eip1559V2Enabled = useSelector(getEIP1559V2Enabled); const eip1559V2Enabled = useSelector(getEIP1559V2Enabled);
const supportsEIP1559V2 = eip1559V2Enabled && networkAndAccountSupports1559; const supportsEIP1559V2 = eip1559V2Enabled && networkAndAccountSupports1559;
const improvedTokenAllowanceEnabled = useSelector(
getIsImprovedTokenAllowanceEnabled,
);
const previousTokenAmount = useRef(tokenAmount); const previousTokenAmount = useRef(tokenAmount);
const { const {
approveTransaction, approveTransaction,
@ -161,7 +166,7 @@ export default function ConfirmApprove({
if (tokenSymbol === undefined && assetName === undefined) { if (tokenSymbol === undefined && assetName === undefined) {
return <Loading />; return <Loading />;
} }
if (process.env.TOKEN_ALLOWANCE_IMPROVEMENTS && assetStandard === ERC20) { if (improvedTokenAllowanceEnabled && assetStandard === ERC20) {
return ( return (
<GasFeeContextProvider transaction={transaction}> <GasFeeContextProvider transaction={transaction}>
<TransactionModalContextProvider> <TransactionModalContextProvider>

@ -20,6 +20,8 @@ export default class ExperimentalTab extends PureComponent {
openSeaEnabled: PropTypes.bool, openSeaEnabled: PropTypes.bool,
eip1559V2Enabled: PropTypes.bool, eip1559V2Enabled: PropTypes.bool,
setEIP1559V2Enabled: PropTypes.func, setEIP1559V2Enabled: PropTypes.func,
improvedTokenAllowanceEnabled: PropTypes.bool,
setImprovedTokenAllowanceEnabled: PropTypes.func,
}; };
settingsRefs = Array( settingsRefs = Array(
@ -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() { render() {
return ( return (
<div className="settings-page__body"> <div className="settings-page__body">
{this.renderImprovedTokenAllowanceToggle()}
{this.renderOpenSeaEnabledToggle()} {this.renderOpenSeaEnabledToggle()}
{this.renderCollectibleDetectionToggle()} {this.renderCollectibleDetectionToggle()}
{this.renderEIP1559V2EnabledToggle()} {this.renderEIP1559V2EnabledToggle()}

@ -5,11 +5,13 @@ import {
setUseCollectibleDetection, setUseCollectibleDetection,
setOpenSeaEnabled, setOpenSeaEnabled,
setEIP1559V2Enabled, setEIP1559V2Enabled,
setImprovedTokenAllowanceEnabled,
} from '../../../store/actions'; } from '../../../store/actions';
import { import {
getUseCollectibleDetection, getUseCollectibleDetection,
getOpenSeaEnabled, getOpenSeaEnabled,
getEIP1559V2Enabled, getEIP1559V2Enabled,
getIsImprovedTokenAllowanceEnabled,
} from '../../../selectors'; } from '../../../selectors';
import ExperimentalTab from './experimental-tab.component'; import ExperimentalTab from './experimental-tab.component';
@ -18,6 +20,7 @@ const mapStateToProps = (state) => {
useCollectibleDetection: getUseCollectibleDetection(state), useCollectibleDetection: getUseCollectibleDetection(state),
openSeaEnabled: getOpenSeaEnabled(state), openSeaEnabled: getOpenSeaEnabled(state),
eip1559V2Enabled: getEIP1559V2Enabled(state), eip1559V2Enabled: getEIP1559V2Enabled(state),
improvedTokenAllowanceEnabled: getIsImprovedTokenAllowanceEnabled(state),
}; };
}; };
@ -27,6 +30,8 @@ const mapDispatchToProps = (dispatch) => {
dispatch(setUseCollectibleDetection(val)), dispatch(setUseCollectibleDetection(val)),
setOpenSeaEnabled: (val) => dispatch(setOpenSeaEnabled(val)), setOpenSeaEnabled: (val) => dispatch(setOpenSeaEnabled(val)),
setEIP1559V2Enabled: (val) => dispatch(setEIP1559V2Enabled(val)), setEIP1559V2Enabled: (val) => dispatch(setEIP1559V2Enabled(val)),
setImprovedTokenAllowanceEnabled: (val) =>
dispatch(setImprovedTokenAllowanceEnabled(val)),
}; };
}; };

@ -1254,6 +1254,16 @@ export function getIstokenDetectionInactiveOnNonMainnetSupportedNetwork(state) {
return isDynamicTokenListAvailable && !useTokenDetection && !isMainnet; 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) { export function getIsCustomNetwork(state) {
const chainId = getCurrentChainId(state); const chainId = getCurrentChainId(state);

@ -3789,6 +3789,20 @@ export function setEnableEIP1559V2NoticeDismissed() {
return submitRequestToBackground('setEnableEIP1559V2NoticeDismissed', [true]); return submitRequestToBackground('setEnableEIP1559V2NoticeDismissed', [true]);
} }
export function setImprovedTokenAllowanceEnabled(
improvedTokenAllowanceEnabled,
) {
return async () => {
try {
await submitRequestToBackground('setImprovedTokenAllowanceEnabled', [
improvedTokenAllowanceEnabled,
]);
} catch (error) {
log.error(error);
}
};
}
export function setFirstTimeUsedNetwork(chainId) { export function setFirstTimeUsedNetwork(chainId) {
return submitRequestToBackground('setFirstTimeUsedNetwork', [chainId]); return submitRequestToBackground('setFirstTimeUsedNetwork', [chainId]);
} }

Loading…
Cancel
Save