From bda07eb33dea737770a31266f099d00dc5d31587 Mon Sep 17 00:00:00 2001 From: Daniel Sanchez Date: Mon, 15 Feb 2021 20:21:42 +0100 Subject: [PATCH] Store threshold value when editing transaction parameters --- .../ThresholdSettings/ChangeThreshold/index.tsx | 15 +++++++++------ .../Transactions/helpers/EditableTxParameters.tsx | 8 +------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/routes/safe/components/Settings/ThresholdSettings/ChangeThreshold/index.tsx b/src/routes/safe/components/Settings/ThresholdSettings/ChangeThreshold/index.tsx index 4397b5ae..34ededcd 100644 --- a/src/routes/safe/components/Settings/ThresholdSettings/ChangeThreshold/index.tsx +++ b/src/routes/safe/components/Settings/ThresholdSettings/ChangeThreshold/index.tsx @@ -2,7 +2,7 @@ import IconButton from '@material-ui/core/IconButton' import MenuItem from '@material-ui/core/MenuItem' import { makeStyles } from '@material-ui/core/styles' import Close from '@material-ui/icons/Close' -import React, { useEffect, useState } from 'react' +import React, { ReactElement, useEffect, useState } from 'react' import { useDispatch } from 'react-redux' import { List } from 'immutable' @@ -44,12 +44,13 @@ export const ChangeThresholdModal = ({ owners, safeAddress, threshold = 1, -}: ChangeThresholdModalProps): React.ReactElement => { +}: ChangeThresholdModalProps): ReactElement => { const classes = useStyles() const dispatch = useDispatch() const [data, setData] = useState('') const [manualSafeTxGas, setManualSafeTxGas] = useState(0) const [manualGasPrice, setManualGasPrice] = useState() + const [editedThreshold, setEditedThreshold] = useState(threshold) const { gasCostFormatted, @@ -71,7 +72,7 @@ export const ChangeThresholdModal = ({ let isCurrent = true const calculateChangeThresholdData = async () => { const safeInstance = await getGnosisSafeInstanceAt(safeAddress) - const txData = safeInstance.methods.changeThreshold(threshold).encodeABI() + const txData = safeInstance.methods.changeThreshold(editedThreshold).encodeABI() if (isCurrent) { setData(txData) } @@ -81,7 +82,7 @@ export const ChangeThresholdModal = ({ return () => { isCurrent = false } - }, [safeAddress, threshold]) + }, [safeAddress, editedThreshold]) const getParametersStatus = () => (threshold > 1 ? 'ETH_DISABLED' : 'ENABLED') @@ -135,7 +136,7 @@ export const ChangeThresholdModal = ({ - + {() => ( <> @@ -147,6 +148,9 @@ export const ChangeThresholdModal = ({ { + setEditedThreshold(parseInt(target.value)) + }} render={(props) => ( <> @@ -177,7 +181,6 @@ export const ChangeThresholdModal = ({ !prev) } - // Sends a callback with the last values of txParameters - useEffect(() => { - if (!isEditMode && closeEditModalCallback) { - closeEditModalCallback(txParameters) - } - }, [isEditMode, closeEditModalCallback, txParameters]) - const closeEditFormHandler = (txParameters?: TxParameters) => { if (txParameters) { setUseManualValues(true) @@ -65,6 +58,7 @@ export const EditableTxParameters = ({ setEthGasLimit(txParameters.ethGasLimit) setEthGasPrice(txParameters.ethGasPrice) setEthNonce(txParameters.ethNonce) + closeEditModalCallback && closeEditModalCallback(txParameters) } toggleStatus() }