moar coinUtils fixes
This commit is contained in:
parent
5a26f718c5
commit
5987f288a7
3 changed files with 18 additions and 13 deletions
|
|
@ -40,13 +40,15 @@ function fetchMachines () {
|
|||
}
|
||||
|
||||
function computeCrypto (cryptoCode, _balance) {
|
||||
const unitScale = coinUtils.coins[cryptoCode].unitScale
|
||||
const cryptoRec = coinUtils.getCryptoCurrency(cryptoCode)
|
||||
const unitScale = cryptoRec.unitScale
|
||||
|
||||
return BN(_balance).shift(-unitScale).round(5)
|
||||
}
|
||||
|
||||
function computeFiat (rate, cryptoCode, _balance) {
|
||||
const unitScale = coinUtils.coins[cryptoCode].unitScale
|
||||
const cryptoRec = coinUtils.getCryptoCurrency(cryptoCode)
|
||||
const unitScale = cryptoRec.unitScale
|
||||
|
||||
return BN(_balance).shift(-unitScale).mul(rate).round(5)
|
||||
}
|
||||
|
|
@ -59,9 +61,11 @@ function getFunding (_cryptoCode) {
|
|||
const cryptoCode = _cryptoCode || cryptoCodes[0]
|
||||
const fiatCode = config.fiatCurrency
|
||||
const pareCoins = c => _.includes(c.cryptoCode, cryptoCodes)
|
||||
const cryptoDisplays = _.filter(pareCoins, coinUtils.cryptoDisplays)
|
||||
const cryptoCurrencies = coinUtils.cryptoCurrencies()
|
||||
const cryptoDisplays = _.filter(pareCoins, cryptoCurrencies)
|
||||
const cryptoRec = coinUtils.getCryptoCurrency(cryptoCode)
|
||||
|
||||
if (!coinUtils.coins[cryptoCode]) throw new Error(`Unsupported coin: ${cryptoCode}`)
|
||||
if (!cryptoRec) throw new Error(`Unsupported coin: ${cryptoCode}`)
|
||||
|
||||
const promises = [
|
||||
wallet.newFunding(settings, cryptoCode),
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ function processCryptos (codes) {
|
|||
|
||||
function setupCrypto (crypto) {
|
||||
logger.info(`Installing ${crypto.display}...`)
|
||||
const cryptoDir = coinUtils.cryptoConfigDir(crypto.cryptoCode)
|
||||
const cryptoDir = coinUtils.cryptoConfigDir(crypto)
|
||||
makeDir.sync(cryptoDir)
|
||||
const cryptoPlugin = plugin(crypto)
|
||||
const oldDir = process.cwd()
|
||||
|
|
|
|||
|
|
@ -27,8 +27,6 @@ const STALE_BALANCE = 3 * T.minutes
|
|||
const PONG_TTL = '1 week'
|
||||
const tradesQueues = {}
|
||||
|
||||
const coins = coinUtils.coins
|
||||
|
||||
function plugins (settings, deviceId) {
|
||||
function buildRates (tickers) {
|
||||
const config = configManager.machineScoped(deviceId, settings.config)
|
||||
|
|
@ -172,15 +170,16 @@ function plugins (settings, deviceId) {
|
|||
}
|
||||
|
||||
function mapCoinSettings (coinParams) {
|
||||
const coin = coinParams[0]
|
||||
const cryptoCode = coinParams[0]
|
||||
const cryptoNetwork = coinParams[1]
|
||||
const config = configManager.scoped(coin, deviceId, settings.config)
|
||||
const config = configManager.scoped(cryptoCode, deviceId, settings.config)
|
||||
const minimumTx = BN(config.minimumTx)
|
||||
const cashInFee = BN(config.cashInFee)
|
||||
const cryptoRec = coinUtils.getCryptoCurrency(cryptoCode)
|
||||
|
||||
return {
|
||||
cryptoCode: coin,
|
||||
display: coinUtils.display(coin),
|
||||
cryptoCode,
|
||||
display: cryptoRec.display,
|
||||
minimumTx: BN.max(minimumTx, cashInFee),
|
||||
cashInFee: cashInFee,
|
||||
cryptoNetwork
|
||||
|
|
@ -284,8 +283,10 @@ function plugins (settings, deviceId) {
|
|||
|
||||
const lowBalanceMargin = BN(1)
|
||||
|
||||
const unitScale = BN(10).pow(coins[cryptoCode].unitScale)
|
||||
const fiatTransferBalance = balance.mul(rate.div(unitScale)).div(lowBalanceMargin)
|
||||
const cryptoRec = coinUtils.getCryptoCurrency(cryptoCode)
|
||||
const unitScale = cryptoRec.unitScale
|
||||
const shiftedRate = rate.shift(-unitScale)
|
||||
const fiatTransferBalance = balance.mul(shiftedRate).div(lowBalanceMargin)
|
||||
|
||||
return {timestamp: balanceRec.timestamp, balance: fiatTransferBalance.truncated().toString()}
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue