From 32757b7e6c7a8e7d5308161b702e011aa3672e48 Mon Sep 17 00:00:00 2001 From: Rafael Taranto Date: Tue, 23 Jul 2019 10:05:12 +0100 Subject: [PATCH] Add expired status to cash-out txs --- .../src/Common/TransactionTypes.elm | 1 + lamassu-admin-elm/src/Transaction/Decoder.elm | 1 + lamassu-admin-elm/src/Transaction/View.elm | 11 +++ lamassu-admin-elm/src/Transactions.elm | 2 + lib/admin/transactions.js | 12 ++- lib/cash-out/cash-out-helper.js | 2 +- public/elm.js | 83 ++++++++++++------- 7 files changed, 75 insertions(+), 37 deletions(-) diff --git a/lamassu-admin-elm/src/Common/TransactionTypes.elm b/lamassu-admin-elm/src/Common/TransactionTypes.elm index b7ccc82e7..4255ae86b 100644 --- a/lamassu-admin-elm/src/Common/TransactionTypes.elm +++ b/lamassu-admin-elm/src/Common/TransactionTypes.elm @@ -50,6 +50,7 @@ type alias CashOutTxRec = , error : Maybe String , created : Date , confirmed : Bool + , expired : Bool } diff --git a/lamassu-admin-elm/src/Transaction/Decoder.elm b/lamassu-admin-elm/src/Transaction/Decoder.elm index d58ae06af..142a88bad 100644 --- a/lamassu-admin-elm/src/Transaction/Decoder.elm +++ b/lamassu-admin-elm/src/Transaction/Decoder.elm @@ -104,3 +104,4 @@ cashOutTxDecoder = |> required "error" (nullable string) |> required "created" date |> required "confirmedAt" confirmedDecoder + |> required "expired" bool diff --git a/lamassu-admin-elm/src/Transaction/View.elm b/lamassu-admin-elm/src/Transaction/View.elm index c9eb48c0b..54a455c4b 100644 --- a/lamassu-admin-elm/src/Transaction/View.elm +++ b/lamassu-admin-elm/src/Transaction/View.elm @@ -6,6 +6,7 @@ import RemoteData exposing (..) import Common.TransactionTypes exposing (..) import Transaction.Types exposing (..) import Numeral exposing (format) +import Maybe.Extra exposing (isJust) -- import Css.Admin exposing (..) @@ -53,6 +54,15 @@ cashInTxView tx = cashOutTxView : CashOutTxRec -> Html Msg cashOutTxView tx = let + cancelStatus = + if isJust tx.error then + "Error" + else if tx.dispense then + "Success" + else if tx.expired then + "Expired" + else + "Pending" error = case tx.error of Nothing -> @@ -66,6 +76,7 @@ cashOutTxView tx = , div [] [ text "This is a cash-out transaction" ] , 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 error ] ] diff --git a/lamassu-admin-elm/src/Transactions.elm b/lamassu-admin-elm/src/Transactions.elm index 9b9f6134f..0b2a18f6f 100644 --- a/lamassu-admin-elm/src/Transactions.elm +++ b/lamassu-admin-elm/src/Transactions.elm @@ -146,6 +146,8 @@ rowView tx = "Error" else if cashOut.dispense then "Success" + else if cashOut.expired then + "Expired" else "Pending" in diff --git a/lib/admin/transactions.js b/lib/admin/transactions.js index 0abdd2013..7ae7ceeac 100644 --- a/lib/admin/transactions.js +++ b/lib/admin/transactions.js @@ -4,6 +4,7 @@ const db = require('../db') const machineLoader = require('../machine-loader') const tx = require('../tx') const cashInTx = require('../cash-in/cash-in-tx') +const { REDEEMABLE_AGE } = require('../cash-out/cash-out-helper') const NUM_RESULTS = 1000 @@ -31,11 +32,12 @@ function batch () { from cash_in_txs order by created desc limit $2` - const cashOutSql = `select 'cashOut' as tx_class, cash_out_txs.* + const cashOutSql = `select 'cashOut' as tx_class, cash_out_txs.*, + (extract(epoch from (now() - greatest(created, confirmed_at))) * 1000) >= $2 as expired from cash_out_txs order by created desc limit $1` - return Promise.all([db.any(cashInSql, [cashInTx.PENDING_INTERVAL, NUM_RESULTS]), db.any(cashOutSql, [NUM_RESULTS])]) + return Promise.all([db.any(cashInSql, [cashInTx.PENDING_INTERVAL, NUM_RESULTS]), db.any(cashOutSql, [NUM_RESULTS, REDEEMABLE_AGE])]) .then(packager) } @@ -48,13 +50,15 @@ function single (txId) { from cash_in_txs where id=$2` - const cashOutSql = `select 'cashOut' as tx_class, cash_out_txs.* + const cashOutSql = `select 'cashOut' as tx_class, + (extract(epoch from (now() - greatest(created, confirmed_at))) * 1000) >= $2 as expired, + cash_out_txs.* from cash_out_txs where id=$1` return Promise.all([ db.oneOrNone(cashInSql, [cashInTx.PENDING_INTERVAL, txId]), - db.oneOrNone(cashOutSql, [txId]) + db.oneOrNone(cashOutSql, [txId, REDEEMABLE_AGE]) ]) .then(packager) .then(_.head) diff --git a/lib/cash-out/cash-out-helper.js b/lib/cash-out/cash-out-helper.js index 174ecd2b3..7ce411565 100644 --- a/lib/cash-out/cash-out-helper.js +++ b/lib/cash-out/cash-out-helper.js @@ -6,7 +6,7 @@ const BN = require('../bn') const REDEEMABLE_AGE = T.day -module.exports = {redeemableTxs, toObj, toDb} +module.exports = { redeemableTxs, toObj, toDb, REDEEMABLE_AGE } const mapValuesWithKey = _.mapValues.convert({cap: false}) diff --git a/public/elm.js b/public/elm.js index fc536c7ab..6f8984337 100644 --- a/public/elm.js +++ b/public/elm.js @@ -28514,7 +28514,9 @@ var _user$project$Common_TransactionTypes$CashOutTxRec = function (a) { return function (o) { return function (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}; + return function (r) { + 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, expired: r}; + }; }; }; }; @@ -34027,73 +34029,77 @@ var _user$project$Transaction_Decoder$cashInTxDecoder = A3( _NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$decode(_user$project$Common_TransactionTypes$CashInTxRec)))))))))))))))))); var _user$project$Transaction_Decoder$cashOutTxDecoder = A3( _NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required, - 'confirmedAt', - _user$project$Transaction_Decoder$confirmedDecoder, + 'expired', + _elm_lang$core$Json_Decode$bool, A3( _NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required, - 'created', - _elm_community$json_extra$Json_Decode_Extra$date, + 'confirmedAt', + _user$project$Transaction_Decoder$confirmedDecoder, A3( _NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required, - 'error', - _elm_lang$core$Json_Decode$nullable(_elm_lang$core$Json_Decode$string), + 'created', + _elm_community$json_extra$Json_Decode_Extra$date, A3( _NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required, - 'phone', + 'error', _elm_lang$core$Json_Decode$nullable(_elm_lang$core$Json_Decode$string), A3( _NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required, - 'redeem', - _elm_lang$core$Json_Decode$bool, + 'phone', + _elm_lang$core$Json_Decode$nullable(_elm_lang$core$Json_Decode$string), A3( _NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required, - 'notified', + 'redeem', _elm_lang$core$Json_Decode$bool, A3( _NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required, - 'dispense', + 'notified', _elm_lang$core$Json_Decode$bool, A3( _NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required, - 'status', - _elm_lang$core$Json_Decode$string, + 'dispense', + _elm_lang$core$Json_Decode$bool, A3( _NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required, - 'fiatCode', + 'status', _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), + 'fiatCode', + _elm_lang$core$Json_Decode$string, A3( _NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required, - 'commissionPercentage', + 'rawTickerPrice', _elm_lang$core$Json_Decode$nullable(_user$project$Transaction_Decoder$floatString), A3( _NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required, - 'fiat', - _user$project$Transaction_Decoder$floatString, + 'commissionPercentage', + _elm_lang$core$Json_Decode$nullable(_user$project$Transaction_Decoder$floatString), A3( _NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required, - 'cryptoCode', - _user$project$Transaction_Decoder$cryptoCodeDecoder, + 'fiat', + _user$project$Transaction_Decoder$floatString, A3( _NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required, - 'cryptoAtoms', - _user$project$Transaction_Decoder$intString, + 'cryptoCode', + _user$project$Transaction_Decoder$cryptoCodeDecoder, A3( _NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required, - 'toAddress', - _elm_lang$core$Json_Decode$string, + 'cryptoAtoms', + _user$project$Transaction_Decoder$intString, A3( _NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required, - 'machineName', + 'toAddress', _elm_lang$core$Json_Decode$string, A3( _NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required, - 'id', + 'machineName', _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 _p4 = txClass; switch (_p4) { @@ -34371,7 +34377,7 @@ var _user$project$Transactions$rowView = function (tx) { }); } else { var _p4 = _p2._0; - var status = _elm_community$maybe_extra$Maybe_Extra$isJust(_p4.error) ? 'Error' : (_p4.dispense ? 'Success' : 'Pending'); + var status = _elm_community$maybe_extra$Maybe_Extra$isJust(_p4.error) ? 'Error' : (_p4.dispense ? 'Success' : (_p4.expired ? 'Expired' : 'Pending')); return A2( _elm_lang$html$Html$tr, { @@ -39097,6 +39103,7 @@ var _user$project$Transaction_View$cashOutTxView = function (tx) { return A2(_elm_lang$core$Basics_ops['++'], 'Error: ', _p0._0); } }(); + var cancelStatus = _elm_community$maybe_extra$Maybe_Extra$isJust(tx.error) ? 'Error' : (tx.dispense ? 'Success' : (tx.expired ? 'Expired' : 'Pending')); return A2( _elm_lang$html$Html$div, {ctor: '[]'}, @@ -39158,10 +39165,22 @@ var _user$project$Transaction_View$cashOutTxView = function (tx) { {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: { + ctor: '::', + _0: A2( + _elm_lang$html$Html$div, + {ctor: '[]'}, + { + ctor: '::', + _0: _elm_lang$html$Html$text(error), + _1: {ctor: '[]'} + }), + _1: {ctor: '[]'} + } } } }