Skip to content

Commit

Permalink
Reuse the same logic in ExecuteForm
Browse files Browse the repository at this point in the history
  • Loading branch information
katspaugh committed Aug 7, 2023
1 parent 579b30e commit 26bd9ec
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
11 changes: 4 additions & 7 deletions src/components/tx/SignOrExecuteForm/ExecuteForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useCurrentChain } from '@/hooks/useChains'
import { getTxOptions } from '@/utils/transactions'
import useIsValidExecution from '@/hooks/useIsValidExecution'
import CheckWallet from '@/components/common/CheckWallet'
import { useImmediatelyExecutable, useIsExecutionLoop, useTxActions } from './hooks'
import { useIsExecutionLoop, useTxActions } from './hooks'
import { useRelaysBySafe } from '@/hooks/useRemainingRelays'
import useWalletCanRelay from '@/hooks/useWalletCanRelay'
import { ExecutionMethod, ExecutionMethodSelector } from '../ExecutionMethodSelector'
Expand All @@ -34,6 +34,7 @@ const ExecuteForm = ({
disableSubmit = false,
origin,
onlyExecute,
isCreation,
}: SignOrExecuteProps & {
safeTx?: SafeTransaction
}): ReactElement => {
Expand All @@ -50,8 +51,6 @@ const ExecuteForm = ({
const { needsRiskConfirmation, isRiskConfirmed, setIsRiskIgnored } = useContext(TxSecurityContext)

// Check that the transaction is executable
const isCreation = safeTx?.signatures.size === 0
const isNewExecutableTx = useImmediatelyExecutable() && isCreation
const isExecutionLoop = useIsExecutionLoop()

// We default to relay, but the option is only shown if we canRelay
Expand Down Expand Up @@ -136,10 +135,8 @@ const ExecuteForm = ({
</ErrorMessage>
) : executionValidationError || gasLimitError ? (
<ErrorMessage error={executionValidationError || gasLimitError}>
This transaction will most likely fail.{' '}
{isNewExecutableTx
? 'To save gas costs, avoid creating the transaction.'
: 'To save gas costs, reject this transaction.'}
This transaction will most likely fail.
{` To save gas costs, ${isCreation ? 'avoid creating' : 'reject'} this transaction.`}
</ErrorMessage>
) : (
submitError && (
Expand Down
2 changes: 1 addition & 1 deletion src/components/tx/SignOrExecuteForm/SignForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const SignForm = ({
origin,
isBatch,
isBatchable,
isCreation,
}: SignOrExecuteProps & {
safeTx?: SafeTransaction
}): ReactElement => {
Expand All @@ -36,7 +37,6 @@ const SignForm = ({
const { setTxFlow } = useContext(TxModalContext)
const { needsRiskConfirmation, isRiskConfirmed, setIsRiskIgnored } = useContext(TxSecurityContext)
const hasSigned = useAlreadySigned(safeTx)
const isCreation = !txId

// On modal submit
const handleSubmit = async (e: SyntheticEvent, isAddingToBatch = false) => {
Expand Down
5 changes: 3 additions & 2 deletions src/components/tx/SignOrExecuteForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export type SignOrExecuteProps = {
onlyExecute?: boolean
disableSubmit?: boolean
origin?: string
isCreation?: boolean
}

const SignOrExecuteForm = (props: SignOrExecuteProps): ReactElement => {
Expand Down Expand Up @@ -93,9 +94,9 @@ const SignOrExecuteForm = (props: SignOrExecuteProps): ReactElement => {
<RiskConfirmationError />

{willExecute ? (
<ExecuteForm {...props} safeTx={safeTx} />
<ExecuteForm {...props} safeTx={safeTx} isCreation={isCreation} />
) : (
<SignForm {...props} safeTx={safeTx} isBatchable={isBatchable} />
<SignForm {...props} safeTx={safeTx} isBatchable={isBatchable} isCreation={isCreation} />
)}
</TxCard>
</>
Expand Down

0 comments on commit 26bd9ec

Please sign in to comment.