From 8e173cf8a88b405da1c36ca1b884d2a01b79290d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Salgado?= Date: Thu, 27 May 2021 14:45:38 +0100 Subject: [PATCH] feat: cash out transaction cancel --- .../graphql/resolvers/transaction.resolver.js | 4 ++ .../graphql/types/transaction.type.js | 4 ++ .../src/pages/Transactions/DetailsCard.js | 51 +++++++++++++++---- .../pages/Transactions/DetailsCard.styles.js | 8 +++ .../src/pages/Transactions/helper.js | 1 + 5 files changed, 59 insertions(+), 9 deletions(-) diff --git a/lib/new-admin/graphql/resolvers/transaction.resolver.js b/lib/new-admin/graphql/resolvers/transaction.resolver.js index 274d39ff..2b0887f3 100644 --- a/lib/new-admin/graphql/resolvers/transaction.resolver.js +++ b/lib/new-admin/graphql/resolvers/transaction.resolver.js @@ -3,6 +3,7 @@ const { parseAsync } = require('json2csv') const _ = require('lodash/fp') const filters = require('../../filters') +const cashOutTx = require('../../../cash-out/cash-out-tx') const transactions = require('../../services/transactions') const anonymous = require('../../../constants').anonymousCustomer const logDateFormat = require('../../../logs').logDateFormat @@ -42,6 +43,9 @@ const resolvers = { parseAsync(logDateFormat(timezone, data, ['created'])) ), transactionFilters: () => filters.transaction() + }, + Mutation: { + cancelCashOutTransaction: (...[, { id }]) => cashOutTx.cancel(id) } } diff --git a/lib/new-admin/graphql/types/transaction.type.js b/lib/new-admin/graphql/types/transaction.type.js index 7dc35a98..17d03460 100644 --- a/lib/new-admin/graphql/types/transaction.type.js +++ b/lib/new-admin/graphql/types/transaction.type.js @@ -57,6 +57,10 @@ const typeDef = gql` txAssociatedDataCsv(id: ID, txClass: String, timezone: String): String @auth transactionFilters: [Filter] @auth } + + type Mutation { + cancelCashOutTransaction(id: ID): Transaction @auth + } ` module.exports = typeDef diff --git a/new-lamassu-admin/src/pages/Transactions/DetailsCard.js b/new-lamassu-admin/src/pages/Transactions/DetailsCard.js index 3ee05fa1..3c161eb1 100644 --- a/new-lamassu-admin/src/pages/Transactions/DetailsCard.js +++ b/new-lamassu-admin/src/pages/Transactions/DetailsCard.js @@ -1,4 +1,4 @@ -import { useLazyQuery } from '@apollo/react-hooks' +import { useLazyQuery, useMutation } from '@apollo/react-hooks' import { makeStyles, Box } from '@material-ui/core' import BigNumber from 'bignumber.js' import FileSaver from 'file-saver' @@ -18,6 +18,8 @@ import { ReactComponent as PhoneIdInverseIcon } from 'src/styling/icons/ID/phone import { ReactComponent as PhoneIdIcon } from 'src/styling/icons/ID/phone/zodiac.svg' import { ReactComponent as CamIdInverseIcon } from 'src/styling/icons/ID/photo/white.svg' import { ReactComponent as CamIdIcon } from 'src/styling/icons/ID/photo/zodiac.svg' +import { ReactComponent as CancelInverseIcon } from 'src/styling/icons/button/cancel/white.svg' +import { ReactComponent as CancelIcon } from 'src/styling/icons/button/cancel/zodiac.svg' import { ReactComponent as DownloadInverseIcon } from 'src/styling/icons/button/download/white.svg' import { ReactComponent as Download } from 'src/styling/icons/button/download/zodiac.svg' import { ReactComponent as TxInIcon } from 'src/styling/icons/direction/cash-in.svg' @@ -59,6 +61,14 @@ const TX_SUMMARY = gql` } ` +const CANCEL_TRANSACTION = gql` + mutation cancelCashOutTransaction($id: ID!) { + cancelCashOutTransaction(id: $id) { + id + } + } +` + const formatAddress = (cryptoCode = '', address = '') => coinUtils.formatCryptoAddress(cryptoCode, address).replace(/(.{5})/g, '$1 ') @@ -76,6 +86,11 @@ const DetailsRow = ({ it: tx, timezone }) => { onCompleted: data => createCsv(data) }) + const [cancelCashOutTransaction] = useMutation(CANCEL_TRANSACTION, { + onError: () => console.error('Error cancelling transaction'), + refetchQueries: () => ['transactions'] + }) + const fiat = Number.parseFloat(tx.fiat) const crypto = coinUtils.toUnit(new BigNumber(tx.cryptoAtoms), tx.cryptoCode) const commissionPercentage = Number.parseFloat(tx.commissionPercentage, 2) @@ -270,14 +285,32 @@ const DetailsRow = ({ it: tx, timezone }) => {
- downloadRawLogs(tx, timezone)}> - Download raw logs - +
+ downloadRawLogs(tx, timezone)}> + Download raw logs + + {tx.txClass === 'cashOut' && ( + + cancelCashOutTransaction({ + variables: { + id: tx.id + } + }) + }> + Cancel transaction + + )} +
diff --git a/new-lamassu-admin/src/pages/Transactions/DetailsCard.styles.js b/new-lamassu-admin/src/pages/Transactions/DetailsCard.styles.js index b26ba30f..2d0fa1f1 100644 --- a/new-lamassu-admin/src/pages/Transactions/DetailsCard.styles.js +++ b/new-lamassu-admin/src/pages/Transactions/DetailsCard.styles.js @@ -77,6 +77,10 @@ export default { downloadRawLogs: { width: 180 }, + cancelTransaction: { + width: 160, + marginLeft: 8 + }, status: { width: 230 }, @@ -103,5 +107,9 @@ export default { }, chipLabel: { color: white + }, + otherActionsGroup: { + display: 'flex', + flexDirection: 'row' } } diff --git a/new-lamassu-admin/src/pages/Transactions/helper.js b/new-lamassu-admin/src/pages/Transactions/helper.js index eb67db49..749782db 100644 --- a/new-lamassu-admin/src/pages/Transactions/helper.js +++ b/new-lamassu-admin/src/pages/Transactions/helper.js @@ -1,4 +1,5 @@ const getCashOutStatus = it => { + if (it.hasError === 'Operator cancel') return 'Cancelled' if (it.hasError) return 'Error' if (it.dispense) return 'Success' if (it.expired) return 'Expired'