Commit 6de3a6ec authored by Moody Salem's avatar Moody Salem

Avoid duplicate popups for mined transactions

parent c1d35cc8
......@@ -23,5 +23,5 @@ export type PopupContent =
export const updateBlockNumber = createAction<{ chainId: number; blockNumber: number }>('updateBlockNumber')
export const toggleWalletModal = createAction<void>('toggleWalletModal')
export const addPopup = createAction<{ content: PopupContent }>('addPopup')
export const addPopup = createAction<{ key?: string; content: PopupContent }>('addPopup')
export const removePopup = createAction<{ key: string }>('removePopup')
......@@ -20,12 +20,12 @@ export function useWalletModalToggle(): () => void {
}
// returns a function that allows adding a popup
export function useAddPopup(): (content: PopupContent) => void {
export function useAddPopup(): (content: PopupContent, key?: string) => void {
const dispatch = useDispatch()
return useCallback(
(content: PopupContent) => {
dispatch(addPopup({ content }))
(content: PopupContent, key?: string) => {
dispatch(addPopup({ content, key }))
},
[dispatch]
)
......
......@@ -28,9 +28,10 @@ export default createReducer(initialState, builder =>
.addCase(toggleWalletModal, state => {
state.walletModalOpen = !state.walletModalOpen
})
.addCase(addPopup, (state, { payload: { content } }) => {
.addCase(addPopup, (state, { payload: { content, key } }) => {
if (key && state.popupList.some(popup => popup.key === key)) return
state.popupList.push({
key: nanoid(),
key: key || nanoid(),
show: true,
content
})
......
......@@ -44,20 +44,17 @@ export default function Updater() {
}
})
)
// add success or failure popup
if (receipt.status === 1) {
addPopup({
addPopup(
{
txn: {
hash,
success: true,
success: receipt.status === 1,
summary: allTransactions[hash]?.summary
}
})
} else {
addPopup({
txn: { hash, success: false, summary: allTransactions[hash]?.summary }
})
}
},
hash
)
}
})
.catch(error => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment