-
Notifications
You must be signed in to change notification settings - Fork 635
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: migrate nonce state * try * audit: ip * clean up * rm redux dep * disable tests
- Loading branch information
1 parent
69b5606
commit 2622bbc
Showing
18 changed files
with
315 additions
and
236 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,39 +0,0 @@ | ||
import { useCallback } from 'react'; | ||
import { useSelector } from 'react-redux'; | ||
import { EthereumAddress } from '@/entities'; | ||
import { getProviderForNetwork } from '@/handlers/web3'; | ||
import { Network } from '@/helpers/networkTypes'; | ||
import { AppState } from '@/redux/store'; | ||
import logger from '@/utils/logger'; | ||
|
||
export default function useCurrentNonce(accountAddress: EthereumAddress, network?: Network) { | ||
const nonceInState = useSelector((state: AppState) => { | ||
if (!network || !accountAddress) return undefined; | ||
return state.nonceManager[accountAddress.toLowerCase()]?.[network]?.nonce; | ||
}); | ||
const getNextNonce = useCallback(async () => { | ||
try { | ||
if (!network || !accountAddress) return undefined; | ||
const provider = await getProviderForNetwork(network); | ||
const transactionCount = await provider.getTransactionCount(accountAddress, 'pending'); | ||
const transactionIndex = transactionCount - 1; | ||
const nextNonceBase = !nonceInState || transactionIndex > nonceInState ? transactionIndex : nonceInState; | ||
const nextNonce = nextNonceBase + 1; | ||
|
||
logger.log('Use current nonce: ', { | ||
accountAddress, | ||
network, | ||
nextNonce, | ||
nonceInState, | ||
transactionCount, | ||
}); | ||
|
||
return nextNonce; | ||
} catch (e) { | ||
logger.log('Error determining next nonce: ', e); | ||
return undefined; | ||
} | ||
}, [accountAddress, network, nonceInState]); | ||
|
||
return getNextNonce; | ||
} | ||
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
Oops, something went wrong.