fix: blacklist modal up to spec and added address validation
This commit is contained in:
parent
2f0ca0ab26
commit
89bbca3647
3 changed files with 23 additions and 16 deletions
|
|
@ -3,6 +3,7 @@ import { Box } from '@material-ui/core'
|
||||||
import Grid from '@material-ui/core/Grid'
|
import Grid from '@material-ui/core/Grid'
|
||||||
import { makeStyles } from '@material-ui/core/styles'
|
import { makeStyles } from '@material-ui/core/styles'
|
||||||
import gql from 'graphql-tag'
|
import gql from 'graphql-tag'
|
||||||
|
import { utils as coinUtils } from 'lamassu-coins'
|
||||||
import * as R from 'ramda'
|
import * as R from 'ramda'
|
||||||
import React, { useState } from 'react'
|
import React, { useState } from 'react'
|
||||||
|
|
||||||
|
|
@ -120,8 +121,21 @@ const Blacklist = () => {
|
||||||
deleteEntry({ variables: { cryptoCode, address } })
|
deleteEntry({ variables: { cryptoCode, address } })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const validateAddress = (cryptoCode, address) => {
|
||||||
|
try {
|
||||||
|
console.log(errorMsg)
|
||||||
|
return !R.isNil(coinUtils.parseUrl(cryptoCode, 'main', address))
|
||||||
|
} catch {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const addToBlacklist = async (cryptoCode, address) => {
|
const addToBlacklist = async (cryptoCode, address) => {
|
||||||
setErrorMsg(null)
|
setErrorMsg(null)
|
||||||
|
if (!validateAddress(cryptoCode, address)) {
|
||||||
|
setErrorMsg('Invalid address')
|
||||||
|
return
|
||||||
|
}
|
||||||
const res = await addEntry({ variables: { cryptoCode, address } })
|
const res = await addEntry({ variables: { cryptoCode, address } })
|
||||||
if (!res.errors) {
|
if (!res.errors) {
|
||||||
return setShowModal(false)
|
return setShowModal(false)
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,4 @@
|
||||||
import {
|
import { spacer, white, errorColor } from 'src/styling/variables'
|
||||||
spacer,
|
|
||||||
fontPrimary,
|
|
||||||
primaryColor,
|
|
||||||
white,
|
|
||||||
errorColor
|
|
||||||
} from 'src/styling/variables'
|
|
||||||
const styles = {
|
const styles = {
|
||||||
grid: {
|
grid: {
|
||||||
flex: 1,
|
flex: 1,
|
||||||
|
|
@ -20,11 +14,7 @@ const styles = {
|
||||||
margin: [['auto', 0, spacer * 3, 'auto']]
|
margin: [['auto', 0, spacer * 3, 'auto']]
|
||||||
},
|
},
|
||||||
modalTitle: {
|
modalTitle: {
|
||||||
lineHeight: '120%',
|
margin: [['auto', 0, 8.5, 'auto']]
|
||||||
color: primaryColor,
|
|
||||||
fontSize: 14,
|
|
||||||
fontFamily: fontPrimary,
|
|
||||||
fontWeight: 900
|
|
||||||
},
|
},
|
||||||
subtitle: {
|
subtitle: {
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { Box } from '@material-ui/core'
|
||||||
import { makeStyles } from '@material-ui/core/styles'
|
import { makeStyles } from '@material-ui/core/styles'
|
||||||
import { Formik, Form, Field } from 'formik'
|
import { Formik, Form, Field } from 'formik'
|
||||||
import * as R from 'ramda'
|
import * as R from 'ramda'
|
||||||
|
|
@ -57,7 +58,7 @@ const BlackListModal = ({
|
||||||
resetForm()
|
resetForm()
|
||||||
}}>
|
}}>
|
||||||
<Form id="address-form">
|
<Form id="address-form">
|
||||||
<H3>
|
<H3 className={classes.modalTitle}>
|
||||||
{selectedCoin.display
|
{selectedCoin.display
|
||||||
? `Blacklist ${R.toLower(selectedCoin.display)} address`
|
? `Blacklist ${R.toLower(selectedCoin.display)} address`
|
||||||
: ''}
|
: ''}
|
||||||
|
|
@ -74,9 +75,11 @@ const BlackListModal = ({
|
||||||
</Form>
|
</Form>
|
||||||
</Formik>
|
</Formik>
|
||||||
<div className={classes.footer}>
|
<div className={classes.footer}>
|
||||||
<Link type="submit" form="address-form">
|
<Box display="flex" justifyContent="flex-end">
|
||||||
Blacklist address
|
<Link type="submit" form="address-form">
|
||||||
</Link>
|
Blacklist address
|
||||||
|
</Link>
|
||||||
|
</Box>
|
||||||
</div>
|
</div>
|
||||||
</Modal>
|
</Modal>
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue