From 4b31e6130e50da51a56576c04d91cb3437c276e9 Mon Sep 17 00:00:00 2001 From: mmv Date: Tue, 18 Jun 2019 15:36:27 +0400 Subject: [PATCH] refactor createTRansaction method to accept safe settings txs wip --- src/routes/safe/components/Layout.jsx | 2 ++ .../ThresholdSettings/ChangeThreshold/index.jsx | 15 +++++++++++---- .../ThresholdSettings/ChangeThreshold/style.js | 2 +- .../Settings/ThresholdSettings/index.jsx | 16 +++++++++++++++- src/routes/safe/components/Settings/index.jsx | 12 ++++++++++-- .../safe/store/actions/createTransaction.js | 1 + 6 files changed, 40 insertions(+), 8 deletions(-) diff --git a/src/routes/safe/components/Layout.jsx b/src/routes/safe/components/Layout.jsx index 80e23b7e..d7c4ac96 100644 --- a/src/routes/safe/components/Layout.jsx +++ b/src/routes/safe/components/Layout.jsx @@ -18,6 +18,7 @@ import { sm, xs, secondary, smallFontSize, } from '~/theme/variables' import { copyToClipboard } from '~/utils/clipboard' +import type { Safe } from '~/routes/safe/store/models/safe' import Balances from './Balances' import Settings from './Settings' @@ -150,6 +151,7 @@ class Layout extends React.Component { etherScanLink={etherScanLink} threshold={safe.threshold} owners={safe.owners} + createTransaction={createTransaction} /> )} diff --git a/src/routes/safe/components/Settings/ThresholdSettings/ChangeThreshold/index.jsx b/src/routes/safe/components/Settings/ThresholdSettings/ChangeThreshold/index.jsx index 4660e621..5155cb37 100644 --- a/src/routes/safe/components/Settings/ThresholdSettings/ChangeThreshold/index.jsx +++ b/src/routes/safe/components/Settings/ThresholdSettings/ChangeThreshold/index.jsx @@ -25,12 +25,19 @@ type Props = { classes: Object, threshold: number, owners: List, + onChangeThreshold: Function, } +const THRESHOLD_FIELD_NAME = 'threshold' + const ChangeThreshold = ({ - onClose, owners, threshold, classes, + onClose, owners, threshold, classes, onChangeThreshold, }: Props) => { - const handleSubmit = () => ({}) + const handleSubmit = (values) => { + const newThreshold = values[THRESHOLD_FIELD_NAME] + + onChangeThreshold(newThreshold) + } return ( @@ -61,7 +68,7 @@ const ChangeThreshold = ({ - + out of {' '} {owners.size} diff --git a/src/routes/safe/components/Settings/ThresholdSettings/ChangeThreshold/style.js b/src/routes/safe/components/Settings/ThresholdSettings/ChangeThreshold/style.js index 9f7ff7ef..7486a68b 100644 --- a/src/routes/safe/components/Settings/ThresholdSettings/ChangeThreshold/style.js +++ b/src/routes/safe/components/Settings/ThresholdSettings/ChangeThreshold/style.js @@ -24,7 +24,7 @@ export const styles = () => ({ modalContent: { padding: `${md} ${lg}`, }, - amount: { + ownersText: { marginLeft: sm, }, buttonRow: { diff --git a/src/routes/safe/components/Settings/ThresholdSettings/index.jsx b/src/routes/safe/components/Settings/ThresholdSettings/index.jsx index 8077c616..3933ec2f 100644 --- a/src/routes/safe/components/Settings/ThresholdSettings/index.jsx +++ b/src/routes/safe/components/Settings/ThresholdSettings/index.jsx @@ -12,20 +12,33 @@ import Paragraph from '~/components/layout/Paragraph' import ChangeThreshold from './ChangeThreshold' import type { Owner } from '~/routes/safe/store/models/owner' import { styles } from './style' +import { getGnosisSafeInstanceAt } from '~/logic/contracts/safeContracts' +import { ZERO_ADDRESS } from '~/logic/wallets/ethAddresses' type Props = { owners: List, threshold: number, classes: Object, + createTransaction: Function, + safeAddress: string, } -const ThresholdSettings = ({ owners, threshold, classes }: Props) => { +const ThresholdSettings = ({ + owners, threshold, classes, createTransaction, safeAddress, +}: Props) => { const [isModalOpen, setModalOpen] = useState(false) const toggleModal = () => { setModalOpen(prevOpen => !prevOpen) } + const onChangeThreshold = async (newThreshold) => { + const safeInstance = await getGnosisSafeInstanceAt(safeAddress) + const data = safeInstance.contract.changeThreshold(newThreshold).encodeABI() + + createTransaction(safeInstance, safeAddress, 0, ZERO_ADDRESS) + } + return ( @@ -66,6 +79,7 @@ owners onClose={toggleModal} owners={owners} threshold={threshold} + onChangeThreshold={onChangeThreshold} /> diff --git a/src/routes/safe/components/Settings/index.jsx b/src/routes/safe/components/Settings/index.jsx index b8b7ca24..46583a51 100644 --- a/src/routes/safe/components/Settings/index.jsx +++ b/src/routes/safe/components/Settings/index.jsx @@ -26,6 +26,7 @@ type Props = { safeName: string, owners: List, threshold: number, + createTransaction: Function, } type Action = 'RemoveSafe' @@ -51,7 +52,7 @@ class Settings extends React.Component { render() { const { showRemoveSafe, menuOptionIndex } = this.state const { - classes, granted, etherScanLink, safeAddress, safeName, owners, threshold, + classes, granted, etherScanLink, safeAddress, safeName, owners, threshold, createTransaction, } = this.props return ( @@ -114,7 +115,14 @@ class Settings extends React.Component { {menuOptionIndex === 1 &&

To be done

} {granted && menuOptionIndex === 2 &&

To be done

} - {granted && menuOptionIndex === 3 && } + {granted && menuOptionIndex === 3 && ( + + )} {granted && menuOptionIndex === 4 &&

To be done

}
diff --git a/src/routes/safe/store/actions/createTransaction.js b/src/routes/safe/store/actions/createTransaction.js index 9471bcd0..ceec6e1a 100644 --- a/src/routes/safe/store/actions/createTransaction.js +++ b/src/routes/safe/store/actions/createTransaction.js @@ -20,6 +20,7 @@ const createTransaction = ( valueInEth: string, token: Token, openSnackbar: Function, + txData: string = EMPTY_DATA, ) => async (dispatch: ReduxDispatch, getState: GetState) => { const isSendingETH = isEther(token.symbol) const state: GlobalState = getState()