This repository has been archived by the owner on Jun 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Claim] Rejected/failed/errors in claim flow (#2169)
* useErrorMessage hook * extend SwapCallbackError to be more generic * add useErrorMessage to claim index & InvestOption * add useErrorMessage to SwapMod * [Claim] Reject tx modals (#2193) * change hook name and add new hooks * add new modal enum * add hooks in app * useMemo in useErrorMessageAndModal hook * remove testing fn
- Loading branch information
Showing
7 changed files
with
131 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { useMemo, useState } from 'react' | ||
import { ErrorMessageProps, SwapCallbackError } from 'components/swap/styleds' | ||
import useTransactionErrorModal from './useTransactionErrorModal' | ||
|
||
/** | ||
* @description hook for getting CowSwap error and handling them visually | ||
* @description ErrorMessage component accepts an error message to override exported error state, and a close option | ||
* @returns returns object: { error, setError, ErrorMessage } => error message, error message setter, and our ErrorMessage component | ||
*/ | ||
export function useErrorMessage() { | ||
const [internalError, setError] = useState<string | undefined>() | ||
|
||
return useMemo(() => { | ||
const handleCloseError = () => setError(undefined) | ||
|
||
return { | ||
error: internalError, | ||
handleSetError: setError, | ||
ErrorMessage: ({ | ||
error = internalError, | ||
showClose = false, | ||
...rest | ||
}: Pick<ErrorMessageProps, 'error' | 'showClose' | '$css'>) => | ||
error ? ( | ||
<SwapCallbackError showClose={showClose} handleClose={handleCloseError} error={error} {...rest} /> | ||
) : null, | ||
} | ||
}, [internalError]) | ||
} | ||
|
||
export function useErrorModal() { | ||
// Any async bc errors | ||
const [internalError, setError] = useState<string | undefined>() | ||
const { openModal, closeModal, TransactionErrorModal } = useTransactionErrorModal() | ||
|
||
return useMemo(() => { | ||
const handleCloseError = () => { | ||
closeModal() | ||
setError(undefined) | ||
} | ||
const handleSetError = (error: string | undefined) => { | ||
setError(error) | ||
|
||
// IF error, open modal | ||
error && openModal() | ||
} | ||
|
||
return { | ||
error: internalError, | ||
handleCloseError, | ||
handleSetError, | ||
ErrorModal: ({ message = internalError }: { message?: string }) => ( | ||
<TransactionErrorModal onDismiss={handleCloseError} message={message} /> | ||
), | ||
} | ||
}, [TransactionErrorModal, closeModal, internalError, openModal]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { useCallback } from 'react' | ||
import { ApplicationModal } from 'state/application/reducer' | ||
import { TransactionErrorContent } from 'components/TransactionConfirmationModal' | ||
import { useOpenModal, useCloseModals, useModalOpen } from 'state/application/hooks' | ||
import { GpModal } from '../components/Modal' | ||
|
||
export default function useTransactionErrorModal() { | ||
const openModal = useOpenModal(ApplicationModal.TRANSACTION_ERROR) | ||
const closeModal = useCloseModals() | ||
const showTransactionErrorModal = useModalOpen(ApplicationModal.TRANSACTION_ERROR) | ||
|
||
return { | ||
openModal, | ||
closeModal, | ||
TransactionErrorModal: useCallback( | ||
({ message, onDismiss }: { message?: string; onDismiss: () => void }) => ( | ||
<GpModal isOpen={showTransactionErrorModal} onDismiss={closeModal}> | ||
<TransactionErrorContent onDismiss={onDismiss} message={message} /> | ||
</GpModal> | ||
), | ||
[closeModal, showTransactionErrorModal] | ||
), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters