fix: uppercasing SQL

fix: remove unnecessary useEffect
fix: transaction polling issue on logout
This commit is contained in:
Sérgio Salgado 2021-06-01 16:29:47 +01:00 committed by Josh Harvey
parent 852bf7b089
commit 9c428a6f8f
4 changed files with 138 additions and 134 deletions

View file

@ -3,25 +3,25 @@ const cashInTx = require('../cash-in/cash-in-tx')
const { CASH_OUT_TRANSACTION_STATES } = require('../cash-out/cash-out-helper') const { CASH_OUT_TRANSACTION_STATES } = require('../cash-out/cash-out-helper')
function transaction() { function transaction() {
const sql = `select distinct * from ( const sql = `SELECT distinct * FROM (
select 'type' as type, 'Cash In' as value union SELECT 'type' AS type, 'Cash In' AS value UNION
select 'type' as type, 'Cash Out' 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_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 '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 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 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 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 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 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 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_in_txs UNION
select 'fiat' as type, fiat_code as value from cash_out_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_in_txs UNION
select 'crypto' as type, crypto_code as value from cash_out_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 '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, ${cashInTx.TRANSACTION_STATES} AS value FROM cash_in_txs UNION
select 'status' as type, ${CASH_OUT_TRANSACTION_STATES} as value from cash_out_txs SELECT 'status' AS type, ${CASH_OUT_TRANSACTION_STATES} AS value FROM cash_out_txs
) f` ) f`
return db.any(sql) return db.any(sql)

View file

@ -40,57 +40,57 @@ function batch (
) { ) {
const packager = _.flow(_.flatten, _.orderBy(_.property('created'), ['desc']), _.map(camelize), addNames) const packager = _.flow(_.flatten, _.orderBy(_.property('created'), ['desc']), _.map(camelize), addNames)
const cashInSql = `select 'cashIn' as tx_class, txs.*, const cashInSql = `SELECT 'cashIn' AS tx_class, txs.*,
c.phone as customer_phone, c.phone AS customer_phone,
c.id_card_data_number as customer_id_card_data_number, 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_expiration AS customer_id_card_data_expiration,
c.id_card_data as customer_id_card_data, 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, 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.front_camera_path AS customer_front_camera_path,
c.id_card_photo_path as customer_id_card_photo_path, c.id_card_photo_path AS customer_id_card_photo_path,
((not txs.send_confirmed) and (txs.created <= now() - interval $1)) as expired ((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 FROM (SELECT *, ${cashInTx.TRANSACTION_STATES} AS txStatus FROM cash_in_txs) AS txs
left outer join customers c on txs.customer_id = c.id LEFT OUTER JOIN customers c ON txs.customer_id = c.id
inner join devices d on txs.device_id = d.device_id INNER JOIN devices d ON txs.device_id = d.device_id
where txs.created >= $2 and txs.created <= $3 ${ WHERE txs.created >= $2 AND txs.created <= $3 ${
id !== null ? `and txs.device_id = $6` : `` id !== null ? `AND txs.device_id = $6` : ``
} }
and ($7 is null or $7 = 'Cash In') AND ($7 is null or $7 = 'Cash In')
and ($8 is null or d.name = $8) 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 ($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 ($10 is null or txs.fiat_code = $10)
and ($11 is null or txs.crypto_code = $11) AND ($11 is null or txs.crypto_code = $11)
and ($12 is null or txs.to_address = $12) AND ($12 is null or txs.to_address = $12)
and ($13 is null or txs.txStatus = $13) AND ($13 is null or txs.txStatus = $13)
order by created desc limit $4 offset $5` ORDER BY created DESC limit $4 offset $5`
const cashOutSql = `select 'cashOut' as tx_class, const cashOutSql = `SELECT 'cashOut' AS tx_class,
txs.*, txs.*,
actions.tx_hash, actions.tx_hash,
c.phone as customer_phone, c.phone AS customer_phone,
c.id_card_data_number as customer_id_card_data_number, 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_expiration AS customer_id_card_data_expiration,
c.id_card_data as customer_id_card_data, 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, 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.front_camera_path AS customer_front_camera_path,
c.id_card_photo_path as customer_id_card_photo_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 (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 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 INNER JOIN cash_out_actions actions ON txs.id = actions.tx_id
and actions.action = 'provisionAddress' AND actions.action = 'provisionAddress'
left outer join customers c on txs.customer_id = c.id LEFT OUTER JOIN customers c ON txs.customer_id = c.id
inner join devices d on txs.device_id = d.device_id INNER JOIN devices d ON txs.device_id = d.device_id
where txs.created >= $2 and txs.created <= $3 ${ WHERE txs.created >= $2 AND txs.created <= $3 ${
id !== null ? `and txs.device_id = $6` : `` id !== null ? `AND txs.device_id = $6` : ``
} }
and ($7 is null or $7 = 'Cash Out') AND ($7 is null or $7 = 'Cash Out')
and ($8 is null or d.name = $8) 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 ($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 ($10 is null or txs.fiat_code = $10)
and ($11 is null or txs.crypto_code = $11) AND ($11 is null or txs.crypto_code = $11)
and ($12 is null or txs.to_address = $12) AND ($12 is null or txs.to_address = $12)
and ($13 is null or txs.txStatus = $13) AND ($13 is null or txs.txStatus = $13)
order by created desc limit $4 offset $5` ORDER BY created DESC limit $4 offset $5`
return Promise.all([ return Promise.all([
db.any(cashInSql, [cashInTx.PENDING_INTERVAL, from, until, limit, offset, id, txClass, machineName, customerName, fiatCode, cryptoCode, toAddress, status]), 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 return it
}, _.flatten, _.orderBy(_.property('created'), ['desc']), _.map(camelize), addNames) }, _.flatten, _.orderBy(_.property('created'), ['desc']), _.map(camelize), addNames)
const cashInSql = `select 'cashIn' as tx_class, txs.*, const cashInSql = `SELECT 'cashIn' AS tx_class, txs.*,
c.phone as customer_phone, c.phone AS customer_phone,
c.id_card_data_number as customer_id_card_data_number, 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_expiration AS customer_id_card_data_expiration,
c.id_card_data as customer_id_card_data, c.id_card_data AS customer_id_card_data,
c.name as customer_name, c.name AS customer_name,
c.front_camera_path as customer_front_camera_path, c.front_camera_path AS customer_front_camera_path,
c.id_card_photo_path as customer_id_card_photo_path, c.id_card_photo_path AS customer_id_card_photo_path,
((not txs.send_confirmed) and (txs.created <= now() - interval $2)) as expired ((NOT txs.send_confirmed) AND (txs.created <= now() - interval $2)) AS expired
from cash_in_txs as txs FROM cash_in_txs AS txs
left outer join customers c on txs.customer_id = c.id LEFT OUTER JOIN customers c ON txs.customer_id = c.id
where c.id IN ($1^) WHERE c.id IN ($1^)
order by created desc limit $3` ORDER BY created DESC limit $3`
const cashOutSql = `select 'cashOut' as tx_class, const cashOutSql = `SELECT 'cashOut' AS tx_class,
txs.*, txs.*,
actions.tx_hash, actions.tx_hash,
c.phone as customer_phone, c.phone AS customer_phone,
c.id_card_data_number as customer_id_card_data_number, 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_expiration AS customer_id_card_data_expiration,
c.id_card_data as customer_id_card_data, c.id_card_data AS customer_id_card_data,
c.name as customer_name, c.name AS customer_name,
c.front_camera_path as customer_front_camera_path, c.front_camera_path AS customer_front_camera_path,
c.id_card_photo_path as customer_id_card_photo_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 (extract(epoch FROM (now() - greatest(txs.created, txs.confirmed_at))) * 1000) >= $3 AS expired
from cash_out_txs txs FROM cash_out_txs txs
inner join cash_out_actions actions on txs.id = actions.tx_id INNER JOIN cash_out_actions actions ON txs.id = actions.tx_id
and actions.action = 'provisionAddress' AND actions.action = 'provisionAddress'
left outer join customers c on txs.customer_id = c.id LEFT OUTER JOIN customers c ON txs.customer_id = c.id
where c.id IN ($1^) WHERE c.id IN ($1^)
order by created desc limit $2` ORDER BY created DESC limit $2`
return Promise.all([ return Promise.all([
db.any(cashInSql, [_.map(pgp.as.text, ids).join(','), cashInTx.PENDING_INTERVAL, NUM_RESULTS]), 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]) db.any(cashOutSql, [_.map(pgp.as.text, ids).join(','), NUM_RESULTS, REDEEMABLE_AGE])
@ -148,35 +148,36 @@ function getCustomerTransactionsBatch (ids) {
function single (txId) { function single (txId) {
const packager = _.flow(_.compact, _.map(camelize), addNames) const packager = _.flow(_.compact, _.map(camelize), addNames)
const cashInSql = `select 'cashIn' as tx_class, txs.*, const cashInSql = `SELECT 'cashIn' AS tx_class, txs.*,
c.phone as customer_phone, c.phone AS customer_phone,
c.id_card_data_number as customer_id_card_data_number, 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_expiration AS customer_id_card_data_expiration,
c.id_card_data as customer_id_card_data, c.id_card_data AS customer_id_card_data,
c.name as customer_name, c.name AS customer_name,
c.front_camera_path as customer_front_camera_path, c.front_camera_path AS customer_front_camera_path,
c.id_card_photo_path as customer_id_card_photo_path, c.id_card_photo_path AS customer_id_card_photo_path,
((not txs.send_confirmed) and (txs.created <= now() - interval $1)) as expired ((NOT txs.send_confirmed) AND (txs.created <= now() - interval $1)) AS expired
from cash_in_txs as txs FROM cash_in_txs AS txs
left outer join customers c on txs.customer_id = c.id LEFT OUTER JOIN customers c ON txs.customer_id = c.id
where id=$2` WHERE id=$2`
const cashOutSql = `select 'cashOut' as tx_class, const cashOutSql = `SELECT 'cashOut' AS tx_class,
txs.*, txs.*,
actions.tx_hash, actions.tx_hash,
c.phone as customer_phone, c.phone AS customer_phone,
c.id_card_data_number as customer_id_card_data_number, 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_expiration AS customer_id_card_data_expiration,
c.id_card_data as customer_id_card_data, c.id_card_data AS customer_id_card_data,
c.name as customer_name, c.name AS customer_name,
c.front_camera_path as customer_front_camera_path, 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 c.id_card_photo_path AS customer_id_card_photo_path,
from cash_out_txs txs (extract(epoch FROM (now() - greatest(txs.created, txs.confirmed_at))) * 1000) >= $2 AS expired
inner join cash_out_actions actions on txs.id = actions.tx_id FROM cash_out_txs txs
and actions.action = 'provisionAddress' INNER JOIN cash_out_actions actions ON txs.id = actions.tx_id
left outer join customers c on txs.customer_id = c.id AND actions.action = 'provisionAddress'
where id=$1` LEFT OUTER JOIN customers c ON txs.customer_id = c.id
WHERE id=$1`
return Promise.all([ return Promise.all([
db.oneOrNone(cashInSql, [cashInTx.PENDING_INTERVAL, txId]), db.oneOrNone(cashInSql, [cashInTx.PENDING_INTERVAL, txId]),

View file

@ -3,7 +3,7 @@ import Paper from '@material-ui/core/Paper'
import { makeStyles } from '@material-ui/core/styles' import { makeStyles } from '@material-ui/core/styles'
import MAutocomplete from '@material-ui/lab/Autocomplete' import MAutocomplete from '@material-ui/lab/Autocomplete'
import classnames from 'classnames' import classnames from 'classnames'
import React, { memo, useState, useEffect } from 'react' import React, { memo, useState } from 'react'
import { P } from 'src/components/typography' import { P } from 'src/components/typography'
import { ReactComponent as SearchIcon } from 'src/styling/icons/circle buttons/search/zodiac.svg' 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) const innerOnChange = filters => onChange(filters)
// eslint-disable-next-line
useEffect(() => innerOnChange(filters), [filters])
return ( return (
<MAutocomplete <MAutocomplete
loading={loading} loading={loading}

View file

@ -4,7 +4,7 @@ import BigNumber from 'bignumber.js'
import gql from 'graphql-tag' import gql from 'graphql-tag'
import { utils as coinUtils } from 'lamassu-coins' import { utils as coinUtils } from 'lamassu-coins'
import * as R from 'ramda' import * as R from 'ramda'
import React, { useState } from 'react' import React, { useEffect, useState } from 'react'
import { useHistory } from 'react-router-dom' import { useHistory } from 'react-router-dom'
import Chip from 'src/components/Chip' import Chip from 'src/components/Chip'
@ -21,7 +21,7 @@ import { formatDate } from 'src/utils/timezones'
import DetailsRow from './DetailsCard' import DetailsRow from './DetailsCard'
import { mainStyles, chipStyles } from './Transactions.styles' import { mainStyles, chipStyles } from './Transactions.styles'
import { getStatus /*, getStatusProperties */ } from './helper' import { getStatus } from './helper'
const useStyles = makeStyles(mainStyles) const useStyles = makeStyles(mainStyles)
const useChipStyles = makeStyles(chipStyles) const useChipStyles = makeStyles(chipStyles)
@ -116,15 +116,21 @@ const Transactions = () => {
) )
const [filteredTransactions, setFilteredTransactions] = useState([]) const [filteredTransactions, setFilteredTransactions] = useState([])
const [variables, setVariables] = useState({ limit: NUM_LOG_RESULTS }) const [variables, setVariables] = useState({ limit: NUM_LOG_RESULTS })
const { data: txResponse, loading: loadingTransactions, refetch } = useQuery( const {
GET_TRANSACTIONS, data: txResponse,
{ loading: loadingTransactions,
variables, refetch,
onCompleted: data => startPolling,
setFilteredTransactions(R.path(['transactions'])(data)), stopPolling
pollInterval: 10000 } = useQuery(GET_TRANSACTIONS, {
} variables,
) onCompleted: data => setFilteredTransactions(R.path(['transactions'])(data))
})
useEffect(() => {
startPolling(10000)
return stopPolling
})
const { data: configResponse, configLoading } = useQuery(GET_DATA) const { data: configResponse, configLoading } = useQuery(GET_DATA)
const timezone = R.path(['config', 'locale_timezone'], configResponse) const timezone = R.path(['config', 'locale_timezone'], configResponse)