feat: use lamassu-coins to display crypto units options
This commit is contained in:
parent
168257bcc4
commit
2ff160cc68
3 changed files with 17 additions and 12 deletions
|
|
@ -2,11 +2,11 @@ const { saveConfig } = require('../lib/new-settings-loader')
|
||||||
|
|
||||||
exports.up = function (next) {
|
exports.up = function (next) {
|
||||||
const cryptoUnits = {
|
const cryptoUnits = {
|
||||||
wallets_BTC_cryptoUnits: 'mUnits',
|
wallets_BTC_cryptoUnits: 'mili',
|
||||||
wallets_ETH_cryptoUnits: 'mUnits',
|
wallets_ETH_cryptoUnits: 'mili',
|
||||||
wallets_LTC_cryptoUnits: 'mUnits',
|
wallets_LTC_cryptoUnits: 'mili',
|
||||||
wallets_ZEC_cryptoUnits: 'mUnits',
|
wallets_ZEC_cryptoUnits: 'mili',
|
||||||
wallets_BCH_cryptoUnits: 'mUnits'
|
wallets_BCH_cryptoUnits: 'mili'
|
||||||
}
|
}
|
||||||
|
|
||||||
return saveConfig(cryptoUnits)
|
return saveConfig(cryptoUnits)
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,8 @@ import { fromNamespace, toNamespace, namespaces } from 'src/utils/config'
|
||||||
|
|
||||||
import { AdvancedWalletSchema, getAdvancedWalletElements } from './helper'
|
import { AdvancedWalletSchema, getAdvancedWalletElements } from './helper'
|
||||||
|
|
||||||
|
const { utils: coinUtils } = require('lamassu-coins')
|
||||||
|
|
||||||
const SAVE_CONFIG = gql`
|
const SAVE_CONFIG = gql`
|
||||||
mutation Save($config: JSONObject, $accounts: JSONObject) {
|
mutation Save($config: JSONObject, $accounts: JSONObject) {
|
||||||
saveConfig(config: $config)
|
saveConfig(config: $config)
|
||||||
|
|
@ -52,7 +54,7 @@ const AdvancedWallet = () => {
|
||||||
editWidth={174}
|
editWidth={174}
|
||||||
save={save}
|
save={save}
|
||||||
validationSchema={AdvancedWalletSchema}
|
validationSchema={AdvancedWalletSchema}
|
||||||
elements={getAdvancedWalletElements(cryptoCurrencies)}
|
elements={getAdvancedWalletElements(cryptoCurrencies, coinUtils)}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -32,13 +32,20 @@ const AdvancedWalletSchema = Yup.object().shape({
|
||||||
cryptoUnits: Yup.string().required()
|
cryptoUnits: Yup.string().required()
|
||||||
})
|
})
|
||||||
|
|
||||||
const getAdvancedWalletElements = (cryptoCurrencies, config) => {
|
const getAdvancedWalletElements = (cryptoCurrencies, coinUtils) => {
|
||||||
const viewCryptoCurrency = it =>
|
const viewCryptoCurrency = it =>
|
||||||
R.compose(
|
R.compose(
|
||||||
R.prop(['display']),
|
R.prop(['display']),
|
||||||
R.find(R.propEq('code', it))
|
R.find(R.propEq('code', it))
|
||||||
)(cryptoCurrencies)
|
)(cryptoCurrencies)
|
||||||
|
|
||||||
|
const getOptions = R.curry((coinUtils, it) => {
|
||||||
|
const options = R.keys(coinUtils.getCryptoCurrency(it.id).units)
|
||||||
|
return R.map(option => {
|
||||||
|
return { code: option, display: option }
|
||||||
|
})(options)
|
||||||
|
})
|
||||||
|
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
name: 'id',
|
name: 'id',
|
||||||
|
|
@ -52,14 +59,10 @@ const getAdvancedWalletElements = (cryptoCurrencies, config) => {
|
||||||
name: 'cryptoUnits',
|
name: 'cryptoUnits',
|
||||||
size: 'sm',
|
size: 'sm',
|
||||||
stripe: true,
|
stripe: true,
|
||||||
view: it => it,
|
|
||||||
width: 190,
|
width: 190,
|
||||||
input: Autocomplete,
|
input: Autocomplete,
|
||||||
inputProps: {
|
inputProps: {
|
||||||
options: [
|
options: getOptions(coinUtils),
|
||||||
{ code: 'mUnits', display: 'mUnits' },
|
|
||||||
{ code: 'fUnits', display: 'fUnits' }
|
|
||||||
],
|
|
||||||
valueProp: 'code',
|
valueProp: 'code',
|
||||||
labelProp: 'display'
|
labelProp: 'display'
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue