fix: do server side validation on blacklist
address validation imports a lot of files that rely on nodejs to run previouly the build was automatically adding polyfills for that
This commit is contained in:
parent
00dc3d0fcd
commit
62f39f3561
3 changed files with 27 additions and 26 deletions
1
.tool-versions
Normal file
1
.tool-versions
Normal file
|
|
@ -0,0 +1 @@
|
|||
nodejs 14
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
const _ = require('lodash/fp')
|
||||
|
||||
const { addressDetector } = require('@lamassu/coins')
|
||||
const db = require('./db')
|
||||
const notifierQueries = require('./notifier/queries')
|
||||
|
||||
|
|
@ -16,7 +17,18 @@ const deleteFromBlacklist = address => {
|
|||
return db.none(sql, [address])
|
||||
}
|
||||
|
||||
const isValidAddress = address => {
|
||||
try {
|
||||
return !_.isEmpty(addressDetector.getSupportedCoinsForAddress(address).matches)
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
const insertIntoBlacklist = address => {
|
||||
if (!isValidAddress(address)) {
|
||||
return Promise.reject(new Error('Invalid address'))
|
||||
}
|
||||
return db
|
||||
.none(
|
||||
'INSERT INTO blacklist (address) VALUES ($1);',
|
||||
|
|
|
|||
|
|
@ -144,7 +144,6 @@ const Blacklist = () => {
|
|||
})
|
||||
|
||||
const [addEntry] = useMutation(ADD_ROW, {
|
||||
onError: () => console.log('Error while adding row'),
|
||||
refetchQueries: () => ['getBlacklistData']
|
||||
})
|
||||
|
||||
|
|
@ -184,33 +183,22 @@ const Blacklist = () => {
|
|||
setConfirmDialog(false)
|
||||
}
|
||||
|
||||
const validateAddress = address => {
|
||||
try {
|
||||
return !R
|
||||
.isEmpty
|
||||
// addressDetector.getSupportedCoinsForAddress(address).matches
|
||||
()
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
const addToBlacklist = async address => {
|
||||
setErrorMsg(null)
|
||||
if (!validateAddress(address)) {
|
||||
setErrorMsg('Invalid address')
|
||||
return
|
||||
}
|
||||
const res = await addEntry({ variables: { address } })
|
||||
if (!res.errors) {
|
||||
return setShowModal(false)
|
||||
}
|
||||
const duplicateKeyError = res.errors.some(e => {
|
||||
return e.message.includes('duplicate')
|
||||
})
|
||||
if (duplicateKeyError) {
|
||||
setErrorMsg('This address is already being blocked')
|
||||
} else {
|
||||
try {
|
||||
const res = await addEntry({ variables: { address } })
|
||||
if (!res?.errors) {
|
||||
return setShowModal(false)
|
||||
}
|
||||
const duplicateKeyError = res?.errors?.some(e => {
|
||||
return e.message.includes('duplicate')
|
||||
})
|
||||
if (duplicateKeyError) {
|
||||
setErrorMsg('This address is already being blocked')
|
||||
} else {
|
||||
setErrorMsg(`Server error${': ' + res?.errors[0]?.message}`)
|
||||
}
|
||||
} catch (e) {
|
||||
setErrorMsg('Server error')
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue