Skip to content

Commit

Permalink
chore(dremovebank): refactor remove bank modal (#6217)
Browse files Browse the repository at this point in the history
* chore(dremovebank): refactor remove bank modal

* chore(refactor): refactor BankDetails modal
  • Loading branch information
mperdomo-bc committed Jan 5, 2024
1 parent 4d6bbb7 commit a0c8aff
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 202 deletions.
Original file line number Diff line number Diff line change
@@ -1,96 +1,42 @@
import React, { PureComponent } from 'react'
import { connect, ConnectedProps } from 'react-redux'
import { bindActionCreators, compose, Dispatch } from 'redux'
import React, { useEffect, useState } from 'react'
import { useSelector } from 'react-redux'
import { compose } from 'redux'

import { WalletCurrencyType } from '@core/types'
import Flyout, { duration, FlyoutChild } from 'components/Flyout'
import { actions, selectors } from 'data'
import { RootState } from 'data/rootReducer'
import { BankTransferAccountType, BrokerageModalOriginType, ModalName } from 'data/types'
import { selectors } from 'data'
import { ModalName } from 'data/types'
import ModalEnhancer from 'providers/ModalEnhancer'

import { ModalPropsType } from '../../../types'
import Template from './template'

export type OwnProps = {
handleClose: () => void
} & ModalPropsType
const BankDetails = (props: ModalPropsType) => {
const [show, setShow] = useState(false)

export type LinkDispatchPropsType = {
brokerageActions: typeof actions.components.brokerage
}
export type LinkStatePropsType = {
account: BankTransferAccountType | undefined
walletCurrency: WalletCurrencyType
}
// export type Props = OwnProps & LinkDispatchPropsType & LinkStatePropsType
const account = useSelector(selectors.components.brokerage.getAccount)

class BankDetails extends PureComponent<Props, {}> {
state: State = { show: false }

componentDidMount() {
/* eslint-disable */
this.setState({ show: true })
/* eslint-enable */
}

handleClose = () => {
this.setState({ show: false })
const handleClose = () => {
setShow(false)
setTimeout(() => {
this.props.close()
props.close()
}, duration)
}

handleSubmit = () => {
if (this.props.account) {
this.props.brokerageActions.showModal({
modalType: 'REMOVE_BANK_MODAL',
origin: BrokerageModalOriginType.BANK
})
this.props.brokerageActions.setBankDetails({
account: this.props.account,
redirectBackToStep: true
})
}
}
useEffect(() => {
setShow(true)
}, [])

render() {
if (!this.props.account) {
return null
}
return (
<Flyout
{...this.props}
onClose={this.handleClose}
isOpen={this.state.show}
data-e2e='bankDetailsModal'
>
<FlyoutChild>
<Template {...this.props} onSubmit={this.handleSubmit} handleClose={this.handleClose} />
</FlyoutChild>
</Flyout>
)
}
}

const mapStateToProps = (state: RootState): LinkStatePropsType => ({
account: selectors.components.brokerage.getAccount(state),
walletCurrency: selectors.core.settings.getCurrency(state).getOrElse('USD')
})

const mapDispatchToProps = (dispatch: Dispatch): LinkDispatchPropsType => ({
brokerageActions: bindActionCreators(actions.components.brokerage, dispatch)
})
if (!account) return null

const connector = connect(mapStateToProps, mapDispatchToProps)

const enhance = compose(
ModalEnhancer(ModalName.BANK_DETAILS_MODAL, { transition: duration }),
connector
)

export type Props = OwnProps & LinkStatePropsType & ConnectedProps<typeof connector>
return (
<Flyout {...props} onClose={handleClose} isOpen={show} data-e2e='bankDetailsModal'>
<FlyoutChild>
<Template account={account} handleClose={handleClose} />
</FlyoutChild>
</Flyout>
)
}

type State = { show: boolean }
const enhance = compose(ModalEnhancer(ModalName.BANK_DETAILS_MODAL, { transition: duration }))

export default enhance(BankDetails)
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import React from 'react'
import { FormattedMessage } from 'react-intl'
import { useDispatch, useSelector } from 'react-redux'
import { InjectedFormProps, reduxForm } from 'redux-form'
import styled from 'styled-components'

import { getCurrency } from '@core/redux/settings/selectors'
import { Button, HeartbeatLoader, Icon, Image, Text } from 'blockchain-info-components'
import { FlyoutWrapper } from 'components/Flyout'
import Form from 'components/Form/Form'
import { brokerage } from 'data/components/actions'
import { BankTransferAccountType, BrokerageModalOriginType } from 'data/types'
import { getBankLogoImageName } from 'services/images'

import { LinkDispatchPropsType, LinkStatePropsType, OwnProps } from '.'

const Wrapper = styled.div`
width: 100%;
height: 100%;
Expand Down Expand Up @@ -49,19 +50,42 @@ export const BankDetails = styled.div`
margin-top: 24px;
`

type Props = OwnProps & LinkDispatchPropsType & LinkStatePropsType
type Props = {
account: BankTransferAccountType
handleClose: () => void
}

const Template: React.FC<InjectedFormProps<{}, Props> & Props> = ({
account,
handleClose,
submitting
}) => {
const dispatch = useDispatch()
const walletCurrency = useSelector(getCurrency).getOrElse('USD')

const Template: React.FC<InjectedFormProps<{}, Props> & Props> = (props) => {
const { account, walletCurrency } = props
const { details } = account

const bankAccountName =
account && 'details' in account ? (
`${account.details?.bankName || ''} ${account.details?.accountNumber || ''}`
) : (
<FormattedMessage id='copy.bank_account' defaultMessage='Bank Account' />
const bankAccountName = details ? (
`${details?.bankName || ''} ${details?.accountNumber || ''}`
) : (
<FormattedMessage id='copy.bank_account' defaultMessage='Bank Account' />
)

const onClick = () => {
dispatch(
brokerage.showModal({
modalType: 'REMOVE_BANK_MODAL',
origin: BrokerageModalOriginType.BANK
})
)
dispatch(
brokerage.setBankDetails({
account,
redirectBackToStep: true
})
)
}

const accountDetails = account && 'details' in account && account.details
return (
<Wrapper>
<FlyoutWrapper>
Expand All @@ -73,21 +97,21 @@ const Template: React.FC<InjectedFormProps<{}, Props> & Props> = (props) => {
size='20px'
color='grey600'
role='button'
onClick={props.handleClose}
onClick={handleClose}
/>
</CloseContainer>

<BankIconWrapper>
{accountDetails && <Image name={getBankLogoImageName(accountDetails.bankName)} />}
{details && <Image name={getBankLogoImageName(details.bankName)} />}
</BankIconWrapper>
<BankDetails>
<Text size='24px' color='grey900' weight={600}>
{bankAccountName}
</Text>
<Text size='24px' color='grey600' weight={500}>
{(accountDetails && accountDetails.bankAccountType?.toLowerCase()) || ''}{' '}
{details.bankAccountType?.toLowerCase() || ''}{' '}
<FormattedMessage id='scenes.settings.general.account' defaultMessage='account' />{' '}
{(account && 'details' in account && account.details.accountNumber) || ''}
{account.details?.accountNumber || ''}
</Text>
</BankDetails>
</FlyoutWrapper>
Expand All @@ -113,23 +137,21 @@ const Template: React.FC<InjectedFormProps<{}, Props> & Props> = (props) => {
</Text>
</DisclaimerWrapper>
<BankFlyoutWrapper>
<Form onSubmit={props.handleSubmit}>
<Button
fullwidth
size='16px'
height='48px'
nature='light-red'
data-e2e='removeBankDetials'
disabled={props.submitting}
type='submit'
>
{props.submitting ? (
<HeartbeatLoader color='blue100' height='20px' width='20px' />
) : (
<FormattedMessage id='buttons.remove' defaultMessage='Remove' />
)}
</Button>
</Form>
<Button
fullwidth
size='16px'
height='48px'
nature='light-red'
data-e2e='removeBankDetails'
disabled={submitting}
onClick={onClick}
>
{submitting ? (
<HeartbeatLoader color='blue100' height='20px' width='20px' />
) : (
<FormattedMessage id='buttons.remove' defaultMessage='Remove' />
)}
</Button>
</BankFlyoutWrapper>
</Wrapper>
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,88 +1,42 @@
import React, { PureComponent } from 'react'
import { connect, ConnectedProps } from 'react-redux'
import { bindActionCreators, compose, Dispatch } from 'redux'
import React, { useEffect, useState } from 'react'
import { useSelector } from 'react-redux'
import { compose } from 'redux'

import Flyout, { duration, FlyoutChild } from 'components/Flyout'
import { actions, selectors } from 'data'
import { RootState } from 'data/rootReducer'
import { BankTransferAccountType, ModalName } from 'data/types'
import { selectors } from 'data'
import { ModalName } from 'data/types'
import ModalEnhancer from 'providers/ModalEnhancer'

import { ModalPropsType } from '../../../types'
import Template from './template'

export type OwnProps = {
handleClose: () => void
} & ModalPropsType
const RemoveBankFlyout = (props: ModalPropsType) => {
const [show, setShow] = useState(false)

export type LinkDispatchPropsType = {
brokerageActions: typeof actions.components.brokerage
}

export type LinkStatePropsType = {
account: BankTransferAccountType | undefined
redirectBackToStep: boolean
}

class CancelOrder extends PureComponent<Props, {}> {
state: State = { show: false }
const account = useSelector(selectors.components.brokerage.getAccount)

componentDidMount() {
/* eslint-disable */
this.setState({ show: true })
/* eslint-enable */
}

handleClose = () => {
this.setState({ show: false })
const handleClose = () => {
setShow(false)
setTimeout(() => {
this.props.close()
props.close()
}, duration)
}

handleSubmit = () => {
if (this.props.account) {
this.props.brokerageActions.deleteSavedBank(this.props.account.id)
}
}

render() {
if (!this.props.account) {
return null
}
return (
<Flyout
{...this.props}
onClose={this.handleClose}
isOpen={this.state.show}
data-e2e='bankRemoveModal'
>
<FlyoutChild>
<Template {...this.props} onSubmit={this.handleSubmit} handleClose={this.handleClose} />
</FlyoutChild>
</Flyout>
)
}
}

const mapStateToProps = (state: RootState): LinkStatePropsType => ({
account: selectors.components.brokerage.getAccount(state),
redirectBackToStep: selectors.components.brokerage.getRedirectBackToStep(state)
})
useEffect(() => {
setShow(true)
}, [])

const mapDispatchToProps = (dispatch: Dispatch): LinkDispatchPropsType => ({
brokerageActions: bindActionCreators(actions.components.brokerage, dispatch)
})
if (!account) return null

const connector = connect(mapStateToProps, mapDispatchToProps)

const enhance = compose(
ModalEnhancer(ModalName.REMOVE_BANK_MODAL, { transition: duration }),
connector
)

export type Props = OwnProps & LinkStatePropsType & ConnectedProps<typeof connector>
return (
<Flyout {...props} onClose={handleClose} isOpen={show} data-e2e='bankRemoveModal'>
<FlyoutChild>
<Template account={account} handleClose={handleClose} />
</FlyoutChild>
</Flyout>
)
}

type State = { show: boolean }
const enhance = compose(ModalEnhancer(ModalName.REMOVE_BANK_MODAL, { transition: duration }))

export default enhance(CancelOrder)
export default enhance(RemoveBankFlyout)
Loading

0 comments on commit a0c8aff

Please sign in to comment.