22 compareAddress ,
33 ContractVerificationStatus ,
44 formatDisplay ,
5+ isTxRejected ,
56 sendTransactions ,
67 TRANSACTION_CONFIRMATIONS_DEFAULT ,
78 useAnalyticsContext
@@ -37,6 +38,8 @@ interface PayWithCryptoTabProps {
3738 isSwitchingChainRef : RefObject < boolean >
3839}
3940
41+ type ErrorCause = 'generic' | 'user-rejection'
42+
4043export const PayWithCryptoTab = ( { skipOnCloseCallback, isSwitchingChainRef } : PayWithCryptoTabProps ) => {
4144 const connectedChainId = useChainId ( )
4245 const { switchChain } = useSwitchChain ( )
@@ -46,7 +49,7 @@ export const PayWithCryptoTab = ({ skipOnCloseCallback, isSwitchingChainRef }: P
4649 const { openTransactionStatusModal } = useTransactionStatusModal ( )
4750 const { selectPaymentSettings = { } as SelectPaymentSettings , closeSelectPaymentModal } = useSelectPaymentModal ( )
4851 const { analytics } = useAnalyticsContext ( )
49- const [ isError , setIsError ] = useState < boolean > ( false )
52+ const [ error , setError ] = useState < null | ErrorCause > ( null )
5053 const { navigation, setNavigation } = useNavigationCheckout ( )
5154 const {
5255 initializeTransactionCounter,
@@ -246,7 +249,7 @@ export const PayWithCryptoTab = ({ skipOnCloseCallback, isSwitchingChainRef }: P
246249 }
247250
248251 setIsPurchasing ( true )
249- setIsError ( false )
252+ setError ( null )
250253
251254 try {
252255 if ( connectedChainId != chainId ) {
@@ -368,7 +371,8 @@ export const PayWithCryptoTab = ({ skipOnCloseCallback, isSwitchingChainRef }: P
368371 } catch ( e ) {
369372 console . error ( 'Failed to purchase...' , e )
370373 onError ( e as Error )
371- setIsError ( true )
374+ const isRejected = isTxRejected ( e as Error )
375+ setError ( isRejected ? 'user-rejection' : 'generic' )
372376 }
373377
374378 resetTransactionCounter ( )
@@ -393,7 +397,7 @@ export const PayWithCryptoTab = ({ skipOnCloseCallback, isSwitchingChainRef }: P
393397 }
394398
395399 setIsPurchasing ( true )
396- setIsError ( false )
400+ setError ( null )
397401
398402 try {
399403 if ( connectedChainId != chainId ) {
@@ -540,7 +544,8 @@ export const PayWithCryptoTab = ({ skipOnCloseCallback, isSwitchingChainRef }: P
540544 } catch ( e ) {
541545 console . error ( 'Failed to purchase...' , e )
542546 onError ( e as Error )
543- setIsError ( true )
547+ const isRejected = isTxRejected ( e as Error )
548+ setError ( isRejected ? 'user-rejection' : 'generic' )
544549 }
545550
546551 setIsPurchasing ( false )
@@ -772,15 +777,22 @@ export const PayWithCryptoTab = ({ skipOnCloseCallback, isSwitchingChainRef }: P
772777 return 'Confirm payment'
773778 }
774779
780+ const getErrorText = ( ) => {
781+ if ( error == 'user-rejection' ) {
782+ return 'The transaction was rejected.'
783+ }
784+ return 'An error occurred. Please try again.'
785+ }
786+
775787 return (
776788 < div className = "flex flex-col gap-4" >
777789 < PriceSection />
778790
779791 < div className = "flex flex-col justify-start items-center w-full gap-1" >
780- { isError && (
792+ { ! ! error && (
781793 < div className = "flex flex-col justify-start items-center w-full" >
782794 < Text variant = "xsmall" color = "negative" >
783- An error occurred. Please try again.
795+ { getErrorText ( ) }
784796 </ Text >
785797 </ div >
786798 ) }
0 commit comments