Skip to content
This repository has been archived by the owner on Jun 24, 2022. It is now read-only.

Commit

Permalink
[Claim-Reject-Modals] Fixes empty modal (#2204)
Browse files Browse the repository at this point in the history
* modal is NOT open without a message

* pass proper closing functions

* better constant naming in hook
  • Loading branch information
W3stside authored Jan 18, 2022
1 parent 7099b6f commit 7751865
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
9 changes: 4 additions & 5 deletions src/custom/hooks/useErrorMessageAndModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,16 @@ export function useErrorMessage() {
}

export function useErrorModal() {
// Any async bc errors
const [internalError, setError] = useState<string | undefined>()
const [internalError, setInternalError] = useState<string | undefined>()
const { openModal, closeModal, TransactionErrorModal } = useTransactionErrorModal()

return useMemo(() => {
const handleCloseError = () => {
closeModal()
setError(undefined)
setInternalError(undefined)
}
const handleSetError = (error: string | undefined) => {
setError(error)
setInternalError(error)

// IF error, open modal
error && openModal()
Expand All @@ -53,5 +52,5 @@ export function useErrorModal() {
<TransactionErrorModal onDismiss={handleCloseError} message={message} />
),
}
}, [TransactionErrorModal, closeModal, internalError, openModal])
}, [internalError, closeModal, openModal, TransactionErrorModal])
}
2 changes: 1 addition & 1 deletion src/custom/hooks/useTransactionErrorModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function useTransactionErrorModal() {
closeModal,
TransactionErrorModal: useCallback(
({ message, onDismiss }: { message?: string; onDismiss: () => void }) => (
<GpModal isOpen={showTransactionErrorModal} onDismiss={closeModal}>
<GpModal isOpen={!!message && showTransactionErrorModal} onDismiss={closeModal}>
<TransactionErrorContent onDismiss={onDismiss} message={message} />
</GpModal>
),
Expand Down
8 changes: 5 additions & 3 deletions src/custom/pages/Claim/InvestmentFlow/InvestOption.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default function InvestOption({ approveData, claim, optionIndex }: Invest
const { updateInvestAmount } = useClaimDispatchers()
const { investFlowData } = useClaimState()

const { handleSetError, ErrorModal } = useErrorModal()
const { handleSetError, handleCloseError, ErrorModal } = useErrorModal()

const investedAmount = useMemo(() => investFlowData[optionIndex].investedAmount, [investFlowData, optionIndex])

Expand Down Expand Up @@ -93,7 +93,9 @@ export default function InvestOption({ approveData, claim, optionIndex }: Invest
// Save "local" approving state (pre-BC) for rendering spinners etc
const [approving, setApproving] = useState(false)
const handleApprove = useCallback(async () => {
handleSetError(undefined)
// reset errors and close any modals
handleCloseError()

if (!approveCallback) return

try {
Expand All @@ -106,7 +108,7 @@ export default function InvestOption({ approveData, claim, optionIndex }: Invest
} finally {
setApproving(false)
}
}, [approveCallback, handleSetError, token?.symbol])
}, [approveCallback, handleCloseError, handleSetError, token?.symbol])

const vCowAmount = useMemo(() => {
if (!token || !price || !investedAmount) {
Expand Down
6 changes: 3 additions & 3 deletions src/custom/pages/Claim/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export default function Claim() {
// toggle wallet when disconnected
const toggleWalletModal = useWalletModalToggle()
// error handling modals
const { handleSetError, ErrorModal } = useErrorModal()
const { handleCloseError, handleSetError, ErrorModal } = useErrorModal()

// get user claim data
const userClaimData = useUserEnhancedClaimData(activeClaimAccount)
Expand Down Expand Up @@ -132,7 +132,7 @@ export default function Claim() {
// handle submit claim
const handleSubmitClaim = () => {
// Reset error handling
handleSetError(undefined)
handleCloseError()

// just to be sure
if (!activeClaimAccount) return
Expand All @@ -149,7 +149,7 @@ export default function Claim() {
})
.catch((error) => {
setClaimStatus(ClaimStatus.DEFAULT)
console.log(error)
console.error('[Claim::index::handleSubmitClaim]::error', error)
handleSetError(error?.message)
})
}
Expand Down

0 comments on commit 7751865

Please sign in to comment.