Feat: warn admin if address is duplicate
This commit is contained in:
parent
fd2a34d475
commit
5823485ab7
4 changed files with 43 additions and 15 deletions
|
|
@ -21,13 +21,10 @@ const deleteFromBlacklist = (cryptoCode, address) => {
|
|||
|
||||
const insertIntoBlacklist = (cryptoCode, address) => {
|
||||
return db
|
||||
.any(
|
||||
.none(
|
||||
'insert into blacklist(crypto_code, address, created_by_operator) values($1, $2, $3);',
|
||||
[cryptoCode, address, true]
|
||||
)
|
||||
.then(() => {
|
||||
return { cryptoCode, address }
|
||||
})
|
||||
}
|
||||
|
||||
function blocked(address, cryptoCode) {
|
||||
|
|
|
|||
|
|
@ -73,14 +73,15 @@ const Blacklist = () => {
|
|||
code: 'BTC',
|
||||
display: 'Bitcoin'
|
||||
})
|
||||
const [errorMsg, setErrorMsg] = useState(null)
|
||||
|
||||
const [deleteEntry] = useMutation(DELETE_ROW, {
|
||||
onError: () => console.error('Error while deleting row'),
|
||||
refetchQueries: () => ['getBlacklistData']
|
||||
})
|
||||
|
||||
const [addEntry] = useMutation(ADD_ROW, {
|
||||
onError: () => console.error('Error while adding row'),
|
||||
onCompleted: () => setShowModal(false),
|
||||
onError: () => console.log('Error while adding row'),
|
||||
refetchQueries: () => ['getBlacklistData']
|
||||
})
|
||||
|
||||
|
|
@ -114,8 +115,20 @@ const Blacklist = () => {
|
|||
deleteEntry({ variables: { cryptoCode, address } })
|
||||
}
|
||||
|
||||
const addToBlacklist = (cryptoCode, address) => {
|
||||
addEntry({ variables: { cryptoCode, address } })
|
||||
const addToBlacklist = async (cryptoCode, address) => {
|
||||
setErrorMsg(null)
|
||||
const res = await addEntry({ variables: { cryptoCode, 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')
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
|
|
@ -169,7 +182,11 @@ const Blacklist = () => {
|
|||
</Grid>
|
||||
{showModal && (
|
||||
<BlackListModal
|
||||
onClose={() => setShowModal(false)}
|
||||
onClose={() => {
|
||||
setErrorMsg(null)
|
||||
setShowModal(false)
|
||||
}}
|
||||
errorMsg={errorMsg}
|
||||
selectedCoin={clickedItem}
|
||||
addToBlacklist={addToBlacklist}
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,11 @@
|
|||
import { spacer, fontPrimary, primaryColor, white } from 'src/styling/variables'
|
||||
|
||||
export default {
|
||||
import {
|
||||
spacer,
|
||||
fontPrimary,
|
||||
primaryColor,
|
||||
white,
|
||||
errorColor
|
||||
} from 'src/styling/variables'
|
||||
const styles = {
|
||||
grid: {
|
||||
flex: 1,
|
||||
height: '100%'
|
||||
|
|
@ -35,5 +40,10 @@ export default {
|
|||
},
|
||||
addressRow: {
|
||||
marginLeft: 8
|
||||
},
|
||||
error: {
|
||||
color: errorColor
|
||||
}
|
||||
}
|
||||
|
||||
export default styles
|
||||
|
|
|
|||
|
|
@ -12,13 +12,16 @@ import { H3 } from 'src/components/typography'
|
|||
import styles from './Blacklist.styles'
|
||||
const useStyles = makeStyles(styles)
|
||||
|
||||
const BlackListModal = ({ onClose, selectedCoin, addToBlacklist }) => {
|
||||
const BlackListModal = ({
|
||||
onClose,
|
||||
selectedCoin,
|
||||
addToBlacklist,
|
||||
errorMsg
|
||||
}) => {
|
||||
const classes = useStyles()
|
||||
|
||||
const handleAddToBlacklist = address => {
|
||||
addToBlacklist(selectedCoin.code, address)
|
||||
}
|
||||
|
||||
const placeholderAddress = {
|
||||
BTC: '1ADwinnimZKGgQ3dpyfoUZvJh4p1UWSSpD',
|
||||
ETH: '0x71C7656EC7ab88b098defB751B7401B5f6d8976F',
|
||||
|
|
@ -54,6 +57,7 @@ const BlackListModal = ({ onClose, selectedCoin, addToBlacklist }) => {
|
|||
? `Blacklist ${R.toLower(selectedCoin.display)} address`
|
||||
: ''}
|
||||
</H3>
|
||||
<span className={classes.error}>{errorMsg}</span>
|
||||
<Field
|
||||
name="address"
|
||||
fullWidth
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue