This commit is contained in:
Josh Harvey 2016-10-24 01:55:17 +03:00
parent 594228e871
commit defb8d0f34
7 changed files with 36 additions and 53 deletions

View file

@ -134,7 +134,6 @@ function pp (o) {
function loadOrConfigPlugin (pluginHandle, pluginType, cryptoCode, config, accounts, options,
onChangeCallback) {
pp(config)
const currentName = config.cryptoServices[pluginType]
currentlyUsedPlugins[cryptoCode] = currentlyUsedPlugins[cryptoCode] || {}
@ -168,16 +167,10 @@ exports.loadOrConfigPlugin = loadOrConfigPlugin
// Note: this whole function gets called every time there's a config update
exports.configure = function configure (config) {
console.log('DEBUG40')
console.log('DEBUG4: %j', config)
cachedConfig = config
console.log('DEBUG41')
const accounts = configManager.loadAccounts()
console.log('DEBUG42')
const cryptoCodes = getCryptoCodes()
console.log('DEBUG30')
@ -216,7 +209,6 @@ exports.configure = function configure (config) {
accounts,
{masterSeed: cryptoSeed},
function onWalletChange (newWallet) {
console.log('DEBUG34: %s, %j', cryptoCode, newWallet)
walletPlugins[cryptoCode] = newWallet
pollBalance(cryptoCode)
}
@ -239,8 +231,6 @@ exports.configure = function configure (config) {
)
})
console.log('DEBUG32')
const unscopedCfg = configManager.unscoped(cachedConfig)
// ID VERIFIER [optional] configure (or load)
@ -577,7 +567,6 @@ function pollBalance (cryptoCode, cb) {
function pollRate (cryptoCode, cb) {
const tickerPlugin = tickerPlugins[cryptoCode]
pp(tickerPlugins)
logger.debug('[%s] polling for rates (%s)', cryptoCode, tickerPlugin.NAME)
let currencies = deviceCurrency
@ -710,8 +699,6 @@ exports.verifyTx = function verifyTx (data, cb) {
function sendMessage (rec) {
const pluginPromises = []
const config = configManager.unscoped(cachedConfig)
console.log('DEBUG35')
pp(config)
if (!config.notifications.notificationsEnabled) return Promise.all([])
@ -789,19 +776,25 @@ exports.getCryptoCodes = getCryptoCodes
function getAllCryptoCodes () {
return db.devices()
.then(rows => {
return rows.reduce((acc, r) => getCryptoCodes(r.device_id).forEach(c => acc.add(c)), new Set())
return rows.reduce((acc, r) => {
getCryptoCodes(r.device_id).forEach(c => acc.add(c))
return acc
}, new Set())
})
}
function checkBalances () {
return Promise.all(getAllCryptoCodes(), db.devices())
return Promise.all([getAllCryptoCodes(), db.devices()])
.then(arr => {
const cryptoCodes = arr[0]
const deviceIds = arr[1].map(r => r.device_id)
const balances = []
cryptoCodes.forEach(cryptoCode => {
const minBalance = deviceIds.map(deviceId => exports.fiatBalance(cryptoCode, deviceId).balance)
const minBalance = deviceIds.map(deviceId => {
const fiatBalanceRec = exports.fiatBalance(cryptoCode, deviceId)
return fiatBalanceRec ? fiatBalanceRec.balance : Infinity
})
.reduce((min, cur) => Math.min(min, cur), Infinity)
const rec = {fiatBalance: minBalance, cryptoCode, fiatCode: deviceCurrency}
@ -814,12 +807,9 @@ function checkBalances () {
exports.startCheckingNotification = function startCheckingNotification () {
const config = configManager.unscoped(cachedConfig)
return checkBalances()
.then(balances => {
notifier.init(db, balances, config.notifications)
checkNotification()
setInterval(checkNotification, CHECK_NOTIFICATION_INTERVAL)
})
notifier.init(db, checkBalances, config.notifications)
checkNotification()
setInterval(checkNotification, CHECK_NOTIFICATION_INTERVAL)
}
exports.getPhoneCode = function getPhoneCode (phone) {