Commit 2bb695d8 authored by Ian Lapham's avatar Ian Lapham Committed by GitHub

reduce popup dismiss time on l2; (#2262)

parent 3ea6f6e0
...@@ -9,6 +9,10 @@ export const NetworkContextName = 'NETWORK' ...@@ -9,6 +9,10 @@ export const NetworkContextName = 'NETWORK'
export const DEFAULT_DEADLINE_FROM_NOW = 60 * 30 export const DEFAULT_DEADLINE_FROM_NOW = 60 * 30
export const L2_DEADLINE_FROM_NOW = 60 * 5 export const L2_DEADLINE_FROM_NOW = 60 * 5
// transaction popup dismisal amounts
export const DEFAULT_TXN_DISMISS_MS = 25000
export const L2_TXN_DISMISS_MS = 5000
// used for rewards deadlines // used for rewards deadlines
export const BIG_INT_SECONDS_IN_WEEK = JSBI.BigInt(60 * 60 * 24 * 7) export const BIG_INT_SECONDS_IN_WEEK = JSBI.BigInt(60 * 60 * 24 * 7)
......
import { DEFAULT_TXN_DISMISS_MS } from 'constants/misc'
import { useCallback, useMemo } from 'react' import { useCallback, useMemo } from 'react'
import { useAppDispatch, useAppSelector } from 'state/hooks' import { useAppDispatch, useAppSelector } from 'state/hooks'
import { useActiveWeb3React } from '../../hooks/web3' import { useActiveWeb3React } from '../../hooks/web3'
...@@ -50,12 +51,12 @@ export function useToggleVoteModal(): () => void { ...@@ -50,12 +51,12 @@ export function useToggleVoteModal(): () => void {
} }
// returns a function that allows adding a popup // returns a function that allows adding a popup
export function useAddPopup(): (content: PopupContent, key?: string) => void { export function useAddPopup(): (content: PopupContent, key?: string, removeAfterMs?: number) => void {
const dispatch = useAppDispatch() const dispatch = useAppDispatch()
return useCallback( return useCallback(
(content: PopupContent, key?: string) => { (content: PopupContent, key?: string, removeAfterMs?: number) => {
dispatch(addPopup({ content, key })) dispatch(addPopup({ content, key, removeAfterMs: removeAfterMs ?? DEFAULT_TXN_DISMISS_MS }))
}, },
[dispatch] [dispatch]
) )
......
import { createReducer, nanoid } from '@reduxjs/toolkit' import { createReducer, nanoid } from '@reduxjs/toolkit'
import { DEFAULT_TXN_DISMISS_MS } from 'constants/misc'
import { import {
addPopup, addPopup,
PopupContent, PopupContent,
...@@ -43,7 +44,7 @@ export default createReducer(initialState, (builder) => ...@@ -43,7 +44,7 @@ export default createReducer(initialState, (builder) =>
.addCase(setOpenModal, (state, action) => { .addCase(setOpenModal, (state, action) => {
state.openModal = action.payload state.openModal = action.payload
}) })
.addCase(addPopup, (state, { payload: { content, key, removeAfterMs = 25000 } }) => { .addCase(addPopup, (state, { payload: { content, key, removeAfterMs = DEFAULT_TXN_DISMISS_MS } }) => {
state.popupList = (key ? state.popupList.filter((popup) => popup.key !== key) : state.popupList).concat([ state.popupList = (key ? state.popupList.filter((popup) => popup.key !== key) : state.popupList).concat([
{ {
key: key || nanoid(), key: key || nanoid(),
......
import { DEFAULT_TXN_DISMISS_MS, L2_TXN_DISMISS_MS } from 'constants/misc'
import { useCallback, useEffect, useMemo } from 'react' import { useCallback, useEffect, useMemo } from 'react'
import { useAppDispatch, useAppSelector } from 'state/hooks' import { useAppDispatch, useAppSelector } from 'state/hooks'
import { SupportedChainId } from '../../constants/chains' import { L2_CHAIN_IDS, SupportedChainId } from '../../constants/chains'
import { useActiveWeb3React } from '../../hooks/web3' import { useActiveWeb3React } from '../../hooks/web3'
import { retry, RetryableError, RetryOptions } from '../../utils/retry' import { retry, RetryableError, RetryOptions } from '../../utils/retry'
import { updateBlockNumber } from '../application/actions' import { updateBlockNumber } from '../application/actions'
...@@ -52,6 +53,9 @@ export default function Updater(): null { ...@@ -52,6 +53,9 @@ export default function Updater(): null {
// show popup on confirm // show popup on confirm
const addPopup = useAddPopup() const addPopup = useAddPopup()
// speed up popup dismisall time if on L2
const isL2 = Boolean(chainId && L2_CHAIN_IDS.includes(chainId))
const getReceipt = useCallback( const getReceipt = useCallback(
(hash: string) => { (hash: string) => {
if (!library || !chainId) throw new Error('No library or chainId') if (!library || !chainId) throw new Error('No library or chainId')
...@@ -106,7 +110,8 @@ export default function Updater(): null { ...@@ -106,7 +110,8 @@ export default function Updater(): null {
summary: transactions[hash]?.summary, summary: transactions[hash]?.summary,
}, },
}, },
hash hash,
isL2 ? L2_TXN_DISMISS_MS : DEFAULT_TXN_DISMISS_MS
) )
// the receipt was fetched before the block, fast forward to that block to trigger balance updates // the receipt was fetched before the block, fast forward to that block to trigger balance updates
...@@ -128,7 +133,7 @@ export default function Updater(): null { ...@@ -128,7 +133,7 @@ export default function Updater(): null {
return () => { return () => {
cancels.forEach((cancel) => cancel()) cancels.forEach((cancel) => cancel())
} }
}, [chainId, library, transactions, lastBlockNumber, dispatch, addPopup, getReceipt]) }, [chainId, library, transactions, lastBlockNumber, dispatch, addPopup, getReceipt, isL2])
return null return null
} }
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