This commit is contained in:
Josh Harvey 2016-10-09 18:49:13 +01:00
parent f62e65fe93
commit bd3441adfb
4 changed files with 43 additions and 21 deletions

View file

@ -38,7 +38,6 @@ const tickerPlugins = {}
const traderPlugins = {}
const walletPlugins = {}
let idVerifierPlugin = null
let infoPlugin = null
let emailPlugin = null
let smsPlugin = null
let hkdf = null
@ -133,11 +132,9 @@ function loadPlugin (name, config) {
return plugin
}
function loadOrConfigPlugin (pluginHandle, pluginType, cryptoCode, options,
function loadOrConfigPlugin (pluginHandle, pluginType, cryptoCode, cfg, accounts, options,
onChangeCallback) {
const currentName = cryptoCode
? cachedConfig.exchanges.plugins.current[cryptoCode][pluginType]
: cachedConfig.exchanges.plugins.current[pluginType]
const currentName = cfg.cryptoServices[pluginType]
currentlyUsedPlugins[cryptoCode] = currentlyUsedPlugins[cryptoCode] || {}
@ -145,7 +142,7 @@ function loadOrConfigPlugin (pluginHandle, pluginType, cryptoCode, options,
if (!currentName) pluginHandle = null
else { // some plugins may be disabled
const pluginConfig = cachedConfig.exchanges.plugins.settings[currentName] || {}
const pluginConfig = accounts[currentName]
const mergedConfig = R.merge(pluginConfig, options)
@ -169,23 +166,26 @@ function loadOrConfigPlugin (pluginHandle, pluginType, cryptoCode, options,
exports.loadOrConfigPlugin = loadOrConfigPlugin
// Note: this whole function gets called every time there's a config update
exports.configure = function configure (config) {
exports.configure = function configure (cfg) {
if (config.exchanges.settings.lowBalanceMargin < 1) {
throw new Error('\'settings.lowBalanceMargin\' has to be >= 1')
}
cachedConfig = config
cachedConfig = cfg
const accounts = config.loadAccounts()
deviceCurrency = config.fiat.fiatCurrency
cryptoCodes = config.crypto.cryptoCurrencies
cryptoCodes.forEach(cryptoCode => {
cryptoScopedConfig = config.cryptoScoped(cryptoCode, cachedConfig)
const cryptoScopedConfig = config.cryptoScoped(cryptoCode, cachedConfig)
// TICKER [required] configure (or load)
loadOrConfigPlugin(
tickerPlugins[cryptoCode],
'ticker',
cryptoCode,
cryptoScopedConfig,
accounts,
{currency: deviceCurrency},
function onTickerChange (newTicker) {
tickerPlugins[cryptoCode] = newTicker
@ -201,6 +201,8 @@ exports.configure = function configure (config) {
walletPlugins[cryptoCode],
'transfer',
cryptoCode,
cryptoScopedConfig,
accounts,
{masterSeed: cryptoSeed},
function onWalletChange (newWallet) {
walletPlugins[cryptoCode] = newWallet
@ -214,6 +216,8 @@ exports.configure = function configure (config) {
traderPlugins[cryptoCode],
'trader',
cryptoCode,
cryptoScopedConfig,
accounts,
null,
function onTraderChange (newTrader) {
traderPlugins[cryptoCode] = newTrader
@ -223,25 +227,31 @@ exports.configure = function configure (config) {
)
})
const unscopedCfg = config.unscoped(cachedConfig)
// ID VERIFIER [optional] configure (or load)
idVerifierPlugin = loadOrConfigPlugin(
idVerifierPlugin,
'idVerifier'
)
infoPlugin = loadOrConfigPlugin(
infoPlugin,
'info'
'idVerifier',
null,
unscopedCfg,
accounts
)
emailPlugin = loadOrConfigPlugin(
emailPlugin,
'email'
'email',
null,
unscopedCfg,
accounts
)
smsPlugin = loadOrConfigPlugin(
smsPlugin,
'sms'
'sms',
null,
unscopedCfg,
accounts
)
}