From c5fd68dae9d53c9b7ce46e684c8d9784d4a72c1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20Mart=C3=ADnez?= Date: Wed, 28 Aug 2019 11:24:07 +0200 Subject: [PATCH] Refactor SendModal component --- .../components/Balances/SendModal/index.jsx | 39 +++++++++++++------ .../SendModal/screens/ReviewTx/index.jsx | 6 +-- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/src/routes/safe/components/Balances/SendModal/index.jsx b/src/routes/safe/components/Balances/SendModal/index.jsx index b20bb25f..cca7b405 100644 --- a/src/routes/safe/components/Balances/SendModal/index.jsx +++ b/src/routes/safe/components/Balances/SendModal/index.jsx @@ -8,6 +8,7 @@ import Modal from '~/components/Modal' import ChooseTxType from './screens/ChooseTxType' import SendFunds from './screens/SendFunds' import ReviewTx from './screens/ReviewTx' +import SendCustomTx from './screens/SendCustomTx' type Props = { onClose: () => void, @@ -20,14 +21,17 @@ type Props = { tokens: List, selectedToken: string, createTransaction: Function, + activeScreenType: string } -type ActiveScreen = 'chooseTxType' | 'sendFunds' | 'reviewTx' + +type ActiveScreen = 'chooseTxType' | 'sendFunds' | 'reviewTx' | 'sendCustomTx' | 'reviewCustomTx' type TxStateType = | { token: Token, recipientAddress: string, amount: string, + data: string, } | Object @@ -49,23 +53,24 @@ const Send = ({ tokens, selectedToken, createTransaction, + activeScreenType, }: Props) => { - const [activeScreen, setActiveScreen] = useState('sendFunds') + const [activeScreen, setActiveScreen] = useState(activeScreenType || 'chooseTxType') const [tx, setTx] = useState({}) const smallerModalSize = activeScreen === 'chooseTxType' const handleTxCreation = (txInfo) => { setActiveScreen('reviewTx') setTx(txInfo) } - const onClickBack = () => setActiveScreen('sendFunds') + const handleCustomTxCreation = (customTxInfo) => { + setActiveScreen('reviewCustomTx') + setTx(customTxInfo) + } - useEffect( - () => () => { - setActiveScreen('sendFunds') - setTx({}) - }, - [isOpen], - ) + useEffect(() => { + setActiveScreen(activeScreenType || 'chooseTxType') + setTx({}) + }, [isOpen]) return ( )} + {activeScreen === 'sendCustomTx' && ( + + )} ) diff --git a/src/routes/safe/components/Balances/SendModal/screens/ReviewTx/index.jsx b/src/routes/safe/components/Balances/SendModal/screens/ReviewTx/index.jsx index a41c1c02..b330156d 100644 --- a/src/routes/safe/components/Balances/SendModal/screens/ReviewTx/index.jsx +++ b/src/routes/safe/components/Balances/SendModal/screens/ReviewTx/index.jsx @@ -27,11 +27,11 @@ import { styles } from './style' type Props = { onClose: () => void, + setActiveScreen: Function, classes: Object, safeAddress: string, etherScanLink: string, safeName: string, - onClickBack: Function, ethBalance: string, tx: Object, createTransaction: Function, @@ -44,13 +44,13 @@ const openIconStyle = { const ReviewTx = ({ onClose, + setActiveScreen, classes, safeAddress, etherScanLink, safeName, ethBalance, tx, - onClickBack, createTransaction, }: Props) => ( @@ -138,7 +138,7 @@ const ReviewTx = ({ -