start moving to new config; WIP
This commit is contained in:
parent
ea54a2d0fe
commit
ee37367c62
1 changed files with 11 additions and 9 deletions
|
|
@ -174,8 +174,8 @@ exports.configure = function configure (config) {
|
||||||
}
|
}
|
||||||
|
|
||||||
cachedConfig = config
|
cachedConfig = config
|
||||||
deviceCurrency = config.exchanges.settings.currency
|
deviceCurrency = config.fiat.fiatCurrency
|
||||||
cryptoCodes = config.exchanges.settings.coins || ['BTC']
|
cryptoCodes = config.crypto.cryptoCurrencies
|
||||||
|
|
||||||
cryptoCodes.forEach(cryptoCode => {
|
cryptoCodes.forEach(cryptoCode => {
|
||||||
// TICKER [required] configure (or load)
|
// TICKER [required] configure (or load)
|
||||||
|
|
@ -266,9 +266,9 @@ function buildCartridges (cartridges, virtualCartridges, rec) {
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.pollQueries = function pollQueries (deviceId) {
|
exports.pollQueries = function pollQueries (deviceId) {
|
||||||
const cartridges = cachedConfig.exchanges.settings.cartridges
|
const cartridges = [ cachedConfig.fiat.topCashOutDenomination,
|
||||||
if (!cartridges) return Promise.resolve({})
|
cachedConfig.fiat.bottomCashOutDenomination ]
|
||||||
const virtualCartridges = cachedConfig.exchanges.settings.virtualCartridges
|
const virtualCartridges = [cachedConfig.fiat.virtualCashOutDenomination]
|
||||||
|
|
||||||
return db.cartridgeCounts(deviceId)
|
return db.cartridgeCounts(deviceId)
|
||||||
.then(result => ({
|
.then(result => ({
|
||||||
|
|
@ -288,7 +288,7 @@ function _sendCoins (toAddress, cryptoAtoms, cryptoCode) {
|
||||||
|
|
||||||
function _sendCoinsCb (toAddress, cryptoAtoms, cryptoCode, cb) {
|
function _sendCoinsCb (toAddress, cryptoAtoms, cryptoCode, cb) {
|
||||||
const walletPlugin = walletPlugins[cryptoCode]
|
const walletPlugin = walletPlugins[cryptoCode]
|
||||||
const transactionFee = cachedConfig.exchanges.settings.transactionFee
|
const transactionFee = null
|
||||||
logger.debug('Sending coins [%s] to: %s', cryptoCode, toAddress)
|
logger.debug('Sending coins [%s] to: %s', cryptoCode, toAddress)
|
||||||
|
|
||||||
if (cryptoCode === 'BTC') {
|
if (cryptoCode === 'BTC') {
|
||||||
|
|
@ -394,7 +394,9 @@ exports.cashOut = function cashOut (deviceId, tx) {
|
||||||
|
|
||||||
exports.dispenseAck = function (deviceId, tx) {
|
exports.dispenseAck = function (deviceId, tx) {
|
||||||
console.log('DEBUG23: %j', tx)
|
console.log('DEBUG23: %j', tx)
|
||||||
const cartridges = cachedConfig.exchanges.settings.cartridges
|
const cartridges = [ cachedConfig.fiat.topCashOutDenomination,
|
||||||
|
cachedConfig.fiat.bottomCashOutDenomination ]
|
||||||
|
|
||||||
return db.addDispense(deviceId, tx, cartridges)
|
return db.addDispense(deviceId, tx, cartridges)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -402,7 +404,7 @@ exports.fiatBalance = function fiatBalance (cryptoCode) {
|
||||||
const deviceRate = exports.getDeviceRate(cryptoCode)
|
const deviceRate = exports.getDeviceRate(cryptoCode)
|
||||||
if (!deviceRate) return null
|
if (!deviceRate) return null
|
||||||
const rawRate = deviceRate.rates.ask
|
const rawRate = deviceRate.rates.ask
|
||||||
const commission = cachedConfig.exchanges.settings.commission
|
const commission = cachedConfig.commissions.cashInCommission
|
||||||
const lastBalanceRec = lastBalances[cryptoCode]
|
const lastBalanceRec = lastBalances[cryptoCode]
|
||||||
if (!lastBalanceRec) return null
|
if (!lastBalanceRec) return null
|
||||||
const lastBalance = lastBalanceRec.balance
|
const lastBalance = lastBalanceRec.balance
|
||||||
|
|
@ -414,7 +416,7 @@ exports.fiatBalance = function fiatBalance (cryptoCode) {
|
||||||
|
|
||||||
// `lowBalanceMargin` is our safety net. It's a number > 1, and we divide
|
// `lowBalanceMargin` is our safety net. It's a number > 1, and we divide
|
||||||
// all our balances by it to provide a safety margin.
|
// all our balances by it to provide a safety margin.
|
||||||
const lowBalanceMargin = cachedConfig.exchanges.settings.lowBalanceMargin || LOW_BALANCE_MARGIN_DEFAULT
|
const lowBalanceMargin = cachedConfig.commissions.lowBalanceMargin || LOW_BALANCE_MARGIN_DEFAULT
|
||||||
|
|
||||||
const unitScale = new BigNumber(10).pow(coins[cryptoCode].unitScale)
|
const unitScale = new BigNumber(10).pow(coins[cryptoCode].unitScale)
|
||||||
const fiatTransferBalance = lastBalance.div(unitScale).times(rate).div(lowBalanceMargin)
|
const fiatTransferBalance = lastBalance.div(unitScale).times(rate).div(lowBalanceMargin)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue