tx.commission_percentage added

This commit is contained in:
Fabio Cigliano 2018-11-23 16:00:51 +13:00 committed by Josh Harvey
parent 038a22aba7
commit 03279c8d2c
7 changed files with 140 additions and 42 deletions

View file

@ -18,6 +18,7 @@ type alias CashInTxRec =
, cryptoAtoms : Int , cryptoAtoms : Int
, cryptoCode : CryptoCode , cryptoCode : CryptoCode
, fiat : Float , fiat : Float
, commissionPercentage : Maybe Float
, fiatCode : String , fiatCode : String
, txHash : Maybe String , txHash : Maybe String
, phone : Maybe String , phone : Maybe String
@ -37,6 +38,7 @@ type alias CashOutTxRec =
, cryptoAtoms : Int , cryptoAtoms : Int
, cryptoCode : CryptoCode , cryptoCode : CryptoCode
, fiat : Float , fiat : Float
, commissionPercentage : Maybe Float
, fiatCode : String , fiatCode : String
, status : String , status : String
, dispense : Bool , dispense : Bool

View file

@ -65,6 +65,7 @@ cashInTxDecoder =
|> required "cryptoAtoms" intString |> required "cryptoAtoms" intString
|> required "cryptoCode" cryptoCodeDecoder |> required "cryptoCode" cryptoCodeDecoder
|> required "fiat" floatString |> required "fiat" floatString
|> required "commissionPercentage" (nullable floatString)
|> required "fiatCode" string |> required "fiatCode" string
|> required "txHash" (nullable string) |> required "txHash" (nullable string)
|> required "phone" (nullable string) |> required "phone" (nullable string)
@ -91,6 +92,7 @@ cashOutTxDecoder =
|> required "cryptoAtoms" intString |> required "cryptoAtoms" intString
|> required "cryptoCode" cryptoCodeDecoder |> required "cryptoCode" cryptoCodeDecoder
|> required "fiat" floatString |> required "fiat" floatString
|> required "commissionPercentage" (nullable floatString)
|> required "fiatCode" string |> required "fiatCode" string
|> required "status" string |> required "status" string
|> required "dispense" bool |> required "dispense" bool

View file

@ -134,6 +134,7 @@ rowView tx =
] ]
, td [] [ cryptoCodeDisplay cashIn.cryptoCode ] , td [] [ cryptoCodeDisplay cashIn.cryptoCode ]
, td [ class [ C.NumberColumn ] ] [ text (format "0,0.00" cashIn.fiat) ] , td [ class [ C.NumberColumn ] ] [ text (format "0,0.00" cashIn.fiat) ]
, td [ class [ C.NumberColumn ] ] [ text (format "0,0.00" (Maybe.withDefault 0.0 cashIn.commissionPercentage)) ]
, td [ class [ C.NumberColumn ] ] [ text (Maybe.withDefault "" cashIn.phone) ] , td [ class [ C.NumberColumn ] ] [ text (Maybe.withDefault "" cashIn.phone) ]
, td [ class [ C.TxAddress ] ] [ text cashIn.toAddress ] , td [ class [ C.TxAddress ] ] [ text cashIn.toAddress ]
] ]
@ -158,6 +159,7 @@ rowView tx =
] ]
, td [] [ cryptoCodeDisplay cashOut.cryptoCode ] , td [] [ cryptoCodeDisplay cashOut.cryptoCode ]
, td [ class [ C.NumberColumn ] ] [ text (format "0,0.00" cashOut.fiat) ] , td [ class [ C.NumberColumn ] ] [ text (format "0,0.00" cashOut.fiat) ]
, td [ class [ C.NumberColumn ] ] [ text (format "0,0.00" (Maybe.withDefault 0.0 cashOut.commissionPercentage)) ]
, td [ class [ C.NumberColumn ] ] [ text (Maybe.withDefault "" cashOut.phone) ] , td [ class [ C.NumberColumn ] ] [ text (Maybe.withDefault "" cashOut.phone) ]
, td [ class [ C.TxAddress ] ] [ text cashOut.toAddress ] , td [ class [ C.TxAddress ] ] [ text cashOut.toAddress ]
] ]
@ -177,6 +179,7 @@ tableView txs =
, td [ class [ C.TxMachine ] ] [ text "Machine" ] , td [ class [ C.TxMachine ] ] [ text "Machine" ]
, td [ colspan 2 ] [ text "Crypto" ] , td [ colspan 2 ] [ text "Crypto" ]
, td [ class [ C.TxAmount ] ] [ text "Fiat" ] , td [ class [ C.TxAmount ] ] [ text "Fiat" ]
, td [ class [ C.TxAmount ] ] [ text "Commission" ]
, td [ class [ C.TxPhone ] ] [ text "Phone" ] , td [ class [ C.TxPhone ] ] [ text "Phone" ]
, td [ class [ C.TxAddress ] ] [ text "To address" ] , td [ class [ C.TxAddress ] ] [ text "To address" ]
] ]

View file

@ -11,7 +11,7 @@ module.exports = {redeemableTxs, toObj, toDb}
const mapValuesWithKey = _.mapValues.convert({cap: false}) const mapValuesWithKey = _.mapValues.convert({cap: false})
function convertBigNumFields (obj) { function convertBigNumFields (obj) {
const convert = (value, key) => _.includes(key, ['cryptoAtoms', 'fiat']) const convert = (value, key) => _.includes(key, ['cryptoAtoms', 'fiat', 'commissionPercentage'])
? value.toString() ? value.toString()
: value : value

View file

@ -32,6 +32,15 @@ const PONG_TTL = '1 week'
const tradesQueues = {} const tradesQueues = {}
function plugins (settings, deviceId) { function plugins (settings, deviceId) {
function getCommissionForTx (tx) {
const direction = _.get('direction', tx)
const cryptoCode = _.get('cryptoCode', tx)
const cryptoConfig = configManager.scoped(cryptoCode, deviceId, settings.config)
if (direction === 'cashIn') return /* cashInCommission */ BN(cryptoConfig.cashInCommission).div(100)
if (direction === 'cashOut') return /* cashOutCommission */ BN(cryptoConfig.cashOutCommission).div(100)
}
function buildRates (tickers) { function buildRates (tickers) {
const config = configManager.machineScoped(deviceId, settings.config) const config = configManager.machineScoped(deviceId, settings.config)
const cryptoCodes = config.cryptoCurrencies const cryptoCodes = config.cryptoCurrencies
@ -783,7 +792,8 @@ function plugins (settings, deviceId) {
buy, buy,
sell, sell,
notificationsEnabled, notificationsEnabled,
notifyOperator notifyOperator,
getCommissionForTx
} }
} }

View file

@ -4,7 +4,7 @@ const CashInTx = require('./cash-in/cash-in-tx')
const CashOutTx = require('./cash-out/cash-out-tx') const CashOutTx = require('./cash-out/cash-out-tx')
function process (tx, pi) { function process (tx, pi) {
const mtx = massage(tx) const mtx = massage(tx, pi)
if (mtx.direction === 'cashIn') return CashInTx.post(mtx, pi) if (mtx.direction === 'cashIn') return CashInTx.post(mtx, pi)
if (mtx.direction === 'cashOut') return CashOutTx.post(mtx, pi) if (mtx.direction === 'cashOut') return CashOutTx.post(mtx, pi)
@ -16,11 +16,12 @@ function post (tx, pi) {
.then(_.set('dirty', false)) .then(_.set('dirty', false))
} }
function massage (tx) { function massage (tx, pi) {
const isDateField = r => r === 'created' || _.endsWith('_time', r) const isDateField = r => r === 'created' || _.endsWith('_time', r)
const transformDate = (v, k) => isDateField(k) ? new Date(v) : v const transformDate = (v, k) => isDateField(k) ? new Date(v) : v
const mapValuesWithKey = _.mapValues.convert({'cap': false}) const mapValuesWithKey = _.mapValues.convert({'cap': false})
const transformDates = r => mapValuesWithKey(transformDate, r) const transformDates = r => mapValuesWithKey(transformDate, r)
const logCommission = r => _.assign(r, {commissionPercentage: pi.getCommissionForTx(tx)})
const mapBN = r => { const mapBN = r => {
const update = r.direction === 'cashIn' const update = r.direction === 'cashIn'
@ -39,7 +40,7 @@ function massage (tx) {
return _.assign(r, update) return _.assign(r, update)
} }
const mapper = _.flow(transformDates, mapBN, _.unset('dirty')) const mapper = _.flow(transformDates, logCommission, mapBN, _.unset('dirty'))
return mapper(tx) return mapper(tx)
} }

View file

@ -28477,7 +28477,9 @@ var _user$project$Common_TransactionTypes$CashInTxRec = function (a) {
return function (m) { return function (m) {
return function (n) { return function (n) {
return function (o) { return function (o) {
return {id: a, machineName: b, toAddress: c, cryptoAtoms: d, cryptoCode: e, fiat: f, fiatCode: g, txHash: h, phone: i, error: j, operatorCompleted: k, send: l, sendConfirmed: m, expired: n, created: o}; return function (p) {
return {id: a, machineName: b, toAddress: c, cryptoAtoms: d, cryptoCode: e, fiat: f, commissionPercentage: g, fiatCode: h, txHash: i, phone: j, error: k, operatorCompleted: l, send: m, sendConfirmed: n, expired: o, created: p};
};
}; };
}; };
}; };
@ -28508,7 +28510,9 @@ var _user$project$Common_TransactionTypes$CashOutTxRec = function (a) {
return function (m) { return function (m) {
return function (n) { return function (n) {
return function (o) { return function (o) {
return {id: a, machineName: b, toAddress: c, cryptoAtoms: d, cryptoCode: e, fiat: f, fiatCode: g, status: h, dispense: i, notified: j, redeemed: k, phone: l, error: m, created: n, confirmed: o}; return function (p) {
return {id: a, machineName: b, toAddress: c, cryptoAtoms: d, cryptoCode: e, fiat: f, commissionPercentage: g, fiatCode: h, status: i, dispense: j, notified: k, redeemed: l, phone: m, error: n, created: o, confirmed: p};
};
}; };
}; };
}; };
@ -33986,29 +33990,33 @@ var _user$project$Transaction_Decoder$cashInTxDecoder = A3(
_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,
'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$CashInTxRec)))))))))))))))); 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$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', 'confirmedAt',
@ -34047,29 +34055,33 @@ var _user$project$Transaction_Decoder$cashOutTxDecoder = A3(
_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,
'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) {
@ -34289,7 +34301,10 @@ var _user$project$Transactions$rowView = function (tx) {
{ {
ctor: '::', ctor: '::',
_0: _elm_lang$html$Html$text( _0: _elm_lang$html$Html$text(
A2(_elm_lang$core$Maybe$withDefault, '', _p3.phone)), A2(
_ggb$numeral_elm$Numeral$format,
'0,0.00',
A2(_elm_lang$core$Maybe$withDefault, 0.0, _p3.commissionPercentage))),
_1: {ctor: '[]'} _1: {ctor: '[]'}
}), }),
_1: { _1: {
@ -34301,17 +34316,38 @@ var _user$project$Transactions$rowView = function (tx) {
_0: _user$project$Css_Admin$class( _0: _user$project$Css_Admin$class(
{ {
ctor: '::', ctor: '::',
_0: _user$project$Css_Classes$TxAddress, _0: _user$project$Css_Classes$NumberColumn,
_1: {ctor: '[]'} _1: {ctor: '[]'}
}), }),
_1: {ctor: '[]'} _1: {ctor: '[]'}
}, },
{ {
ctor: '::', ctor: '::',
_0: _elm_lang$html$Html$text(_p3.toAddress), _0: _elm_lang$html$Html$text(
A2(_elm_lang$core$Maybe$withDefault, '', _p3.phone)),
_1: {ctor: '[]'} _1: {ctor: '[]'}
}), }),
_1: {ctor: '[]'} _1: {
ctor: '::',
_0: A2(
_elm_lang$html$Html$td,
{
ctor: '::',
_0: _user$project$Css_Admin$class(
{
ctor: '::',
_0: _user$project$Css_Classes$TxAddress,
_1: {ctor: '[]'}
}),
_1: {ctor: '[]'}
},
{
ctor: '::',
_0: _elm_lang$html$Html$text(_p3.toAddress),
_1: {ctor: '[]'}
}),
_1: {ctor: '[]'}
}
} }
} }
} }
@ -34460,7 +34496,10 @@ var _user$project$Transactions$rowView = function (tx) {
{ {
ctor: '::', ctor: '::',
_0: _elm_lang$html$Html$text( _0: _elm_lang$html$Html$text(
A2(_elm_lang$core$Maybe$withDefault, '', _p4.phone)), A2(
_ggb$numeral_elm$Numeral$format,
'0,0.00',
A2(_elm_lang$core$Maybe$withDefault, 0.0, _p4.commissionPercentage))),
_1: {ctor: '[]'} _1: {ctor: '[]'}
}), }),
_1: { _1: {
@ -34472,17 +34511,38 @@ var _user$project$Transactions$rowView = function (tx) {
_0: _user$project$Css_Admin$class( _0: _user$project$Css_Admin$class(
{ {
ctor: '::', ctor: '::',
_0: _user$project$Css_Classes$TxAddress, _0: _user$project$Css_Classes$NumberColumn,
_1: {ctor: '[]'} _1: {ctor: '[]'}
}), }),
_1: {ctor: '[]'} _1: {ctor: '[]'}
}, },
{ {
ctor: '::', ctor: '::',
_0: _elm_lang$html$Html$text(_p4.toAddress), _0: _elm_lang$html$Html$text(
A2(_elm_lang$core$Maybe$withDefault, '', _p4.phone)),
_1: {ctor: '[]'} _1: {ctor: '[]'}
}), }),
_1: {ctor: '[]'} _1: {
ctor: '::',
_0: A2(
_elm_lang$html$Html$td,
{
ctor: '::',
_0: _user$project$Css_Admin$class(
{
ctor: '::',
_0: _user$project$Css_Classes$TxAddress,
_1: {ctor: '[]'}
}),
_1: {ctor: '[]'}
},
{
ctor: '::',
_0: _elm_lang$html$Html$text(_p4.toAddress),
_1: {ctor: '[]'}
}),
_1: {ctor: '[]'}
}
} }
} }
} }
@ -34633,14 +34693,14 @@ var _user$project$Transactions$tableView = function (txs) {
_0: _user$project$Css_Admin$class( _0: _user$project$Css_Admin$class(
{ {
ctor: '::', ctor: '::',
_0: _user$project$Css_Classes$TxPhone, _0: _user$project$Css_Classes$TxAmount,
_1: {ctor: '[]'} _1: {ctor: '[]'}
}), }),
_1: {ctor: '[]'} _1: {ctor: '[]'}
}, },
{ {
ctor: '::', ctor: '::',
_0: _elm_lang$html$Html$text('Phone'), _0: _elm_lang$html$Html$text('Commission'),
_1: {ctor: '[]'} _1: {ctor: '[]'}
}), }),
_1: { _1: {
@ -34652,17 +34712,37 @@ var _user$project$Transactions$tableView = function (txs) {
_0: _user$project$Css_Admin$class( _0: _user$project$Css_Admin$class(
{ {
ctor: '::', ctor: '::',
_0: _user$project$Css_Classes$TxAddress, _0: _user$project$Css_Classes$TxPhone,
_1: {ctor: '[]'} _1: {ctor: '[]'}
}), }),
_1: {ctor: '[]'} _1: {ctor: '[]'}
}, },
{ {
ctor: '::', ctor: '::',
_0: _elm_lang$html$Html$text('To address'), _0: _elm_lang$html$Html$text('Phone'),
_1: {ctor: '[]'} _1: {ctor: '[]'}
}), }),
_1: {ctor: '[]'} _1: {
ctor: '::',
_0: A2(
_elm_lang$html$Html$td,
{
ctor: '::',
_0: _user$project$Css_Admin$class(
{
ctor: '::',
_0: _user$project$Css_Classes$TxAddress,
_1: {ctor: '[]'}
}),
_1: {ctor: '[]'}
},
{
ctor: '::',
_0: _elm_lang$html$Html$text('To address'),
_1: {ctor: '[]'}
}),
_1: {ctor: '[]'}
}
} }
} }
} }