Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add expired status to cash-out txs #296

Merged
merged 1 commit into from
Jul 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lamassu-admin-elm/src/Common/TransactionTypes.elm
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type alias CashOutTxRec =
, error : Maybe String
, created : Date
, confirmed : Bool
, expired : Bool
}


Expand Down
1 change: 1 addition & 0 deletions lamassu-admin-elm/src/Transaction/Decoder.elm
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,4 @@ cashOutTxDecoder =
|> required "error" (nullable string)
|> required "created" date
|> required "confirmedAt" confirmedDecoder
|> required "expired" bool
11 changes: 11 additions & 0 deletions lamassu-admin-elm/src/Transaction/View.elm
Original file line number Diff line number Diff line change
Expand Up @@ -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 (..)
Expand Down Expand Up @@ -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 ->
Expand All @@ -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 ]
]

Expand Down
2 changes: 2 additions & 0 deletions lamassu-admin-elm/src/Transactions.elm
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ rowView tx =
"Error"
else if cashOut.dispense then
"Success"
else if cashOut.expired then
"Expired"
else
"Pending"
in
Expand Down
12 changes: 8 additions & 4 deletions lib/admin/transactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
}

Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/cash-out/cash-out-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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})

Expand Down
83 changes: 51 additions & 32 deletions public/elm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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};
};
};
};
};
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
{
Expand Down Expand Up @@ -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: '[]'},
Expand Down Expand Up @@ -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: '[]'}
}
}
}
}
Expand Down