1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-26 12:29:06 +01:00

Allow specific origin to direct to second page of token allowance flow (#18395)

* Allow specific origin to direct to second page of token allowance flow

* Remove accidentally committed git diff text

---------

Co-authored-by: Erik Marks <25517051+rekmarks@users.noreply.github.com>
This commit is contained in:
Dan J Miller 2023-03-31 07:04:55 -07:00 committed by GitHub
parent fbd68d4a3f
commit 41210084dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -65,6 +65,8 @@ import SimulationErrorMessage from '../../components/ui/simulation-error-message
import { Icon, ICON_NAMES } from '../../components/component-library'; import { Icon, ICON_NAMES } from '../../components/component-library';
import LedgerInstructionField from '../../components/app/ledger-instruction-field/ledger-instruction-field'; import LedgerInstructionField from '../../components/app/ledger-instruction-field/ledger-instruction-field';
const ALLOWED_HOSTS = ['portfolio.metamask.io'];
export default function TokenAllowance({ export default function TokenAllowance({
origin, origin,
siteImage, siteImage,
@ -94,10 +96,13 @@ export default function TokenAllowance({
const history = useHistory(); const history = useHistory();
const mostRecentOverviewPage = useSelector(getMostRecentOverviewPage); const mostRecentOverviewPage = useSelector(getMostRecentOverviewPage);
const { hostname } = new URL(origin);
const thisOriginIsAllowedToSkipFirstPage = ALLOWED_HOSTS.includes(hostname);
const [showContractDetails, setShowContractDetails] = useState(false); const [showContractDetails, setShowContractDetails] = useState(false);
const [showFullTxDetails, setShowFullTxDetails] = useState(false); const [showFullTxDetails, setShowFullTxDetails] = useState(false);
const [isFirstPage, setIsFirstPage] = useState( const [isFirstPage, setIsFirstPage] = useState(
dappProposedTokenAmount !== '0', dappProposedTokenAmount !== '0' && !thisOriginIsAllowedToSkipFirstPage,
); );
const [errorText, setErrorText] = useState(''); const [errorText, setErrorText] = useState('');
const [userAcknowledgedGasMissing, setUserAcknowledgedGasMissing] = const [userAcknowledgedGasMissing, setUserAcknowledgedGasMissing] =
@ -109,11 +114,14 @@ export default function TokenAllowance({
const currentAccount = useSelector(getCurrentAccountWithSendEtherInfo); const currentAccount = useSelector(getCurrentAccountWithSendEtherInfo);
const networkIdentifier = useSelector(getNetworkIdentifier); const networkIdentifier = useSelector(getNetworkIdentifier);
const rpcPrefs = useSelector(getRpcPrefsForCurrentProvider); const rpcPrefs = useSelector(getRpcPrefsForCurrentProvider);
const customTokenAmount = useSelector(getCustomTokenAmount);
const unapprovedTxCount = useSelector(getUnapprovedTxCount); const unapprovedTxCount = useSelector(getUnapprovedTxCount);
const unapprovedTxs = useSelector(getUnapprovedTransactions); const unapprovedTxs = useSelector(getUnapprovedTransactions);
const useCurrencyRateCheck = useSelector(getUseCurrencyRateCheck); const useCurrencyRateCheck = useSelector(getUseCurrencyRateCheck);
const isHardwareWalletConnected = useSelector(isHardwareWallet); const isHardwareWalletConnected = useSelector(isHardwareWallet);
let customTokenAmount = useSelector(getCustomTokenAmount);
if (thisOriginIsAllowedToSkipFirstPage && dappProposedTokenAmount) {
customTokenAmount = dappProposedTokenAmount;
}
const replaceCommaToDot = (inputValue) => { const replaceCommaToDot = (inputValue) => {
return inputValue.replace(/,/gu, '.'); return inputValue.replace(/,/gu, '.');