From e843020215d263668e3dbfbd9b693f5f6374a794 Mon Sep 17 00:00:00 2001 From: Rafael Taranto Date: Mon, 18 Jan 2021 15:22:51 +0000 Subject: [PATCH] Liordino feature/config migration review (#552) * feat: changed old server ports so it can coexists with the new server feat: removed deleted references from old server feat: created reset and migrate mutations on gql server and correspondent functions on new settings loader feat: created front end for the config migration with reset and migrate functionalities style: add spacing between buttons * feat: added ALL_COINS option to the commissions migration fix: only compare arrays when both variables are arrays fix: 'all coins' must be on a array to work Signed-off-by: Liordino Neto Co-authored-by: Liordino Neto --- lib/config-migration.js | 5 +++-- lib/new-settings-loader.js | 1 - 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/config-migration.js b/lib/config-migration.js index defac75d..2cffa11e 100644 --- a/lib/config-migration.js +++ b/lib/config-migration.js @@ -5,6 +5,7 @@ const { scopedValue } = require('./admin/config-manager') const GLOBAL = 'global' const ALL_CRYPTOS = _.values(COINS).sort() +const ALL_CRYPTOS_STRING = 'ALL_COINS' const ALL_MACHINES = 'ALL_MACHINES' const GLOBAL_SCOPE = { @@ -66,7 +67,7 @@ function getConfigFields (codes, config) { } function migrateCommissions (config) { - const areArraysEquals = (arr1, arr2) => _.isEmpty(_.xor(arr1, arr2)) + const areArraysEquals = (arr1, arr2) => Array.isArray(arr1) && Array.isArray(arr2) && _.isEmpty(_.xor(arr1, arr2)) const getMachine = _.get('scope.machine') const getCrypto = _.get('scope.crypto') const flattenCoins = _.compose(_.flatten, _.map(getCrypto)) @@ -116,7 +117,7 @@ function migrateCommissions (config) { commissions_overrides: allCommissionsOverrides.map(s => ({ ..._.fromPairs(s.values.map(f => [codes[f.code], f.value])), machine: s.scope.machine === GLOBAL ? ALL_MACHINES : s.scope.machine, - cryptoCurrencies: s.scope.crypto, + cryptoCurrencies: areArraysEquals(s.scope.crypto, ALL_CRYPTOS) ? [ALL_CRYPTOS_STRING] : s.scope.crypto, id: uuid.v4() })) }) diff --git a/lib/new-settings-loader.js b/lib/new-settings-loader.js index ab435c18..916c6c5b 100644 --- a/lib/new-settings-loader.js +++ b/lib/new-settings-loader.js @@ -42,7 +42,6 @@ function loadAccounts (schemaVersion) { const configSql = 'insert into user_config (type, data, valid, schema_version) values ($1, $2, $3, $4)' function saveConfig (config) { - console.log(config) return loadLatestConfigOrNone() .then(currentConfig => { const newConfig = _.assign(currentConfig, config)