Merge pull request #1320 from chaotixkilla/fix-remove-coin-specific-unit-fields

Remove coin-specific cryptounits from config
This commit is contained in:
Rafael Taranto 2022-08-01 09:55:06 +01:00 committed by GitHub
commit 1d0f3cd27c
4 changed files with 37 additions and 13 deletions

View file

@ -151,9 +151,7 @@ const getCryptosFromWalletNamespace = config => {
const getCashInSettings = config => fromNamespace(namespaces.CASH_IN)(config)
const getCryptoUnits = (crypto, config) => {
return getWalletSettings(crypto, config).cryptoUnits
}
const getCryptoUnits = (crypto, config) => getWalletSettings(crypto, config).cryptoUnits
const setTermsConditions = toNamespace(namespaces.TERMS_CONDITIONS)

View file

@ -112,6 +112,17 @@ function saveConfig (config) {
})
}
function removeFromConfig (fields) {
return Promise.all([loadLatestConfigOrNone(), getOperatorId('middleware')])
.then(([currentConfig, operatorId]) => {
const newConfig = _.omit(fields, currentConfig)
return db.tx(t => {
return t.none(configSql, ['config', { config: newConfig }, true, NEW_SETTINGS_LOADER_SCHEMA_VERSION])
.then(() => t.none('NOTIFY $1:name, $2', ['reload', JSON.stringify({ schema: asyncLocalStorage.getStore().get('schema'), operatorId })]))
}).catch(console.error)
})
}
function migrationSaveConfig (config) {
return loadLatestConfigOrNone()
.then(currentConfig => {
@ -221,5 +232,6 @@ module.exports = {
loadLatestConfig,
loadLatestConfigOrNone,
load,
migrate
migrate,
removeFromConfig
}

View file

@ -0,0 +1,22 @@
const { removeFromConfig, loadLatest } = require('../lib/new-settings-loader')
const { getCryptosFromWalletNamespace } = require('../lib/new-config-manager.js')
const _ = require('lodash/fp')
exports.up = function (next) {
loadLatest()
.then(settings => {
const configuredCryptos = getCryptosFromWalletNamespace(settings.config)
if (!configuredCryptos.length) return Promise.resolve()
return removeFromConfig(_.map(it => `wallets_${it}_cryptoUnits`, configuredCryptos))
})
.then(() => next())
.catch(err => {
console.log(err.message)
return next(err)
})
}
exports.down = function (next) {
next()
}

View file

@ -1,4 +1,3 @@
import { utils as coinUtils } from '@lamassu/coins'
import * as R from 'ramda'
import React, { useState } from 'react'
import * as Yup from 'yup'
@ -104,14 +103,7 @@ const Wizard = ({
: accountsToSave
if (isLastStep) {
const defaultCryptoUnit = R.head(
R.keys(coinUtils.getCryptoCurrency(coin.code).units)
)
const configToSave = {
...newConfig,
cryptoUnits: defaultCryptoUnit
}
return save(toNamespace(coin.code, configToSave), newAccounts)
return save(toNamespace(coin.code, newConfig), newAccounts)
}
setState({