Chore: put cryptoCodes from wallet function in new config manager
This commit is contained in:
parent
65a55a669d
commit
a521b679c4
4 changed files with 19 additions and 36 deletions
|
|
@ -3,45 +3,26 @@ var db = require('../lib/db')
|
||||||
const settingsLoader = require('../lib/new-settings-loader')
|
const settingsLoader = require('../lib/new-settings-loader')
|
||||||
const configManager = require('../lib/new-config-manager')
|
const configManager = require('../lib/new-config-manager')
|
||||||
|
|
||||||
const stripl = _.curry((q, str) => _.startsWith(q, str) ? str.slice(q.length) : str)
|
const isNil = val => val == null
|
||||||
const filter = namespace => _.pickBy((value, key) => _.startsWith(`${namespace}_`)(key))
|
const curriedGetCashout = _.curry(configManager.getCashOut)
|
||||||
const strip = key => _.mapKeys(stripl(`${key}_`))
|
|
||||||
|
|
||||||
const fromNamespace = _.curry((key, config) => _.compose(strip(key), filter(key))(config))
|
|
||||||
|
|
||||||
const split = _.curry(_.split)
|
|
||||||
const composed = _.compose(_.head, split('_'))
|
|
||||||
|
|
||||||
const getCryptoCodes = (config) => {
|
|
||||||
const walletKeys = _.keys(fromNamespace('wallets', config))
|
|
||||||
return _.uniq(_.map(composed, walletKeys))
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.up = function (next) {
|
exports.up = function (next) {
|
||||||
db.tx(async t => {
|
db.tx(async t => {
|
||||||
let min = Infinity
|
const settingsPromise = settingsLoader.loadLatest()
|
||||||
const sp = settingsLoader.loadLatest()
|
const machinesPromise = t.any('SELECT device_id FROM devices')
|
||||||
const mp = t.any('SELECT device_id FROM devices')
|
const [{ config }, machines] = await Promise.all([settingsPromise, machinesPromise])
|
||||||
const [{ config }, machines] = await Promise.all([sp, mp])
|
const cryptoCodes = configManager.getCryptosFromWalletNamespace(config)
|
||||||
const cryptoCodes = getCryptoCodes(config)
|
|
||||||
|
const zeroConfLimits = _.map(_.flow(_.get('device_id'), curriedGetCashout(_, config), _.get('zeroConfLimit')), machines)
|
||||||
|
const minArr = _.min(zeroConfLimits)
|
||||||
|
const min = !isNil(minArr) && minArr < Infinity ? Number(minArr) : 0
|
||||||
|
|
||||||
_.forEach(o => {
|
|
||||||
const machineId = o.device_id
|
|
||||||
const cashOutConfig = configManager.getCashOut(machineId, config)
|
|
||||||
const zeroConfLimit = cashOutConfig.zeroConfLimit || Infinity
|
|
||||||
if (zeroConfLimit < min) {
|
|
||||||
min = zeroConfLimit
|
|
||||||
}
|
|
||||||
}, machines)
|
|
||||||
if (min === Infinity) {
|
|
||||||
min = 0
|
|
||||||
}
|
|
||||||
_.forEach(cryptoCode => {
|
_.forEach(cryptoCode => {
|
||||||
const walletConfig = configManager.getWalletSettings(cryptoCode, config)
|
const walletConfig = configManager.getWalletSettings(cryptoCode, config)
|
||||||
const zeroConfLimit = walletConfig.zeroConfLimit || null
|
const zeroConfLimit = _.get('zeroConfLimit', walletConfig)
|
||||||
const key = `wallets_${cryptoCode}_zeroConfLimit`
|
const key = `wallets_${cryptoCode}_zeroConfLimit`
|
||||||
if (!zeroConfLimit) {
|
if (isNil(zeroConfLimit)) {
|
||||||
config[key] = Number(min)
|
config[key] = min
|
||||||
}
|
}
|
||||||
}, cryptoCodes)
|
}, cryptoCodes)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -149,7 +149,6 @@ const Locales = ({ name: SCREEN_KEY }) => {
|
||||||
if (!coin) return setValue(curr)
|
if (!coin) return setValue(curr)
|
||||||
|
|
||||||
const namespaced = fromNamespace(coin)(wallets)
|
const namespaced = fromNamespace(coin)(wallets)
|
||||||
console.log(namespaced)
|
|
||||||
if (!WalletSchema.isValidSync(namespaced)) {
|
if (!WalletSchema.isValidSync(namespaced)) {
|
||||||
setOnChangeFunction(() => () => setValue(curr))
|
setOnChangeFunction(() => () => setValue(curr))
|
||||||
setWizard(coin)
|
setWizard(coin)
|
||||||
|
|
@ -226,6 +225,7 @@ const Locales = ({ name: SCREEN_KEY }) => {
|
||||||
accounts={accounts}
|
accounts={accounts}
|
||||||
accountsConfig={accountsConfig}
|
accountsConfig={accountsConfig}
|
||||||
locale={locale}
|
locale={locale}
|
||||||
|
zeroConfLimit={wallets[`${wizard}_zeroConfLimit`]}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
|
|
|
||||||
|
|
@ -66,6 +66,7 @@ const Wallet = ({ name: SCREEN_KEY }) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const config = data?.config && fromNamespace(SCREEN_KEY)(data.config)
|
const config = data?.config && fromNamespace(SCREEN_KEY)(data.config)
|
||||||
|
|
||||||
const accountsConfig = data?.accountsConfig
|
const accountsConfig = data?.accountsConfig
|
||||||
const cryptoCurrencies = data?.cryptoCurrencies ?? []
|
const cryptoCurrencies = data?.cryptoCurrencies ?? []
|
||||||
const accounts = data?.accounts ?? []
|
const accounts = data?.accounts ?? []
|
||||||
|
|
@ -95,7 +96,6 @@ const Wallet = ({ name: SCREEN_KEY }) => {
|
||||||
setOnChangeFunction(null)
|
setOnChangeFunction(null)
|
||||||
return it
|
return it
|
||||||
})
|
})
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<TitleSection title="Wallet Settings" />
|
<TitleSection title="Wallet Settings" />
|
||||||
|
|
@ -124,6 +124,7 @@ const Wallet = ({ name: SCREEN_KEY }) => {
|
||||||
accounts={accounts}
|
accounts={accounts}
|
||||||
accountsConfig={accountsConfig}
|
accountsConfig={accountsConfig}
|
||||||
locale={data?.config && fromNamespace('locale')(data.config)}
|
locale={data?.config && fromNamespace('locale')(data.config)}
|
||||||
|
zeroConfLimit={config[`${wizard}_zeroConfLimit`]}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{editingSchema && (
|
{editingSchema && (
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,8 @@ const Wizard = ({
|
||||||
accounts,
|
accounts,
|
||||||
save,
|
save,
|
||||||
error,
|
error,
|
||||||
locale
|
locale,
|
||||||
|
zeroConfLimit
|
||||||
}) => {
|
}) => {
|
||||||
const [{ step, config, accountsToSave }, setState] = useState({
|
const [{ step, config, accountsToSave }, setState] = useState({
|
||||||
step: 0,
|
step: 0,
|
||||||
|
|
@ -65,7 +66,7 @@ const Wizard = ({
|
||||||
: accountsToSave
|
: accountsToSave
|
||||||
|
|
||||||
if (isLastStep) {
|
if (isLastStep) {
|
||||||
newConfig.zeroConfLimit = 0
|
newConfig.zeroConfLimit = zeroConfLimit || 0
|
||||||
return save(toNamespace(coin.code, newConfig), newAccounts)
|
return save(toNamespace(coin.code, newConfig), newAccounts)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue