-
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(onHold): refactor code (#6290)
- Loading branch information
1 parent
436824b
commit db68b2c
Showing
4 changed files
with
37 additions
and
67 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
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
74 changes: 31 additions & 43 deletions
74
packages/blockchain-wallet-v4-frontend/src/layouts/Wallet/MenuLeft/FundsOnHold/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,56 +1,44 @@ | ||
import React, { useCallback, useEffect } from 'react' | ||
import { connect, ConnectedProps } from 'react-redux' | ||
import { bindActionCreators } from 'redux' | ||
import { useDispatch, useSelector } from 'react-redux' | ||
|
||
import { FiatType } from '@core/types' | ||
import { getCurrency } from '@core/redux/settings/selectors' | ||
import WithdrawalLockHold from 'components/Brokerage/WithdrawalLockHold' | ||
import { actions, selectors } from 'data' | ||
import { RootState } from 'data/rootReducer' | ||
import { modals } from 'data/actions' | ||
import { withdraw } from 'data/components/actions' | ||
import { getWithdrawalLocks } from 'data/components/withdraw/selectors' | ||
import { ModalName, WithdrawStepEnum } from 'data/types' | ||
import { useRemote } from 'hooks' | ||
|
||
import getData from './selectors' | ||
export const FundsOnHoldContainer = () => { | ||
const { data, hasError, isLoading, isNotAsked } = useRemote(getWithdrawalLocks) | ||
|
||
const { data: walletCurrency } = useSelector(getCurrency) | ||
|
||
const dispatch = useDispatch() | ||
|
||
export const FundsOnHoldContainer = (props: Props) => { | ||
useEffect(() => { | ||
props.withdrawActions.fetchWithdrawalLock({ currency: props.walletCurrency }) | ||
}, [props.walletCurrency, props.withdrawActions]) | ||
dispatch(withdraw.fetchWithdrawalLock({ currency: walletCurrency })) | ||
}, [walletCurrency]) | ||
|
||
const handleClick = useCallback(() => { | ||
props.modalActions.showModal(ModalName.CUSTODY_WITHDRAW_MODAL, { | ||
origin: 'SideNav' | ||
}) | ||
props.withdrawActions.setStep({ | ||
step: WithdrawStepEnum.ON_HOLD | ||
}) | ||
}, []) | ||
|
||
return props.data.cata({ | ||
Failure: () => null, | ||
Loading: () => null, | ||
NotAsked: () => null, | ||
Success: (val) => ( | ||
<WithdrawalLockHold | ||
{...val.withdrawalLocks.totalLocked} | ||
handleClick={handleClick} | ||
mode='flyout' | ||
/> | ||
dispatch( | ||
modals.showModal(ModalName.CUSTODY_WITHDRAW_MODAL, { | ||
origin: 'SideNav' | ||
}) | ||
) | ||
}) | ||
} | ||
|
||
const mapStateToProps = (state: RootState) => ({ | ||
data: getData(state), | ||
walletCurrency: selectors.core.settings.getCurrency(state).getOrElse('USD') as FiatType | ||
}) | ||
|
||
const mapDispatchToProps = (dispatch) => ({ | ||
modalActions: bindActionCreators(actions.modals, dispatch), | ||
withdrawActions: bindActionCreators(actions.components.withdraw, dispatch) | ||
}) | ||
dispatch(withdraw.setStep({ step: WithdrawStepEnum.ON_HOLD })) | ||
}, []) | ||
|
||
const connector = connect(mapStateToProps, mapDispatchToProps) | ||
if (isLoading || isNotAsked || !data || hasError) return null | ||
|
||
export type SuccessStateType = ReturnType<typeof getData> | ||
export type Props = ConnectedProps<typeof connector> | ||
return ( | ||
<WithdrawalLockHold | ||
amount={data.totalLocked.amount} | ||
currency={data.totalLocked.currency} | ||
handleClick={handleClick} | ||
mode='flyout' | ||
/> | ||
) | ||
} | ||
|
||
export default connector(FundsOnHoldContainer) | ||
export default FundsOnHoldContainer |
20 changes: 0 additions & 20 deletions
20
packages/blockchain-wallet-v4-frontend/src/layouts/Wallet/MenuLeft/FundsOnHold/selectors.ts
This file was deleted.
Oops, something went wrong.