fix: uppercasing SQL
fix: remove unnecessary useEffect fix: transaction polling issue on logout
This commit is contained in:
parent
852bf7b089
commit
9c428a6f8f
4 changed files with 138 additions and 134 deletions
|
|
@ -3,25 +3,25 @@ const cashInTx = require('../cash-in/cash-in-tx')
|
|||
const { CASH_OUT_TRANSACTION_STATES } = require('../cash-out/cash-out-helper')
|
||||
|
||||
function transaction() {
|
||||
const sql = `select distinct * from (
|
||||
select 'type' as type, 'Cash In' as value union
|
||||
select 'type' as type, 'Cash Out' as value union
|
||||
select 'machine' as type, name as value from devices d inner join cash_in_txs t on d.device_id = t.device_id union
|
||||
select 'machine' as type, name as value from devices d inner join cash_out_txs t on d.device_id = t.device_id union
|
||||
select 'customer' as type, concat(id_card_data::json->>'firstName', ' ', id_card_data::json->>'lastName') as value
|
||||
from customers c inner join cash_in_txs t on c.id = t.customer_id
|
||||
where c.id_card_data::json->>'firstName' is not null or c.id_card_data::json->>'lastName' is not null union
|
||||
select 'customer' as type, concat(id_card_data::json->>'firstName', ' ', id_card_data::json->>'lastName') as value
|
||||
from customers c inner join cash_out_txs t on c.id = t.customer_id
|
||||
where c.id_card_data::json->>'firstName' is not null or c.id_card_data::json->>'lastName' is not null union
|
||||
select 'fiat' as type, fiat_code as value from cash_in_txs union
|
||||
select 'fiat' as type, fiat_code as value from cash_out_txs union
|
||||
select 'crypto' as type, crypto_code as value from cash_in_txs union
|
||||
select 'crypto' as type, crypto_code as value from cash_out_txs union
|
||||
select 'address' as type, to_address as value from cash_in_txs union
|
||||
select 'address' as type, to_address as value from cash_in_txs union
|
||||
select 'status' as type, ${cashInTx.TRANSACTION_STATES} as value from cash_in_txs union
|
||||
select 'status' as type, ${CASH_OUT_TRANSACTION_STATES} as value from cash_out_txs
|
||||
const sql = `SELECT distinct * FROM (
|
||||
SELECT 'type' AS type, 'Cash In' AS value UNION
|
||||
SELECT 'type' AS type, 'Cash Out' AS value UNION
|
||||
SELECT 'machine' AS type, name AS value FROM devices d INNER JOIN cash_in_txs t ON d.device_id = t.device_id UNION
|
||||
SELECT 'machine' AS type, name AS value FROM devices d INNER JOIN cash_out_txs t ON d.device_id = t.device_id UNION
|
||||
SELECT 'customer' AS type, concat(id_card_data::json->>'firstName', ' ', id_card_data::json->>'lastName') AS value
|
||||
FROM customers c INNER JOIN cash_in_txs t ON c.id = t.customer_id
|
||||
WHERE c.id_card_data::json->>'firstName' IS NOT NULL or c.id_card_data::json->>'lastName' IS NOT NULL UNION
|
||||
SELECT 'customer' AS type, concat(id_card_data::json->>'firstName', ' ', id_card_data::json->>'lastName') AS value
|
||||
FROM customers c INNER JOIN cash_out_txs t ON c.id = t.customer_id
|
||||
WHERE c.id_card_data::json->>'firstName' IS NOT NULL or c.id_card_data::json->>'lastName' IS NOT NULL UNION
|
||||
SELECT 'fiat' AS type, fiat_code AS value FROM cash_in_txs UNION
|
||||
SELECT 'fiat' AS type, fiat_code AS value FROM cash_out_txs UNION
|
||||
SELECT 'crypto' AS type, crypto_code AS value FROM cash_in_txs UNION
|
||||
SELECT 'crypto' AS type, crypto_code AS value FROM cash_out_txs UNION
|
||||
SELECT 'address' AS type, to_address AS value FROM cash_in_txs UNION
|
||||
SELECT 'address' AS type, to_address AS value FROM cash_in_txs UNION
|
||||
SELECT 'status' AS type, ${cashInTx.TRANSACTION_STATES} AS value FROM cash_in_txs UNION
|
||||
SELECT 'status' AS type, ${CASH_OUT_TRANSACTION_STATES} AS value FROM cash_out_txs
|
||||
) f`
|
||||
|
||||
return db.any(sql)
|
||||
|
|
|
|||
|
|
@ -40,57 +40,57 @@ function batch (
|
|||
) {
|
||||
const packager = _.flow(_.flatten, _.orderBy(_.property('created'), ['desc']), _.map(camelize), addNames)
|
||||
|
||||
const cashInSql = `select 'cashIn' as tx_class, txs.*,
|
||||
c.phone as customer_phone,
|
||||
c.id_card_data_number as customer_id_card_data_number,
|
||||
c.id_card_data_expiration as customer_id_card_data_expiration,
|
||||
c.id_card_data as customer_id_card_data,
|
||||
concat(c.id_card_data::json->>'firstName', ' ', c.id_card_data::json->>'lastName') as customer_name,
|
||||
c.front_camera_path as customer_front_camera_path,
|
||||
c.id_card_photo_path as customer_id_card_photo_path,
|
||||
((not txs.send_confirmed) and (txs.created <= now() - interval $1)) as expired
|
||||
from (select *, ${cashInTx.TRANSACTION_STATES} as txStatus from cash_in_txs) as txs
|
||||
left outer join customers c on txs.customer_id = c.id
|
||||
inner join devices d on txs.device_id = d.device_id
|
||||
where txs.created >= $2 and txs.created <= $3 ${
|
||||
id !== null ? `and txs.device_id = $6` : ``
|
||||
const cashInSql = `SELECT 'cashIn' AS tx_class, txs.*,
|
||||
c.phone AS customer_phone,
|
||||
c.id_card_data_number AS customer_id_card_data_number,
|
||||
c.id_card_data_expiration AS customer_id_card_data_expiration,
|
||||
c.id_card_data AS customer_id_card_data,
|
||||
concat(c.id_card_data::json->>'firstName', ' ', c.id_card_data::json->>'lastName') AS customer_name,
|
||||
c.front_camera_path AS customer_front_camera_path,
|
||||
c.id_card_photo_path AS customer_id_card_photo_path,
|
||||
((NOT txs.send_confirmed) AND (txs.created <= now() - interval $1)) AS expired
|
||||
FROM (SELECT *, ${cashInTx.TRANSACTION_STATES} AS txStatus FROM cash_in_txs) AS txs
|
||||
LEFT OUTER JOIN customers c ON txs.customer_id = c.id
|
||||
INNER JOIN devices d ON txs.device_id = d.device_id
|
||||
WHERE txs.created >= $2 AND txs.created <= $3 ${
|
||||
id !== null ? `AND txs.device_id = $6` : ``
|
||||
}
|
||||
and ($7 is null or $7 = 'Cash In')
|
||||
and ($8 is null or d.name = $8)
|
||||
and ($9 is null or concat(c.id_card_data::json->>'firstName', ' ', c.id_card_data::json->>'lastName') = $9)
|
||||
and ($10 is null or txs.fiat_code = $10)
|
||||
and ($11 is null or txs.crypto_code = $11)
|
||||
and ($12 is null or txs.to_address = $12)
|
||||
and ($13 is null or txs.txStatus = $13)
|
||||
order by created desc limit $4 offset $5`
|
||||
AND ($7 is null or $7 = 'Cash In')
|
||||
AND ($8 is null or d.name = $8)
|
||||
AND ($9 is null or concat(c.id_card_data::json->>'firstName', ' ', c.id_card_data::json->>'lastName') = $9)
|
||||
AND ($10 is null or txs.fiat_code = $10)
|
||||
AND ($11 is null or txs.crypto_code = $11)
|
||||
AND ($12 is null or txs.to_address = $12)
|
||||
AND ($13 is null or txs.txStatus = $13)
|
||||
ORDER BY created DESC limit $4 offset $5`
|
||||
|
||||
const cashOutSql = `select 'cashOut' as tx_class,
|
||||
const cashOutSql = `SELECT 'cashOut' AS tx_class,
|
||||
txs.*,
|
||||
actions.tx_hash,
|
||||
c.phone as customer_phone,
|
||||
c.id_card_data_number as customer_id_card_data_number,
|
||||
c.id_card_data_expiration as customer_id_card_data_expiration,
|
||||
c.id_card_data as customer_id_card_data,
|
||||
concat(c.id_card_data::json->>'firstName', ' ', c.id_card_data::json->>'lastName') as customer_name,
|
||||
c.front_camera_path as customer_front_camera_path,
|
||||
c.id_card_photo_path as customer_id_card_photo_path,
|
||||
(extract(epoch from (now() - greatest(txs.created, txs.confirmed_at))) * 1000) >= $1 as expired
|
||||
from (select *, ${CASH_OUT_TRANSACTION_STATES} as txStatus from cash_out_txs) txs
|
||||
inner join cash_out_actions actions on txs.id = actions.tx_id
|
||||
and actions.action = 'provisionAddress'
|
||||
left outer join customers c on txs.customer_id = c.id
|
||||
inner join devices d on txs.device_id = d.device_id
|
||||
where txs.created >= $2 and txs.created <= $3 ${
|
||||
id !== null ? `and txs.device_id = $6` : ``
|
||||
c.phone AS customer_phone,
|
||||
c.id_card_data_number AS customer_id_card_data_number,
|
||||
c.id_card_data_expiration AS customer_id_card_data_expiration,
|
||||
c.id_card_data AS customer_id_card_data,
|
||||
concat(c.id_card_data::json->>'firstName', ' ', c.id_card_data::json->>'lastName') AS customer_name,
|
||||
c.front_camera_path AS customer_front_camera_path,
|
||||
c.id_card_photo_path AS customer_id_card_photo_path,
|
||||
(extract(epoch FROM (now() - greatest(txs.created, txs.confirmed_at))) * 1000) >= $1 AS expired
|
||||
FROM (SELECT *, ${CASH_OUT_TRANSACTION_STATES} AS txStatus FROM cash_out_txs) txs
|
||||
INNER JOIN cash_out_actions actions ON txs.id = actions.tx_id
|
||||
AND actions.action = 'provisionAddress'
|
||||
LEFT OUTER JOIN customers c ON txs.customer_id = c.id
|
||||
INNER JOIN devices d ON txs.device_id = d.device_id
|
||||
WHERE txs.created >= $2 AND txs.created <= $3 ${
|
||||
id !== null ? `AND txs.device_id = $6` : ``
|
||||
}
|
||||
and ($7 is null or $7 = 'Cash Out')
|
||||
and ($8 is null or d.name = $8)
|
||||
and ($9 is null or concat(c.id_card_data::json->>'firstName', ' ', c.id_card_data::json->>'lastName') = $9)
|
||||
and ($10 is null or txs.fiat_code = $10)
|
||||
and ($11 is null or txs.crypto_code = $11)
|
||||
and ($12 is null or txs.to_address = $12)
|
||||
and ($13 is null or txs.txStatus = $13)
|
||||
order by created desc limit $4 offset $5`
|
||||
AND ($7 is null or $7 = 'Cash Out')
|
||||
AND ($8 is null or d.name = $8)
|
||||
AND ($9 is null or concat(c.id_card_data::json->>'firstName', ' ', c.id_card_data::json->>'lastName') = $9)
|
||||
AND ($10 is null or txs.fiat_code = $10)
|
||||
AND ($11 is null or txs.crypto_code = $11)
|
||||
AND ($12 is null or txs.to_address = $12)
|
||||
AND ($13 is null or txs.txStatus = $13)
|
||||
ORDER BY created DESC limit $4 offset $5`
|
||||
|
||||
return Promise.all([
|
||||
db.any(cashInSql, [cashInTx.PENDING_INTERVAL, from, until, limit, offset, id, txClass, machineName, customerName, fiatCode, cryptoCode, toAddress, status]),
|
||||
|
|
@ -104,37 +104,37 @@ function getCustomerTransactionsBatch (ids) {
|
|||
return it
|
||||
}, _.flatten, _.orderBy(_.property('created'), ['desc']), _.map(camelize), addNames)
|
||||
|
||||
const cashInSql = `select 'cashIn' as tx_class, txs.*,
|
||||
c.phone as customer_phone,
|
||||
c.id_card_data_number as customer_id_card_data_number,
|
||||
c.id_card_data_expiration as customer_id_card_data_expiration,
|
||||
c.id_card_data as customer_id_card_data,
|
||||
c.name as customer_name,
|
||||
c.front_camera_path as customer_front_camera_path,
|
||||
c.id_card_photo_path as customer_id_card_photo_path,
|
||||
((not txs.send_confirmed) and (txs.created <= now() - interval $2)) as expired
|
||||
from cash_in_txs as txs
|
||||
left outer join customers c on txs.customer_id = c.id
|
||||
where c.id IN ($1^)
|
||||
order by created desc limit $3`
|
||||
const cashInSql = `SELECT 'cashIn' AS tx_class, txs.*,
|
||||
c.phone AS customer_phone,
|
||||
c.id_card_data_number AS customer_id_card_data_number,
|
||||
c.id_card_data_expiration AS customer_id_card_data_expiration,
|
||||
c.id_card_data AS customer_id_card_data,
|
||||
c.name AS customer_name,
|
||||
c.front_camera_path AS customer_front_camera_path,
|
||||
c.id_card_photo_path AS customer_id_card_photo_path,
|
||||
((NOT txs.send_confirmed) AND (txs.created <= now() - interval $2)) AS expired
|
||||
FROM cash_in_txs AS txs
|
||||
LEFT OUTER JOIN customers c ON txs.customer_id = c.id
|
||||
WHERE c.id IN ($1^)
|
||||
ORDER BY created DESC limit $3`
|
||||
|
||||
const cashOutSql = `select 'cashOut' as tx_class,
|
||||
const cashOutSql = `SELECT 'cashOut' AS tx_class,
|
||||
txs.*,
|
||||
actions.tx_hash,
|
||||
c.phone as customer_phone,
|
||||
c.id_card_data_number as customer_id_card_data_number,
|
||||
c.id_card_data_expiration as customer_id_card_data_expiration,
|
||||
c.id_card_data as customer_id_card_data,
|
||||
c.name as customer_name,
|
||||
c.front_camera_path as customer_front_camera_path,
|
||||
c.id_card_photo_path as customer_id_card_photo_path,
|
||||
(extract(epoch from (now() - greatest(txs.created, txs.confirmed_at))) * 1000) >= $3 as expired
|
||||
from cash_out_txs txs
|
||||
inner join cash_out_actions actions on txs.id = actions.tx_id
|
||||
and actions.action = 'provisionAddress'
|
||||
left outer join customers c on txs.customer_id = c.id
|
||||
where c.id IN ($1^)
|
||||
order by created desc limit $2`
|
||||
c.phone AS customer_phone,
|
||||
c.id_card_data_number AS customer_id_card_data_number,
|
||||
c.id_card_data_expiration AS customer_id_card_data_expiration,
|
||||
c.id_card_data AS customer_id_card_data,
|
||||
c.name AS customer_name,
|
||||
c.front_camera_path AS customer_front_camera_path,
|
||||
c.id_card_photo_path AS customer_id_card_photo_path,
|
||||
(extract(epoch FROM (now() - greatest(txs.created, txs.confirmed_at))) * 1000) >= $3 AS expired
|
||||
FROM cash_out_txs txs
|
||||
INNER JOIN cash_out_actions actions ON txs.id = actions.tx_id
|
||||
AND actions.action = 'provisionAddress'
|
||||
LEFT OUTER JOIN customers c ON txs.customer_id = c.id
|
||||
WHERE c.id IN ($1^)
|
||||
ORDER BY created DESC limit $2`
|
||||
return Promise.all([
|
||||
db.any(cashInSql, [_.map(pgp.as.text, ids).join(','), cashInTx.PENDING_INTERVAL, NUM_RESULTS]),
|
||||
db.any(cashOutSql, [_.map(pgp.as.text, ids).join(','), NUM_RESULTS, REDEEMABLE_AGE])
|
||||
|
|
@ -148,35 +148,36 @@ function getCustomerTransactionsBatch (ids) {
|
|||
function single (txId) {
|
||||
const packager = _.flow(_.compact, _.map(camelize), addNames)
|
||||
|
||||
const cashInSql = `select 'cashIn' as tx_class, txs.*,
|
||||
c.phone as customer_phone,
|
||||
c.id_card_data_number as customer_id_card_data_number,
|
||||
c.id_card_data_expiration as customer_id_card_data_expiration,
|
||||
c.id_card_data as customer_id_card_data,
|
||||
c.name as customer_name,
|
||||
c.front_camera_path as customer_front_camera_path,
|
||||
c.id_card_photo_path as customer_id_card_photo_path,
|
||||
((not txs.send_confirmed) and (txs.created <= now() - interval $1)) as expired
|
||||
from cash_in_txs as txs
|
||||
left outer join customers c on txs.customer_id = c.id
|
||||
where id=$2`
|
||||
const cashInSql = `SELECT 'cashIn' AS tx_class, txs.*,
|
||||
c.phone AS customer_phone,
|
||||
c.id_card_data_number AS customer_id_card_data_number,
|
||||
c.id_card_data_expiration AS customer_id_card_data_expiration,
|
||||
c.id_card_data AS customer_id_card_data,
|
||||
c.name AS customer_name,
|
||||
c.front_camera_path AS customer_front_camera_path,
|
||||
c.id_card_photo_path AS customer_id_card_photo_path,
|
||||
((NOT txs.send_confirmed) AND (txs.created <= now() - interval $1)) AS expired
|
||||
FROM cash_in_txs AS txs
|
||||
LEFT OUTER JOIN customers c ON txs.customer_id = c.id
|
||||
WHERE id=$2`
|
||||
|
||||
const cashOutSql = `select 'cashOut' as tx_class,
|
||||
const cashOutSql = `SELECT 'cashOut' AS tx_class,
|
||||
txs.*,
|
||||
actions.tx_hash,
|
||||
c.phone as customer_phone,
|
||||
c.id_card_data_number as customer_id_card_data_number,
|
||||
c.id_card_data_expiration as customer_id_card_data_expiration,
|
||||
c.id_card_data as customer_id_card_data,
|
||||
c.name as customer_name,
|
||||
c.front_camera_path as customer_front_camera_path,
|
||||
c.id_card_photo_path as customer_id_card_photo_path,
|
||||
(extract(epoch from (now() - greatest(txs.created, txs.confirmed_at))) * 1000) >= $2 as expired
|
||||
from cash_out_txs txs
|
||||
inner join cash_out_actions actions on txs.id = actions.tx_id
|
||||
and actions.action = 'provisionAddress'
|
||||
left outer join customers c on txs.customer_id = c.id
|
||||
where id=$1`
|
||||
c.phone AS customer_phone,
|
||||
c.id_card_data_number AS customer_id_card_data_number,
|
||||
c.id_card_data_expiration AS customer_id_card_data_expiration,
|
||||
c.id_card_data AS customer_id_card_data,
|
||||
c.name AS customer_name,
|
||||
c.front_camera_path AS customer_front_camera_path,
|
||||
|
||||
c.id_card_photo_path AS customer_id_card_photo_path,
|
||||
(extract(epoch FROM (now() - greatest(txs.created, txs.confirmed_at))) * 1000) >= $2 AS expired
|
||||
FROM cash_out_txs txs
|
||||
INNER JOIN cash_out_actions actions ON txs.id = actions.tx_id
|
||||
AND actions.action = 'provisionAddress'
|
||||
LEFT OUTER JOIN customers c ON txs.customer_id = c.id
|
||||
WHERE id=$1`
|
||||
|
||||
return Promise.all([
|
||||
db.oneOrNone(cashInSql, [cashInTx.PENDING_INTERVAL, txId]),
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import Paper from '@material-ui/core/Paper'
|
|||
import { makeStyles } from '@material-ui/core/styles'
|
||||
import MAutocomplete from '@material-ui/lab/Autocomplete'
|
||||
import classnames from 'classnames'
|
||||
import React, { memo, useState, useEffect } from 'react'
|
||||
import React, { memo, useState } from 'react'
|
||||
|
||||
import { P } from 'src/components/typography'
|
||||
import { ReactComponent as SearchIcon } from 'src/styling/icons/circle buttons/search/zodiac.svg'
|
||||
|
|
@ -33,9 +33,6 @@ const SearchBox = memo(
|
|||
|
||||
const innerOnChange = filters => onChange(filters)
|
||||
|
||||
// eslint-disable-next-line
|
||||
useEffect(() => innerOnChange(filters), [filters])
|
||||
|
||||
return (
|
||||
<MAutocomplete
|
||||
loading={loading}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import BigNumber from 'bignumber.js'
|
|||
import gql from 'graphql-tag'
|
||||
import { utils as coinUtils } from 'lamassu-coins'
|
||||
import * as R from 'ramda'
|
||||
import React, { useState } from 'react'
|
||||
import React, { useEffect, useState } from 'react'
|
||||
import { useHistory } from 'react-router-dom'
|
||||
|
||||
import Chip from 'src/components/Chip'
|
||||
|
|
@ -21,7 +21,7 @@ import { formatDate } from 'src/utils/timezones'
|
|||
|
||||
import DetailsRow from './DetailsCard'
|
||||
import { mainStyles, chipStyles } from './Transactions.styles'
|
||||
import { getStatus /*, getStatusProperties */ } from './helper'
|
||||
import { getStatus } from './helper'
|
||||
|
||||
const useStyles = makeStyles(mainStyles)
|
||||
const useChipStyles = makeStyles(chipStyles)
|
||||
|
|
@ -116,15 +116,21 @@ const Transactions = () => {
|
|||
)
|
||||
const [filteredTransactions, setFilteredTransactions] = useState([])
|
||||
const [variables, setVariables] = useState({ limit: NUM_LOG_RESULTS })
|
||||
const { data: txResponse, loading: loadingTransactions, refetch } = useQuery(
|
||||
GET_TRANSACTIONS,
|
||||
{
|
||||
const {
|
||||
data: txResponse,
|
||||
loading: loadingTransactions,
|
||||
refetch,
|
||||
startPolling,
|
||||
stopPolling
|
||||
} = useQuery(GET_TRANSACTIONS, {
|
||||
variables,
|
||||
onCompleted: data =>
|
||||
setFilteredTransactions(R.path(['transactions'])(data)),
|
||||
pollInterval: 10000
|
||||
}
|
||||
)
|
||||
onCompleted: data => setFilteredTransactions(R.path(['transactions'])(data))
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
startPolling(10000)
|
||||
return stopPolling
|
||||
})
|
||||
|
||||
const { data: configResponse, configLoading } = useQuery(GET_DATA)
|
||||
const timezone = R.path(['config', 'locale_timezone'], configResponse)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue