log raw ticker price within tx

This commit is contained in:
Fabio Cigliano 2018-11-26 12:07:15 +13:00 committed by Josh Harvey
parent 5815a606f2
commit 578a39a721
8 changed files with 132 additions and 39 deletions

View file

@ -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

View file

@ -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

View file

@ -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 ]
] ]

View file

@ -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

View file

@ -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
} }
} }

View file

@ -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)
} }

View 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()
}

View file

@ -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};
};
}; };
}; };
}; };
@ -33990,33 +33994,37 @@ var _user$project$Transaction_Decoder$cashInTxDecoder = A3(
_elm_lang$core$Json_Decode$string, _elm_lang$core$Json_Decode$string,
A3( A3(
_NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required, _NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required,
'commissionPercentage', 'rawTickerPrice',
_elm_lang$core$Json_Decode$nullable(_user$project$Transaction_Decoder$floatString), _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,
'fiat', 'commissionPercentage',
_user$project$Transaction_Decoder$floatString, _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,
'cryptoCode', 'fiat',
_user$project$Transaction_Decoder$cryptoCodeDecoder, _user$project$Transaction_Decoder$floatString,
A3( A3(
_NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required, _NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required,
'cryptoAtoms', 'cryptoCode',
_user$project$Transaction_Decoder$intString, _user$project$Transaction_Decoder$cryptoCodeDecoder,
A3( A3(
_NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required, _NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required,
'toAddress', 'cryptoAtoms',
_elm_lang$core$Json_Decode$string, _user$project$Transaction_Decoder$intString,
A3( A3(
_NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required, _NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required,
'machineName', 'toAddress',
_elm_lang$core$Json_Decode$string, _elm_lang$core$Json_Decode$string,
A3( A3(
_NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required, _NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required,
'id', 'machineName',
_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))))))))))))))))); A3(
_NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required,
'id',
_elm_lang$core$Json_Decode$string,
_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',
@ -34055,33 +34063,37 @@ var _user$project$Transaction_Decoder$cashOutTxDecoder = A3(
_elm_lang$core$Json_Decode$string, _elm_lang$core$Json_Decode$string,
A3( A3(
_NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required, _NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required,
'commissionPercentage', 'rawTickerPrice',
_elm_lang$core$Json_Decode$nullable(_user$project$Transaction_Decoder$floatString), _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,
'fiat', 'commissionPercentage',
_user$project$Transaction_Decoder$floatString, _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,
'cryptoCode', 'fiat',
_user$project$Transaction_Decoder$cryptoCodeDecoder, _user$project$Transaction_Decoder$floatString,
A3( A3(
_NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required, _NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required,
'cryptoAtoms', 'cryptoCode',
_user$project$Transaction_Decoder$intString, _user$project$Transaction_Decoder$cryptoCodeDecoder,
A3( A3(
_NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required, _NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required,
'toAddress', 'cryptoAtoms',
_elm_lang$core$Json_Decode$string, _user$project$Transaction_Decoder$intString,
A3( A3(
_NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required, _NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required,
'machineName', 'toAddress',
_elm_lang$core$Json_Decode$string, _elm_lang$core$Json_Decode$string,
A3( A3(
_NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required, _NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required,
'id', 'machineName',
_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))))))))))))))))); A3(
_NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required,
'id',
_elm_lang$core$Json_Decode$string,
_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) {
@ -39084,10 +39096,28 @@ var _user$project$Transaction_View$cashOutTxView = function (tx) {
{ctor: '[]'}, {ctor: '[]'},
{ {
ctor: '::', ctor: '::',
_0: _elm_lang$html$Html$text(error), _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: {ctor: '[]'}
}), }),
_1: {ctor: '[]'} _1: {
ctor: '::',
_0: A2(
_elm_lang$html$Html$div,
{ctor: '[]'},
{
ctor: '::',
_0: _elm_lang$html$Html$text(error),
_1: {ctor: '[]'}
}),
_1: {ctor: '[]'}
}
} }
} }
} }
@ -39165,7 +39195,13 @@ var _user$project$Transaction_View$cashInTxView = function (tx) {
{ {
ctor: '::', ctor: '::',
_0: _elm_lang$html$Html$text( _0: _elm_lang$html$Html$text(
A2(_elm_lang$core$Basics_ops['++'], 'Status: ', cancelStatus)), 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: {ctor: '[]'}
}), }),
_1: { _1: {
@ -39175,13 +39211,25 @@ var _user$project$Transaction_View$cashInTxView = function (tx) {
{ctor: '[]'}, {ctor: '[]'},
{ {
ctor: '::', ctor: '::',
_0: _elm_lang$html$Html$text(error), _0: _elm_lang$html$Html$text(
A2(_elm_lang$core$Basics_ops['++'], 'Status: ', cancelStatus)),
_1: {ctor: '[]'} _1: {ctor: '[]'}
}), }),
_1: { _1: {
ctor: '::', ctor: '::',
_0: cancelButtonDiv, _0: A2(
_1: {ctor: '[]'} _elm_lang$html$Html$div,
{ctor: '[]'},
{
ctor: '::',
_0: _elm_lang$html$Html$text(error),
_1: {ctor: '[]'}
}),
_1: {
ctor: '::',
_0: cancelButtonDiv,
_1: {ctor: '[]'}
}
} }
} }
} }