Merge pull request #1105 from chaotixkilla/fix-ciphertrace-threshold-value

Add error messages to all 3rd party services
This commit is contained in:
Rafael Taranto 2022-02-14 15:43:29 +00:00 committed by GitHub
commit 5a63a89c27
15 changed files with 160 additions and 127 deletions

View file

@ -4,12 +4,19 @@ import { Formik, Form, FastField } from 'formik'
import * as R from 'ramda' import * as R from 'ramda'
import React from 'react' import React from 'react'
import ErrorMessage from 'src/components/ErrorMessage'
import { Button } from 'src/components/buttons' import { Button } from 'src/components/buttons'
import { SecretInput } from 'src/components/inputs/formik' import { SecretInput } from 'src/components/inputs/formik'
import { spacer } from 'src/styling/variables'
const styles = { const styles = {
footer: {
display: 'flex',
flexDirection: 'row',
margin: [['auto', 0, spacer * 4, 0]]
},
button: { button: {
margin: [['auto', 0, 32, 'auto']] margin: [['auto', 0, 0, 'auto']]
}, },
form: { form: {
flex: 1, flex: 1,
@ -61,29 +68,36 @@ const FormRenderer = ({
initialValues={values} initialValues={values}
validationSchema={validationSchema} validationSchema={validationSchema}
onSubmit={saveNonEmptySecret}> onSubmit={saveNonEmptySecret}>
<Form className={classes.form}> {({ errors }) => (
<Grid container spacing={3} className={classes.grid}> <Form className={classes.form}>
{elements.map( <Grid container spacing={3} className={classes.grid}>
({ component, code, display, settings, inputProps }) => ( {elements.map(
<Grid item xs={xs} key={code}> ({ component, code, display, settings, inputProps }) => (
<FastField <Grid item xs={xs} key={code}>
component={component} <FastField
{...inputProps} component={component}
name={code} {...inputProps}
label={display} name={code}
settings={settings} label={display}
fullWidth={true} settings={settings}
/> fullWidth={true}
</Grid> />
) </Grid>
)} )
</Grid> )}
<Button </Grid>
className={classnames(classes.button, buttonClass)} <div className={classes.footer}>
type="submit"> {!R.isEmpty(errors) && (
{buttonLabel} <ErrorMessage>{R.head(R.values(errors))}</ErrorMessage>
</Button> )}
</Form> <Button
className={classnames(classes.button, buttonClass)}
type="submit">
{buttonLabel}
</Button>
</div>
</Form>
)}
</Formik> </Formik>
) )
} }

View file

@ -119,7 +119,7 @@ const Services = () => {
{editingSchema && ( {editingSchema && (
<Modal <Modal
title={`Edit ${editingSchema.name}`} title={`Edit ${editingSchema.name}`}
width={478} width={525}
handleClose={() => setEditingSchema(null)} handleClose={() => setEditingSchema(null)}
open={true}> open={true}>
<FormRenderer <FormRenderer

View file

@ -25,11 +25,11 @@ export default {
], ],
getValidationSchema: account => { getValidationSchema: account => {
return Yup.object().shape({ return Yup.object().shape({
apiKey: Yup.string() apiKey: Yup.string('The API key must be a string')
.max(100, 'Too long') .max(100, 'The API key is too long')
.required(), .required('The API key is required'),
privateKey: Yup.string() privateKey: Yup.string('The private key must be a string')
.max(100, 'Too long') .max(100, 'The private key is too long')
.test(secretTest(account?.privateKey)) .test(secretTest(account?.privateKey))
}) })
} }

View file

@ -98,37 +98,52 @@ export default {
], ],
getValidationSchema: account => { getValidationSchema: account => {
return Yup.object().shape({ return Yup.object().shape({
token: Yup.string() token: Yup.string('The token must be a string')
.max(100, 'Too long') .max(100, 'The token is too long')
.required(), .required('The token is required'),
BTCWalletId: Yup.string().max(100, 'Too long'), BTCWalletId: Yup.string('The BTC wallet ID must be a string').max(
100,
'The BTC wallet ID is too long'
),
BTCWalletPassphrase: buildTestValidation( BTCWalletPassphrase: buildTestValidation(
'BTCWalletId', 'BTCWalletId',
account?.BTCWalletPassphrase account?.BTCWalletPassphrase
), ),
LTCWalletId: Yup.string().max(100, 'Too long'), LTCWalletId: Yup.string('The LTC wallet ID must be a string').max(
100,
'The LTC wallet ID is too long'
),
LTCWalletPassphrase: buildTestValidation( LTCWalletPassphrase: buildTestValidation(
'LTCWalletId', 'LTCWalletId',
account?.LTCWalletPassphrase account?.LTCWalletPassphrase
), ),
ZECWalletId: Yup.string().max(100, 'Too long'), ZECWalletId: Yup.string('The ZEC wallet ID must be a string').max(
100,
'The ZEC wallet ID is too long'
),
ZECWalletPassphrase: buildTestValidation( ZECWalletPassphrase: buildTestValidation(
'ZECWalletId', 'ZECWalletId',
account?.ZECWalletPassphrase account?.ZECWalletPassphrase
), ),
BCHWalletId: Yup.string().max(100, 'Too long'), BCHWalletId: Yup.string('The BCH wallet ID must be a string').max(
100,
'The BCH wallet ID is too long'
),
BCHWalletPassphrase: buildTestValidation( BCHWalletPassphrase: buildTestValidation(
'BCHWalletId', 'BCHWalletId',
account?.BCHWalletPassphrase account?.BCHWalletPassphrase
), ),
DASHWalletId: Yup.string().max(100, 'Too long'), DASHWalletId: Yup.string('The DASH wallet ID must be a string').max(
100,
'The DASH wallet ID is too long'
),
DASHWalletPassphrase: buildTestValidation( DASHWalletPassphrase: buildTestValidation(
'DASHWalletId', 'DASHWalletId',
account?.DASHWalletPassphrase account?.DASHWalletPassphrase
), ),
environment: Yup.string() environment: Yup.string('The environment must be a string')
.matches(/(prod|test)/) .matches(/(prod|test)/)
.required() .required('The environment is required')
}) })
} }
} }

View file

@ -32,14 +32,14 @@ export default {
], ],
getValidationSchema: account => { getValidationSchema: account => {
return Yup.object().shape({ return Yup.object().shape({
clientId: Yup.string() clientId: Yup.string('The client ID must be a string')
.max(100, 'Too long') .max(100, 'The client ID is too long')
.required(), .required('The client ID is required'),
key: Yup.string() key: Yup.string('The key must be a string')
.max(100, 'Too long') .max(100, 'The key is too long')
.required(), .required('The key is required'),
secret: Yup.string() secret: Yup.string('The secret must be a string')
.max(100, 'Too long') .max(100, 'The secret is too long')
.test(secretTest(account?.secret)) .test(secretTest(account?.secret))
}) })
} }

View file

@ -38,13 +38,13 @@ export default {
], ],
getValidationSchema: () => { getValidationSchema: () => {
return Yup.object().shape({ return Yup.object().shape({
token: Yup.string() token: Yup.string('The token must be a string')
.max(100, 'Too long') .max(100, 'The token is too long')
.required(), .required('The token is required'),
confidenceFactor: Yup.number() confidenceFactor: Yup.number('The confidence factor must be a number')
.integer('Please input a positive integer') .integer('The confidence factor must be an integer')
.positive('Please input a positive integer') .positive('The confidence factor must be positive')
.required() .required('The confidence factor is required')
}) })
} }
} }

View file

@ -25,11 +25,11 @@ export default {
], ],
getValidationSchema: account => { getValidationSchema: account => {
return Yup.object().shape({ return Yup.object().shape({
apiKey: Yup.string() apiKey: Yup.string('The API key must be a string')
.max(100, 'Too long') .max(100, 'The API key is too long')
.required(), .required('The API key is required'),
privateKey: Yup.string() privateKey: Yup.string('The private key must be a string')
.max(100, 'Too long') .max(100, 'The private key is too long')
.test(secretTest(account?.privateKey)) .test(secretTest(account?.privateKey))
}) })
} }

View file

@ -37,10 +37,12 @@ export default {
], ],
getValidationSchema: account => { getValidationSchema: account => {
return Yup.object().shape({ return Yup.object().shape({
authorizationValue: Yup.string() authorizationValue: Yup.string('The score threshold must be a string')
.required('The authorization value is required')
.max(100, 'Too long') .max(100, 'Too long')
.test(secretTest(account?.authorizationValue)), .test(secretTest(account?.authorizationValue)),
scoreThreshold: Yup.number() scoreThreshold: Yup.number('The score threshold must be a number')
.required('A score threshold is required')
.min(1, 'The number should be between 1 and 10') .min(1, 'The number should be between 1 and 10')
.max(10, 'The number should be between 1 and 10') .max(10, 'The number should be between 1 and 10')
.test(secretTest(account?.scoreThreshold)) .test(secretTest(account?.scoreThreshold))

View file

@ -25,11 +25,11 @@ export default {
], ],
getValidationSchema: account => { getValidationSchema: account => {
return Yup.object().shape({ return Yup.object().shape({
apiKey: Yup.string() apiKey: Yup.string('The API key must be a string')
.max(100, 'Too long') .max(100, 'The API key is too long')
.required(), .required('The API key is required'),
privateKey: Yup.string() privateKey: Yup.string('The private key must be a string')
.max(100, 'Too long') .max(100, 'The private key is too long')
.test(secretTest(account?.privateKey)) .test(secretTest(account?.privateKey))
}) })
} }

View file

@ -31,15 +31,15 @@ export default {
], ],
getValidationSchema: account => { getValidationSchema: account => {
return Yup.object().shape({ return Yup.object().shape({
apiKey: Yup.string() apiKey: Yup.string('The API key must be a string')
.max(100, 'Too long') .max(100, 'The API key is too long')
.required(), .required('The API key is required'),
apiSecret: Yup.string() apiSecret: Yup.string('The API secret must be a string')
.max(100, 'Too long') .max(100, 'The API secret is too long')
.test(secretTest(account?.apiSecret)), .test(secretTest(account?.apiSecret)),
endpoint: Yup.string() endpoint: Yup.string('The endpoint must be a string')
.max(100, 'Too long') .max(100, 'The endpoint is too long')
.required() .required('The endpoint is required')
}) })
} }
} }

View file

@ -37,17 +37,17 @@ export default {
], ],
getValidationSchema: account => { getValidationSchema: account => {
return Yup.object().shape({ return Yup.object().shape({
userId: Yup.string() userId: Yup.string('The user ID must be a string')
.max(100, 'Too long') .max(100, 'The user ID is too long')
.required(), .required('The user ID is required'),
walletId: Yup.string() walletId: Yup.string('The wallet ID must be a string')
.max(100, 'Too long') .max(100, 'The wallet ID is too long')
.required(), .required('The wallet ID is required'),
clientKey: Yup.string() clientKey: Yup.string('The client key must be a string')
.max(100, 'Too long') .max(100, 'The client key is too long')
.required(), .required('The client key is required'),
clientSecret: Yup.string() clientSecret: Yup.string('The client secret must be a string')
.max(100, 'Too long') .max(100, 'The client secret is too long')
.test(secretTest(account?.clientSecret)) .test(secretTest(account?.clientSecret))
}) })
} }

View file

@ -25,11 +25,11 @@ export default {
], ],
getValidationSchema: account => { getValidationSchema: account => {
return Yup.object().shape({ return Yup.object().shape({
apiKey: Yup.string() apiKey: Yup.string('The API key must be a string')
.max(100, 'Too long') .max(100, 'The API key is too long')
.required(), .required('The API key is required'),
privateKey: Yup.string() privateKey: Yup.string('The private key must be a string')
.max(100, 'Too long') .max(100, 'The private key is too long')
.test(secretTest(account?.privateKey)) .test(secretTest(account?.privateKey))
}) })
} }

