Merge pull request #845 from chaotixkilla/feat-cancel-cash-in-txs
Cancel cash-in transactions
This commit is contained in:
commit
f8e5d0585c
3 changed files with 36 additions and 12 deletions
|
|
@ -4,6 +4,7 @@ const _ = require('lodash/fp')
|
||||||
|
|
||||||
const filters = require('../../filters')
|
const filters = require('../../filters')
|
||||||
const cashOutTx = require('../../../cash-out/cash-out-tx')
|
const cashOutTx = require('../../../cash-out/cash-out-tx')
|
||||||
|
const cashInTx = require('../../../cash-in/cash-in-tx')
|
||||||
const transactions = require('../../services/transactions')
|
const transactions = require('../../services/transactions')
|
||||||
const anonymous = require('../../../constants').anonymousCustomer
|
const anonymous = require('../../../constants').anonymousCustomer
|
||||||
const logDateFormat = require('../../../logs').logDateFormat
|
const logDateFormat = require('../../../logs').logDateFormat
|
||||||
|
|
@ -45,7 +46,8 @@ const resolvers = {
|
||||||
transactionFilters: () => filters.transaction()
|
transactionFilters: () => filters.transaction()
|
||||||
},
|
},
|
||||||
Mutation: {
|
Mutation: {
|
||||||
cancelCashOutTransaction: (...[, { id }]) => cashOutTx.cancel(id)
|
cancelCashOutTransaction: (...[, { id }]) => cashOutTx.cancel(id),
|
||||||
|
cancelCashInTransaction: (...[, { id }]) => cashInTx.cancel(id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -62,6 +62,7 @@ const typeDef = gql`
|
||||||
|
|
||||||
type Mutation {
|
type Mutation {
|
||||||
cancelCashOutTransaction(id: ID): Transaction @auth
|
cancelCashOutTransaction(id: ID): Transaction @auth
|
||||||
|
cancelCashInTransaction(id: ID): Transaction @auth
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ const TX_SUMMARY = gql`
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
const CANCEL_TRANSACTION = gql`
|
const CANCEL_CASH_OUT_TRANSACTION = gql`
|
||||||
mutation cancelCashOutTransaction($id: ID!) {
|
mutation cancelCashOutTransaction($id: ID!) {
|
||||||
cancelCashOutTransaction(id: $id) {
|
cancelCashOutTransaction(id: $id) {
|
||||||
id
|
id
|
||||||
|
|
@ -70,6 +70,14 @@ const CANCEL_TRANSACTION = gql`
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
|
const CANCEL_CASH_IN_TRANSACTION = gql`
|
||||||
|
mutation cancelCashInTransaction($id: ID!) {
|
||||||
|
cancelCashInTransaction(id: $id) {
|
||||||
|
id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
const formatAddress = (cryptoCode = '', address = '') =>
|
const formatAddress = (cryptoCode = '', address = '') =>
|
||||||
coinUtils.formatCryptoAddress(cryptoCode, address).replace(/(.{5})/g, '$1 ')
|
coinUtils.formatCryptoAddress(cryptoCode, address).replace(/(.{5})/g, '$1 ')
|
||||||
|
|
||||||
|
|
@ -83,16 +91,22 @@ const DetailsRow = ({ it: tx, timezone }) => {
|
||||||
const [action, setAction] = useState({ command: null })
|
const [action, setAction] = useState({ command: null })
|
||||||
const [errorMessage, setErrorMessage] = useState('')
|
const [errorMessage, setErrorMessage] = useState('')
|
||||||
|
|
||||||
|
const isCashIn = tx.txClass === 'cashIn'
|
||||||
|
|
||||||
const zip = new JSZip()
|
const zip = new JSZip()
|
||||||
|
|
||||||
const [fetchSummary] = useLazyQuery(TX_SUMMARY, {
|
const [fetchSummary] = useLazyQuery(TX_SUMMARY, {
|
||||||
onCompleted: data => createCsv(data)
|
onCompleted: data => createCsv(data)
|
||||||
})
|
})
|
||||||
|
|
||||||
const [cancelCashOutTransaction] = useMutation(CANCEL_TRANSACTION, {
|
const [cancelTransaction] = useMutation(
|
||||||
onError: ({ message }) => setErrorMessage(message ?? 'An error occurred.'),
|
isCashIn ? CANCEL_CASH_IN_TRANSACTION : CANCEL_CASH_OUT_TRANSACTION,
|
||||||
refetchQueries: () => ['transactions']
|
{
|
||||||
})
|
onError: ({ message }) =>
|
||||||
|
setErrorMessage(message ?? 'An error occurred.'),
|
||||||
|
refetchQueries: () => ['transactions']
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
const fiat = Number.parseFloat(tx.fiat)
|
const fiat = Number.parseFloat(tx.fiat)
|
||||||
const crypto = coinUtils.toUnit(new BigNumber(tx.cryptoAtoms), tx.cryptoCode)
|
const crypto = coinUtils.toUnit(new BigNumber(tx.cryptoAtoms), tx.cryptoCode)
|
||||||
|
|
@ -142,6 +156,13 @@ const DetailsRow = ({ it: tx, timezone }) => {
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const getCancelMessage = () => {
|
||||||
|
const cashInMessage = `The user will not be able to redeem the inserted bills, even if they subsequently confirm the transaction. If they've already deposited bills, you'll need to reconcile this transaction with them manually.`
|
||||||
|
const cashOutMessage = `The user will not be able to redeem the cash, even if they subsequently send the required coins. If they've already sent you coins, you'll need to reconcile this transaction with them manually.`
|
||||||
|
|
||||||
|
return isCashIn ? cashInMessage : cashOutMessage
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={classes.wrapper}>
|
<div className={classes.wrapper}>
|
||||||
<div className={classes.row}>
|
<div className={classes.row}>
|
||||||
|
|
@ -149,9 +170,9 @@ const DetailsRow = ({ it: tx, timezone }) => {
|
||||||
<Label>Direction</Label>
|
<Label>Direction</Label>
|
||||||
<div>
|
<div>
|
||||||
<span className={classes.txIcon}>
|
<span className={classes.txIcon}>
|
||||||
{tx.txClass === 'cashOut' ? <TxOutIcon /> : <TxInIcon />}
|
{!isCashIn ? <TxOutIcon /> : <TxInIcon />}
|
||||||
</span>
|
</span>
|
||||||
<span>{tx.txClass === 'cashOut' ? 'Cash-out' : 'Cash-in'}</span>
|
<span>{!isCashIn ? 'Cash-out' : 'Cash-in'}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
@ -246,7 +267,7 @@ const DetailsRow = ({ it: tx, timezone }) => {
|
||||||
<div>
|
<div>
|
||||||
<Label>Fixed fee</Label>
|
<Label>Fixed fee</Label>
|
||||||
<div>
|
<div>
|
||||||
{tx.txClass === 'cashIn'
|
{isCashIn
|
||||||
? `${Number.parseFloat(tx.cashInFee)} ${tx.fiatCode}`
|
? `${Number.parseFloat(tx.cashInFee)} ${tx.fiatCode}`
|
||||||
: 'N/A'}
|
: 'N/A'}
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -285,7 +306,7 @@ const DetailsRow = ({ it: tx, timezone }) => {
|
||||||
) : (
|
) : (
|
||||||
errorElements
|
errorElements
|
||||||
)}
|
)}
|
||||||
{tx.txClass === 'cashOut' && getStatus(tx) === 'Pending' && (
|
{getStatus(tx) === 'Pending' && (
|
||||||
<ActionButton
|
<ActionButton
|
||||||
color="primary"
|
color="primary"
|
||||||
Icon={CancelIcon}
|
Icon={CancelIcon}
|
||||||
|
|
@ -319,11 +340,11 @@ const DetailsRow = ({ it: tx, timezone }) => {
|
||||||
title={`Cancel this transaction?`}
|
title={`Cancel this transaction?`}
|
||||||
errorMessage={errorMessage}
|
errorMessage={errorMessage}
|
||||||
toBeConfirmed={tx.machineName}
|
toBeConfirmed={tx.machineName}
|
||||||
message={`The user will not be able to redeem the cash, even if they subsequently send the required coins. If they've already sent you coins, you'll need to reconcile this transaction with them manually.`}
|
message={getCancelMessage()}
|
||||||
onConfirmed={() => {
|
onConfirmed={() => {
|
||||||
setErrorMessage(null)
|
setErrorMessage(null)
|
||||||
setAction({ command: null })
|
setAction({ command: null })
|
||||||
cancelCashOutTransaction({
|
cancelTransaction({
|
||||||
variables: {
|
variables: {
|
||||||
id: tx.id
|
id: tx.id
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue