fix: update mainnet block (#7042)

* fix: update mainnet block

* fix: typecheck
This commit is contained in:
Zach Pomerantz 2023-07-27 15:40:10 -07:00 committed by GitHub
parent 9ced714718
commit 6a3abbfb56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 13 deletions

@ -29,7 +29,7 @@ describe('Permit2', () => {
cy.hardhat()
.then(({ approval, wallet }) => approval.getTokenAllowanceForPermit2({ owner: wallet, token: inputToken }))
.then((allowance) => {
Cypress.log({ name: `Token allowace: ${allowance.toString()}` })
Cypress.log({ name: `Token allowance: ${allowance.toString()}` })
cy.wrap(allowance).should('deep.equal', MaxUint256)
})
}
@ -39,7 +39,7 @@ describe('Permit2', () => {
cy.hardhat()
.then(({ approval, wallet }) => approval.getPermit2Allowance({ owner: wallet, token: inputToken }))
.then((allowance) => {
Cypress.log({ name: `Permit2 allowace: ${allowance.amount.toString()}` })
Cypress.log({ name: `Permit2 allowance: ${allowance.amount.toString()}` })
cy.wrap(allowance.amount).should('deep.equal', MaxUint160)
// Asserts that the on-chain expiration is in 30 days, within a tolerance of 40 seconds.
const THIRTY_DAYS_SECONDS = 2_592_000

@ -7,9 +7,9 @@ import { createContext, ReactNode, useCallback, useContext, useEffect, useMemo,
const MISSING_PROVIDER = Symbol()
const BlockNumberContext = createContext<
| {
value?: number
fastForward(block: number): void
mainnetValue?: number
block?: number
mainnetBlock?: number
}
| typeof MISSING_PROVIDER
>(MISSING_PROVIDER)
@ -22,17 +22,17 @@ function useBlockNumberContext() {
return blockNumber
}
/** Requires that BlockUpdater be installed in the DOM tree. */
export default function useBlockNumber(): number | undefined {
return useBlockNumberContext().value
}
export function useFastForwardBlockNumber(): (block: number) => void {
return useBlockNumberContext().fastForward
}
/** Requires that BlockUpdater be installed in the DOM tree. */
export default function useBlockNumber(): number | undefined {
return useBlockNumberContext().block
}
export function useMainnetBlockNumber(): number | undefined {
return useBlockNumberContext().mainnetValue
return useBlockNumberContext().mainnetBlock
}
export function BlockNumberProvider({ children }: { children: ReactNode }) {
@ -106,13 +106,17 @@ export function BlockNumberProvider({ children }: { children: ReactNode }) {
const value = useMemo(
() => ({
value: chainId === activeChainId ? block : undefined,
fastForward: (update: number) => {
if (block && update > block) {
setChainBlock({ chainId: activeChainId, block: update })
setChainBlock({
chainId: activeChainId,
block: update,
mainnetBlock: activeChainId === ChainId.MAINNET ? update : mainnetBlock,
})
}
},
mainnetValue: mainnetBlock,
block: chainId === activeChainId ? block : undefined,
mainnetBlock,
}),
[activeChainId, block, chainId, mainnetBlock]
)