Skip to content

Commit

Permalink
Merge branch 'dev' into firebase
Browse files Browse the repository at this point in the history
  • Loading branch information
iamacook authored Sep 25, 2023
2 parents 8c2ae58 + 89bcb82 commit 8c381b2
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
4 changes: 1 addition & 3 deletions src/components/tx-flow/SafeTxProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import type { SafeTransaction } from '@safe-global/safe-core-sdk-types'
import { createTx } from '@/services/tx/tx-sender'
import { useRecommendedNonce, useSafeTxGas } from '../tx/SignOrExecuteForm/hooks'
import { Errors, logError } from '@/services/exceptions'
import useSafeInfo from '@/hooks/useSafeInfo'

export const SafeTxContext = createContext<{
safeTx?: SafeTransaction
Expand Down Expand Up @@ -36,13 +35,12 @@ const SafeTxProvider = ({ children }: { children: ReactNode }): ReactElement =>
const [nonce, setNonce] = useState<number>()
const [nonceNeeded, setNonceNeeded] = useState<boolean>(true)
const [safeTxGas, setSafeTxGas] = useState<number>()
const { safe } = useSafeInfo()

// Signed txs cannot be updated
const isSigned = safeTx && safeTx.signatures.size > 0

// Recommended nonce and safeTxGas
const recommendedNonce = Math.max(safe.nonce, useRecommendedNonce() ?? 0)
const recommendedNonce = useRecommendedNonce()
const recommendedSafeTxGas = useSafeTxGas(safeTx)

// Priority to external nonce, then to the recommended one
Expand Down
5 changes: 4 additions & 1 deletion src/components/tx-flow/common/TxNonce/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const TxNonceForm = ({ nonce, recommendedNonce }: { nonce: string; recommendedNo
defaultValues: {
[TxNonceFormFieldNames.NONCE]: nonce,
},
mode: 'onTouched',
mode: 'all',
values: {
[TxNonceFormFieldNames.NONCE]: nonce,
},
Expand All @@ -122,6 +122,9 @@ const TxNonceForm = ({ nonce, recommendedNonce }: { nonce: string; recommendedNo
required: 'Nonce is required',
// Validation must be async to allow resetting invalid values onBlur
validate: async (value) => {
// nonce is always valid so no need to validate if the input is the same
if (value === nonce) return

const newNonce = Number(value)

if (isNaN(newNonce)) {
Expand Down
6 changes: 4 additions & 2 deletions src/components/tx/SignOrExecuteForm/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,12 @@ export const useRecommendedNonce = (): number | undefined => {
const { safeAddress, safe } = useSafeInfo()

const [recommendedNonce] = useAsync(
() => {
async () => {
if (!safe.chainId || !safeAddress) return

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

return recommendedNonce ? Math.max(safe.nonce, recommendedNonce) : undefined
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[safeAddress, safe.chainId, safe.txQueuedTag], // update when tx queue changes
Expand Down
2 changes: 1 addition & 1 deletion src/config/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export const DISCORD_URL = 'https://chat.safe.global'
export const TWITTER_URL = 'https://twitter.com/safe'

// Legal
export const IS_OFFICIAL_HOST = process.env.NEXT_PUBLIC_IS_OFFICIAL_HOST === 'true' || false
export const IS_OFFICIAL_HOST = process.env.NEXT_PUBLIC_IS_OFFICIAL_HOST === 'true'

// Risk mitigation (Redefine)
export const REDEFINE_SIMULATION_URL = 'https://dashboard.redefine.net/reports/'
Expand Down

0 comments on commit 8c381b2

Please sign in to comment.