Commit 6a3abbfb authored by Zach Pomerantz's avatar Zach Pomerantz Committed by GitHub

fix: update mainnet block (#7042)

* fix: update mainnet block

* fix: typecheck
parent 9ced7147
...@@ -29,7 +29,7 @@ describe('Permit2', () => { ...@@ -29,7 +29,7 @@ describe('Permit2', () => {
cy.hardhat() cy.hardhat()
.then(({ approval, wallet }) => approval.getTokenAllowanceForPermit2({ owner: wallet, token: inputToken })) .then(({ approval, wallet }) => approval.getTokenAllowanceForPermit2({ owner: wallet, token: inputToken }))
.then((allowance) => { .then((allowance) => {
Cypress.log({ name: `Token allowace: ${allowance.toString()}` }) Cypress.log({ name: `Token allowance: ${allowance.toString()}` })
cy.wrap(allowance).should('deep.equal', MaxUint256) cy.wrap(allowance).should('deep.equal', MaxUint256)
}) })
} }
...@@ -39,7 +39,7 @@ describe('Permit2', () => { ...@@ -39,7 +39,7 @@ describe('Permit2', () => {
cy.hardhat() cy.hardhat()
.then(({ approval, wallet }) => approval.getPermit2Allowance({ owner: wallet, token: inputToken })) .then(({ approval, wallet }) => approval.getPermit2Allowance({ owner: wallet, token: inputToken }))
.then((allowance) => { .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) cy.wrap(allowance.amount).should('deep.equal', MaxUint160)
// Asserts that the on-chain expiration is in 30 days, within a tolerance of 40 seconds. // Asserts that the on-chain expiration is in 30 days, within a tolerance of 40 seconds.
const THIRTY_DAYS_SECONDS = 2_592_000 const THIRTY_DAYS_SECONDS = 2_592_000
......
...@@ -7,9 +7,9 @@ import { createContext, ReactNode, useCallback, useContext, useEffect, useMemo, ...@@ -7,9 +7,9 @@ import { createContext, ReactNode, useCallback, useContext, useEffect, useMemo,
const MISSING_PROVIDER = Symbol() const MISSING_PROVIDER = Symbol()
const BlockNumberContext = createContext< const BlockNumberContext = createContext<
| { | {
value?: number
fastForward(block: number): void fastForward(block: number): void
mainnetValue?: number block?: number
mainnetBlock?: number
} }
| typeof MISSING_PROVIDER | typeof MISSING_PROVIDER
>(MISSING_PROVIDER) >(MISSING_PROVIDER)
...@@ -22,17 +22,17 @@ function useBlockNumberContext() { ...@@ -22,17 +22,17 @@ function useBlockNumberContext() {
return blockNumber 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 { export function useFastForwardBlockNumber(): (block: number) => void {
return useBlockNumberContext().fastForward 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 { export function useMainnetBlockNumber(): number | undefined {
return useBlockNumberContext().mainnetValue return useBlockNumberContext().mainnetBlock
} }
export function BlockNumberProvider({ children }: { children: ReactNode }) { export function BlockNumberProvider({ children }: { children: ReactNode }) {
...@@ -106,13 +106,17 @@ export function BlockNumberProvider({ children }: { children: ReactNode }) { ...@@ -106,13 +106,17 @@ export function BlockNumberProvider({ children }: { children: ReactNode }) {
const value = useMemo( const value = useMemo(
() => ({ () => ({
value: chainId === activeChainId ? block : undefined,
fastForward: (update: number) => { fastForward: (update: number) => {
if (block && update > block) { 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] [activeChainId, block, chainId, mainnetBlock]
) )
......
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