fix: remove unused crypto unit fields
This commit is contained in:
parent
3b01820242
commit
65b8491354
4 changed files with 38 additions and 11 deletions
|
|
@ -152,7 +152,8 @@ const getCryptosFromWalletNamespace = config => {
|
||||||
const getCashInSettings = config => fromNamespace(namespaces.CASH_IN)(config)
|
const getCashInSettings = config => fromNamespace(namespaces.CASH_IN)(config)
|
||||||
|
|
||||||
const getCryptoUnits = (crypto, config) => {
|
const getCryptoUnits = (crypto, config) => {
|
||||||
return getWalletSettings(crypto, config).cryptoUnits
|
const walletSettings = getWalletSettings(crypto, config)
|
||||||
|
return walletSettings.cryptoUnits
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
|
||||||
|
|
@ -85,6 +85,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) {
|
function migrationSaveConfig (config) {
|
||||||
return loadLatestConfigOrNone()
|
return loadLatestConfigOrNone()
|
||||||
.then(currentConfig => {
|
.then(currentConfig => {
|
||||||
|
|
@ -194,5 +205,6 @@ module.exports = {
|
||||||
loadLatestConfig,
|
loadLatestConfig,
|
||||||
loadLatestConfigOrNone,
|
loadLatestConfigOrNone,
|
||||||
load,
|
load,
|
||||||
migrate
|
migrate,
|
||||||
|
removeFromConfig
|
||||||
}
|
}
|
||||||
|
|
|
||||||
22
migrations/1658940716689-remove-coin-specific-cryptounits.js
Normal file
22
migrations/1658940716689-remove-coin-specific-cryptounits.js
Normal 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()
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
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'
|
||||||
import * as Yup from 'yup'
|
import * as Yup from 'yup'
|
||||||
|
|
@ -97,14 +96,7 @@ const Wizard = ({
|
||||||
: accountsToSave
|
: accountsToSave
|
||||||
|
|
||||||
if (isLastStep) {
|
if (isLastStep) {
|
||||||
const defaultCryptoUnit = R.head(
|
return save(toNamespace(coin.code, newConfig), newAccounts)
|
||||||
R.keys(coinUtils.getCryptoCurrency(coin.code).units)
|
|
||||||
)
|
|
||||||
const configToSave = {
|
|
||||||
...newConfig,
|
|
||||||
cryptoUnits: defaultCryptoUnit
|
|
||||||
}
|
|
||||||
return save(toNamespace(coin.code, configToSave), newAccounts)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setState({
|
setState({
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue