From 2ff160cc68fbd5ec02a0a420ee74c3b1828acdf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Oliveira?= Date: Sat, 26 Jun 2021 02:06:43 +0100 Subject: [PATCH] feat: use lamassu-coins to display crypto units options --- .../1623975493095-add-crypto-units-to-config.js | 10 +++++----- .../src/pages/Wallet/AdvancedWallet.js | 4 +++- new-lamassu-admin/src/pages/Wallet/helper.js | 15 +++++++++------ 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/migrations/1623975493095-add-crypto-units-to-config.js b/migrations/1623975493095-add-crypto-units-to-config.js index 5c398d36..8a5ec333 100644 --- a/migrations/1623975493095-add-crypto-units-to-config.js +++ b/migrations/1623975493095-add-crypto-units-to-config.js @@ -2,11 +2,11 @@ const { saveConfig } = require('../lib/new-settings-loader') exports.up = function (next) { const cryptoUnits = { - wallets_BTC_cryptoUnits: 'mUnits', - wallets_ETH_cryptoUnits: 'mUnits', - wallets_LTC_cryptoUnits: 'mUnits', - wallets_ZEC_cryptoUnits: 'mUnits', - wallets_BCH_cryptoUnits: 'mUnits' + wallets_BTC_cryptoUnits: 'mili', + wallets_ETH_cryptoUnits: 'mili', + wallets_LTC_cryptoUnits: 'mili', + wallets_ZEC_cryptoUnits: 'mili', + wallets_BCH_cryptoUnits: 'mili' } return saveConfig(cryptoUnits) diff --git a/new-lamassu-admin/src/pages/Wallet/AdvancedWallet.js b/new-lamassu-admin/src/pages/Wallet/AdvancedWallet.js index 993bcfc5..ddcacf82 100644 --- a/new-lamassu-admin/src/pages/Wallet/AdvancedWallet.js +++ b/new-lamassu-admin/src/pages/Wallet/AdvancedWallet.js @@ -8,6 +8,8 @@ import { fromNamespace, toNamespace, namespaces } from 'src/utils/config' import { AdvancedWalletSchema, getAdvancedWalletElements } from './helper' +const { utils: coinUtils } = require('lamassu-coins') + const SAVE_CONFIG = gql` mutation Save($config: JSONObject, $accounts: JSONObject) { saveConfig(config: $config) @@ -52,7 +54,7 @@ const AdvancedWallet = () => { editWidth={174} save={save} validationSchema={AdvancedWalletSchema} - elements={getAdvancedWalletElements(cryptoCurrencies)} + elements={getAdvancedWalletElements(cryptoCurrencies, coinUtils)} /> ) diff --git a/new-lamassu-admin/src/pages/Wallet/helper.js b/new-lamassu-admin/src/pages/Wallet/helper.js index 8f8521cb..a735208f 100644 --- a/new-lamassu-admin/src/pages/Wallet/helper.js +++ b/new-lamassu-admin/src/pages/Wallet/helper.js @@ -32,13 +32,20 @@ const AdvancedWalletSchema = Yup.object().shape({ cryptoUnits: Yup.string().required() }) -const getAdvancedWalletElements = (cryptoCurrencies, config) => { +const getAdvancedWalletElements = (cryptoCurrencies, coinUtils) => { const viewCryptoCurrency = it => R.compose( R.prop(['display']), R.find(R.propEq('code', it)) )(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 [ { name: 'id', @@ -52,14 +59,10 @@ const getAdvancedWalletElements = (cryptoCurrencies, config) => { name: 'cryptoUnits', size: 'sm', stripe: true, - view: it => it, width: 190, input: Autocomplete, inputProps: { - options: [ - { code: 'mUnits', display: 'mUnits' }, - { code: 'fUnits', display: 'fUnits' } - ], + options: getOptions(coinUtils), valueProp: 'code', labelProp: 'display' }