-
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(balances): refactor code (#6289)
- Loading branch information
1 parent
539d988
commit 11179a1
Showing
5 changed files
with
75 additions
and
113 deletions.
There are no files selected for viewing
27 changes: 11 additions & 16 deletions
27
...ontend/src/layouts/Wallet/MenuLeft/Balances/WalletBalance/PendingBSTransactions/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,33 +1,28 @@ | ||
import React from 'react' | ||
import { FormattedMessage } from 'react-intl' | ||
import { connect, ConnectedProps } from 'react-redux' | ||
import { useSelector } from 'react-redux' | ||
import styled from 'styled-components' | ||
|
||
import { getTotalBSTransactionsPendingN } from '@core/redux/data/custodial/selectors' | ||
import { Text } from 'blockchain-info-components' | ||
import { selectors } from 'data' | ||
import { RootState } from 'data/rootReducer' | ||
|
||
const Wrapper = styled.div` | ||
margin-bottom: 16px; | ||
cursor: initial; | ||
` | ||
|
||
const PendingBSTransactions: React.FC<Props> = ({ n }) => { | ||
return n > 0 ? ( | ||
const PendingBSTransactions = () => { | ||
const pendingTransactions = useSelector(getTotalBSTransactionsPendingN) | ||
|
||
if (pendingTransactions <= 0) return null | ||
return ( | ||
<Wrapper> | ||
<Text size='12px' weight={600} color='grey600'> | ||
{n} <FormattedMessage defaultMessage='Pending Transactions' id='copy.pending_txs' /> | ||
{pendingTransactions}{' '} | ||
<FormattedMessage defaultMessage='Pending Transactions' id='copy.pending_txs' /> | ||
</Text> | ||
</Wrapper> | ||
) : null | ||
) | ||
} | ||
|
||
const mapStateToProps = (state: RootState) => ({ | ||
n: selectors.core.data.custodial.getTotalBSTransactionsPendingN(state) | ||
}) | ||
|
||
const connector = connect(mapStateToProps) | ||
|
||
type Props = ConnectedProps<typeof connector> | ||
|
||
export default connector(PendingBSTransactions) | ||
export default PendingBSTransactions |
63 changes: 24 additions & 39 deletions
63
...lockchain-wallet-v4-frontend/src/layouts/Wallet/MenuLeft/Balances/WalletBalance/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,42 +1,27 @@ | ||
import React from 'react' | ||
import { connect, ConnectedProps } from 'react-redux' | ||
import { prop } from 'ramda' | ||
import { bindActionCreators } from 'redux' | ||
|
||
import { actions, selectors } from 'data' | ||
|
||
import Template from './template' | ||
|
||
class WalletBalanceContainer extends React.PureComponent<Props> { | ||
render() { | ||
const { coins, preferencesActions, totalBalancesDropdown } = this.props | ||
const isActive = prop('wallet', totalBalancesDropdown) | ||
return ( | ||
<Template | ||
isActive={isActive} | ||
coins={coins} | ||
handleToggle={() => | ||
preferencesActions.setTotalBalancesDropdown({ | ||
key: 'wallet', | ||
val: !isActive | ||
}) | ||
} | ||
/> | ||
) | ||
} | ||
import { useSelector } from 'react-redux' | ||
|
||
import { Wrapper } from 'components/Balances' | ||
import { selectors } from 'data' | ||
|
||
import { BalancesWrapper } from '../model' | ||
import Balance from './Balance' | ||
import PendingBSTransactions from './PendingBSTransactions' | ||
|
||
const WalletBalance = () => { | ||
const coins = useSelector(selectors.balances.getTotalWalletBalancesSorted).getOrElse([]) | ||
const isActive = useSelector(selectors.preferences.getTotalBalancesDropdown)?.wallet | ||
|
||
return ( | ||
<Wrapper> | ||
<PendingBSTransactions /> | ||
<BalancesWrapper className={isActive ? 'active' : ''}> | ||
{coins.map((coin) => ( | ||
<Balance coin={coin.symbol} coinTicker={coin.symbol} key={coin.symbol} /> | ||
))} | ||
</BalancesWrapper> | ||
</Wrapper> | ||
) | ||
} | ||
|
||
const mapStateToProps = (state) => ({ | ||
coins: selectors.balances.getTotalWalletBalancesSorted(state).getOrElse([]), | ||
totalBalancesDropdown: selectors.preferences.getTotalBalancesDropdown(state) | ||
}) | ||
|
||
const mapDispatchToProps = (dispatch) => ({ | ||
preferencesActions: bindActionCreators(actions.preferences, dispatch) | ||
}) | ||
|
||
const connector = connect(mapStateToProps, mapDispatchToProps) | ||
|
||
type Props = ConnectedProps<typeof connector> | ||
|
||
export default connector(WalletBalanceContainer) | ||
export default WalletBalance |
27 changes: 0 additions & 27 deletions
27
...kchain-wallet-v4-frontend/src/layouts/Wallet/MenuLeft/Balances/WalletBalance/template.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
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