log raw ticker price within tx
This commit is contained in:
parent
5815a606f2
commit
578a39a721
8 changed files with 132 additions and 39 deletions
|
|
@ -19,6 +19,7 @@ type alias CashInTxRec =
|
||||||
, cryptoCode : CryptoCode
|
, cryptoCode : CryptoCode
|
||||||
, fiat : Float
|
, fiat : Float
|
||||||
, commissionPercentage : Maybe Float
|
, commissionPercentage : Maybe Float
|
||||||
|
, rawTickerPrice : Maybe Float
|
||||||
, fiatCode : String
|
, fiatCode : String
|
||||||
, txHash : Maybe String
|
, txHash : Maybe String
|
||||||
, phone : Maybe String
|
, phone : Maybe String
|
||||||
|
|
@ -39,6 +40,7 @@ type alias CashOutTxRec =
|
||||||
, cryptoCode : CryptoCode
|
, cryptoCode : CryptoCode
|
||||||
, fiat : Float
|
, fiat : Float
|
||||||
, commissionPercentage : Maybe Float
|
, commissionPercentage : Maybe Float
|
||||||
|
, rawTickerPrice : Maybe Float
|
||||||
, fiatCode : String
|
, fiatCode : String
|
||||||
, status : String
|
, status : String
|
||||||
, dispense : Bool
|
, dispense : Bool
|
||||||
|
|
|
||||||
|
|
@ -66,6 +66,7 @@ cashInTxDecoder =
|
||||||
|> required "cryptoCode" cryptoCodeDecoder
|
|> required "cryptoCode" cryptoCodeDecoder
|
||||||
|> required "fiat" floatString
|
|> required "fiat" floatString
|
||||||
|> required "commissionPercentage" (nullable floatString)
|
|> required "commissionPercentage" (nullable floatString)
|
||||||
|
|> required "rawTickerPrice" (nullable floatString)
|
||||||
|> required "fiatCode" string
|
|> required "fiatCode" string
|
||||||
|> required "txHash" (nullable string)
|
|> required "txHash" (nullable string)
|
||||||
|> required "phone" (nullable string)
|
|> required "phone" (nullable string)
|
||||||
|
|
@ -93,6 +94,7 @@ cashOutTxDecoder =
|
||||||
|> required "cryptoCode" cryptoCodeDecoder
|
|> required "cryptoCode" cryptoCodeDecoder
|
||||||
|> required "fiat" floatString
|
|> required "fiat" floatString
|
||||||
|> required "commissionPercentage" (nullable floatString)
|
|> required "commissionPercentage" (nullable floatString)
|
||||||
|
|> required "rawTickerPrice" (nullable floatString)
|
||||||
|> required "fiatCode" string
|
|> required "fiatCode" string
|
||||||
|> required "status" string
|
|> required "status" string
|
||||||
|> required "dispense" bool
|
|> required "dispense" bool
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,7 @@ cashInTxView tx =
|
||||||
[ div [] [ text tx.id ]
|
[ div [] [ text tx.id ]
|
||||||
, div [] [ text "This is a cash-in transaction" ]
|
, div [] [ text "This is a cash-in transaction" ]
|
||||||
, div [] [ text ("Fiat: " ++ (format "0,0.00" tx.fiat)) ]
|
, div [] [ text ("Fiat: " ++ (format "0,0.00" tx.fiat)) ]
|
||||||
|
, div [] [ text ("Raw ticker price: " ++ (format "0,0.00" (Maybe.withDefault 0.0 tx.rawTickerPrice))) ]
|
||||||
, div [] [ text ("Status: " ++ cancelStatus) ]
|
, div [] [ text ("Status: " ++ cancelStatus) ]
|
||||||
, div [] [ text error ]
|
, div [] [ text error ]
|
||||||
, cancelButtonDiv
|
, cancelButtonDiv
|
||||||
|
|
@ -64,6 +65,7 @@ cashOutTxView tx =
|
||||||
[ div [] [ text tx.id ]
|
[ div [] [ text tx.id ]
|
||||||
, div [] [ text "This is a cash-out transaction" ]
|
, div [] [ text "This is a cash-out transaction" ]
|
||||||
, div [] [ text ("Fiat: " ++ (format "0,0.00" tx.fiat)) ]
|
, div [] [ text ("Fiat: " ++ (format "0,0.00" tx.fiat)) ]
|
||||||
|
, div [] [ text ("Raw ticker price: " ++ (format "0,0.00" (Maybe.withDefault 0.0 tx.rawTickerPrice))) ]
|
||||||
, div [] [ text error ]
|
, div [] [ text error ]
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,8 @@ function convertBigNumFields (obj) {
|
||||||
const convert = (value, key) => _.includes(key, [
|
const convert = (value, key) => _.includes(key, [
|
||||||
'cryptoAtoms',
|
'cryptoAtoms',
|
||||||
'fiat',
|
'fiat',
|
||||||
'commissionPercentage'
|
'commissionPercentage',
|
||||||
|
'rawTickerPrice'
|
||||||
])
|
])
|
||||||
? value.toString()
|
? value.toString()
|
||||||
: value
|
: value
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,15 @@ function plugins (settings, deviceId) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getRawTickerPrice (fiatCode, cryptoCode) {
|
||||||
|
const tickers = await ticker.getRates(settings, fiatCode, cryptoCode)
|
||||||
|
|
||||||
|
return {
|
||||||
|
cashIn: _.get(['rates', 'ask'], tickers),
|
||||||
|
cashOut: _.get(['rates', 'bid'], tickers)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function buildRates (tickers) {
|
function buildRates (tickers) {
|
||||||
const config = configManager.machineScoped(deviceId, settings.config)
|
const config = configManager.machineScoped(deviceId, settings.config)
|
||||||
const cryptoCodes = config.cryptoCurrencies
|
const cryptoCodes = config.cryptoCurrencies
|
||||||
|
|
@ -793,7 +802,8 @@ function plugins (settings, deviceId) {
|
||||||
sell,
|
sell,
|
||||||
notificationsEnabled,
|
notificationsEnabled,
|
||||||
notifyOperator,
|
notifyOperator,
|
||||||
getCommissionPercentage
|
getCommissionPercentage,
|
||||||
|
getRawTickerPrice
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
22
lib/tx.js
22
lib/tx.js
|
|
@ -3,8 +3,8 @@ const BN = require('./bn')
|
||||||
const CashInTx = require('./cash-in/cash-in-tx')
|
const CashInTx = require('./cash-in/cash-in-tx')
|
||||||
const CashOutTx = require('./cash-out/cash-out-tx')
|
const CashOutTx = require('./cash-out/cash-out-tx')
|
||||||
|
|
||||||
function process (tx, pi) {
|
async function process (tx, pi) {
|
||||||
const mtx = massage(tx, pi)
|
const mtx = await massage(tx, pi)
|
||||||
if (mtx.direction === 'cashIn') return CashInTx.post(mtx, pi)
|
if (mtx.direction === 'cashIn') return CashInTx.post(mtx, pi)
|
||||||
if (mtx.direction === 'cashOut') return CashOutTx.post(mtx, pi)
|
if (mtx.direction === 'cashOut') return CashOutTx.post(mtx, pi)
|
||||||
|
|
||||||
|
|
@ -16,15 +16,22 @@ function post (tx, pi) {
|
||||||
.then(_.set('dirty', false))
|
.then(_.set('dirty', false))
|
||||||
}
|
}
|
||||||
|
|
||||||
function massage (tx, pi) {
|
async function massage (tx, pi) {
|
||||||
const direction = _.get('direction', tx)
|
const direction = _.get('direction', tx)
|
||||||
const cryptoCode = _.get('cryptoCode', tx)
|
const cryptoCode = _.get('cryptoCode', tx)
|
||||||
|
const fiatCode = _.get('fiatCode', tx)
|
||||||
const isDateField = r => r === 'created' || _.endsWith('_time', r)
|
const isDateField = r => r === 'created' || _.endsWith('_time', r)
|
||||||
const transformDate = (v, k) => isDateField(k) ? new Date(v) : v
|
const transformDate = (v, k) => isDateField(k) ? new Date(v) : v
|
||||||
const mapValuesWithKey = _.mapValues.convert({'cap': false})
|
const mapValuesWithKey = _.mapValues.convert({'cap': false})
|
||||||
const transformDates = r => mapValuesWithKey(transformDate, r)
|
const transformDates = r => mapValuesWithKey(transformDate, r)
|
||||||
const logCommission = r => _.assign(r, {
|
const logCommission = r => _.assign(r, {
|
||||||
commissionPercentage: _.get(direction, pi.getCommissionPercentage(cryptoCode))
|
commissionPercentage: _.get(direction
|
||||||
|
, pi.getCommissionPercentage(cryptoCode))
|
||||||
|
})
|
||||||
|
|
||||||
|
const tickerPrice = await pi.getRawTickerPrice(fiatCode, cryptoCode)
|
||||||
|
const logRawTickerPrice = r => _.assign(r, {
|
||||||
|
rawTickerPrice: _.get(direction, tickerPrice)
|
||||||
})
|
})
|
||||||
|
|
||||||
const mapBN = r => {
|
const mapBN = r => {
|
||||||
|
|
@ -44,7 +51,12 @@ function massage (tx, pi) {
|
||||||
return _.assign(r, update)
|
return _.assign(r, update)
|
||||||
}
|
}
|
||||||
|
|
||||||
const mapper = _.flow(transformDates, logCommission, mapBN, _.unset('dirty'))
|
const mapper = _.flow(
|
||||||
|
transformDates,
|
||||||
|
mapBN,
|
||||||
|
logCommission,
|
||||||
|
logRawTickerPrice,
|
||||||
|
_.unset('dirty'))
|
||||||
|
|
||||||
return mapper(tx)
|
return mapper(tx)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
16
migrations/1543182139555-tx-ticker-price.js
Normal file
16
migrations/1543182139555-tx-ticker-price.js
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
'use strict'
|
||||||
|
|
||||||
|
const db = require('./db')
|
||||||
|
|
||||||
|
exports.up = function (next) {
|
||||||
|
var sql = [
|
||||||
|
'ALTER TABLE cash_in_txs ADD COLUMN raw_ticker_price numeric(14, 5) null DEFAULT null',
|
||||||
|
'ALTER TABLE cash_out_txs ADD COLUMN raw_ticker_price numeric(14, 5) null DEFAULT null'
|
||||||
|
]
|
||||||
|
|
||||||
|
db.multi(sql, next)
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.down = function (next) {
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
|
@ -28478,7 +28478,9 @@ var _user$project$Common_TransactionTypes$CashInTxRec = function (a) {
|
||||||
return function (n) {
|
return function (n) {
|
||||||
return function (o) {
|
return function (o) {
|
||||||
return function (p) {
|
return function (p) {
|
||||||
return {id: a, machineName: b, toAddress: c, cryptoAtoms: d, cryptoCode: e, fiat: f, commissionPercentage: g, fiatCode: h, txHash: i, phone: j, error: k, operatorCompleted: l, send: m, sendConfirmed: n, expired: o, created: p};
|
return function (q) {
|
||||||
|
return {id: a, machineName: b, toAddress: c, cryptoAtoms: d, cryptoCode: e, fiat: f, commissionPercentage: g, rawTickerPrice: h, fiatCode: i, txHash: j, phone: k, error: l, operatorCompleted: m, send: n, sendConfirmed: o, expired: p, created: q};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
@ -28511,7 +28513,9 @@ var _user$project$Common_TransactionTypes$CashOutTxRec = function (a) {
|
||||||
return function (n) {
|
return function (n) {
|
||||||
return function (o) {
|
return function (o) {
|
||||||
return function (p) {
|
return function (p) {
|
||||||
return {id: a, machineName: b, toAddress: c, cryptoAtoms: d, cryptoCode: e, fiat: f, commissionPercentage: g, fiatCode: h, status: i, dispense: j, notified: k, redeemed: l, phone: m, error: n, created: o, confirmed: p};
|
return function (q) {
|
||||||
|
return {id: a, machineName: b, toAddress: c, cryptoAtoms: d, cryptoCode: e, fiat: f, commissionPercentage: g, rawTickerPrice: h, fiatCode: i, status: j, dispense: k, notified: l, redeemed: m, phone: n, error: o, created: p, confirmed: q};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
@ -33988,6 +33992,10 @@ var _user$project$Transaction_Decoder$cashInTxDecoder = A3(
|
||||||
_NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required,
|
_NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required,
|
||||||
'fiatCode',
|
'fiatCode',
|
||||||
_elm_lang$core$Json_Decode$string,
|
_elm_lang$core$Json_Decode$string,
|
||||||
|
A3(
|
||||||
|
_NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required,
|
||||||
|
'rawTickerPrice',
|
||||||
|
_elm_lang$core$Json_Decode$nullable(_user$project$Transaction_Decoder$floatString),
|
||||||
A3(
|
A3(
|
||||||
_NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required,
|
_NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required,
|
||||||
'commissionPercentage',
|
'commissionPercentage',
|
||||||
|
|
@ -34016,7 +34024,7 @@ var _user$project$Transaction_Decoder$cashInTxDecoder = A3(
|
||||||
_NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required,
|
_NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required,
|
||||||
'id',
|
'id',
|
||||||
_elm_lang$core$Json_Decode$string,
|
_elm_lang$core$Json_Decode$string,
|
||||||
_NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$decode(_user$project$Common_TransactionTypes$CashInTxRec)))))))))))))))));
|
_NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$decode(_user$project$Common_TransactionTypes$CashInTxRec))))))))))))))))));
|
||||||
var _user$project$Transaction_Decoder$cashOutTxDecoder = A3(
|
var _user$project$Transaction_Decoder$cashOutTxDecoder = A3(
|
||||||
_NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required,
|
_NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required,
|
||||||
'confirmedAt',
|
'confirmedAt',
|
||||||
|
|
@ -34053,6 +34061,10 @@ var _user$project$Transaction_Decoder$cashOutTxDecoder = A3(
|
||||||
_NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required,
|
_NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required,
|
||||||
'fiatCode',
|
'fiatCode',
|
||||||
_elm_lang$core$Json_Decode$string,
|
_elm_lang$core$Json_Decode$string,
|
||||||
|
A3(
|
||||||
|
_NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required,
|
||||||
|
'rawTickerPrice',
|
||||||
|
_elm_lang$core$Json_Decode$nullable(_user$project$Transaction_Decoder$floatString),
|
||||||
A3(
|
A3(
|
||||||
_NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required,
|
_NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required,
|
||||||
'commissionPercentage',
|
'commissionPercentage',
|
||||||
|
|
@ -34081,7 +34093,7 @@ var _user$project$Transaction_Decoder$cashOutTxDecoder = A3(
|
||||||
_NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required,
|
_NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required,
|
||||||
'id',
|
'id',
|
||||||
_elm_lang$core$Json_Decode$string,
|
_elm_lang$core$Json_Decode$string,
|
||||||
_NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$decode(_user$project$Common_TransactionTypes$CashOutTxRec)))))))))))))))));
|
_NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$decode(_user$project$Common_TransactionTypes$CashOutTxRec))))))))))))))))));
|
||||||
var _user$project$Transaction_Decoder$txDecode = function (txClass) {
|
var _user$project$Transaction_Decoder$txDecode = function (txClass) {
|
||||||
var _p4 = txClass;
|
var _p4 = txClass;
|
||||||
switch (_p4) {
|
switch (_p4) {
|
||||||
|
|
@ -39077,6 +39089,23 @@ var _user$project$Transaction_View$cashOutTxView = function (tx) {
|
||||||
A2(_ggb$numeral_elm$Numeral$format, '0,0.00', tx.fiat))),
|
A2(_ggb$numeral_elm$Numeral$format, '0,0.00', tx.fiat))),
|
||||||
_1: {ctor: '[]'}
|
_1: {ctor: '[]'}
|
||||||
}),
|
}),
|
||||||
|
_1: {
|
||||||
|
ctor: '::',
|
||||||
|
_0: A2(
|
||||||
|
_elm_lang$html$Html$div,
|
||||||
|
{ctor: '[]'},
|
||||||
|
{
|
||||||
|
ctor: '::',
|
||||||
|
_0: _elm_lang$html$Html$text(
|
||||||
|
A2(
|
||||||
|
_elm_lang$core$Basics_ops['++'],
|
||||||
|
'Raw ticker price: ',
|
||||||
|
A2(
|
||||||
|
_ggb$numeral_elm$Numeral$format,
|
||||||
|
'0,0.00',
|
||||||
|
A2(_elm_lang$core$Maybe$withDefault, 0.0, tx.rawTickerPrice)))),
|
||||||
|
_1: {ctor: '[]'}
|
||||||
|
}),
|
||||||
_1: {
|
_1: {
|
||||||
ctor: '::',
|
ctor: '::',
|
||||||
_0: A2(
|
_0: A2(
|
||||||
|
|
@ -39091,6 +39120,7 @@ var _user$project$Transaction_View$cashOutTxView = function (tx) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
var _user$project$Transaction_View$cashInTxView = function (tx) {
|
var _user$project$Transaction_View$cashInTxView = function (tx) {
|
||||||
|
|
@ -39157,6 +39187,23 @@ var _user$project$Transaction_View$cashInTxView = function (tx) {
|
||||||
A2(_ggb$numeral_elm$Numeral$format, '0,0.00', tx.fiat))),
|
A2(_ggb$numeral_elm$Numeral$format, '0,0.00', tx.fiat))),
|
||||||
_1: {ctor: '[]'}
|
_1: {ctor: '[]'}
|
||||||
}),
|
}),
|
||||||
|
_1: {
|
||||||
|
ctor: '::',
|
||||||
|
_0: A2(
|
||||||
|
_elm_lang$html$Html$div,
|
||||||
|
{ctor: '[]'},
|
||||||
|
{
|
||||||
|
ctor: '::',
|
||||||
|
_0: _elm_lang$html$Html$text(
|
||||||
|
A2(
|
||||||
|
_elm_lang$core$Basics_ops['++'],
|
||||||
|
'Raw ticker price: ',
|
||||||
|
A2(
|
||||||
|
_ggb$numeral_elm$Numeral$format,
|
||||||
|
'0,0.00',
|
||||||
|
A2(_elm_lang$core$Maybe$withDefault, 0.0, tx.rawTickerPrice)))),
|
||||||
|
_1: {ctor: '[]'}
|
||||||
|
}),
|
||||||
_1: {
|
_1: {
|
||||||
ctor: '::',
|
ctor: '::',
|
||||||
_0: A2(
|
_0: A2(
|
||||||
|
|
@ -39187,6 +39234,7 @@ var _user$project$Transaction_View$cashInTxView = function (tx) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
var _user$project$Transaction_View$txView = function (subModel) {
|
var _user$project$Transaction_View$txView = function (subModel) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue