Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Update to new recommended nonce endpoint #2737

Merged
merged 1 commit into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"@safe-global/safe-core-sdk-utils": "^1.7.4",
"@safe-global/safe-deployments": "1.25.0",
"@safe-global/safe-ethers-lib": "^1.9.4",
"@safe-global/safe-gateway-typescript-sdk": "^3.12.0",
"@safe-global/safe-gateway-typescript-sdk": "^3.13.2",
"@safe-global/safe-modules-deployments": "^1.0.0",
"@safe-global/safe-react-components": "^2.0.6",
"@sentry/react": "^7.74.0",
Expand Down
6 changes: 3 additions & 3 deletions src/components/tx/SignOrExecuteForm/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import { useHasPendingTxs } from '@/hooks/usePendingTxs'
import type { ConnectedWallet } from '@/services/onboard'
import type { OnboardAPI } from '@web3-onboard/core'
import { getSafeTxGas, getRecommendedNonce } from '@/services/tx/tx-sender/recommendedNonce'
import { getSafeTxGas, getNonces } from '@/services/tx/tx-sender/recommendedNonce'
import useAsync from '@/hooks/useAsync'
import { useUpdateBatch } from '@/hooks/useDraftBatch'
import { type TransactionDetails } from '@safe-global/safe-gateway-typescript-sdk'
Expand Down Expand Up @@ -163,9 +163,9 @@ export const useRecommendedNonce = (): number | undefined => {
async () => {
if (!safe.chainId || !safeAddress) return

const recommendedNonce = await getRecommendedNonce(safe.chainId, safeAddress)
const nonces = await getNonces(safe.chainId, safeAddress)

return recommendedNonce !== undefined ? Math.max(safe.nonce, recommendedNonce) : undefined
return nonces?.recommendedNonce
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[safeAddress, safe.chainId, safe.txQueuedTag], // update when tx queue changes
Expand Down
15 changes: 8 additions & 7 deletions src/services/tx/tx-sender/recommendedNonce.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import type { SafeTransactionEstimation } from '@safe-global/safe-gateway-typescript-sdk'
import { Operation, postSafeGasEstimation } from '@safe-global/safe-gateway-typescript-sdk'
import {
Operation,
postSafeGasEstimation,
getNonces as fetchNonces,
type SafeTransactionEstimation,
} from '@safe-global/safe-gateway-typescript-sdk'
import type { MetaTransactionData, SafeTransactionDataPartial } from '@safe-global/safe-core-sdk-types'
import { isLegacyVersion } from '@/hooks/coreSDK/safeCoreSDK'
import { Errors, logError } from '@/services/exceptions'
import { EMPTY_DATA } from '@safe-global/safe-core-sdk/dist/src/utils/constants'

const fetchRecommendedParams = async (
chainId: string,
Expand Down Expand Up @@ -37,11 +40,9 @@ export const getSafeTxGas = async (
}
}

export const getRecommendedNonce = async (chainId: string, safeAddress: string): Promise<number | undefined> => {
const blankTxParams = { data: EMPTY_DATA, to: safeAddress, value: '0' }
export const getNonces = async (chainId: string, safeAddress: string) => {
try {
const estimation = await fetchRecommendedParams(chainId, safeAddress, blankTxParams)
return Number(estimation.recommendedNonce)
return fetchNonces(chainId, safeAddress)
} catch (e) {
logError(Errors._616, e)
}
Expand Down
7 changes: 6 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3789,7 +3789,12 @@
"@safe-global/safe-core-sdk-utils" "^1.7.4"
ethers "5.7.2"

"@safe-global/safe-gateway-typescript-sdk@^3.12.0", "@safe-global/safe-gateway-typescript-sdk@^3.5.3":
"@safe-global/safe-gateway-typescript-sdk@^3.13.2":
version "3.13.2"
resolved "https://registry.yarnpkg.com/@safe-global/safe-gateway-typescript-sdk/-/safe-gateway-typescript-sdk-3.13.2.tgz#f03884c7eb766f5508085d95ab96063a28e20920"
integrity sha512-kGlJecJHBzGrGTq/yhLANh56t+Zur6Ubpt+/w03ARX1poDb4TM8vKU3iV8tuYpk359PPWp+Qvjnqb9oW2YQcYw==

"@safe-global/safe-gateway-typescript-sdk@^3.5.3":
version "3.12.0"
resolved "https://registry.yarnpkg.com/@safe-global/safe-gateway-typescript-sdk/-/safe-gateway-typescript-sdk-3.12.0.tgz#aa767a32f4d10f4ec9a47ad7e32d547d3b51e94c"
integrity sha512-hExCo62lScVC9/ztVqYEYL2pFxcqLTvB8fj0WtdP5FWrvbtEgD0pbVolchzD5bf85pbzvEwdAxSVS7EdCZxTNw==
Expand Down
Loading