Skip to content

Commit

Permalink
feat: Add error message on approve/confirm (pancakeswap#465)
Browse files Browse the repository at this point in the history
  • Loading branch information
hachiojidev authored Feb 16, 2021
1 parent 2c915f8 commit 4d07ca2
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/hooks/useApproveConfirmTransaction.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useEffect, useReducer, useRef } from 'react'
import { noop } from 'lodash'
import { useWallet } from '@binance-chain/bsc-use-wallet'
import { useToast } from 'state/hooks'

type Web3Payload = Record<string, unknown> | null

Expand Down Expand Up @@ -97,6 +98,7 @@ const useApproveConfirmTransaction = ({
const { account } = useWallet()
const [state, dispatch] = useReducer(reducer, initialState)
const handlePreApprove = useRef(onRequiresApproval)
const { toastError } = useToast()

// Check if approval is necessary, re-check if account changes
useEffect(() => {
Expand Down Expand Up @@ -128,6 +130,8 @@ const useApproveConfirmTransaction = ({
})
.on('error', (error: Web3Payload) => {
dispatch({ type: 'approve_error', payload: error })
console.error('An error occurred approving transaction:', error)
toastError('An error occurred approving transaction')
})
},
handleConfirm: () => {
Expand All @@ -141,6 +145,8 @@ const useApproveConfirmTransaction = ({
})
.on('error', (error: Web3Payload) => {
dispatch({ type: 'confirm_error', payload: error })
console.error('An error occurred confirming transaction:', error)
toastError('An error occurred confirming transaction')
})
},
}
Expand Down

0 comments on commit 4d07ca2

Please sign in to comment.