Skip to content

Commit

Permalink
Feat/ricardian contract params and styles adjustments (#91)
Browse files Browse the repository at this point in the history
* feat(webapp): pass params to abi and actions urls in ricardian contract

* chore(webapp): add spacing to BP Json Generator

* chore(webapp): adjust styles of the add node modal

* chore(webapp): bp.json generator styles adjustments

* chore(webapp): update dependencies with no breaking changes

* fix(webapp): fix bug when a wrong file is upload and improve error modal

* feat(webapp): pass additional nodes types as params

* feat(webapp): allow to insert a custom feature in a node

* fix(webapp): fix error when try to insert features

* chore(webapp): update dependencies with no breaking changes

* chore(webapp): remove unneeded validation
  • Loading branch information
Torresmorah authored Nov 30, 2023
1 parent 2e31556 commit 74c82ec
Show file tree
Hide file tree
Showing 15 changed files with 3,565 additions and 2,948 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"clsx": "^1.1.1",
"clsx": "^2.0.0",
"crypto-js": "^4.1.1",
"eosjs": "^22.1.0",
"eosjs-api": "^7.0.4",
"js-file-download": "^0.4.12",
"prop-types": "^15.7.2",
"react-dropzone": "^11.4.2",
"react-file-download": "^0.3.5",
"react-google-recaptcha": "^2.1.0",
"react-identicons": "^1.2.5",
"react-image-file-resizer": "^0.4.8",
Expand Down Expand Up @@ -84,6 +84,7 @@
"@babel/cli": "^7.15.4",
"@babel/core": "^7.15.5",
"@babel/plugin-proposal-optional-chaining": "^7.14.5",
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
"@babel/preset-env": "^7.15.6",
"@babel/preset-react": "^7.14.5",
"@eoscostarica/eoscr-theme": "^1.0.3",
Expand Down
17 changes: 11 additions & 6 deletions src/lib/BPJsonGenerator/BoxDropzone.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,33 +24,38 @@ const Dropzone = ({ onSubmit }) => {
const reader = new FileReader()

reader.onload = (e) => {

if (acceptedFiles[0] !== lastFile) {
try {
onSubmit(JSON.parse(e.target.result))
setLastFile(acceptedFiles[0])
} catch (error) {
setErrorMessage(error instanceof SyntaxError ? "The file does not have the correct JSON format" : error.message)
setErrorMessage(
error instanceof SyntaxError
? 'The file does not have the correct JSON format'
: error.message
)
setOpenModal(true)
onSubmit({})
} finally {
setLastFile(acceptedFiles[0])
}
}
}
reader.readAsText(acceptedFiles[0])

}, [acceptedFiles, lastFile, onSubmit])

return (
<>
<section>
<div {...getRootProps({ className: classes.dropzoneArea })}>
<input {...getInputProps()} />
<p>Drop your BP json file here</p>
<p>Drop your BP.json file here</p>
</div>
</section>
<ErrorModal
openModal={openModal}
setOpenModal={(value) => setOpenModal(value)}
message={errorMessage} />
message={errorMessage}
/>
</>
)
}
Expand Down
28 changes: 14 additions & 14 deletions src/lib/BPJsonGenerator/EndpointsForm.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
import React from 'react'
import PropTypes from 'prop-types'
import { makeStyles } from '@mui/styles'
import Divider from '@mui/material/Divider'
import TextField from '@mui/material/TextField'
import Typography from '@mui/material/Typography'

import { Validator, NODE_TYPES, NODE_EXTRA_KEYS } from '../utils'
import { Validator } from '../utils'

import Styles from './styles'

