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) {
|
exports.up = function (next) {
|
||||||
const cryptoUnits = {
|
loadLatest()
|
||||||
wallets_BTC_cryptoUnits: 'mili',
|
.then(settings => {
|
||||||
wallets_ETH_cryptoUnits: 'mili',
|
const newSettings = {}
|
||||||
wallets_LTC_cryptoUnits: 'mili',
|
const activeCryptos = getAllCryptoCurrencies(settings.config)
|
||||||
wallets_ZEC_cryptoUnits: 'mili',
|
if (_.head(activeCryptos)) {
|
||||||
wallets_BCH_cryptoUnits: 'mili'
|
_.map(crypto => {
|
||||||
}
|
const defaultUnit = _.head(_.keys(coinUtils.getCryptoCurrency(crypto).units))
|
||||||
|
newSettings[`wallets_${crypto}_cryptoUnits`] = defaultUnit
|
||||||
return saveConfig(cryptoUnits)
|
return newSettings
|
||||||
|
}, activeCryptos)
|
||||||
|
}
|
||||||
|
return saveConfig(newSettings)
|
||||||
|
})
|
||||||
.then(() => next())
|
.then(() => next())
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(err.message)
|
console.log(err.message)
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { utils as coinUtils } from 'lamassu-coins'
|
||||||
import * as R from 'ramda'
|
import * as R from 'ramda'
|
||||||
import React, { useState } from 'react'
|
import React, { useState } from 'react'
|
||||||
|
|
||||||
|
|
@ -57,7 +58,14 @@ const Wizard = ({ coin, onClose, accountsConfig, accounts, save, error }) => {
|
||||||
: accountsToSave
|
: accountsToSave
|
||||||
|
|
||||||
if (isLastStep) {
|
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)
|
return save(toNamespace(coin.code, configToSave), newAccounts)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import { useQuery, useMutation } from '@apollo/react-hooks'
|
import { useQuery, useMutation } from '@apollo/react-hooks'
|
||||||
import { makeStyles } from '@material-ui/core'
|
import { makeStyles } from '@material-ui/core'
|
||||||
import gql from 'graphql-tag'
|
import gql from 'graphql-tag'
|
||||||
|
import { utils as coinUtils } from 'lamassu-coins'
|
||||||
import * as R from 'ramda'
|
import * as R from 'ramda'
|
||||||
import React, { useState } from 'react'
|
import React, { useState } from 'react'
|
||||||
|
|
||||||
|
|
@ -53,7 +54,14 @@ const AllSet = ({ data: currentData, doContinue }) => {
|
||||||
const cryptoCurrencies = data?.cryptoCurrencies ?? []
|
const cryptoCurrencies = data?.cryptoCurrencies ?? []
|
||||||
|
|
||||||
const save = () => {
|
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)
|
if (!WalletSchema.isValidSync(adjustedData)) return setError(true)
|
||||||
|
|
||||||
const withCoin = toNamespace(coin, R.omit('coin', adjustedData))
|
const withCoin = toNamespace(coin, R.omit('coin', adjustedData))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue