Add expired status to cash-out txs

This commit is contained in:
Rafael Taranto 2019-07-23 10:05:12 +01:00 committed by Josh Harvey
parent 919848aecd
commit 9ca3e88495
7 changed files with 75 additions and 37 deletions

View file

@ -50,6 +50,7 @@ type alias CashOutTxRec =
, error : Maybe String , error : Maybe String
, created : Date , created : Date
, confirmed : Bool , confirmed : Bool
, expired : Bool
} }

View file

@ -104,3 +104,4 @@ cashOutTxDecoder =
|> required "error" (nullable string) |> required "error" (nullable string)
|> required "created" date |> required "created" date
|> required "confirmedAt" confirmedDecoder |> required "confirmedAt" confirmedDecoder
|> required "expired" bool

View file

@ -6,6 +6,7 @@ import RemoteData exposing (..)
import Common.TransactionTypes exposing (..) import Common.TransactionTypes exposing (..)
import Transaction.Types exposing (..) import Transaction.Types exposing (..)
import Numeral exposing (format) import Numeral exposing (format)
import Maybe.Extra exposing (isJust)
-- import Css.Admin exposing (..) -- import Css.Admin exposing (..)
@ -53,6 +54,15 @@ cashInTxView tx =
cashOutTxView : CashOutTxRec -> Html Msg cashOutTxView : CashOutTxRec -> Html Msg
cashOutTxView tx = cashOutTxView tx =
let let
cancelStatus =
if isJust tx.error then
"Error"
else if tx.dispense then
"Success"
else if tx.expired then
"Expired"
else
"Pending"
error = error =
case tx.error of case tx.error of
Nothing -> Nothing ->
@ -66,6 +76,7 @@ cashOutTxView tx =
, 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 ("Raw ticker price: " ++ (format "0,0.00" (Maybe.withDefault 0.0 tx.rawTickerPrice))) ]
, div [] [ text ("Status: " ++ cancelStatus) ]
, div [] [ text error ] , div [] [ text error ]
] ]

View file

@ -146,6 +146,8 @@ rowView tx =
"Error" "Error"
else if cashOut.dispense then else if cashOut.dispense then
"Success" "Success"
else if cashOut.expired then
"Expired"
else else
"Pending" "Pending"
in in

View file

@ -4,6 +4,7 @@ const db = require('../db')
const machineLoader = require('../machine-loader') const machineLoader = require('../machine-loader')
const tx = require('../tx') const tx = require('../tx')
const cashInTx = require('../cash-in/cash-in-tx') const cashInTx = require('../cash-in/cash-in-tx')
const { REDEEMABLE_AGE } = require('../cash-out/cash-out-helper')
const NUM_RESULTS = 1000 const NUM_RESULTS = 1000
@ -31,11 +32,12 @@ function batch () {
from cash_in_txs from cash_in_txs
order by created desc limit $2` 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 from cash_out_txs
order by created desc limit $1` 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) .then(packager)
} }
@ -48,13 +50,15 @@ function single (txId) {
from cash_in_txs from cash_in_txs
where id=$2` 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 from cash_out_txs
where id=$1` where id=$1`
return Promise.all([ return Promise.all([
db.oneOrNone(cashInSql, [cashInTx.PENDING_INTERVAL, txId]), db.oneOrNone(cashInSql, [cashInTx.PENDING_INTERVAL, txId]),
db.oneOrNone(cashOutSql, [txId]) db.oneOrNone(cashOutSql, [txId, REDEEMABLE_AGE])
]) ])
.then(packager) .then(packager)
.then(_.head) .then(_.head)

View file

@ -6,7 +6,7 @@ const BN = require('../bn')
const REDEEMABLE_AGE = T.day const REDEEMABLE_AGE = T.day
module.exports = {redeemableTxs, toObj, toDb} module.exports = { redeemableTxs, toObj, toDb, REDEEMABLE_AGE }
const mapValuesWithKey = _.mapValues.convert({cap: false}) const mapValuesWithKey = _.mapValues.convert({cap: false})

View file

@ -28514,7 +28514,9 @@ var _user$project$Common_TransactionTypes$CashOutTxRec = function (a) {
return function (o) { return function (o) {
return function (p) { return function (p) {
return function (q) { 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};
};
}; };
}; };
}; };
@ -34030,73 +34032,77 @@ var _user$project$Transaction_Decoder$cashInTxDecoder = A3(
_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', 'expired',
_user$project$Transaction_Decoder$confirmedDecoder, _elm_lang$core$Json_Decode$bool,
A3( A3(
_NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required, _NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required,
'created', 'confirmedAt',
_elm_community$json_extra$Json_Decode_Extra$date, _user$project$Transaction_Decoder$confirmedDecoder,
A3( A3(
_NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required, _NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required,
'error', 'created',
_elm_lang$core$Json_Decode$nullable(_elm_lang$core$Json_Decode$string), _elm_community$json_extra$Json_Decode_Extra$date,
A3( A3(
_NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required, _NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required,
'phone', 'error',
_elm_lang$core$Json_Decode$nullable(_elm_lang$core$Json_Decode$string), _elm_lang$core$Json_Decode$nullable(_elm_lang$core$Json_Decode$string),
A3( A3(
_NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required, _NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required,
'redeem', 'phone',
_elm_lang$core$Json_Decode$bool, _elm_lang$core$Json_Decode$nullable(_elm_lang$core$Json_Decode$string),
A3( A3(
_NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required, _NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required,
'notified', 'redeem',
_elm_lang$core$Json_Decode$bool, _elm_lang$core$Json_Decode$bool,
A3( A3(
_NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required, _NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required,
'dispense', 'notified',
_elm_lang$core$Json_Decode$bool, _elm_lang$core$Json_Decode$bool,
A3( A3(
_NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required, _NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required,
'status', 'dispense',
_elm_lang$core$Json_Decode$string, _elm_lang$core$Json_Decode$bool,
A3( A3(
_NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required, _NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required,
'fiatCode', 'status',
_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,
'rawTickerPrice', 'fiatCode',
_elm_lang$core$Json_Decode$nullable(_user$project$Transaction_Decoder$floatString), _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) {
@ -34374,7 +34380,7 @@ var _user$project$Transactions$rowView = function (tx) {
}); });
} else { } else {
var _p4 = _p2._0; 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( return A2(
_elm_lang$html$Html$tr, _elm_lang$html$Html$tr,
{ {
@ -39152,6 +39158,7 @@ var _user$project$Transaction_View$cashOutTxView = function (tx) {
return A2(_elm_lang$core$Basics_ops['++'], 'Error: ', _p0._0); 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( return A2(
_elm_lang$html$Html$div, _elm_lang$html$Html$div,
{ctor: '[]'}, {ctor: '[]'},
@ -39213,10 +39220,22 @@ 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['++'], 'Status: ', cancelStatus)),
_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: '[]'}
}
} }
} }
} }