-
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(settings): refactor linked banks (#6162)
* chore(settings): refactor linked banks * chore(refactor): addres linked banks pr comment
- Loading branch information
1 parent
1045e11
commit ea1e7bb
Showing
2 changed files
with
88 additions
and
121 deletions.
There are no files selected for viewing
111 changes: 22 additions & 89 deletions
111
packages/blockchain-wallet-v4-frontend/src/scenes/Settings/General/LinkedBanks/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,102 +1,35 @@ | ||
import React, { PureComponent } from 'react' | ||
import { connect, ConnectedProps } from 'react-redux' | ||
import { path } from 'ramda' | ||
import { bindActionCreators, Dispatch } from 'redux' | ||
import React, { useEffect } from 'react' | ||
import { useDispatch, useSelector } from 'react-redux' | ||
|
||
import { ExtractSuccess, RemoteDataType, WalletFiatType } from '@core/types' | ||
import { actions, selectors } from 'data' | ||
import { RootState } from 'data/rootReducer' | ||
import { | ||
AddBankStepType, | ||
BankTransferAccountType, | ||
BrokerageModalOriginType, | ||
UserDataType | ||
} from 'data/types' | ||
import { BSPaymentMethodsType } from '@core/types' | ||
import { brokerage, buySell } from 'data/components/actions' | ||
import { getTradingCurrency } from 'data/modules/profile/selectors' | ||
import { BankTransferAccountType } from 'data/types' | ||
import { useRemote } from 'hooks' | ||
|
||
import getData from './selectors' | ||
import Loading from './template.loading' | ||
import Success from './template.success' | ||
|
||
class LinkedBanks extends PureComponent<Props> { | ||
componentDidMount() { | ||
this.props.brokerageActions.fetchBankTransferAccounts() | ||
this.props.buySellActions.fetchPaymentMethods(this.props.tradingCurrency) | ||
} | ||
|
||
handleBankClick = () => { | ||
const { plaidEnabled, tradingCurrency } = this.props | ||
const ACHProvider = plaidEnabled ? 'ADD_BANK_PLAID_MODAL' : 'ADD_BANK_YODLEE_MODAL' | ||
this.props.brokerageActions.showModal({ | ||
modalType: tradingCurrency === 'USD' ? ACHProvider : 'ADD_BANK_YAPILY_MODAL', | ||
origin: BrokerageModalOriginType.ADD_BANK_SETTINGS | ||
}) | ||
|
||
this.props.brokerageActions.setAddBankStep({ | ||
addBankStep: AddBankStepType.ADD_BANK | ||
}) | ||
} | ||
|
||
handleShowBankClick = (account: BankTransferAccountType) => { | ||
this.props.brokerageActions.showModal({ | ||
modalType: 'BANK_DETAILS_MODAL', | ||
origin: BrokerageModalOriginType.BANK | ||
}) | ||
this.props.brokerageActions.setBankDetails({ | ||
account | ||
}) | ||
} | ||
|
||
handleDeleteBank = (account: BankTransferAccountType) => { | ||
this.props.brokerageActions.showModal({ | ||
modalType: 'REMOVE_BANK_MODAL', | ||
origin: BrokerageModalOriginType.BANK | ||
}) | ||
this.props.brokerageActions.setBankDetails({ | ||
account | ||
}) | ||
} | ||
|
||
render() { | ||
return this.props.data.cata({ | ||
Failure: () => null, | ||
Loading: () => <Loading />, | ||
NotAsked: () => <Loading />, | ||
Success: (val) => ( | ||
<Success | ||
{...this.props} | ||
{...val} | ||
handleBankClick={this.handleBankClick} | ||
handleShowBankClick={this.handleShowBankClick} | ||
handleDeleteBank={this.handleDeleteBank} | ||
/> | ||
) | ||
}) | ||
} | ||
type DataType = { | ||
bankAccounts: BankTransferAccountType[] | ||
paymentMethods: BSPaymentMethodsType | ||
} | ||
|
||
const mapStateToProps = (state: RootState): LinkStatePropsType => ({ | ||
data: getData(state), | ||
plaidEnabled: selectors.core.walletOptions.getAddPlaidPaymentProvider(state).getOrElse(false), | ||
tradingCurrency: selectors.modules.profile.getTradingCurrency(state).getOrElse('USD'), | ||
userData: selectors.modules.profile.getUserData(state).getOrElse({} as UserDataType) | ||
}) | ||
const LinkedBanks = () => { | ||
const { data, hasError, isLoading, isNotAsked } = useRemote(getData) | ||
const tradingCurrency = useSelector(getTradingCurrency).getOrElse('USD') | ||
|
||
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 dispatch = useDispatch() | ||
|
||
const connector = connect(mapStateToProps, mapDispatchToProps) | ||
useEffect(() => { | ||
dispatch(brokerage.fetchBankTransferAccounts()) | ||
dispatch(buySell.fetchPaymentMethods(tradingCurrency)) | ||
}, []) | ||
|
||
type LinkStatePropsType = { | ||
data: RemoteDataType<string, SuccessStateType> | ||
plaidEnabled: unknown | boolean | ||
tradingCurrency: WalletFiatType | ||
userData: UserDataType | ||
if (isLoading || isNotAsked) return <Loading /> | ||
if (hasError || !data) return null | ||
return <Success tradingCurrency={tradingCurrency} {...(data as DataType)} /> | ||
} | ||
export type SuccessStateType = ExtractSuccess<ReturnType<typeof getData>> | ||
export type Props = ConnectedProps<typeof connector> | ||
|
||
export default connector(LinkedBanks) | ||
export default LinkedBanks |
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