-
Notifications
You must be signed in to change notification settings - Fork 504
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(refactor): refactor bank picker (#6263)
- Loading branch information
1 parent
7a05d0f
commit 58c2cee
Showing
11 changed files
with
115 additions
and
167 deletions.
There are no files selected for viewing
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
81 changes: 36 additions & 45 deletions
81
...es/blockchain-wallet-v4-frontend/src/modals/Brokerage/Banks/Withdraw/BankPicker/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,60 +1,51 @@ | ||
import React, { PureComponent } from 'react' | ||
import { connect, ConnectedProps } from 'react-redux' | ||
import { bindActionCreators, Dispatch } from 'redux' | ||
import React, { useEffect } from 'react' | ||
import { useDispatch } from 'react-redux' | ||
|
||
import { Remote } from '@core' | ||
import { BeneficiaryType, ExtractSuccess, WalletFiatType } from '@core/types' | ||
import { BeneficiaryType, WalletFiatType } from '@core/types' | ||
import { FlyoutOopsError } from 'components/Flyout/Errors' | ||
import { actions } from 'data' | ||
import { custodial } from 'data/actions' | ||
import { fetchBankTransferAccounts } from 'data/components/brokerage/slice' | ||
import { RootState } from 'data/rootReducer' | ||
import { useRemote } from 'hooks' | ||
|
||
import Loading from '../EnterAmount/template.loading' | ||
import WithdrawLoading from '../WithdrawLoading' | ||
import getData from './selectors' | ||
import Success from './template.success' | ||
|
||
class BankPicker extends PureComponent<Props> { | ||
componentDidMount() { | ||
if (!Remote.Success.is(this.props.data)) { | ||
this.props.custodialActions.fetchCustodialBeneficiaries({ currency: this.props.fiatCurrency }) | ||
this.props.brokerageActions.fetchBankTransferAccounts() | ||
} | ||
} | ||
|
||
render() { | ||
return this.props.data.cata({ | ||
Failure: () => ( | ||
<FlyoutOopsError | ||
action='close' | ||
data-e2e='withdrawReload' | ||
handler={this.props.handleClose} | ||
/> | ||
), | ||
Loading: () => <Loading />, | ||
NotAsked: () => <Loading />, | ||
Success: (val) => <Success {...this.props} {...val} /> | ||
}) | ||
} | ||
} | ||
|
||
const mapStateToProps = (state: RootState, ownProps: OwnProps) => ({ | ||
data: getData(state, ownProps) | ||
}) | ||
const BankPicker = ({ fiatCurrency, handleClose }: Props) => { | ||
const dispatch = useDispatch() | ||
|
||
const mapDispatchToProps = (dispatch: Dispatch) => ({ | ||
brokerageActions: bindActionCreators(actions.components.brokerage, dispatch), | ||
buySellActions: bindActionCreators(actions.components.buySell, dispatch), | ||
custodialActions: bindActionCreators(actions.custodial, dispatch), | ||
withdrawActions: bindActionCreators(actions.components.withdraw, dispatch) | ||
}) | ||
const { data, error, isLoading, isNotAsked } = useRemote((state: RootState) => | ||
getData(state, { fiatCurrency }) | ||
) | ||
|
||
const connector = connect(mapStateToProps, mapDispatchToProps) | ||
useEffect(() => { | ||
if (!Remote.Success.is(data)) { | ||
dispatch(custodial.fetchCustodialBeneficiaries({ currency: fiatCurrency })) | ||
dispatch(fetchBankTransferAccounts()) | ||
} | ||
}, []) | ||
|
||
if (error) | ||
return <FlyoutOopsError action='close' data-e2e='withdrawReload' handler={handleClose} /> | ||
if (!data || isLoading || isNotAsked) return <WithdrawLoading /> | ||
return ( | ||
<Success | ||
fiatCurrency={fiatCurrency} | ||
bankTransferAccounts={data.bankTransferAccounts} | ||
beneficiaries={data.beneficiaries} | ||
defaultBeneficiary={data.defaultBeneficiary} | ||
defaultMethod={data.defaultMethod} | ||
/> | ||
) | ||
} | ||
|
||
export type OwnProps = { | ||
export type BankPickerProps = { | ||
beneficiary?: BeneficiaryType | ||
fiatCurrency: WalletFiatType | ||
handleClose: () => void | ||
} | ||
export type SuccessStateType = ExtractSuccess<ReturnType<typeof getData>> | ||
export type Props = OwnProps & ConnectedProps<typeof connector> | ||
|
||
export default connector(BankPicker) | ||
type Props = BankPickerProps & { handleClose: () => void } | ||
|
||
export default BankPicker |
23 changes: 20 additions & 3 deletions
23
...blockchain-wallet-v4-frontend/src/modals/Brokerage/Banks/Withdraw/BankPicker/selectors.ts
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
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
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
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
27 changes: 0 additions & 27 deletions
27
...n-wallet-v4-frontend/src/modals/Brokerage/Banks/Withdraw/EnterAmount/template.loading.tsx
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.