-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #187 from jediswaplabs/retroboydev/deadline
added tx deadline functionality
- Loading branch information
Showing
7 changed files
with
37 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,15 @@ | ||
import { BigNumber } from '@ethersproject/bignumber' | ||
import { useAccountDetails } from 'hooks/starknet-react' | ||
import { L2_DEADLINE_FROM_NOW } from 'constants/misc' | ||
import { useMemo } from 'react' | ||
import { useAppSelector } from 'state/hooks' | ||
import { useBlock, useContractRead } from '@starknet-react/core' | ||
import MultiContractABI from 'contracts/multicall/abi.json' | ||
import { MULTICALL_NETWORKS } from 'contracts/multicall' | ||
import { DEFAULT_CHAIN_ID } from 'constants/tokens' | ||
|
||
// combines the block timestamp with the user setting to give the deadline that should be used for any submitted transaction | ||
export default function useTransactionDeadline(): BigNumber | undefined { | ||
const { chainId } = useAccountDetails() | ||
const ttl = useAppSelector((state) => state.user.userDeadline) | ||
const blockTimestamp = useCurrentBlockTimestamp() | ||
const currentTimestamp = BigNumber.from(Math.round(Number(new Date()) / 1000).toString()) | ||
return useMemo(() => { | ||
if (blockTimestamp && ttl) return BigNumber.from(blockTimestamp).add(ttl) | ||
if (currentTimestamp && ttl) return BigNumber.from(currentTimestamp).add(ttl) | ||
return undefined | ||
}, [blockTimestamp, chainId, ttl]) | ||
} | ||
|
||
const useCurrentBlockTimestamp = () => { | ||
const { chainId } = useAccountDetails() | ||
const { data: blockTimeStamp } = useContractRead({ | ||
functionName: 'get_current_block_timestamp', | ||
args: [], | ||
abi: MultiContractABI, | ||
address: MULTICALL_NETWORKS[chainId ?? DEFAULT_CHAIN_ID], | ||
watch: true, | ||
}) | ||
|
||
if (!blockTimeStamp) return undefined | ||
const { block_timestamp } = blockTimeStamp as any | ||
|
||
return BigNumber.from(block_timestamp.toString()) | ||
}, [currentTimestamp, chainId, ttl]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters