Skip to content

Commit

Permalink
handled current block time stamp using rpc
Browse files Browse the repository at this point in the history
  • Loading branch information
vnaysngh-mudrex committed Apr 9, 2024
1 parent 62a2fb9 commit 197b517
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
22 changes: 12 additions & 10 deletions src/hooks/useCurrentBlockTimestamp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,23 @@ import { useContractRead } from '@starknet-react/core'
import { MULTICALL_NETWORKS } from 'contracts/multicall'
import { DEFAULT_CHAIN_ID } from 'constants/tokens'
import { MULTICALL_ABI } from 'contracts/multicall'
import { useQuery } from 'react-query'
import { providerInstance } from 'utils/getLibrary'
import { num } from 'starknet'

const useCurrentBlockTimestamp = () => {
const { chainId } = useAccountDetails()
const { data: blockTimeStamp } = useContractRead({
functionName: 'get_current_block_timestamp',
args: [],
abi: MULTICALL_ABI,
address: MULTICALL_NETWORKS[chainId ?? DEFAULT_CHAIN_ID],
watch: true,
const current_block_timestamp = useQuery({
queryKey: [`timestamp/${chainId}`],
queryFn: async () => {
if (!chainId) return undefined
const provider = providerInstance(chainId)
const results: any = await provider.getBlockWithTxHashes()
return results?.timestamp
},
})

if (!blockTimeStamp) return undefined
const { block_timestamp } = blockTimeStamp as any

return BigNumber.from(block_timestamp.toString())
return current_block_timestamp.data
}

export default useCurrentBlockTimestamp
2 changes: 1 addition & 1 deletion src/lib/hooks/transactions/updater.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default function Updater({ pendingTransactions, onCheck, onReceipt }: Upd
// Remove transactions past their deadline or - if there is no deadline - older than 6 hours.
if (tx.deadline) {
// Deadlines are expressed as seconds since epoch, as they are used on-chain.
if (blockTimestamp && tx.deadline < blockTimestamp.toNumber()) {
if (blockTimestamp && tx.deadline < blockTimestamp) {
removeTransaction(hash)
}
} else if (tx.addedTime + ms(`6h`) < Date.now()) {
Expand Down

0 comments on commit 197b517

Please sign in to comment.