Fix ratchet errors on commission and ticker
This commit is contained in:
parent
fe72b4fcaf
commit
3dd7503e45
5 changed files with 22 additions and 41 deletions
|
|
@ -29,7 +29,7 @@ function toObj (row) {
|
|||
|
||||
keys.forEach(key => {
|
||||
const objKey = _.camelCase(key)
|
||||
if (_.includes(key, ['crypto_atoms', 'fiat', 'cash_in_fee', 'cash_in_fee_crypto'])) {
|
||||
if (_.includes(key, ['crypto_atoms', 'fiat', 'cash_in_fee', 'cash_in_fee_crypto', 'commission_percentage', 'raw_ticker_price'])) {
|
||||
newObj[objKey] = BN(row[key])
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ function toObj (row) {
|
|||
|
||||
keys.forEach(key => {
|
||||
const objKey = _.camelCase(key)
|
||||
if (key === 'crypto_atoms' || key === 'fiat') {
|
||||
if (_.includes(key, ['crypto_atoms', 'fiat', 'commission_percentage', 'raw_ticker_price'])) {
|
||||
newObj[objKey] = BN(row[key])
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,14 +32,6 @@ const PONG_TTL = '1 week'
|
|||
const tradesQueues = {}
|
||||
|
||||
function plugins (settings, deviceId) {
|
||||
function getRawTickerPrice (fiatCode, cryptoCode) {
|
||||
return ticker.getRates(settings, fiatCode, cryptoCode)
|
||||
.then(tickers => ({
|
||||
cashIn: _.get(['rates', 'ask'], tickers),
|
||||
cashOut: _.get(['rates', 'bid'], tickers)
|
||||
}))
|
||||
}
|
||||
|
||||
function buildRates (tickers) {
|
||||
const config = configManager.machineScoped(deviceId, settings.config)
|
||||
const cryptoCodes = config.cryptoCurrencies
|
||||
|
|
@ -198,8 +190,8 @@ function plugins (settings, deviceId) {
|
|||
const config = configManager.scoped(cryptoCode, deviceId, settings.config)
|
||||
const minimumTx = BN(config.minimumTx)
|
||||
const cashInFee = BN(config.cashInFee)
|
||||
const cashInCommission = BN(config.cashInCommission || 0)
|
||||
const cashOutCommission = BN(config.cashOutCommission || 0)
|
||||
const cashInCommission = BN(config.cashInCommission)
|
||||
const cashOutCommission = config.cashOutCommission ? BN(config.cashOutCommission) : null
|
||||
const cryptoRec = coinUtils.getCryptoCurrency(cryptoCode)
|
||||
|
||||
return {
|
||||
|
|
@ -239,12 +231,13 @@ function plugins (settings, deviceId) {
|
|||
const balances = arr.slice(cryptoCodesCount + 3, 2 * cryptoCodesCount + 3)
|
||||
const testNets = arr.slice(2 * cryptoCodesCount + 3)
|
||||
const coinParams = _.zip(cryptoCodes, testNets)
|
||||
const coinsWithoutRate = _.map(mapCoinSettings, coinParams)
|
||||
|
||||
return {
|
||||
cassettes,
|
||||
rates: buildRates(tickers),
|
||||
balances: buildBalances(balances),
|
||||
coins: _.map(mapCoinSettings, coinParams),
|
||||
coins: _.zipWith(_.assign, coinsWithoutRate, tickers),
|
||||
configVersion
|
||||
}
|
||||
})
|
||||
|
|
@ -795,8 +788,7 @@ function plugins (settings, deviceId) {
|
|||
buy,
|
||||
sell,
|
||||
notificationsEnabled,
|
||||
notifyOperator,
|
||||
getRawTickerPrice
|
||||
notifyOperator
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
25
lib/tx.js
25
lib/tx.js
|
|
@ -4,11 +4,10 @@ const CashInTx = require('./cash-in/cash-in-tx')
|
|||
const CashOutTx = require('./cash-out/cash-out-tx')
|
||||
|
||||
function process (tx, pi) {
|
||||
return massage(tx, pi).then(mtx => {
|
||||
if (mtx.direction === 'cashIn') return CashInTx.post(mtx, pi)
|
||||
if (mtx.direction === 'cashOut') return CashOutTx.post(mtx, pi)
|
||||
return Promise.reject(new Error('No such tx direction: ' + mtx.direction))
|
||||
})
|
||||
const mtx = massage(tx, pi)
|
||||
if (mtx.direction === 'cashIn') return CashInTx.post(mtx, pi)
|
||||
if (mtx.direction === 'cashOut') return CashOutTx.post(mtx, pi)
|
||||
return Promise.reject(new Error('No such tx direction: ' + mtx.direction))
|
||||
}
|
||||
|
||||
function post (tx, pi) {
|
||||
|
|
@ -17,9 +16,6 @@ function post (tx, pi) {
|
|||
}
|
||||
|
||||
function massage (tx, pi) {
|
||||
const direction = _.get('direction', tx)
|
||||
const cryptoCode = _.get('cryptoCode', tx)
|
||||
const fiatCode = _.get('fiatCode', tx)
|
||||
const isDateField = r => r === 'created' || _.endsWith('_time', r)
|
||||
const transformDate = (v, k) => isDateField(k) ? new Date(v) : v
|
||||
const mapValuesWithKey = _.mapValues.convert({'cap': false})
|
||||
|
|
@ -33,11 +29,13 @@ function massage (tx, pi) {
|
|||
cashInFee: BN(r.cashInFee),
|
||||
cashInFeeCrypto: BN(r.cashInFeeCrypto),
|
||||
commissionPercentage: BN(r.commissionPercentage),
|
||||
rawTickerPrice: BN(r.rawTickerPrice),
|
||||
minimumTx: BN(r.minimumTx)
|
||||
}
|
||||
: {
|
||||
cryptoAtoms: BN(r.cryptoAtoms),
|
||||
fiat: BN(r.fiat),
|
||||
rawTickerPrice: BN(r.rawTickerPrice),
|
||||
commissionPercentage: BN(r.commissionPercentage)
|
||||
}
|
||||
|
||||
|
|
@ -47,16 +45,7 @@ function massage (tx, pi) {
|
|||
const mapper = _.flow(
|
||||
transformDates,
|
||||
mapBN,
|
||||
_.unset('dirty'),
|
||||
withTickerPrice)
|
||||
|
||||
function withTickerPrice (r) {
|
||||
return pi.getRawTickerPrice(fiatCode, cryptoCode).then(tickerPrice => {
|
||||
return _.assign(r, {
|
||||
rawTickerPrice: _.get(direction, tickerPrice)
|
||||
})
|
||||
})
|
||||
}
|
||||
_.unset('dirty'))
|
||||
|
||||
return mapper(tx)
|
||||
}
|
||||
|
|
|
|||
16
package-lock.json
generated
16
package-lock.json
generated
|
|
@ -2888,7 +2888,7 @@
|
|||
},
|
||||
"debug-log": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "http://registry.npmjs.org/debug-log/-/debug-log-1.0.1.tgz",
|
||||
"resolved": "https://registry.npmjs.org/debug-log/-/debug-log-1.0.1.tgz",
|
||||
"integrity": "sha1-IwdjLUwEOCuN+KMvcLiVBG1SdF8=",
|
||||
"dev": true
|
||||
},
|
||||
|
|
@ -3457,7 +3457,7 @@
|
|||
"dependencies": {
|
||||
"chalk": {
|
||||
"version": "1.1.3",
|
||||
"resolved": "http://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz",
|
||||
"resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz",
|
||||
"integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
|
|
@ -3470,7 +3470,7 @@
|
|||
},
|
||||
"strip-ansi": {
|
||||
"version": "3.0.1",
|
||||
"resolved": "http://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz",
|
||||
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz",
|
||||
"integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
|
|
@ -3670,7 +3670,7 @@
|
|||
"dependencies": {
|
||||
"doctrine": {
|
||||
"version": "1.5.0",
|
||||
"resolved": "http://registry.npmjs.org/doctrine/-/doctrine-1.5.0.tgz",
|
||||
"resolved": "https://registry.npmjs.org/doctrine/-/doctrine-1.5.0.tgz",
|
||||
"integrity": "sha1-N53Ocw9hZvds76TmcHoVmwLFpvo=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
|
|
@ -3689,7 +3689,7 @@
|
|||
},
|
||||
"load-json-file": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "http://registry.npmjs.org/load-json-file/-/load-json-file-2.0.0.tgz",
|
||||
"resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-2.0.0.tgz",
|
||||
"integrity": "sha1-eUfkIUmvgNaWy/eXvKq8/h/inKg=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
|
|
@ -3710,7 +3710,7 @@
|
|||
},
|
||||
"pify": {
|
||||
"version": "2.3.0",
|
||||
"resolved": "http://registry.npmjs.org/pify/-/pify-2.3.0.tgz",
|
||||
"resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz",
|
||||
"integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=",
|
||||
"dev": true
|
||||
},
|
||||
|
|
@ -9002,7 +9002,7 @@
|
|||
},
|
||||
"require-uncached": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "http://registry.npmjs.org/require-uncached/-/require-uncached-1.0.3.tgz",
|
||||
"resolved": "https://registry.npmjs.org/require-uncached/-/require-uncached-1.0.3.tgz",
|
||||
"integrity": "sha1-Tg1W1slmL9MeQwEcS5WqSZVUIdM=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
|
|
@ -10422,7 +10422,7 @@
|
|||
},
|
||||
"table": {
|
||||
"version": "4.0.3",
|
||||
"resolved": "http://registry.npmjs.org/table/-/table-4.0.3.tgz",
|
||||
"resolved": "https://registry.npmjs.org/table/-/table-4.0.3.tgz",
|
||||
"integrity": "sha512-S7rnFITmBH1EnyKcvxBh1LjYeQMmnZtCXSEbHcH6S0NoKit24ZuFO/T1vDcLdYsLQkM188PVVhQmzKIuThNkKg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue