-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
factor out containers for currency components (#8543)
- Loading branch information
1 parent
54b423d
commit 0aa41e3
Showing
21 changed files
with
735 additions
and
607 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
2 changes: 1 addition & 1 deletion
2
ui/app/components/app/user-preferenced-currency-display/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 |
---|---|---|
@@ -1 +1 @@ | ||
export { default } from './user-preferenced-currency-display.container' | ||
export { default } from './user-preferenced-currency-display.component' |
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
202 changes: 0 additions & 202 deletions
202
...er-preferenced-currency-display/tests/user-preferenced-currency-display.container.test.js
This file was deleted.
Oops, something went wrong.
63 changes: 29 additions & 34 deletions
63
...ents/app/user-preferenced-currency-display/user-preferenced-currency-display.component.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 |
---|---|---|
@@ -1,47 +1,42 @@ | ||
import React, { PureComponent } from 'react' | ||
import React, { useMemo } from 'react' | ||
import PropTypes from 'prop-types' | ||
import { PRIMARY, SECONDARY, ETH } from '../../../helpers/constants/common' | ||
import CurrencyDisplay from '../../ui/currency-display' | ||
import { useUserPreferencedCurrency } from '../../../hooks/useUserPreferencedCurrency' | ||
|
||
export default class UserPreferencedCurrencyDisplay extends PureComponent { | ||
static propTypes = { | ||
className: PropTypes.string, | ||
prefix: PropTypes.string, | ||
value: PropTypes.string, | ||
numberOfDecimals: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), | ||
hideLabel: PropTypes.bool, | ||
hideTitle: PropTypes.bool, | ||
style: PropTypes.object, | ||
showEthLogo: PropTypes.bool, | ||
ethLogoHeight: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), | ||
// Used in container | ||
type: PropTypes.oneOf([PRIMARY, SECONDARY]), | ||
ethNumberOfDecimals: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), | ||
fiatNumberOfDecimals: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), | ||
ethPrefix: PropTypes.string, | ||
fiatPrefix: PropTypes.string, | ||
// From container | ||
currency: PropTypes.string, | ||
nativeCurrency: PropTypes.string, | ||
} | ||
|
||
renderEthLogo () { | ||
const { currency, showEthLogo, ethLogoHeight = 12 } = this.props | ||
export default function UserPreferencedCurrencyDisplay ({ type, showEthLogo, ethLogoHeight = 12, ethNumberOfDecimals, fiatNumberOfDecimals, numberOfDecimals: propsNumberOfDecimals, ...restProps }) { | ||
const { currency, numberOfDecimals } = useUserPreferencedCurrency(type, { ethNumberOfDecimals, fiatNumberOfDecimals, numberOfDecimals: propsNumberOfDecimals }) | ||
|
||
const prefixComponent = useMemo(() => { | ||
return currency === ETH && showEthLogo && ( | ||
<img | ||
src="/images/eth.svg" | ||
height={ethLogoHeight} | ||
/> | ||
) | ||
} | ||
}, [currency, showEthLogo, ethLogoHeight]) | ||
|
||
render () { | ||
return ( | ||
<CurrencyDisplay | ||
{...this.props} | ||
prefixComponent={this.renderEthLogo()} | ||
/> | ||
) | ||
} | ||
return ( | ||
<CurrencyDisplay | ||
{...restProps} | ||
currency={currency} | ||
numberOfDecimals={numberOfDecimals} | ||
prefixComponent={prefixComponent} | ||
/> | ||
) | ||
} | ||
|
||
UserPreferencedCurrencyDisplay.propTypes = { | ||
className: PropTypes.string, | ||
prefix: PropTypes.string, | ||
value: PropTypes.string, | ||
numberOfDecimals: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), | ||
hideLabel: PropTypes.bool, | ||
hideTitle: PropTypes.bool, | ||
style: PropTypes.object, | ||
showEthLogo: PropTypes.bool, | ||
ethLogoHeight: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), | ||
type: PropTypes.oneOf([PRIMARY, SECONDARY]), | ||
ethNumberOfDecimals: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), | ||
fiatNumberOfDecimals: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), | ||
} |
67 changes: 0 additions & 67 deletions
67
...ents/app/user-preferenced-currency-display/user-preferenced-currency-display.container.js
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.