feat: pick wallet scoring without UI

This commit is contained in:
Rafael Taranto 2024-08-27 10:59:00 +01:00
parent d7d2b89556
commit d619974de7
2 changed files with 26 additions and 7 deletions

View file

@ -63,6 +63,16 @@ function saveAccounts (accounts) {
return Promise.all([loadAccounts(), getOperatorId('middleware')]) return Promise.all([loadAccounts(), getOperatorId('middleware')])
.then(([currentAccounts, operatorId]) => { .then(([currentAccounts, operatorId]) => {
const newAccounts = _.merge(currentAccounts, accounts) 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 db.tx(t => {
return t.none(accountsSql, ['accounts', { accounts: newAccounts }, true, NEW_SETTINGS_LOADER_SCHEMA_VERSION]) 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 })])) .then(() => t.none('NOTIFY $1:name, $2', ['reload', JSON.stringify({ schema: asyncLocalStorage.getStore().get('schema'), operatorId })]))

View file

@ -1,14 +1,23 @@
const ph = require('./plugin-helper') const ph = require('./plugin-helper')
const argv = require('minimist')(process.argv.slice(2)) const argv = require('minimist')(process.argv.slice(2))
const configManager = require('./new-config-manager')
function loadWalletScoring (settings, cryptoCode) { // TODO - This function should be rolled back after UI is created for this feature
const pluginCode = argv.mockScoring ? 'mock-scoring' : 'scorechain' function loadWalletScoring (settings) {
const wallet = cryptoCode ? ph.load(ph.WALLET, configManager.getWalletSettings(cryptoCode, settings.config).wallet) : null if (argv.mockScoring) {
const plugin = ph.load(ph.WALLET_SCORING, pluginCode) const mock = ph.load(ph.WALLET_SCORING, 'mock-scoring')
const account = settings.accounts[pluginCode] 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) { function rateTransaction (settings, cryptoCode, address) {