Skip to content
Permalink
Browse files

feat(settings): add ability to select exchange rate provider

  • Loading branch information...
korhaliv committed Jun 13, 2019
1 parent d076cb6 commit cb3124330136839d23cf33869d762cad6490bc0a
@@ -2,6 +2,7 @@ import React from 'react'
import PropTypes from 'prop-types'
import get from 'lodash/get'
import { Bar, DataRow, Select } from 'components/UI'

import { FieldLabel, NumberField } from './SettingsFieldHelpers'
import messages from './messages'

@@ -24,7 +25,9 @@ const blockExplorerMessageMapper = key => {
return filters[key]
}

const SettingsFieldsWallet = ({ currentConfig }) => {
const rateProviderMessageMapper = key => messages[`rateProvider_option_${key}`]

const SettingsFieldsWallet = ({ currentConfig, rateProviderItems }) => {
const renderNumberDataRow = path => (
<DataRow
left={<FieldLabel itemKey={path} />}
@@ -47,8 +50,6 @@ const SettingsFieldsWallet = ({ currentConfig }) => {
}
/>

<Bar variant="light" />

<DataRow
left={<FieldLabel itemKey="blockExplorer" />}
right={
@@ -61,6 +62,19 @@ const SettingsFieldsWallet = ({ currentConfig }) => {
/>
}
/>
<Bar variant="light" />
<DataRow
left={<FieldLabel itemKey="rateProvider" />}
right={
<Select
field="rateProvider"
highlightOnValid={false}
initialValue={currentConfig.rateProvider}
items={rateProviderItems}
messageMapper={rateProviderMessageMapper}
/>
}
/>

<Bar variant="light" />

@@ -79,6 +93,7 @@ const SettingsFieldsWallet = ({ currentConfig }) => {

SettingsFieldsWallet.propTypes = {
currentConfig: PropTypes.object.isRequired,
rateProviderItems: PropTypes.array.isRequired,
}

export default SettingsFieldsWallet
@@ -81,7 +81,7 @@ SettingsActions.propTypes = {
currentConfig: PropTypes.object.isRequired,
}

const SettingsPage = ({ currentConfig, ...rest }) => {
const SettingsPage = ({ currentConfig, rateProviderItems, fetchTickers, ...rest }) => {
const [group, setGroup] = useState('general')

return (
@@ -105,9 +105,14 @@ const SettingsPage = ({ currentConfig, ...rest }) => {
<FormattedMessage {...messages.settings_title} />
</Heading.h1>

<SettingsForm>
<SettingsForm onSubmit={fetchTickers}>
{group === 'general' && <SettingsFieldsGeneral currentConfig={currentConfig} />}
{group === 'wallet' && <SettingsFieldsWallet currentConfig={currentConfig} />}
{group === 'wallet' && (
<SettingsFieldsWallet
currentConfig={currentConfig}
rateProviderItems={rateProviderItems}
/>
)}
<SettingsActions currentConfig={currentConfig} />
</SettingsForm>
</MainContent>
@@ -117,6 +122,8 @@ const SettingsPage = ({ currentConfig, ...rest }) => {

SettingsPage.propTypes = {
currentConfig: PropTypes.object.isRequired,
fetchTickers: PropTypes.func.isRequired,
rateProviderItems: PropTypes.array.isRequired,
}

export default SettingsPage
@@ -1,9 +1,18 @@
import { connect } from 'react-redux'
import SettingsPage from 'components/Settings/SettingsPage'
import { settingsSelectors } from 'reducers/settings'
import { tickerSelectors, fetchTickers } from 'reducers/ticker'

const mapStateToProps = state => ({
currentConfig: settingsSelectors.currentConfig(state),
rateProviderItems: tickerSelectors.rateProviderSelector(state).map(key => ({ key })),
})

export default connect(mapStateToProps)(SettingsPage)
const mapDispatchToProps = {
fetchTickers,
}

export default connect(
mapStateToProps,
mapDispatchToProps
)(SettingsPage)
@@ -1,7 +1,7 @@
import { createSelector } from 'reselect'
import get from 'lodash/get'
import { currencies, getDefaultCurrency } from '@zap/i18n'
import { requestTickerWithFallback } from '@zap/utils/fiat/rateProvider'
import { requestTickerWithFallback, getSupportedProviders } from '@zap/utils/fiat/rateProvider'
import { infoSelectors } from './info'
import { putConfig, settingsSelectors } from './settings'
// ------------------------------------
@@ -163,6 +163,12 @@ tickerSelectors.autopayCurrencyName = createSelector(
cryptoUnits => cryptoUnits && cryptoUnits[cryptoUnits.length - 1].value
)

tickerSelectors.rateProviderSelector = createSelector(
fiatTickerSelector,
infoSelectors.chainSelector,
(currency, chain) => getSupportedProviders(chain === 'bitcoin' ? 'BTC' : 'LTC', currency)
)

export { tickerSelectors }

// ------------------------------------

0 comments on commit cb31243

Please sign in to comment.
You can’t perform that action at this time.