-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
feat: enable tx submission before swap quotes are loaded #22905
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
254cad9
a5a7b73
bfefc6b
2cb4426
c61c167
dd85cd6
b32e5e2
86defd5
28214fa
2eb32f1
1a7dcd3
464a5d9
2f0e4c9
e0c73c5
a924831
6dc45ba
cc2a216
fc0ad59
a4c5251
444d246
53fca2f
4d57ca5
14ee4b1
ad06a20
edad063
63bafb9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| import React, { useEffect, useState, useRef } from 'react'; | ||
| import React, { useEffect, useState, useRef, useMemo } from 'react'; | ||
| import { useSelector, useDispatch } from 'react-redux'; | ||
| import ScreenView from '../../../../Base/ScreenView'; | ||
| import { | ||
|
|
@@ -77,7 +77,7 @@ | |
| import { useRecipientInitialization } from '../../hooks/useRecipientInitialization'; | ||
| import ApprovalTooltip from '../../components/ApprovalText'; | ||
| import { RootState } from '../../../../../reducers/index.ts'; | ||
| import { BRIDGE_MM_FEE_RATE } from '@metamask/bridge-controller'; | ||
| import { BRIDGE_MM_FEE_RATE, QuoteWarning } from '@metamask/bridge-controller'; | ||
| import { isNullOrUndefined } from '@metamask/utils'; | ||
| import { useBridgeQuoteEvents } from '../../hooks/useBridgeQuoteEvents/index.ts'; | ||
| import { SwapsKeypad } from '../../components/SwapsKeypad/index.tsx'; | ||
|
|
@@ -206,20 +206,34 @@ | |
| }); | ||
|
|
||
| const isSubmitDisabled = | ||
| isLoading || | ||
| hasInsufficientBalance || | ||
| isSubmittingTx || | ||
| (isHardwareAddress && isSolanaSourced) || | ||
| !!blockaidError || | ||
| !hasSufficientGas; | ||
|
|
||
| useBridgeQuoteEvents({ | ||
| const warnings = useMemo(() => { | ||
| const latestWarnings: QuoteWarning[] = []; | ||
|
|
||
| isNoQuotesAvailable && latestWarnings.push('no_quotes'); | ||
| !hasSufficientGas && | ||
| latestWarnings.push('insufficient_gas_for_selected_quote'); | ||
| hasInsufficientBalance && latestWarnings.push('insufficient_balance'); | ||
| Boolean(blockaidError) && latestWarnings.push('tx_alert'); | ||
| shouldShowPriceImpactWarning && latestWarnings.push('price_impact'); | ||
micaelae marked this conversation as resolved.
Show resolved
Hide resolved
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| return latestWarnings; | ||
| }, [ | ||
| isNoQuotesAvailable, | ||
| hasSufficientGas, | ||
| hasInsufficientBalance, | ||
| hasNoQuotesAvailable: isNoQuotesAvailable, | ||
| hasInsufficientGas: !hasSufficientGas, | ||
| hasTxAlert: Boolean(blockaidError), | ||
| blockaidError, | ||
| shouldShowPriceImpactWarning, | ||
| ]); | ||
|
|
||
| useBridgeQuoteEvents({ | ||
| warnings, | ||
| isSubmitDisabled, | ||
| isPriceImpactWarningVisible: shouldShowPriceImpactWarning, | ||
| }); | ||
|
|
||
| // Compute error state directly from dependencies | ||
|
|
@@ -322,6 +336,7 @@ | |
| dispatch(setIsSubmittingTx(true)); | ||
| await submitBridgeTx({ | ||
| quoteResponse: activeQuote, | ||
| warnings, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Navigation occurs even when transaction submission failsThe
micaelae marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }); | ||
| } | ||
| } catch (error) { | ||
|
|
@@ -402,7 +417,7 @@ | |
| ); | ||
| } | ||
|
|
||
| // TODO: remove this once controller types are updated | ||
|
Check warning on line 420 in app/components/UI/Bridge/Views/BridgeView/index.tsx
|
||
| // @ts-expect-error: controller types are not up to date yet | ||
| const quoteBpsFee = activeQuote?.quote?.feeData?.metabridge?.quoteBpsFee; | ||
| const feePercentage = !isNullOrUndefined(quoteBpsFee) | ||
|
|
@@ -456,11 +471,11 @@ | |
| ? strings('bridge.fee_disclaimer', { | ||
| feePercentage, | ||
| }) | ||
| : !hasFee && isNoFeeDestinationAsset | ||
| ? strings('bridge.no_mm_fee_disclaimer', { | ||
| destTokenSymbol: destToken?.symbol, | ||
| }) | ||
| : ''} | ||
|
Check warning on line 478 in app/components/UI/Bridge/Views/BridgeView/index.tsx
|
||
| {approval | ||
| ? ` ${strings('bridge.approval_needed', approval)}` | ||
| : ''}{' '} | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.