const useStyles = makeStyles(Styles)
const { hostValidation, urlInputValidation } = Validator
const EndpointsForm = ({ currentNode, handleOnChange }) => {
const EndpointsForm = ({ currentNode, nodesKeys, handleOnChange }) => {
const classes = useStyles()
if (currentNode.node_type === NODE_TYPES.PRODUCER || currentNode.node_type === '') {
if (!nodesKeys[currentNode.node_type]) {
return <></>
}

return (
<>
<Typography
className={classes.sectionTitle}
variant="h5"
>
<div className={classes.wrapperForm}>
<Typography className={classes.sectionTitle} variant="h5">
Endpoints
</Typography>
{(NODE_EXTRA_KEYS[currentNode.node_type]?.indexOf('p2p_endpoint') > -1) && (
<Divider className={classes.divider} />
{nodesKeys[currentNode.node_type]?.indexOf('p2p_endpoint') > -1 && (
<TextField
onChange={(e) => handleOnChange('p2p_endpoint', e.target.value)}
variant="outlined"
Expand All @@ -37,7 +36,7 @@ const EndpointsForm = ({ currentNode, handleOnChange }) => {
className={classes.formFieldForm}
/>
)}
{(NODE_EXTRA_KEYS[currentNode.node_type]?.indexOf('api_endpoint') > -1) && (
{nodesKeys[currentNode.node_type]?.indexOf('api_endpoint') > -1 && (
<TextField
onChange={(e) => handleOnChange('api_endpoint', e.target.value)}
variant="outlined"
Expand All @@ -50,7 +49,7 @@ const EndpointsForm = ({ currentNode, handleOnChange }) => {
className={classes.formFieldForm}
/>
)}
{((NODE_EXTRA_KEYS[currentNode.node_type]?.indexOf('ssl_endpoint') > -1) &&
{nodesKeys[currentNode.node_type]?.indexOf('ssl_endpoint') > -1 && (
<TextField
onChange={(e) => handleOnChange('ssl_endpoint', e.target.value)}
variant="outlined"
Expand All @@ -63,13 +62,14 @@ const EndpointsForm = ({ currentNode, handleOnChange }) => {
className={classes.formFieldForm}
/>
)}
</>
</div>
)
}

EndpointsForm.propTypes = {
currentNode: PropTypes.object,
handleOnChange: PropTypes.func,
nodesKeys: PropTypes.object,
handleOnChange: PropTypes.func
}

export default EndpointsForm
export default EndpointsForm
37 changes: 27 additions & 10 deletions src/lib/BPJsonGenerator/ErrorModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import React from 'react'
import { makeStyles } from '@mui/styles'
import Typography from '@mui/material/Typography'
import Grid from '@mui/material/Grid'
import Button from '@mui/material/Button'
import ReportIcon from '@mui/icons-material/Report'

import Modal from './Modal'
import Styles from './styles'
Expand All @@ -13,18 +15,33 @@ const ErrorModal = ({ openModal, setOpenModal, message }) => {

return (
<Modal openModal={openModal} setOpenModal={(value) => setOpenModal(value)}>
<Grid container justify="center" className={classes.nodes}>
<Grid>
<Typography className={classes.sectionTitle} variant="h3">
Error
</Typography>
<Typography variant="h5">
{message}
</Typography>
</Grid>
<Grid
container
flexDirection="column"
justify="center"
alignItems="center"
className={classes.nodes}
>
<ReportIcon className={classes.iconError} />
<Typography className={classes.sectionTitle} variant="h4" component="p">
Error
</Typography>
<Typography variant="h6" component="p">
{message}
</Typography>
<Button
variant="contained"
color="primary"
className={classes.addButton}
onClick={() => {
setOpenModal(false)
}}
>
{'OK'}
</Button>
</Grid>
</Modal>
)
}

export default ErrorModal
export default ErrorModal
138 changes: 42 additions & 96 deletions src/lib/BPJsonGenerator/FeaturesForm.js
Original file line number Diff line number Diff line change
@@ -1,125 +1,71 @@
import React from 'react'
import PropTypes from 'prop-types'
import { makeStyles } from '@mui/styles'
import Checkbox from '@mui/material/Checkbox'
import Chip from '@mui/material/Chip'
import MenuItem from '@mui/material/MenuItem'
import ListItemText from '@mui/material/ListItemText'
import Autocomplete, { createFilterOptions } from '@mui/material/Autocomplete'
import Divider from '@mui/material/Divider'
import TextField from '@mui/material/TextField'
import Typography from '@mui/material/Typography'

import { NODE_EXTRA_KEYS } from '../utils'
import { NODE_FEATURES } from '../utils'

import Styles from './styles'

const useStyles = makeStyles(Styles)

const features = [
{
label: 'chain-api',
value: 'chain-api',
info: 'basic eosio::chain_api_plugin (/v1/chain/*)'
},
{
label: 'account-query',
value: 'account-query',
info: '(/v1/chain/get_accounts_by_authorizers)'
},
{
label: 'history-v1',
value: 'history-v1',
info: '(/v1/history/*)'
},
{
label: 'hyperion-v2',
value: 'hyperion-v2',
info: '(/v2/*)'
},
{
label: 'dfuse',
value: 'dfuse',
info: ''
},
{
label: 'fio-api',
value: 'fio-api',
info: ''
},
{
label: 'snapshot-api',
value: 'snapshot-api',
info: ''
},
{
label: 'dsp-api',
value: 'dsp-api',
info: ''
},
{
label: 'atomic-assets-api',
value: 'atomic-assets-api',
info: '',
}
]
const filter = createFilterOptions()

const FeaturesForm = ({ currentNode, handleOnChange }) => {
const FeaturesForm = ({ currentNode, nodesKeys, handleOnChange }) => {
const classes = useStyles()

if (!(NODE_EXTRA_KEYS[currentNode.node_type]?.indexOf('features') > -1)) {
if (!(nodesKeys[currentNode.node_type]?.indexOf('features') > -1)) {
return <></>
}

return (
<>
<Typography
className={classes.sectionTitle}
variant="h5"
>
<div className={classes.wrapperForm}>
<Typography className={classes.sectionTitle} variant="h5">
Features
</Typography>
<TextField
onChange={handleOnChange}
<Divider className={classes.divider} />
<Autocomplete
multiple
variant="outlined"
label="Node Features"
select
SelectProps={{
multiple: true,
classes: {
root: currentNode.features?.length ? classes.selectChips : ''
},
renderValue: (selected) => (
<div className={classes.chips}>
{selected.map((value, index) => (
<Chip
key={`chip-item-${index}`}
label={value}
className={classes.chip}
/>
))}
</div>
)
}}
options={NODE_FEATURES}
onChange={handleOnChange}
value={currentNode.features || []}
className={classes.formFieldForm}
>
{features.map((option, index) => (
<MenuItem key={`menu-item-${index}`} value={option.value}>
<Checkbox
checked={
(currentNode.features || []).indexOf(option.value) > -1
}
/>
<ListItemText primary={option.label} />
</MenuItem>
))}
</TextField>
</>
defaultValue={currentNode.features || []}
filterOptions={(options, params) => {
const filtered = filter(options, params)

if (params.inputValue !== '') {
filtered.push({
label: params.inputValue,
value: params.inputValue,
info: ''
})
}

return filtered
}}
getOptionLabel={(option) => {
if (typeof option === 'string') return option

if (option.inputValue) return option.inputValue

return option.label
}}
renderInput={(params) => (
<TextField {...params} variant="outlined" label="Node Features" />
)}
/>
</div>
)
}

FeaturesForm.propTypes = {
currentNode: PropTypes.object,
handleOnChange: PropTypes.func,
nodesKeys: PropTypes.object,
handleOnChange: PropTypes.func
}

export default FeaturesForm
export default FeaturesForm
Loading

0 comments on commit 74c82ec

Please sign in to comment.