1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

Show the right "balance needed" value if we fallback from STX to regular Swaps (#19230)

* Show the right balance needed value if we fallback from STX to regular Swaps
* Fix usage of StxErrorTypes
This commit is contained in:
Daniel 2023-05-25 19:30:10 +02:00 committed by GitHub
parent af018efcb6
commit e1b12279ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 14 deletions

View File

@ -208,7 +208,7 @@ const slice = createSlice({
setCurrentSmartTransactionsError: (state, action) => { setCurrentSmartTransactionsError: (state, action) => {
const errorType = Object.values(StxErrorTypes).includes(action.payload) const errorType = Object.values(StxErrorTypes).includes(action.payload)
? action.payload ? action.payload
: StxErrorTypes.UNAVAILABLE; : StxErrorTypes.unavailable;
state.currentSmartTransactionsError = errorType; state.currentSmartTransactionsError = errorType;
}, },
setSwapsSTXSubmitLoading: (state, action) => { setSwapsSTXSubmitLoading: (state, action) => {
@ -554,7 +554,7 @@ const disableStxIfRegularTxInProgress = (dispatch, transactions) => {
for (const transaction of transactions) { for (const transaction of transactions) {
if (IN_PROGRESS_TRANSACTION_STATUSES.includes(transaction.status)) { if (IN_PROGRESS_TRANSACTION_STATUSES.includes(transaction.status)) {
dispatch( dispatch(
setCurrentSmartTransactionsError(StxErrorTypes.REGULAR_TX_IN_PROGRESS), setCurrentSmartTransactionsError(StxErrorTypes.regularTxPending),
); );
break; break;
} }
@ -939,7 +939,7 @@ export const signAndSendSwapsSmartTransaction = ({
if (!fees) { if (!fees) {
log.error('"fetchSwapsSmartTransactionFees" failed'); log.error('"fetchSwapsSmartTransactionFees" failed');
dispatch(setSwapsSTXSubmitLoading(false)); dispatch(setSwapsSTXSubmitLoading(false));
dispatch(setCurrentSmartTransactionsError(StxErrorTypes.UNAVAILABLE)); dispatch(setCurrentSmartTransactionsError(StxErrorTypes.unavailable));
return; return;
} }
if (approveTxParams) { if (approveTxParams) {
@ -1329,7 +1329,7 @@ export function fetchSwapsSmartTransactionFees({
const errorObj = parseSmartTransactionsError(e.message); const errorObj = parseSmartTransactionsError(e.message);
if ( if (
fallbackOnNotEnoughFunds || fallbackOnNotEnoughFunds ||
errorObj?.error !== StxErrorTypes.NOT_ENOUGH_FUNDS errorObj?.error !== StxErrorTypes.notEnoughFunds
) { ) {
dispatch(setCurrentSmartTransactionsError(errorObj?.error)); dispatch(setCurrentSmartTransactionsError(errorObj?.error));
} }

View File

@ -201,6 +201,8 @@ export default function ViewQuote() {
); );
const swapsNetworkConfig = useSelector(getSwapsNetworkConfig, shallowEqual); const swapsNetworkConfig = useSelector(getSwapsNetworkConfig, shallowEqual);
const unsignedTransaction = usedQuote.trade; const unsignedTransaction = usedQuote.trade;
const isSmartTransaction =
currentSmartTransactionsEnabled && smartTransactionsOptInStatus;
let gasFeeInputs; let gasFeeInputs;
if (networkAndAccountSupports1559) { if (networkAndAccountSupports1559) {
@ -458,7 +460,7 @@ export default function ViewQuote() {
: null; : null;
let ethBalanceNeededStx; let ethBalanceNeededStx;
if (smartTransactionsError?.balanceNeededWei) { if (isSmartTransaction && smartTransactionsError?.balanceNeededWei) {
ethBalanceNeededStx = decWEIToDecETH( ethBalanceNeededStx = decWEIToDecETH(
smartTransactionsError.balanceNeededWei - smartTransactionsError.balanceNeededWei -
smartTransactionsError.currentBalanceWei, smartTransactionsError.currentBalanceWei,
@ -467,7 +469,7 @@ export default function ViewQuote() {
const destinationToken = useSelector(getDestinationTokenInfo, isEqual); const destinationToken = useSelector(getDestinationTokenInfo, isEqual);
useEffect(() => { useEffect(() => {
if (currentSmartTransactionsEnabled && smartTransactionsOptInStatus) { if (isSmartTransaction) {
if (insufficientTokens) { if (insufficientTokens) {
dispatch(setBalanceError(true)); dispatch(setBalanceError(true));
} else if (balanceError && !insufficientTokens) { } else if (balanceError && !insufficientTokens) {
@ -483,8 +485,7 @@ export default function ViewQuote() {
insufficientEth, insufficientEth,
balanceError, balanceError,
dispatch, dispatch,
currentSmartTransactionsEnabled, isSmartTransaction,
smartTransactionsOptInStatus,
]); ]);
useEffect(() => { useEffect(() => {
@ -520,10 +521,7 @@ export default function ViewQuote() {
ethBalanceNeeded; ethBalanceNeeded;
// If it's a Smart Transaction and ETH balance is needed, we want to show a warning. // If it's a Smart Transaction and ETH balance is needed, we want to show a warning.
const isStxAndEthBalanceIsNeeded = const isStxAndEthBalanceIsNeeded = isSmartTransaction && ethBalanceNeededStx;
currentSmartTransactionsEnabled &&
smartTransactionsOptInStatus &&
ethBalanceNeededStx;
// Indicates if we should show to a user a warning about insufficient funds for swapping. // Indicates if we should show to a user a warning about insufficient funds for swapping.
const showInsufficientWarning = const showInsufficientWarning =
@ -924,14 +922,14 @@ export default function ViewQuote() {
]); ]);
useEffect(() => { useEffect(() => {
if (currentSmartTransactionsEnabled && smartTransactionsOptInStatus) { if (isSmartTransaction) {
// Removes a smart transactions error when the component loads. // Removes a smart transactions error when the component loads.
dispatch({ dispatch({
type: SET_SMART_TRANSACTIONS_ERROR, type: SET_SMART_TRANSACTIONS_ERROR,
payload: null, payload: null,
}); });
} }
}, [currentSmartTransactionsEnabled, smartTransactionsOptInStatus, dispatch]); }, [isSmartTransaction, dispatch]);
return ( return (
<div className="view-quote"> <div className="view-quote">