-
Notifications
You must be signed in to change notification settings - Fork 510
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(dremovebank): refactor remove bank modal (#6217)
* chore(dremovebank): refactor remove bank modal * chore(refactor): refactor BankDetails modal
- Loading branch information
1 parent
4d6bbb7
commit a0c8aff
Showing
4 changed files
with
139 additions
and
202 deletions.
There are no files selected for viewing
102 changes: 24 additions & 78 deletions
102
packages/blockchain-wallet-v4-frontend/src/modals/Brokerage/Banks/BankDetails/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 25 additions & 71 deletions
96
packages/blockchain-wallet-v4-frontend/src/modals/Brokerage/Banks/RemoveBank/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Oops, something went wrong.