From d619974de782b279665ea8a3b3c0083739da3248 Mon Sep 17 00:00:00 2001 From: Rafael Taranto Date: Tue, 27 Aug 2024 10:59:00 +0100 Subject: [PATCH] feat: pick wallet scoring without UI --- lib/new-settings-loader.js | 10 ++++++++++ lib/wallet-scoring.js | 23 ++++++++++++++++------- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/lib/new-settings-loader.js b/lib/new-settings-loader.js index 1b10db64..58a490cd 100644 --- a/lib/new-settings-loader.js +++ b/lib/new-settings-loader.js @@ -63,6 +63,16 @@ function saveAccounts (accounts) { return Promise.all([loadAccounts(), getOperatorId('middleware')]) .then(([currentAccounts, operatorId]) => { const newAccounts = _.merge(currentAccounts, accounts) + + // Only allow one wallet scoring active at a time + if (accounts.elliptic?.enabled && newAccounts.scorechain) { + newAccounts.scorechain.enabled = false + } + + if (accounts.scorechain?.enabled && newAccounts.elliptic) { + newAccounts.elliptic.enabled = false + } + return db.tx(t => { return t.none(accountsSql, ['accounts', { accounts: newAccounts }, true, NEW_SETTINGS_LOADER_SCHEMA_VERSION]) .then(() => t.none('NOTIFY $1:name, $2', ['reload', JSON.stringify({ schema: asyncLocalStorage.getStore().get('schema'), operatorId })])) diff --git a/lib/wallet-scoring.js b/lib/wallet-scoring.js index 516ac19b..9b426faf 100644 --- a/lib/wallet-scoring.js +++ b/lib/wallet-scoring.js @@ -1,14 +1,23 @@ const ph = require('./plugin-helper') const argv = require('minimist')(process.argv.slice(2)) -const configManager = require('./new-config-manager') -function loadWalletScoring (settings, cryptoCode) { - const pluginCode = argv.mockScoring ? 'mock-scoring' : 'scorechain' - const wallet = cryptoCode ? ph.load(ph.WALLET, configManager.getWalletSettings(cryptoCode, settings.config).wallet) : null - const plugin = ph.load(ph.WALLET_SCORING, pluginCode) - const account = settings.accounts[pluginCode] +// TODO - This function should be rolled back after UI is created for this feature +function loadWalletScoring (settings) { + if (argv.mockScoring) { + const mock = ph.load(ph.WALLET_SCORING, 'mock-scoring') + return { plugin: mock, account: {} } + } - return { plugin, account, wallet } + const scorechainAccount = settings.accounts['scorechain'] + if (scorechainAccount?.enabled) { + const scorechain = ph.load(ph.WALLET_SCORING, 'scorechain') + return { plugin: scorechain, account: scorechainAccount} + } + + const ellipticAccount = settings.accounts['elliptic'] + const elliptic = ph.load(ph.WALLET_SCORING, 'elliptic') + + return { plugin: elliptic, account: ellipticAccount } } function rateTransaction (settings, cryptoCode, address) {