mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 01:39:44 +01:00
Ensure users reacknowledge price slippage risks when it changes (#10376)
This commit is contained in:
parent
913fd5aad6
commit
531c35bc96
@ -9,6 +9,7 @@ import SelectQuotePopover from '../select-quote-popover';
|
||||
import { useEthFiatAmount } from '../../../hooks/useEthFiatAmount';
|
||||
import { useEqualityCheck } from '../../../hooks/useEqualityCheck';
|
||||
import { useNewMetricEvent } from '../../../hooks/useMetricEvent';
|
||||
import { usePrevious } from '../../../hooks/usePrevious';
|
||||
import { useSwapsEthToken } from '../../../hooks/useSwapsEthToken';
|
||||
import { MetaMetricsContext } from '../../../contexts/metametrics.new';
|
||||
import FeeCard from '../fee-card';
|
||||
@ -93,6 +94,7 @@ export default function ViewQuote() {
|
||||
acknowledgedPriceDifference,
|
||||
setAcknowledgedPriceDifference,
|
||||
] = useState(false);
|
||||
const priceDifferenceRiskyBuckets = ['high', 'medium'];
|
||||
|
||||
const routeState = useSelector(getBackgroundSwapRouteState);
|
||||
const quotes = useSelector(getQuotes, isEqual);
|
||||
@ -481,6 +483,24 @@ export default function ViewQuote() {
|
||||
]);
|
||||
|
||||
// Price difference warning
|
||||
const priceSlippageBucket = usedQuote?.priceSlippage?.bucket;
|
||||
const lastPriceDifferenceBucket = usePrevious(priceSlippageBucket);
|
||||
|
||||
// If the user agreed to a different bucket of risk, make them agree again
|
||||
useEffect(() => {
|
||||
if (
|
||||
acknowledgedPriceDifference &&
|
||||
lastPriceDifferenceBucket === 'medium' &&
|
||||
priceSlippageBucket === 'high'
|
||||
) {
|
||||
setAcknowledgedPriceDifference(false);
|
||||
}
|
||||
}, [
|
||||
priceSlippageBucket,
|
||||
acknowledgedPriceDifference,
|
||||
lastPriceDifferenceBucket,
|
||||
]);
|
||||
|
||||
let viewQuotePriceDifferenceComponent = null;
|
||||
const priceSlippageFromSource = useEthFiatAmount(
|
||||
usedQuote?.priceSlippage?.sourceAmountInETH || 0,
|
||||
@ -510,7 +530,7 @@ export default function ViewQuote() {
|
||||
const shouldShowPriceDifferenceWarning =
|
||||
!showInsufficientWarning &&
|
||||
usedQuote &&
|
||||
(['high', 'medium'].includes(usedQuote.priceSlippage.bucket) ||
|
||||
(priceDifferenceRiskyBuckets.includes(priceSlippageBucket) ||
|
||||
priceSlippageUnknownFiatValue);
|
||||
|
||||
if (shouldShowPriceDifferenceWarning) {
|
||||
|
Loading…
Reference in New Issue
Block a user