fix: add crypto unit config when setting up a new wallet
This commit is contained in:
parent
bcbae6f19a
commit
ce0c7efe52
3 changed files with 35 additions and 12 deletions
|
|
@ -1,15 +1,22 @@
|
|||
const { saveConfig } = require('../lib/new-settings-loader')
|
||||
const { saveConfig, loadLatest } = require('../lib/new-settings-loader')
|
||||
const { getAllCryptoCurrencies } = require('../lib/new-config-manager.js')
|
||||
const { utils: coinUtils } = require('lamassu-coins')
|
||||
const _ = require('lodash/fp')
|
||||
|
||||
exports.up = function (next) {
|
||||
const cryptoUnits = {
|
||||
wallets_BTC_cryptoUnits: 'mili',
|
||||
wallets_ETH_cryptoUnits: 'mili',
|
||||
wallets_LTC_cryptoUnits: 'mili',
|
||||
wallets_ZEC_cryptoUnits: 'mili',
|
||||
wallets_BCH_cryptoUnits: 'mili'
|
||||
}
|
||||
|
||||
return saveConfig(cryptoUnits)
|
||||
loadLatest()
|
||||
.then(settings => {
|
||||
const newSettings = {}
|
||||
const activeCryptos = getAllCryptoCurrencies(settings.config)
|
||||
if (_.head(activeCryptos)) {
|
||||
_.map(crypto => {
|
||||
const defaultUnit = _.head(_.keys(coinUtils.getCryptoCurrency(crypto).units))
|
||||
newSettings[`wallets_${crypto}_cryptoUnits`] = defaultUnit
|
||||
return newSettings
|
||||
}, activeCryptos)
|
||||
}
|
||||
return saveConfig(newSettings)
|
||||
})
|
||||
.then(() => next())
|
||||
.catch(err => {
|
||||
console.log(err.message)
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import { utils as coinUtils } from 'lamassu-coins'
|
||||
import * as R from 'ramda'
|
||||
import React, { useState } from 'react'
|
||||
|
||||
|
|
@ -57,7 +58,14 @@ const Wizard = ({ coin, onClose, accountsConfig, accounts, save, error }) => {
|
|||
: accountsToSave
|
||||
|
||||
if (isLastStep) {
|
||||
const configToSave = { ...newConfig, zeroConfLimit: 0 }
|
||||
const defaultCryptoUnit = R.head(
|
||||
R.keys(coinUtils.getCryptoCurrency(coin.code).units)
|
||||
)
|
||||
const configToSave = {
|
||||
...newConfig,
|
||||
zeroConfLimit: 0,
|
||||
cryptoUnits: defaultCryptoUnit
|
||||
}
|
||||
return save(toNamespace(coin.code, configToSave), newAccounts)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { useQuery, useMutation } from '@apollo/react-hooks'
|
||||
import { makeStyles } from '@material-ui/core'
|
||||
import gql from 'graphql-tag'
|
||||
import { utils as coinUtils } from 'lamassu-coins'
|
||||
import * as R from 'ramda'
|
||||
import React, { useState } from 'react'
|
||||
|
||||
|
|
@ -53,7 +54,14 @@ const AllSet = ({ data: currentData, doContinue }) => {
|
|||
const cryptoCurrencies = data?.cryptoCurrencies ?? []
|
||||
|
||||
const save = () => {
|
||||
const adjustedData = { zeroConfLimit: 0, ...currentData }
|
||||
const defaultCryptoUnit = R.head(
|
||||
R.keys(coinUtils.getCryptoCurrency(coin).units)
|
||||
)
|
||||
const adjustedData = {
|
||||
zeroConfLimit: 0,
|
||||
...currentData,
|
||||
cryptoUnits: defaultCryptoUnit
|
||||
}
|
||||
if (!WalletSchema.isValidSync(adjustedData)) return setError(true)
|
||||
|
||||
const withCoin = toNamespace(coin, R.omit('coin', adjustedData))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue