From 9ffe15b2b509c5e24b4a477f2c49c821452fb2a2 Mon Sep 17 00:00:00 2001 From: katspaugh <381895+katspaugh@users.noreply.github.com> Date: Mon, 26 Jun 2023 11:42:28 +0200 Subject: [PATCH] Fix: hide Edit for safeTxGas when 0 in 1.3.0+ (#2163) * Fix: hide Edit for safeTxGas when 0 in 1.3.0+ * Simplify onBlur --- .../transactions/TxDetails/SafeTxGasForm.tsx | 86 ++++++++++--------- .../transactions/TxDetails/Summary/index.tsx | 2 + 2 files changed, 48 insertions(+), 40 deletions(-) diff --git a/src/components/transactions/TxDetails/SafeTxGasForm.tsx b/src/components/transactions/TxDetails/SafeTxGasForm.tsx index 5f234569af..5cbae524ca 100644 --- a/src/components/transactions/TxDetails/SafeTxGasForm.tsx +++ b/src/components/transactions/TxDetails/SafeTxGasForm.tsx @@ -3,15 +3,15 @@ import { Link, Box, Paper, Button } from '@mui/material' import { useForm } from 'react-hook-form' import { SafeTxContext } from '@/components/tx-flow/SafeTxProvider' import NumberField from '@/components/common/NumberField' +import useSafeInfo from '@/hooks/useSafeInfo' +import { isLegacyVersion } from '@/hooks/coreSDK/safeCoreSDK' type FormFields = { safeTxGas: number } -const SafeTxGasForm = () => { - const { safeTx, safeTxGas = 0, setSafeTxGas } = useContext(SafeTxContext) - const isEditable = safeTx?.signatures.size === 0 - const [editing, setEditing] = useState(false) +const Form = ({ onSubmit }: { onSubmit: () => void }) => { + const { safeTxGas = 0, setSafeTxGas } = useContext(SafeTxContext) const formMethods = useForm({ defaultValues: { @@ -20,52 +20,58 @@ const SafeTxGasForm = () => { mode: 'onChange', }) - const onSubmit = (values: FormFields) => { + const onFormSubmit = (values: FormFields) => { setSafeTxGas(values.safeTxGas || 0) - setEditing(false) + onSubmit() } + // Close the form w/o submitting if the user clicks outside of it const onBlur = () => { - setTimeout(() => { - setEditing(false) - formMethods.setValue('safeTxGas', safeTxGas) - }, 100) + setTimeout(onSubmit, 100) } return ( - - <> - {safeTxGas} + +
+ + + +
+ ) +} - {isEditable && ( - setEditing(true)} fontSize="small"> - Edit - - )} - +const SafeTxGasForm = () => { + const { safeTx, safeTxGas = 0 } = useContext(SafeTxContext) + const { safe } = useSafeInfo() + const isOldSafe = safe.version && isLegacyVersion(safe.version) + const isEditable = safeTx?.signatures.size === 0 && (safeTxGas > 0 || isOldSafe) + const [editing, setEditing] = useState(false) - {editing && ( - -
- - - -
+ return ( + + {safeTxGas} + + {isEditable && ( + setEditing(true)} fontSize="small"> + Edit + )} + + {editing &&
setEditing(false)} />} ) } diff --git a/src/components/transactions/TxDetails/Summary/index.tsx b/src/components/transactions/TxDetails/Summary/index.tsx index 316e478d02..24eb2a0ef4 100644 --- a/src/components/transactions/TxDetails/Summary/index.tsx +++ b/src/components/transactions/TxDetails/Summary/index.tsx @@ -79,6 +79,8 @@ export const PartialSummary = ({ safeTx }: { safeTx: SafeTransaction }) => { + {txData.baseGas} + {generateDataRowValue(txData.refundReceiver, 'hash', true)} {generateDataRowValue(txData.data, 'rawData')} )