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
, created : Date
, confirmed : Bool
, expired : Bool
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -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};
};
};
};
};
@ -34030,73 +34032,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) {
@ -34374,7 +34380,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,
{
@ -39152,6 +39158,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: '[]'},
@ -39213,10 +39220,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: '[]'}
}
}
}
}