View file

@ -32,20 +32,20 @@ export default {
], ],
getValidationSchema: () => { getValidationSchema: () => {
return Yup.object().shape({ return Yup.object().shape({
apiKey: Yup.string() apiKey: Yup.string('The API key must be a string')
.max(100, 'Too long') .max(100, 'The API key is too long')
.required(), .required('The API key is required'),
domain: Yup.string() domain: Yup.string('The domain must be a string')
.max(100, 'Too long') .max(100, 'The domain is too long')
.required(), .required('The domain is required'),
fromEmail: Yup.string() fromEmail: Yup.string('The from email must be a string')
.max(100, 'Too long') .max(100, 'The from email is too long')
.email('Please input a valid email address') .email('The from email must be a valid email address')
.required(), .required('The from email is required'),
toEmail: Yup.string() toEmail: Yup.string('The to email must be a string')
.max(100, 'Too long') .max(100, 'The to email is too long')
.email('Please input a valid email address') .email('The to email must be a valid email address')
.required() .required('The to email is required')
}) })
} }
} }

View file

@ -44,18 +44,20 @@ const singleBitgo = code => ({
} }
], ],
validationSchema: Yup.object().shape({ validationSchema: Yup.object().shape({
token: Yup.string() token: Yup.string('The token must be a string')
.max(100, 'Too long') .max(100, 'The token is too long')
.required(), .required('The token is required'),
environment: Yup.string() environment: Yup.string('The environment must be a string')
.matches(/(prod|test)/) .matches(/(prod|test)/)
.required(), .required('The environment is required'),
[`${code}WalletId`]: Yup.string() [`${code}WalletId`]: Yup.string(`The ${code} wallet ID must be a string`)
.max(100, 'Too long') .max(100, `The ${code} wallet ID is too long`)
.required(), .required(`The ${code} wallet ID is required`),
[`${code}WalletPassphrase`]: Yup.string() [`${code}WalletPassphrase`]: Yup.string(
.max(100, 'Too long') `The ${code} passphrase must be a string`
.required() )
.max(100, `The ${code} wallet passphrase is too long`)
.required(`The ${code} wallet passphrase is required`)
}) })
}) })

View file

@ -35,18 +35,18 @@ export default {
], ],
getValidationSchema: account => { getValidationSchema: account => {
return Yup.object().shape({ return Yup.object().shape({
accountSid: Yup.string() accountSid: Yup.string('The account SID must be a string')
.max(100, 'Too long') .max(100, 'The account SID is too long')
.required(), .required('The account SID is required'),
authToken: Yup.string() authToken: Yup.string('The auth token must be a string')
.max(100, 'Too long') .max(100, 'The auth token is too long')
.test(secretTest(account?.authToken)), .test(secretTest(account?.authToken)),
fromNumber: Yup.string() fromNumber: Yup.string('The from number must be a string')
.max(100, 'Too long') .max(100, 'The from number is too long')
.required(), .required('The from number is required'),
toNumber: Yup.string() toNumber: Yup.string('The to number must be a string')
.max(100, 'Too long') .max(100, 'The to number is too long')
.required() .required('The to number is required')
}) })
} }
} }