-
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.
refactor(Swap): split min/max buttons
- Loading branch information
1 parent
65ab1c0
commit c9b82a9
Showing
6 changed files
with
123 additions
and
99 deletions.
There are no files selected for viewing
104 changes: 104 additions & 0 deletions
104
...kchain-wallet-v4-frontend/src/scenes/Exchange/ExchangeForm/MinMaxButtons/MinMaxButtons.js
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 |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import React from 'react' | ||
import styled from 'styled-components' | ||
import { bindActionCreators } from 'redux' | ||
import { FormattedMessage } from 'react-intl' | ||
import { connect } from 'react-redux' | ||
import { contains, equals, gte, isNil, prop } from 'ramda' | ||
|
||
import { actions, model } from 'data' | ||
import { getData } from './selectors' | ||
import { Row } from '../Layout' | ||
import { Button } from 'blockchain-info-components' | ||
|
||
const { | ||
NO_LIMITS_ERROR, | ||
REACHED_DAILY_ERROR, | ||
REACHED_WEEKLY_ERROR, | ||
REACHED_ANNUAL_ERROR, | ||
MINIMUM_NO_LINK_ERROR | ||
} = model.components.exchange | ||
|
||
const MinMaxButton = styled(Button)` | ||
width: 48%; | ||
font-size: 10px; | ||
justify-content: space-between; | ||
> * { | ||
color: ${props => props.theme['brand-primary']}; | ||
} | ||
` | ||
const MinMaxValue = styled.div` | ||
font-weight: 600; | ||
font-size: 14px; | ||
` | ||
|
||
const formatAmount = (isFiat, symbol, value) => | ||
isFiat ? `${symbol}${value}` : `${value} ${symbol}` | ||
|
||
class MinMaxButtons extends React.PureComponent { | ||
render () { | ||
const { error, min, max, actions } = this.props | ||
const minMaxDisabled = | ||
contains(error, [ | ||
NO_LIMITS_ERROR, | ||
MINIMUM_NO_LINK_ERROR, | ||
REACHED_DAILY_ERROR, | ||
REACHED_WEEKLY_ERROR, | ||
REACHED_ANNUAL_ERROR | ||
]) || | ||
(equals(prop('symbol', min), prop('symbol', max)) && | ||
gte(prop('amount', min), prop('amount', max))) || | ||
isNil(min) || | ||
isNil(max) | ||
return ( | ||
<Row> | ||
<MinMaxButton | ||
fullwidth | ||
disabled={minMaxDisabled} | ||
onClick={actions.useMin} | ||
> | ||
<FormattedMessage | ||
id='scenes.exchange.exchangeform.min' | ||
defaultMessage='MIN' | ||
/> | ||
| ||
<MinMaxValue> | ||
{!minMaxDisabled && | ||
formatAmount( | ||
prop('fiat', min), | ||
prop('symbol', min), | ||
prop('amount', min) | ||
)} | ||
</MinMaxValue> | ||
</MinMaxButton> | ||
<MinMaxButton | ||
fullwidth | ||
disabled={minMaxDisabled} | ||
onClick={actions.useMax} | ||
> | ||
<FormattedMessage | ||
id='scenes.exchange.exchangeform.max' | ||
defaultMessage='MAX' | ||
/> | ||
| ||
<MinMaxValue> | ||
{!minMaxDisabled && | ||
formatAmount( | ||
prop('fiat', max), | ||
prop('symbol', max), | ||
prop('amount', max) | ||
)} | ||
</MinMaxValue> | ||
</MinMaxButton> | ||
</Row> | ||
) | ||
} | ||
} | ||
|
||
const mapDispatchToProps = dispatch => ({ | ||
actions: bindActionCreators(actions.components.exchange, dispatch) | ||
}) | ||
|
||
export default connect( | ||
getData, | ||
mapDispatchToProps | ||
)(MinMaxButtons) |
2 changes: 2 additions & 0 deletions
2
...ges/blockchain-wallet-v4-frontend/src/scenes/Exchange/ExchangeForm/MinMaxButtons/index.js
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import MinMaxButtons from './MinMaxButtons' | ||
export default MinMaxButtons |
9 changes: 9 additions & 0 deletions
9
...blockchain-wallet-v4-frontend/src/scenes/Exchange/ExchangeForm/MinMaxButtons/selectors.js
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { createDeepEqualSelector } from 'services/ReselectHelper' | ||
import { selectors } from 'data' | ||
|
||
export const { getMin, getMax } = selectors.components.exchange | ||
|
||
export const getData = createDeepEqualSelector( | ||
[getMin, getMax], | ||
(min, max) => ({ min, max }) | ||
) |
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