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 = ...@@ -23,5 +23,5 @@ export type PopupContent =
export const updateBlockNumber = createAction<{ chainId: number; blockNumber: number }>('updateBlockNumber') export const updateBlockNumber = createAction<{ chainId: number; blockNumber: number }>('updateBlockNumber')
export const toggleWalletModal = createAction<void>('toggleWalletModal') 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') export const removePopup = createAction<{ key: string }>('removePopup')
...@@ -20,12 +20,12 @@ export function useWalletModalToggle(): () => void { ...@@ -20,12 +20,12 @@ export function useWalletModalToggle(): () => void {
} }
// returns a function that allows adding a popup // 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() const dispatch = useDispatch()
return useCallback( return useCallback(
(content: PopupContent) => { (content: PopupContent, key?: string) => {
dispatch(addPopup({ content })) dispatch(addPopup({ content, key }))
}, },
[dispatch] [dispatch]
) )
......
...@@ -28,9 +28,10 @@ export default createReducer(initialState, builder => ...@@ -28,9 +28,10 @@ export default createReducer(initialState, builder =>
.addCase(toggleWalletModal, state => { .addCase(toggleWalletModal, state => {
state.walletModalOpen = !state.walletModalOpen 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({ state.popupList.push({
key: nanoid(), key: key || nanoid(),
show: true, show: true,
content content
}) })
......
...@@ -44,20 +44,17 @@ export default function Updater() { ...@@ -44,20 +44,17 @@ export default function Updater() {
} }
}) })
) )
// add success or failure popup
if (receipt.status === 1) { addPopup(
addPopup({ {
txn: { txn: {
hash, hash,
success: true, success: receipt.status === 1,
summary: allTransactions[hash]?.summary summary: allTransactions[hash]?.summary
} }
}) },
} else { hash
addPopup({ )
txn: { hash, success: false, summary: allTransactions[hash]?.summary }
})
}
} }
}) })
.catch(error => { .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