From 653c78313e4d85a6563eb2b259211925ac52bcb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Salgado?= Date: Thu, 14 Jul 2022 15:43:27 +0100 Subject: [PATCH] feat: add currency market migration --- migrations/1732874039534-market-currency.js | 31 +++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 migrations/1732874039534-market-currency.js diff --git a/migrations/1732874039534-market-currency.js b/migrations/1732874039534-market-currency.js new file mode 100644 index 00000000..5f0b7135 --- /dev/null +++ b/migrations/1732874039534-market-currency.js @@ -0,0 +1,31 @@ +const _ = require('lodash/fp') +const { loadLatest, saveAccounts } = require('../lib/new-settings-loader') +const { ACCOUNT_LIST } = require('../lib/new-admin/config/accounts') +const { ALL } = require('../lib/plugins/common/ccxt') + +exports.up = function (next) { + return loadLatest() + .then(({ config, accounts }) => { + const allExchanges = _.map(it => it.code)(_.filter(it => it.class === 'exchange', ACCOUNT_LIST)) + const configuredExchanges = _.intersection(allExchanges, _.keys(accounts)) + const localeCurrency = config.locale_fiatCurrency + + const newAccounts = _.reduce( + (acc, value) => { + if (!_.isNil(accounts[value].currencyMarket)) return acc + if (_.includes(localeCurrency, ALL[value].FIAT)) return { ...acc, [value]: { currencyMarket: localeCurrency } } + return { ...acc, [value]: { currencyMarket: _.head(ALL[value].FIAT) } } + }, + {}, + configuredExchanges + ) + + return saveAccounts(newAccounts) + }) + .then(next) + .catch(next) +} + +module.exports.down = function (next) { + next() +}