Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Philip London
committed
Jul 15, 2020
1 parent
57266c7
commit 71f2096
Showing
13 changed files
with
195 additions
and
38 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
10 changes: 7 additions & 3 deletions
10
...t-v4-frontend/src/modals/SimpleBuy/CryptoSelection/CryptoSelector/CryptoItem/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,18 @@ | ||
import { ExtractSuccess } from 'core/types' | ||
import { getCoinFromPair } from 'data/components/simpleBuy/model' | ||
import { getRatesSelector } from 'core/redux/data/misc/selectors' | ||
import { lift } from 'ramda' | ||
import { RootState } from 'data/rootReducer' | ||
|
||
import { OwnProps } from '.' | ||
import { selectors } from 'data' | ||
|
||
export const getData = (state: RootState, ownProps: OwnProps) => { | ||
const coin = getCoinFromPair(ownProps.value.pair) | ||
const ratesR = getRatesSelector(coin, state) | ||
const ratesR = selectors.core.data.misc.getRatesSelector(coin, state) | ||
const fiatCurrency = selectors.components.simpleBuy.getFiatCurrency(state) | ||
|
||
return lift((rates: ExtractSuccess<typeof ratesR>) => ({ rates }))(ratesR) | ||
return lift((rates: ExtractSuccess<typeof ratesR>) => ({ | ||
fiatCurrency, | ||
rates | ||
}))(ratesR) | ||
} |
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
86 changes: 86 additions & 0 deletions
86
...t-v4-frontend/src/modals/SimpleBuy/CryptoSelection/CryptoSelector/PriceMovement/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 |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { actions } from 'data' | ||
import { bindActionCreators, Dispatch } from 'redux' | ||
import { connect, ConnectedProps } from 'react-redux' | ||
import { FiatType, SBPairType } from 'core/types' | ||
import { getCoinFromPair } from 'data/components/simpleBuy/model' | ||
import { RootState } from 'data/rootReducer' | ||
import React, { PureComponent } from 'react' | ||
import styled, { DefaultTheme } from 'styled-components' | ||
|
||
import { getData } from './selectors' | ||
import { SkeletonRectangle } from 'blockchain-info-components' | ||
|
||
const Container = styled.span` | ||
margin-left: 8px; | ||
` | ||
const Change = styled.span<{ color: keyof DefaultTheme }>` | ||
font-weight: 500; | ||
color: ${props => props.theme[props.color]}; | ||
` | ||
|
||
const getSignFromMovement = (movement: 'none' | 'up' | 'down') => { | ||
switch (movement) { | ||
case 'down': | ||
return '-' | ||
case 'up': | ||
return '+' | ||
default: | ||
return '' | ||
} | ||
} | ||
|
||
const getColorFromMovement = (movement: 'none' | 'up' | 'down') => { | ||
This comment has been minimized.
Sorry, something went wrong. |
||
switch (movement) { | ||
case 'down': | ||
return 'red600' | ||
case 'up': | ||
return 'green600' | ||
default: | ||
return 'grey600' | ||
} | ||
} | ||
|
||
class PriceMovement extends PureComponent<Props, State> { | ||
componentDidMount () { | ||
const coin = getCoinFromPair(this.props.value.pair) | ||
this.props.miscActions.fetchPrice24H(coin, this.props.fiatCurrency || 'EUR') | ||
} | ||
|
||
render () { | ||
return ( | ||
<Container> | ||
{this.props.data.cata({ | ||
Success: val => ( | ||
<Change color={getColorFromMovement(val.price24Hr.movement)}> | ||
{getSignFromMovement(val.price24Hr.movement)} | ||
{val.price24Hr.change}% | ||
</Change> | ||
), | ||
Loading: () => <SkeletonRectangle height={'12px'} width={'40px'} />, | ||
Failure: () => null, | ||
NotAsked: () => null | ||
})} | ||
</Container> | ||
) | ||
} | ||
} | ||
|
||
const mapStateToProps = (state: RootState, ownProps: OwnProps) => ({ | ||
data: getData(state, ownProps) | ||
}) | ||
|
||
const mapDispatchToProps = (dispatch: Dispatch) => ({ | ||
miscActions: bindActionCreators(actions.core.data.misc, dispatch) | ||
}) | ||
|
||
const connector = connect(mapStateToProps, mapDispatchToProps) | ||
|
||
export type OwnProps = { | ||
fiatCurrency?: FiatType | ||
value: SBPairType | ||
} | ||
type SuccessStateType = ReturnType<typeof getData>['data'] | ||
type Props = OwnProps & ConnectedProps<typeof connector> | ||
type State = {} | ||
|
||
export default connector(PriceMovement) |
16 changes: 16 additions & 0 deletions
16
...4-frontend/src/modals/SimpleBuy/CryptoSelection/CryptoSelector/PriceMovement/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { ExtractSuccess } from 'core/types' | ||
import { getCoinFromPair } from 'data/components/simpleBuy/model' | ||
import { lift } from 'ramda' | ||
import { RootState } from 'data/rootReducer' | ||
|
||
import { OwnProps } from '.' | ||
import { selectors } from 'data' | ||
|
||
export const getData = (state: RootState, ownProps: OwnProps) => { | ||
const coin = getCoinFromPair(ownProps.value.pair) | ||
const price24HrR = selectors.core.data.misc.getPrice24H(coin, state) | ||
|
||
return lift((price24Hr: ExtractSuccess<typeof price24HrR>) => ({ | ||
price24Hr | ||
}))(price24HrR) | ||
} |
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
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
you can move this
'none' | 'up' | 'down'
to be one common type and reuse it on both places