Refactor modal window handling

This commit is contained in:
Germán Martínez 2019-08-28 11:00:49 +02:00
parent a1b787a9d9
commit 44bd6b1070
3 changed files with 67 additions and 3 deletions

View File

@ -220,6 +220,7 @@ class Balances extends React.Component<Props, State> {
tokens={activeTokens} tokens={activeTokens}
selectedToken={sendFunds.selectedToken} selectedToken={sendFunds.selectedToken}
createTransaction={createTransaction} createTransaction={createTransaction}
activeScreenType="sendFunds"
/> />
<Modal <Modal
title="Receive Tokens" title="Receive Tokens"

View File

@ -14,6 +14,9 @@ import Button from '~/components/layout/Button'
import Link from '~/components/layout/Link' import Link from '~/components/layout/Link'
import Paragraph from '~/components/layout/Paragraph' import Paragraph from '~/components/layout/Paragraph'
import Img from '~/components/layout/Img' import Img from '~/components/layout/Img'
import Modal from '~/components/Modal'
import SendModal from './Balances/SendModal'
import Receive from './Balances/Receive'
import NoSafe from '~/components/NoSafe' import NoSafe from '~/components/NoSafe'
import { type SelectorProps } from '~/routes/safe/container/selector' import { type SelectorProps } from '~/routes/safe/container/selector'
import { getEtherScanLink } from '~/logic/wallets/getWeb3' import { getEtherScanLink } from '~/logic/wallets/getWeb3'
@ -43,6 +46,12 @@ type Props = SelectorProps &
Actions & { Actions & {
classes: Object, classes: Object,
granted: boolean, granted: boolean,
sendFunds: Object,
showReceive: boolean,
onShow: Function,
onHide: Function,
showSendFunds: Function,
hideSendFunds: Function
} }
const openIconStyle = { const openIconStyle = {
@ -119,6 +128,12 @@ class Layout extends React.Component<Props, State> {
updateSafe, updateSafe,
transactions, transactions,
userAddress, userAddress,
sendFunds,
showReceive,
onShow,
onHide,
showSendFunds,
hideSendFunds,
} = this.props } = this.props
const { tabIndex } = this.state const { tabIndex } = this.state
@ -156,7 +171,7 @@ class Layout extends React.Component<Props, State> {
size="small" size="small"
color="primary" color="primary"
className={classes.receive} className={classes.receive}
onClick={() => {}} onClick={onShow('Receive')}
rounded rounded
> >
<Img src={ReceiveTx} alt="Receive Transaction" className={classNames(classes.leftIcon, classes.iconSmall)} /> <Img src={ReceiveTx} alt="Receive Transaction" className={classNames(classes.leftIcon, classes.iconSmall)} />
@ -168,7 +183,7 @@ class Layout extends React.Component<Props, State> {
size="small" size="small"
color="primary" color="primary"
className={classes.send} className={classes.send}
onClick={() => {}} onClick={() => showSendFunds('Ether')}
rounded rounded
testId="balance-send-btn" testId="balance-send-btn"
> >

View File

@ -6,6 +6,13 @@ import Layout from '~/routes/safe/components/Layout'
import selector, { type SelectorProps } from './selector' import selector, { type SelectorProps } from './selector'
import actions, { type Actions } from './actions' import actions, { type Actions } from './actions'
type State = {
showReceive: boolean,
sendFunds: Object,
}
type Action = 'Send' | 'Receive'
export type Props = Actions & export type Props = Actions &
SelectorProps & { SelectorProps & {
granted: boolean, granted: boolean,
@ -13,7 +20,15 @@ export type Props = Actions &
const TIMEOUT = process.env.NODE_ENV === 'test' ? 1500 : 5000 const TIMEOUT = process.env.NODE_ENV === 'test' ? 1500 : 5000
class SafeView extends React.Component<Props> { class SafeView extends React.Component<Props, State> {
state = {
sendFunds: {
isOpen: false,
selectedToken: undefined,
},
showReceive: false,
}
intervalId: IntervalID intervalId: IntervalID
componentDidMount() { componentDidMount() {
@ -44,6 +59,32 @@ class SafeView extends React.Component<Props> {
clearInterval(this.intervalId) clearInterval(this.intervalId)
} }
onShow = (action: Action) => () => {
this.setState(() => ({ [`show${action}`]: true }))
}
onHide = (action: Action) => () => {
this.setState(() => ({ [`show${action}`]: false }))
}
showSendFunds = (token: Token) => {
this.setState({
sendFunds: {
isOpen: true,
selectedToken: token,
},
})
}
hideSendFunds = () => {
this.setState({
sendFunds: {
isOpen: false,
selectedToken: undefined,
},
})
}
checkForUpdates() { checkForUpdates() {
const { const {
safeUrl, activeTokens, fetchTokenBalances, safeUrl, activeTokens, fetchTokenBalances,
@ -53,6 +94,7 @@ class SafeView extends React.Component<Props> {
} }
render() { render() {
const { sendFunds, showReceive } = this.state
const { const {
safe, safe,
provider, provider,
@ -83,6 +125,12 @@ class SafeView extends React.Component<Props> {
fetchTransactions={fetchTransactions} fetchTransactions={fetchTransactions}
updateSafe={updateSafe} updateSafe={updateSafe}
transactions={transactions} transactions={transactions}
sendFunds={sendFunds}
showReceive={showReceive}
onShow={this.onShow}
onHide={this.onHide}
showSendFunds={this.showSendFunds}
hideSendFunds={this.hideSendFunds}
/> />
</Page> </Page>
) )