handle cash-out errors
This commit is contained in:
parent
d23c419442
commit
fc17d2cdf8
3 changed files with 92 additions and 17 deletions
|
|
@ -98,7 +98,7 @@ function mapDispense (tx) {
|
||||||
function logDispense (tx) {
|
function logDispense (tx) {
|
||||||
const baseRec = {error: tx.error, error_code: tx.errorCode}
|
const baseRec = {error: tx.error, error_code: tx.errorCode}
|
||||||
const rec = _.merge(mapDispense(tx), baseRec)
|
const rec = _.merge(mapDispense(tx), baseRec)
|
||||||
const action = tx.dispenseConfirmed ? 'dispense' : 'dispenseError'
|
const action = _.isEmpty(tx.error) ? 'dispense' : 'dispenseError'
|
||||||
return logAction(action, rec, tx)
|
return logAction(action, rec, tx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -176,7 +176,13 @@ function nextHd (isHd, tx) {
|
||||||
.then(row => _.set('hdIndex', row.hd_index, tx))
|
.then(row => _.set('hdIndex', row.hd_index, tx))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function dispenseOccurred (bills) {
|
||||||
|
return _.every(_.overEvery([_.has('dispensed'), _.has('rejected')]), bills)
|
||||||
|
}
|
||||||
|
|
||||||
function updateCassettes (tx) {
|
function updateCassettes (tx) {
|
||||||
|
if (!dispenseOccurred(tx.bills)) return Promise.resolve()
|
||||||
|
|
||||||
const sql = `update devices set
|
const sql = `update devices set
|
||||||
cassette1 = cassette1 - $1,
|
cassette1 = cassette1 - $1,
|
||||||
cassette2 = cassette2 - $2
|
cassette2 = cassette2 - $2
|
||||||
|
|
@ -235,7 +241,11 @@ function preProcess (oldTx, newTx, pi) {
|
||||||
return logAction(updatedTx.status, rec, updatedTx)
|
return logAction(updatedTx.status, rec, updatedTx)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!oldTx.dispenseConfirmed && updatedTx.dispenseConfirmed) {
|
const hasError = !oldTx.error && newTx.error
|
||||||
|
const hasDispenseOccurred = !dispenseOccurred(oldTx.bills) && dispenseOccurred(newTx.bills)
|
||||||
|
|
||||||
|
if (hasError || hasDispenseOccurred) {
|
||||||
|
console.log('DEBUG100')
|
||||||
return logDispense(updatedTx)
|
return logDispense(updatedTx)
|
||||||
.then(updateCassettes(updatedTx))
|
.then(updateCassettes(updatedTx))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,8 @@ const coinUtils = require('../../../coin-utils')
|
||||||
const NAME = 'FakeWallet'
|
const NAME = 'FakeWallet'
|
||||||
|
|
||||||
const SECONDS = 1000
|
const SECONDS = 1000
|
||||||
const PUBLISH_TIME = 2 * SECONDS
|
const PUBLISH_TIME = 1 * SECONDS
|
||||||
const AUTHORIZE_TIME = PUBLISH_TIME + 6 * SECONDS
|
const AUTHORIZE_TIME = PUBLISH_TIME + 1 * SECONDS
|
||||||
const CONFIRM_TIME = AUTHORIZE_TIME + 120 * SECONDS
|
const CONFIRM_TIME = AUTHORIZE_TIME + 120 * SECONDS
|
||||||
|
|
||||||
let t0
|
let t0
|
||||||
|
|
|
||||||
|
|
@ -33803,6 +33803,7 @@ var _user$project$Transactions$rowView = function (tx) {
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
var _p3 = _p1._0;
|
var _p3 = _p1._0;
|
||||||
|
var status = _elm_community$maybe_extra$Maybe_Extra$isJust(_p3.error) ? 'Error' : 'Success';
|
||||||
return A2(
|
return A2(
|
||||||
_elm_lang$html$Html$tr,
|
_elm_lang$html$Html$tr,
|
||||||
{
|
{
|
||||||
|
|
@ -33832,7 +33833,7 @@ var _user$project$Transactions$rowView = function (tx) {
|
||||||
{ctor: '[]'},
|
{ctor: '[]'},
|
||||||
{
|
{
|
||||||
ctor: '::',
|
ctor: '::',
|
||||||
_0: _elm_lang$html$Html$text('Cash out'),
|
_0: _elm_lang$html$Html$text(status),
|
||||||
_1: {ctor: '[]'}
|
_1: {ctor: '[]'}
|
||||||
}),
|
}),
|
||||||
_1: {
|
_1: {
|
||||||
|
|
@ -38326,16 +38327,69 @@ var _user$project$Transaction_State$load = function (txId) {
|
||||||
var _user$project$Transaction_State$init = _krisajenkins$remotedata$RemoteData$NotAsked;
|
var _user$project$Transaction_State$init = _krisajenkins$remotedata$RemoteData$NotAsked;
|
||||||
|
|
||||||
var _user$project$Transaction_View$cashOutTxView = function (tx) {
|
var _user$project$Transaction_View$cashOutTxView = function (tx) {
|
||||||
|
var error = function () {
|
||||||
|
var _p0 = tx.error;
|
||||||
|
if (_p0.ctor === 'Nothing') {
|
||||||
|
return 'No errors';
|
||||||
|
} else {
|
||||||
|
return A2(_elm_lang$core$Basics_ops['++'], 'Error: ', _p0._0);
|
||||||
|
}
|
||||||
|
}();
|
||||||
return A2(
|
return A2(
|
||||||
_elm_lang$html$Html$div,
|
_elm_lang$html$Html$div,
|
||||||
{ctor: '[]'},
|
{ctor: '[]'},
|
||||||
{
|
{
|
||||||
ctor: '::',
|
ctor: '::',
|
||||||
_0: _elm_lang$html$Html$text(tx.id),
|
_0: A2(
|
||||||
_1: {ctor: '[]'}
|
_elm_lang$html$Html$div,
|
||||||
|
{ctor: '[]'},
|
||||||
|
{
|
||||||
|
ctor: '::',
|
||||||
|
_0: _elm_lang$html$Html$text(tx.id),
|
||||||
|
_1: {ctor: '[]'}
|
||||||
|
}),
|
||||||
|
_1: {
|
||||||
|
ctor: '::',
|
||||||
|
_0: A2(
|
||||||
|
_elm_lang$html$Html$div,
|
||||||
|
{ctor: '[]'},
|
||||||
|
{
|
||||||
|
ctor: '::',
|
||||||
|
_0: _elm_lang$html$Html$text('This is a cash-out transaction'),
|
||||||
|
_1: {ctor: '[]'}
|
||||||
|
}),
|
||||||
|
_1: {
|
||||||
|
ctor: '::',
|
||||||
|
_0: A2(
|
||||||
|
_elm_lang$html$Html$div,
|
||||||
|
{ctor: '[]'},
|
||||||
|
{
|
||||||
|
ctor: '::',
|
||||||
|
_0: _elm_lang$html$Html$text(
|
||||||
|
A2(
|
||||||
|
_elm_lang$core$Basics_ops['++'],
|
||||||
|
'Fiat: ',
|
||||||
|
A2(_ggb$numeral_elm$Numeral$format, '0,0.00', tx.fiat))),
|
||||||
|
_1: {ctor: '[]'}
|
||||||
|
}),
|
||||||
|
_1: {
|
||||||
|
ctor: '::',
|
||||||
|
_0: A2(
|
||||||
|
_elm_lang$html$Html$div,
|
||||||
|
{ctor: '[]'},
|
||||||
|
{
|
||||||
|
ctor: '::',
|
||||||
|
_0: _elm_lang$html$Html$text(error),
|
||||||
|
_1: {ctor: '[]'}
|
||||||
|
}),
|
||||||
|
_1: {ctor: '[]'}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
var _user$project$Transaction_View$cashInTxView = function (tx) {
|
var _user$project$Transaction_View$cashInTxView = function (tx) {
|
||||||
|
var error = A2(_elm_lang$core$Maybe$withDefault, 'Successfull', tx.error);
|
||||||
var cancellable = !(tx.operatorCompleted || (tx.sendConfirmed || tx.expired));
|
var cancellable = !(tx.operatorCompleted || (tx.sendConfirmed || tx.expired));
|
||||||
var cancelButtonDiv = cancellable ? A2(
|
var cancelButtonDiv = cancellable ? A2(
|
||||||
_elm_lang$html$Html$div,
|
_elm_lang$html$Html$div,
|
||||||
|
|
@ -38411,8 +38465,19 @@ var _user$project$Transaction_View$cashInTxView = function (tx) {
|
||||||
}),
|
}),
|
||||||
_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: '[]'}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -38420,16 +38485,16 @@ var _user$project$Transaction_View$cashInTxView = function (tx) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
var _user$project$Transaction_View$txView = function (subModel) {
|
var _user$project$Transaction_View$txView = function (subModel) {
|
||||||
var _p0 = subModel.tx;
|
var _p1 = subModel.tx;
|
||||||
if (_p0.ctor === 'CashInTx') {
|
if (_p1.ctor === 'CashInTx') {
|
||||||
return _user$project$Transaction_View$cashInTxView(_p0._0);
|
return _user$project$Transaction_View$cashInTxView(_p1._0);
|
||||||
} else {
|
} else {
|
||||||
return _user$project$Transaction_View$cashOutTxView(_p0._0);
|
return _user$project$Transaction_View$cashOutTxView(_p1._0);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var _user$project$Transaction_View$view = function (model) {
|
var _user$project$Transaction_View$view = function (model) {
|
||||||
var _p1 = model;
|
var _p2 = model;
|
||||||
switch (_p1.ctor) {
|
switch (_p2.ctor) {
|
||||||
case 'NotAsked':
|
case 'NotAsked':
|
||||||
return A2(
|
return A2(
|
||||||
_elm_lang$html$Html$div,
|
_elm_lang$html$Html$div,
|
||||||
|
|
@ -38451,11 +38516,11 @@ var _user$project$Transaction_View$view = function (model) {
|
||||||
{
|
{
|
||||||
ctor: '::',
|
ctor: '::',
|
||||||
_0: _elm_lang$html$Html$text(
|
_0: _elm_lang$html$Html$text(
|
||||||
_elm_lang$core$Basics$toString(_p1._0)),
|
_elm_lang$core$Basics$toString(_p2._0)),
|
||||||
_1: {ctor: '[]'}
|
_1: {ctor: '[]'}
|
||||||
});
|
});
|
||||||
default:
|
default:
|
||||||
return _user$project$Transaction_View$txView(_p1._0);
|
return _user$project$Transaction_View$txView(_p2._0);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue