From abbcda793b187cf37d1e89f635d55c9f8d2c12b5 Mon Sep 17 00:00:00 2001 From: Taranto Date: Fri, 1 Oct 2021 13:46:10 +0100 Subject: [PATCH] chore: re-add feature missing from merge --- lib/db.js | 4 +- .../graphql/resolvers/transaction.resolver.js | 4 +- .../graphql/types/transaction.type.js | 2 +- lib/new-admin/services/transactions.js | 52 ++++++++++++++++++- new-lamassu-admin/package-lock.json | 16 +++--- .../pages/Maintenance/MachineDetailsCard.js | 3 +- .../src/pages/Wallet/WizardSplash.js | 4 -- package-lock.json | 2 +- 8 files changed, 67 insertions(+), 20 deletions(-) diff --git a/lib/db.js b/lib/db.js index 9288ad14..55c65983 100644 --- a/lib/db.js +++ b/lib/db.js @@ -20,7 +20,8 @@ const stripDefaultDbFuncs = dbCtx => { manyOrNone: dbCtx.$manyOrNone, tx: dbCtx.$tx, task: dbCtx.$task, - batch: dbCtx.batch + batch: dbCtx.batch, + multi: dbCtx.$multi } } @@ -67,6 +68,7 @@ const pgp = Pgp({ obj.$one = (query, variables) => obj.__taskEx(t => t.one(query, variables)) obj.$none = (query, variables) => obj.__taskEx(t => t.none(query, variables)) obj.$any = (query, variables) => obj.__taskEx(t => t.any(query, variables)) + obj.$multi = (query, variables) => obj.__taskEx(t => t.multi(query, variables)) // when opts is not defined "cb" occupies the "opts" spot of the arguments obj.$tx = (opts, cb) => typeof opts === 'function' ? _tx(obj, {}, opts) : _tx(obj, opts, cb) obj.$task = (opts, cb) => typeof opts === 'function' ? _task(obj, {}, opts) : _task(obj, opts, cb) diff --git a/lib/new-admin/graphql/resolvers/transaction.resolver.js b/lib/new-admin/graphql/resolvers/transaction.resolver.js index 2b0887f3..de9909d4 100644 --- a/lib/new-admin/graphql/resolvers/transaction.resolver.js +++ b/lib/new-admin/graphql/resolvers/transaction.resolver.js @@ -31,8 +31,8 @@ const resolvers = { Query: { transactions: (...[, { from, until, limit, offset, deviceId, txClass, machineName, customerName, fiatCode, cryptoCode, toAddress, status }]) => transactions.batch(from, until, limit, offset, deviceId, txClass, machineName, customerName, fiatCode, cryptoCode, toAddress, status), - transactionsCsv: (...[, { from, until, limit, offset, txClass, machineName, customerName, fiatCode, cryptoCode, toAddress, status, timezone }]) => - transactions.batch(from, until, limit, offset, txClass, machineName, customerName, fiatCode, cryptoCode, toAddress, status) + transactionsCsv: (...[, { from, until, limit, offset, txClass, machineName, customerName, fiatCode, cryptoCode, toAddress, status, timezone, simplified }]) => + transactions.batch(from, until, limit, offset, txClass, machineName, customerName, fiatCode, cryptoCode, toAddress, status, simplified) .then(data => parseAsync(logDateFormat(timezone, data, ['created', 'sendTime']), { fields: txLogFields })), transactionCsv: (...[, { id, txClass, timezone }]) => transactions.getTx(id, txClass).then(data => diff --git a/lib/new-admin/graphql/types/transaction.type.js b/lib/new-admin/graphql/types/transaction.type.js index 17d03460..a50f0494 100644 --- a/lib/new-admin/graphql/types/transaction.type.js +++ b/lib/new-admin/graphql/types/transaction.type.js @@ -52,7 +52,7 @@ const typeDef = gql` type Query { transactions(from: Date, until: Date, limit: Int, offset: Int, deviceId: ID, txClass: String, machineName: String, customerName: String, fiatCode: String, cryptoCode: String, toAddress: String, status: String): [Transaction] @auth - transactionsCsv(from: Date, until: Date, limit: Int, offset: Int, txClass: String, machineName: String, customerName: String, fiatCode: String, cryptoCode: String, toAddress: String, status: String, timezone: String): String @auth + transactionsCsv(from: Date, until: Date, limit: Int, offset: Int, txClass: String, machineName: String, customerName: String, fiatCode: String, cryptoCode: String, toAddress: String, status: String, timezone: String, simplified: Boolean): String @auth transactionCsv(id: ID, txClass: String, timezone: String): String @auth txAssociatedDataCsv(id: ID, txClass: String, timezone: String): String @auth transactionFilters: [Filter] @auth diff --git a/lib/new-admin/services/transactions.js b/lib/new-admin/services/transactions.js index 3fc65671..84630d33 100644 --- a/lib/new-admin/services/transactions.js +++ b/lib/new-admin/services/transactions.js @@ -36,7 +36,8 @@ function batch ( fiatCode = null, cryptoCode = null, toAddress = null, - status = null + status = null, + simplified = false ) { const packager = _.flow(_.flatten, _.orderBy(_.property('created'), ['desc']), _.map(camelize), addNames) @@ -99,6 +100,55 @@ function batch ( db.any(cashOutSql, [REDEEMABLE_AGE, from, until, limit, offset, id, txClass, machineName, customerName, fiatCode, cryptoCode, toAddress, status]) ]) .then(packager) + .then(res => { + if (simplified) return simplifiedBatch(res) + else return res + }) +} + +function simplifiedBatch (data) { + const fields = ['txClass', 'id', 'created', 'machineName', + 'cryptoCode', 'fiat', 'fiatCode', 'phone', 'toAddress', + 'txHash', 'dispense', 'error', 'status', 'fiatProfit', 'cryptoAmount'] + + const addSimplifiedFields = _.map(it => ({ + ...it, + status: getStatus(it), + fiatProfit: getProfit(it).toString(), + cryptoAmount: getCryptoAmount(it) + })) + + return _.compose(_.map(_.pick(fields)), addSimplifiedFields)(data) +} + +const getCryptoAmount = it => coinUtils.toUnit(BN(it.cryptoAtoms), it.cryptoCode).toString() + +const getProfit = it => { + const getCommissionFee = it => BN(it.commissionPercentage).mul(BN(it.fiat)) + if (!it.cashInFee) return getCommissionFee(it) + return getCommissionFee(it).add(BN(it.cashInFee)) +} + +const getCashOutStatus = it => { + if (it.hasError) return 'Error' + if (it.dispense) return 'Success' + if (it.expired) return 'Expired' + return 'Pending' +} + +const getCashInStatus = it => { + if (it.operatorCompleted) return 'Cancelled' + if (it.hasError) return 'Error' + if (it.sendConfirmed) return 'Sent' + if (it.expired) return 'Expired' + return 'Pending' +} + +const getStatus = it => { + if (it.txClass === 'cashOut') { + return getCashOutStatus(it) + } + return getCashInStatus(it) } function getCustomerTransactionsBatch (ids) { diff --git a/new-lamassu-admin/package-lock.json b/new-lamassu-admin/package-lock.json index 0a5018f6..92ddcad7 100644 --- a/new-lamassu-admin/package-lock.json +++ b/new-lamassu-admin/package-lock.json @@ -17157,7 +17157,7 @@ "version": "git+https://github.com/lamassu/lamassu-coins.git#f80395e4bab0fccc860de166c97e981ca3ae66a6", "from": "git+https://github.com/lamassu/lamassu-coins.git", "requires": { - "bech32": "^1.1.3", + "bech32": "2.0.0", "bignumber.js": "^9.0.0", "bitcoinjs-lib": "4.0.3", "bs58check": "^2.0.2", @@ -17165,6 +17165,13 @@ "crypto-js": "^3.1.9-1", "ethereumjs-icap": "^0.3.1", "lodash": "^4.17.10" + }, + "dependencies": { + "bech32": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/bech32/-/bech32-2.0.0.tgz", + "integrity": "sha512-LcknSilhIGatDAsY1ak2I8VtGaHNhgMSYVxFrGLXv+xLHytaKZKcaUJJUE7qmBr7h33o5YQwP55pMI0xmkpJwg==" + } } }, "language-subtag-registry": { @@ -18301,13 +18308,6 @@ "dev": true, "optional": true }, - "nan": { - "version": "2.14.2", - "resolved": "https://registry.npmjs.org/nan/-/nan-2.14.2.tgz", - "integrity": "sha512-M2ufzIiINKCuDfBSAUr1vWQ+vuVcA9kqx8JJUsbQi6yf1uGRyb7HfpdfUr5qLXf3B/t8dPvcjhKMmlfnP47EzQ==", - "dev": true, - "optional": true - }, "nano-css": { "version": "5.3.0", "resolved": "https://registry.npmjs.org/nano-css/-/nano-css-5.3.0.tgz", diff --git a/new-lamassu-admin/src/pages/Maintenance/MachineDetailsCard.js b/new-lamassu-admin/src/pages/Maintenance/MachineDetailsCard.js index 6cc6c5d2..a81e6a5f 100644 --- a/new-lamassu-admin/src/pages/Maintenance/MachineDetailsCard.js +++ b/new-lamassu-admin/src/pages/Maintenance/MachineDetailsCard.js @@ -3,10 +3,9 @@ import { makeStyles } from '@material-ui/core/styles' import BigNumber from 'bignumber.js' import React from 'react' -import MachineActions from 'src/components/machineActions/MachineActions' - // import { Status } from 'src/components/Status' // import { ReactComponent as LinkIcon } from 'src/styling/icons/button/link/zodiac.svg' +import MachineActions from 'src/components/machineActions/MachineActions' import { modelPrettifier } from 'src/utils/machine' import { formatDate } from 'src/utils/timezones' diff --git a/new-lamassu-admin/src/pages/Wallet/WizardSplash.js b/new-lamassu-admin/src/pages/Wallet/WizardSplash.js index 5cdce3f9..64ca440b 100644 --- a/new-lamassu-admin/src/pages/Wallet/WizardSplash.js +++ b/new-lamassu-admin/src/pages/Wallet/WizardSplash.js @@ -8,12 +8,8 @@ import { ReactComponent as BitcoinCashLogo } from 'src/styling/logos/icon-bitcoi import { ReactComponent as DashLogo } from 'src/styling/logos/icon-dash-colour.svg' import { ReactComponent as EthereumLogo } from 'src/styling/logos/icon-ethereum-colour.svg' import { ReactComponent as LitecoinLogo } from 'src/styling/logos/icon-litecoin-colour.svg' -<<<<<<< HEAD import { ReactComponent as TetherLogo } from 'src/styling/logos/icon-tether-colour.svg' import { ReactComponent as ZCashLogo } from 'src/styling/logos/icon-zcash-colour.svg' -======= -import { ReactComponent as ZcashLogo } from 'src/styling/logos/icon-zcash-colour.svg' ->>>>>>> 8daa184b (chore: order coins alphabetically, bch logo green) const styles = { logo: { diff --git a/package-lock.json b/package-lock.json index 6e004a15..dfcc1394 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14372,7 +14372,7 @@ "version": "git+https://github.com/lamassu/lamassu-coins.git#de843fb210ad8adfa29a0441796125fcb0ab3b67", "from": "git+https://github.com/lamassu/lamassu-coins.git", "requires": { - "bech32": "^1.1.3", + "bech32": "2.0.0", "bignumber.js": "^9.0.0", "bitcoinjs-lib": "4.0.3", "bs58check": "^2.0.2",