mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Feat/swaps link buy gas (#20241)
* Add link to buy more ETH if insufficient gas * Fix lint error * Use native currency per network * Use localized msg for buy more gas * Add the word "more" * Fix smart tx not showing msg * Pull out not enough balance into own component * Add story for not enough balance * Fix btn text not being aligned with rest of text * Move inline style to class, remove empty classname * Update ui/pages/swaps/prepare-swap-page/not-enough-balance.stories.tsx Co-authored-by: George Marshall <georgewrmarshall@gmail.com> * Update ui/pages/swaps/prepare-swap-page/index.scss Co-authored-by: Nidhi Kumari <nidhi.kumari@consensys.net> * Remove line * Move BannerAlert back into review-quote and use BannerAlert props * Remove unused CSS --------- Co-authored-by: George Marshall <georgewrmarshall@gmail.com> Co-authored-by: Nidhi Kumari <nidhi.kumari@consensys.net>
This commit is contained in:
parent
f91d4fb858
commit
1099a3763b
4
app/_locales/en/messages.json
generated
4
app/_locales/en/messages.json
generated
@ -611,6 +611,10 @@
|
|||||||
"message": "Buy $1",
|
"message": "Buy $1",
|
||||||
"description": "$1 is the ticker symbol of a an asset the user is being prompted to purchase"
|
"description": "$1 is the ticker symbol of a an asset the user is being prompted to purchase"
|
||||||
},
|
},
|
||||||
|
"buyMoreAsset": {
|
||||||
|
"message": "Buy more $1",
|
||||||
|
"description": "$1 is the ticker symbol of a an asset the user is being prompted to purchase"
|
||||||
|
},
|
||||||
"buyNow": {
|
"buyNow": {
|
||||||
"message": "Buy Now"
|
"message": "Buy Now"
|
||||||
},
|
},
|
||||||
|
@ -108,22 +108,22 @@ import {
|
|||||||
DISPLAY,
|
DISPLAY,
|
||||||
AlignItems,
|
AlignItems,
|
||||||
FLEX_DIRECTION,
|
FLEX_DIRECTION,
|
||||||
SEVERITIES,
|
|
||||||
TextVariant,
|
TextVariant,
|
||||||
FRACTIONS,
|
FRACTIONS,
|
||||||
TEXT_ALIGN,
|
TEXT_ALIGN,
|
||||||
Size,
|
Size,
|
||||||
|
Severity,
|
||||||
} from '../../../helpers/constants/design-system';
|
} from '../../../helpers/constants/design-system';
|
||||||
import {
|
|
||||||
BannerAlert,
|
|
||||||
ButtonLink,
|
|
||||||
Text,
|
|
||||||
} from '../../../components/component-library';
|
|
||||||
import {
|
import {
|
||||||
MetaMetricsEventCategory,
|
MetaMetricsEventCategory,
|
||||||
MetaMetricsEventName,
|
MetaMetricsEventName,
|
||||||
MetaMetricsEventErrorType,
|
MetaMetricsEventErrorType,
|
||||||
} from '../../../../shared/constants/metametrics';
|
} from '../../../../shared/constants/metametrics';
|
||||||
|
import {
|
||||||
|
ButtonLink,
|
||||||
|
Text,
|
||||||
|
BannerAlert,
|
||||||
|
} from '../../../components/component-library';
|
||||||
import { isEqualCaseInsensitive } from '../../../../shared/modules/string-utils';
|
import { isEqualCaseInsensitive } from '../../../../shared/modules/string-utils';
|
||||||
import { parseStandardTokenTransactionData } from '../../../../shared/modules/transaction.utils';
|
import { parseStandardTokenTransactionData } from '../../../../shared/modules/transaction.utils';
|
||||||
import { getTokenValueParam } from '../../../../shared/lib/metamask-controller-utils';
|
import { getTokenValueParam } from '../../../../shared/lib/metamask-controller-utils';
|
||||||
@ -137,6 +137,7 @@ import { calcTokenValue } from '../../../../shared/lib/swaps-utils';
|
|||||||
import fetchEstimatedL1Fee from '../../../helpers/utils/optimism/fetchEstimatedL1Fee';
|
import fetchEstimatedL1Fee from '../../../helpers/utils/optimism/fetchEstimatedL1Fee';
|
||||||
import ExchangeRateDisplay from '../exchange-rate-display';
|
import ExchangeRateDisplay from '../exchange-rate-display';
|
||||||
import InfoTooltip from '../../../components/ui/info-tooltip';
|
import InfoTooltip from '../../../components/ui/info-tooltip';
|
||||||
|
import useRamps from '../../../hooks/experiences/useRamps';
|
||||||
import ViewQuotePriceDifference from './view-quote-price-difference';
|
import ViewQuotePriceDifference from './view-quote-price-difference';
|
||||||
|
|
||||||
let intervalId;
|
let intervalId;
|
||||||
@ -160,6 +161,7 @@ export default function ReviewQuote({ setReceiveToAmount }) {
|
|||||||
useState(null);
|
useState(null);
|
||||||
// We need to have currentTimestamp in state, otherwise it would change with each rerender.
|
// We need to have currentTimestamp in state, otherwise it would change with each rerender.
|
||||||
const [currentTimestamp] = useState(Date.now());
|
const [currentTimestamp] = useState(Date.now());
|
||||||
|
const { openBuyCryptoInPdapp } = useRamps();
|
||||||
|
|
||||||
const [acknowledgedPriceDifference, setAcknowledgedPriceDifference] =
|
const [acknowledgedPriceDifference, setAcknowledgedPriceDifference] =
|
||||||
useState(false);
|
useState(false);
|
||||||
@ -782,6 +784,9 @@ export default function ReviewQuote({ setReceiveToAmount }) {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const needsMoreGas = Boolean(ethBalanceNeededStx || ethBalanceNeeded);
|
||||||
|
|
||||||
const actionableBalanceErrorMessage = tokenBalanceUnavailable
|
const actionableBalanceErrorMessage = tokenBalanceUnavailable
|
||||||
? t('swapTokenBalanceUnavailable', [sourceTokenSymbol])
|
? t('swapTokenBalanceUnavailable', [sourceTokenSymbol])
|
||||||
: t('swapApproveNeedMoreTokens', [
|
: t('swapApproveNeedMoreTokens', [
|
||||||
@ -1066,20 +1071,23 @@ export default function ReviewQuote({ setReceiveToAmount }) {
|
|||||||
<>
|
<>
|
||||||
{viewQuotePriceDifferenceWarning}
|
{viewQuotePriceDifferenceWarning}
|
||||||
{(showInsufficientWarning || tokenBalanceUnavailable) && (
|
{(showInsufficientWarning || tokenBalanceUnavailable) && (
|
||||||
<Box display={DISPLAY.FLEX} marginTop={2}>
|
|
||||||
<BannerAlert
|
<BannerAlert
|
||||||
severity={SEVERITIES.INFO}
|
|
||||||
title={t('notEnoughBalance')}
|
title={t('notEnoughBalance')}
|
||||||
>
|
severity={Severity.Info}
|
||||||
<Text
|
description={actionableBalanceErrorMessage}
|
||||||
variant={TextVariant.bodyMd}
|
descriptionProps={{
|
||||||
as="h6"
|
'data-testid': 'mm-banner-alert-notification-text',
|
||||||
data-testid="mm-banner-alert-notification-text"
|
}}
|
||||||
>
|
actionButtonLabel={
|
||||||
{actionableBalanceErrorMessage}
|
needsMoreGas
|
||||||
</Text>
|
? t('buyMoreAsset', [nativeCurrencySymbol])
|
||||||
</BannerAlert>
|
: undefined
|
||||||
</Box>
|
}
|
||||||
|
actionButtonOnClick={
|
||||||
|
needsMoreGas ? () => openBuyCryptoInPdapp() : undefined
|
||||||
|
}
|
||||||
|
marginTop={2}
|
||||||
|
/>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user