Refactor SendModal component
This commit is contained in:
parent
44bd6b1070
commit
c5fd68dae9
|
@ -8,6 +8,7 @@ import Modal from '~/components/Modal'
|
||||||
import ChooseTxType from './screens/ChooseTxType'
|
import ChooseTxType from './screens/ChooseTxType'
|
||||||
import SendFunds from './screens/SendFunds'
|
import SendFunds from './screens/SendFunds'
|
||||||
import ReviewTx from './screens/ReviewTx'
|
import ReviewTx from './screens/ReviewTx'
|
||||||
|
import SendCustomTx from './screens/SendCustomTx'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
onClose: () => void,
|
onClose: () => void,
|
||||||
|
@ -20,14 +21,17 @@ type Props = {
|
||||||
tokens: List<Token>,
|
tokens: List<Token>,
|
||||||
selectedToken: string,
|
selectedToken: string,
|
||||||
createTransaction: Function,
|
createTransaction: Function,
|
||||||
|
activeScreenType: string
|
||||||
}
|
}
|
||||||
type ActiveScreen = 'chooseTxType' | 'sendFunds' | 'reviewTx'
|
|
||||||
|
type ActiveScreen = 'chooseTxType' | 'sendFunds' | 'reviewTx' | 'sendCustomTx' | 'reviewCustomTx'
|
||||||
|
|
||||||
type TxStateType =
|
type TxStateType =
|
||||||
| {
|
| {
|
||||||
token: Token,
|
token: Token,
|
||||||
recipientAddress: string,
|
recipientAddress: string,
|
||||||
amount: string,
|
amount: string,
|
||||||
|
data: string,
|
||||||
}
|
}
|
||||||
| Object
|
| Object
|
||||||
|
|
||||||
|
@ -49,23 +53,24 @@ const Send = ({
|
||||||
tokens,
|
tokens,
|
||||||
selectedToken,
|
selectedToken,
|
||||||
createTransaction,
|
createTransaction,
|
||||||
|
activeScreenType,
|
||||||
}: Props) => {
|
}: Props) => {
|
||||||
const [activeScreen, setActiveScreen] = useState<ActiveScreen>('sendFunds')
|
const [activeScreen, setActiveScreen] = useState<ActiveScreen>(activeScreenType || 'chooseTxType')
|
||||||
const [tx, setTx] = useState<TxStateType>({})
|
const [tx, setTx] = useState<TxStateType>({})
|
||||||
const smallerModalSize = activeScreen === 'chooseTxType'
|
const smallerModalSize = activeScreen === 'chooseTxType'
|
||||||
const handleTxCreation = (txInfo) => {
|
const handleTxCreation = (txInfo) => {
|
||||||
setActiveScreen('reviewTx')
|
setActiveScreen('reviewTx')
|
||||||
setTx(txInfo)
|
setTx(txInfo)
|
||||||
}
|
}
|
||||||
const onClickBack = () => setActiveScreen('sendFunds')
|
const handleCustomTxCreation = (customTxInfo) => {
|
||||||
|
setActiveScreen('reviewCustomTx')
|
||||||
|
setTx(customTxInfo)
|
||||||
|
}
|
||||||
|
|
||||||
useEffect(
|
useEffect(() => {
|
||||||
() => () => {
|
setActiveScreen(activeScreenType || 'chooseTxType')
|
||||||
setActiveScreen('sendFunds')
|
|
||||||
setTx({})
|
setTx({})
|
||||||
},
|
}, [isOpen])
|
||||||
[isOpen],
|
|
||||||
)
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal
|
<Modal
|
||||||
|
@ -95,14 +100,26 @@ const Send = ({
|
||||||
<ReviewTx
|
<ReviewTx
|
||||||
tx={tx}
|
tx={tx}
|
||||||
onClose={onClose}
|
onClose={onClose}
|
||||||
|
setActiveScreen={setActiveScreen}
|
||||||
safeAddress={safeAddress}
|
safeAddress={safeAddress}
|
||||||
etherScanLink={etherScanLink}
|
etherScanLink={etherScanLink}
|
||||||
safeName={safeName}
|
safeName={safeName}
|
||||||
ethBalance={ethBalance}
|
ethBalance={ethBalance}
|
||||||
onClickBack={onClickBack}
|
|
||||||
createTransaction={createTransaction}
|
createTransaction={createTransaction}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
{activeScreen === 'sendCustomTx' && (
|
||||||
|
<SendCustomTx
|
||||||
|
onClose={onClose}
|
||||||
|
setActiveScreen={setActiveScreen}
|
||||||
|
safeAddress={safeAddress}
|
||||||
|
etherScanLink={etherScanLink}
|
||||||
|
safeName={safeName}
|
||||||
|
ethBalance={ethBalance}
|
||||||
|
onSubmit={handleCustomTxCreation}
|
||||||
|
initialValues={tx}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
</Modal>
|
</Modal>
|
||||||
)
|
)
|
||||||
|
|
|
@ -27,11 +27,11 @@ import { styles } from './style'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
onClose: () => void,
|
onClose: () => void,
|
||||||
|
setActiveScreen: Function,
|
||||||
classes: Object,
|
classes: Object,
|
||||||
safeAddress: string,
|
safeAddress: string,
|
||||||
etherScanLink: string,
|
etherScanLink: string,
|
||||||
safeName: string,
|
safeName: string,
|
||||||
onClickBack: Function,
|
|
||||||
ethBalance: string,
|
ethBalance: string,
|
||||||
tx: Object,
|
tx: Object,
|
||||||
createTransaction: Function,
|
createTransaction: Function,
|
||||||
|
@ -44,13 +44,13 @@ const openIconStyle = {
|
||||||
|
|
||||||
const ReviewTx = ({
|
const ReviewTx = ({
|
||||||
onClose,
|
onClose,
|
||||||
|
setActiveScreen,
|
||||||
classes,
|
classes,
|
||||||
safeAddress,
|
safeAddress,
|
||||||
etherScanLink,
|
etherScanLink,
|
||||||
safeName,
|
safeName,
|
||||||
ethBalance,
|
ethBalance,
|
||||||
tx,
|
tx,
|
||||||
onClickBack,
|
|
||||||
createTransaction,
|
createTransaction,
|
||||||
}: Props) => (
|
}: Props) => (
|
||||||
<SharedSnackbarConsumer>
|
<SharedSnackbarConsumer>
|
||||||
|
@ -138,7 +138,7 @@ const ReviewTx = ({
|
||||||
</Block>
|
</Block>
|
||||||
<Hairline style={{ position: 'absolute', bottom: 85 }} />
|
<Hairline style={{ position: 'absolute', bottom: 85 }} />
|
||||||
<Row align="center" className={classes.buttonRow}>
|
<Row align="center" className={classes.buttonRow}>
|
||||||
<Button minWidth={140} minHeight={42} onClick={onClickBack}>
|
<Button minWidth={140} minHeight={42} onClick={() => setActiveScreen('sendFunds')}>
|
||||||
Back
|
Back
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
|
|
Loading…
Reference in New Issue