Skip to content

Commit

Permalink
Fix small alert errors
Browse files Browse the repository at this point in the history
  • Loading branch information
l3wi committed Oct 3, 2021
1 parent 479645f commit 8fef2c4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
7 changes: 5 additions & 2 deletions components/page/alerts.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import {
Link,
Icon,
useColorModeValue,
chakra,
chakra
} from '@chakra-ui/react'
import {
CheckCircleIcon,
WarningTwoIcon,
TimeIcon,
IoMdCheckmarkCircle,
IoMdCheckmarkCircle
} from '@chakra-ui/icons'

import useAlerts from '../../contexts/useAlerts'
Expand Down Expand Up @@ -41,6 +41,7 @@ function Alerts() {
rounded="lg"
overflow="hidden"
mt="10px"
key={item.text}
>
<Flex
justifyContent="center"
Expand Down Expand Up @@ -75,6 +76,7 @@ function Alerts() {
rounded="lg"
overflow="hidden"
mt="10px"
key={item.text}
>
<Flex
justifyContent="center"
Expand Down Expand Up @@ -109,6 +111,7 @@ function Alerts() {
rounded="lg"
overflow="hidden"
mt="10px"
key={item.text}
>
<Flex
justifyContent="center"
Expand Down
30 changes: 16 additions & 14 deletions contexts/useAlerts.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React, {
useContext,
useMemo,
useEffect,
useCallback,
useCallback
} from 'react'

import { web3 } from '../utils/ethers'
Expand Down Expand Up @@ -35,17 +35,19 @@ export const AlertProvider = (props) => {
// watchTx - listen for success/fail
const watchTx = (hash, actionName) => {
const id = addAlert('pending', actionName)
web3.once(hash, (transaction) => {
console.log(transaction)

if (transaction.status === 1) {
addAlert('success', actionName)
} else {
addAlert('fail', actionName)
}
setTimeout(() => {
removeAlert(id)
}, 3000)
return new Promise((resolve, reject) => {
web3.once(hash, (transaction) => {
setTimeout(() => {
removeAlert(id)
}, 3000)
if (transaction.status === 1) {
addAlert('success', actionName)
resolve(transaction)
} else {
addAlert('fail', actionName)
reject(transaction)
}
})
})
}

Expand All @@ -54,7 +56,7 @@ export const AlertProvider = (props) => {
alerts,
addAlert,
removeAlert,
watchTx,
watchTx
}),
[alerts]
)
Expand All @@ -63,7 +65,7 @@ export const AlertProvider = (props) => {
return (
<UseAlertContext.Provider
value={{
tools,
tools
}}
>
{props.children}
Expand Down

0 comments on commit 8fef2c4

Please sign in to comment.