fix: clean up code
This commit is contained in:
parent
677cb39f0c
commit
01303d6454
4 changed files with 13 additions and 22 deletions
|
|
@ -27,15 +27,8 @@ const insertIntoBlacklist = address => {
|
||||||
|
|
||||||
function blocked (address) {
|
function blocked (address) {
|
||||||
const sql = `SELECT address, content FROM blacklist b LEFT OUTER JOIN blacklist_messages bm ON bm.id = b.blacklist_message_id WHERE address = $1`
|
const sql = `SELECT address, content FROM blacklist b LEFT OUTER JOIN blacklist_messages bm ON bm.id = b.blacklist_message_id WHERE address = $1`
|
||||||
return db.any(sql, [address])
|
|
||||||
}
|
|
||||||
|
|
||||||
function addToUsedAddresses (address) {
|
|
||||||
// ETH reuses addresses
|
|
||||||
// if (cryptoCode === 'ETH') return Promise.resolve()
|
|
||||||
|
|
||||||
const sql = `INSERT INTO blacklist (address) VALUES ($1)`
|
|
||||||
return db.oneOrNone(sql, [address])
|
return db.oneOrNone(sql, [address])
|
||||||
|
.then(r => !_.isNil(r))
|
||||||
}
|
}
|
||||||
|
|
||||||
function getMessages () {
|
function getMessages () {
|
||||||
|
|
@ -50,7 +43,6 @@ function editBlacklistMessage (id, content) {
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
blocked,
|
blocked,
|
||||||
addToUsedAddresses,
|
|
||||||
getBlacklist,
|
getBlacklist,
|
||||||
deleteFromBlacklist,
|
deleteFromBlacklist,
|
||||||
insertIntoBlacklist,
|
insertIntoBlacklist,
|
||||||
|
|
|
||||||
|
|
@ -40,28 +40,31 @@ function post (machineTx, pi) {
|
||||||
|
|
||||||
const isFirstPost = !r.tx.fiat || r.tx.fiat.isZero()
|
const isFirstPost = !r.tx.fiat || r.tx.fiat.isZero()
|
||||||
if (isFirstPost) {
|
if (isFirstPost) {
|
||||||
promises.push(checkForBlacklisted(updatedTx), doesTxReuseAddress(updatedTx), getWalletScore(updatedTx, pi))
|
promises.push(
|
||||||
|
checkForBlacklisted(updatedTx),
|
||||||
|
doesTxReuseAddress(updatedTx),
|
||||||
|
getWalletScore(updatedTx, pi)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return Promise.all(promises)
|
return Promise.all(promises)
|
||||||
.then(([config, blacklistItems = false, isReusedAddress = false, fetchedWalletScore = null]) => {
|
.then(([config, isBlacklisted = false, isReusedAddress = false, fetchedWalletScore = null]) => {
|
||||||
const rejectAddressReuse = configManager.getCompliance(config).rejectAddressReuse
|
const rejectAddressReuse = configManager.getCompliance(config).rejectAddressReuse
|
||||||
|
|
||||||
walletScore = fetchedWalletScore
|
walletScore = fetchedWalletScore
|
||||||
|
|
||||||
if (_.some(it => it.address === updatedTx.toAddress)(blacklistItems)) {
|
if (isBlacklisted) {
|
||||||
blacklisted = _.find(it => it.address === updatedTx.toAddress)(blacklistItems)
|
|
||||||
notifier.notifyIfActive('compliance', 'blacklistNotify', r.tx, false)
|
notifier.notifyIfActive('compliance', 'blacklistNotify', r.tx, false)
|
||||||
} else if (isReusedAddress && rejectAddressReuse) {
|
} else if (isReusedAddress && rejectAddressReuse) {
|
||||||
notifier.notifyIfActive('compliance', 'blacklistNotify', r.tx, true)
|
notifier.notifyIfActive('compliance', 'blacklistNotify', r.tx, true)
|
||||||
addressReuse = true
|
addressReuse = true
|
||||||
}
|
}
|
||||||
return postProcess(r, pi, blacklisted, addressReuse, walletScore)
|
return postProcess(r, pi, isBlacklisted, addressReuse, walletScore)
|
||||||
})
|
})
|
||||||
.then(changes => _.set('walletScore', _.isNil(walletScore) ? null : walletScore.score, changes))
|
.then(changes => _.set('walletScore', _.isNil(walletScore) ? null : walletScore.score, changes))
|
||||||
.then(changes => cashInLow.update(db, updatedTx, changes))
|
.then(changes => cashInLow.update(db, updatedTx, changes))
|
||||||
.then(tx => _.set('bills', machineTx.bills, tx))
|
.then(tx => _.set('bills', machineTx.bills, tx))
|
||||||
.then(tx => _.set('blacklisted', Boolean(blacklisted), tx))
|
.then(tx => _.set('blacklisted', isBlacklisted, tx))
|
||||||
.then(tx => _.set('blacklistMessage', blacklisted?.content, tx))
|
.then(tx => _.set('blacklistMessage', blacklisted?.content, tx))
|
||||||
.then(tx => _.set('addressReuse', addressReuse, tx))
|
.then(tx => _.set('addressReuse', addressReuse, tx))
|
||||||
.then(tx => _.set('validWalletScore', _.isNil(walletScore) ? true : walletScore.isValid, tx))
|
.then(tx => _.set('validWalletScore', _.isNil(walletScore) ? true : walletScore.isValid, tx))
|
||||||
|
|
|
||||||
|
|
@ -35,11 +35,6 @@ const GET_BLACKLIST = gql`
|
||||||
query getBlacklistData {
|
query getBlacklistData {
|
||||||
blacklist {
|
blacklist {
|
||||||
address
|
address
|
||||||
blacklistMessage {
|
|
||||||
id
|
|
||||||
label
|
|
||||||
content
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
cryptoCurrencies {
|
cryptoCurrencies {
|
||||||
display
|
display
|
||||||
|
|
|
||||||
|
|
@ -22,8 +22,8 @@ const useStyles = makeStyles(styles)
|
||||||
const DEFAULT_MESSAGE = `This address may be associated with a deceptive offer or a prohibited group. Please make sure you're using an address from your own wallet.`
|
const DEFAULT_MESSAGE = `This address may be associated with a deceptive offer or a prohibited group. Please make sure you're using an address from your own wallet.`
|
||||||
|
|
||||||
const getErrorMsg = (formikErrors, formikTouched, mutationError) => {
|
const getErrorMsg = (formikErrors, formikTouched, mutationError) => {
|
||||||
if (!formikErrors || !formikTouched) return null
|
|
||||||
if (mutationError) return 'Internal server error'
|
if (mutationError) return 'Internal server error'
|
||||||
|
if (!formikErrors || !formikTouched) return null
|
||||||
if (formikErrors.event && formikTouched.event) return formikErrors.event
|
if (formikErrors.event && formikTouched.event) return formikErrors.event
|
||||||
if (formikErrors.message && formikTouched.message) return formikErrors.message
|
if (formikErrors.message && formikTouched.message) return formikErrors.message
|
||||||
return null
|
return null
|
||||||
|
|
@ -79,7 +79,8 @@ const BlacklistAdvanced = ({
|
||||||
<IconButton
|
<IconButton
|
||||||
className={classes.deleteButton}
|
className={classes.deleteButton}
|
||||||
disabled={
|
disabled={
|
||||||
!R.isNil(R.path(['allowToggle']) && !R.path(['allowToggle'], it))
|
!R.isNil(R.path(['allowToggle'], it)) &&
|
||||||
|
!R.path(['allowToggle'], it)
|
||||||
}>
|
}>
|
||||||
{R.path(['allowToggle'], it) ? (
|
{R.path(['allowToggle'], it) ? (
|
||||||
<DeleteIcon />
|
<DeleteIcon />
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue