settings & linting

pull/5370/head
filip mertens 3 years ago
parent 60fb5e6c25
commit fc20858d26
  1. 12
      libs/remix-core-plugin/src/lib/code-parser.ts
  2. 2
      libs/remix-core-plugin/src/lib/editor-context-listener.ts
  3. 1
      libs/remix-ui/settings/src/lib/constants.ts
  4. 20
      libs/remix-ui/settings/src/lib/remix-ui-settings.tsx
  5. 5
      libs/remix-ui/settings/src/lib/settingsAction.ts
  6. 15
      libs/remix-ui/settings/src/lib/settingsReducer.ts

@ -90,7 +90,7 @@ export class CodeParser extends Plugin {
if (data.errors) {
for (const error of data.errors) {
console.log('ERROR POS', error)
let pos = helper.getPositionDetails(error.formattedMessage)
const pos = helper.getPositionDetails(error.formattedMessage)
console.log('ERROR POS', pos)
const sources = result.getSourceCode().sources
const source = sources[pos.file]
@ -258,7 +258,7 @@ export class CodeParser extends Plugin {
*/
async listAstNodes() {
await this.getCurrentFileAST();
let nodes = [];
const nodes = [];
(SolidityParser as any).visit(this.currentFileAST, {
StateVariableDeclaration: (node) => {
if (node.variables) {
@ -403,7 +403,7 @@ export class CodeParser extends Plugin {
}
return nodeDefinition
} else {
let astNodes = await this.listAstNodes()
const astNodes = await this.listAstNodes()
for (const node of astNodes) {
if (node.range[0] <= position && node.range[1] >= position) {
if (nodeDefinition && nodeDefinition.range[0] < node.range[0]) {
@ -427,7 +427,7 @@ export class CodeParser extends Plugin {
* @returns
*/
async findIdentifier(identifierNode: any) {
let astNodes = await this.listAstNodes()
const astNodes = await this.listAstNodes()
for (const node of astNodes) {
if (node.name === identifierNode.name && node.nodeType !== 'Identifier') {
return node
@ -621,7 +621,7 @@ export class CodeParser extends Plugin {
* @returns
*/
async getFunctionParamaters(node: any) {
let localParam = (node.parameters && node.parameters.parameters) || (node.parameters)
const localParam = (node.parameters && node.parameters.parameters) || (node.parameters)
if (localParam) {
const params = []
for (const param of localParam) {
@ -637,7 +637,7 @@ export class CodeParser extends Plugin {
* @returns
*/
async getFunctionReturnParameters(node: any) {
let localParam = (node.returnParameters && node.returnParameters.parameters)
const localParam = (node.returnParameters && node.returnParameters.parameters)
if (localParam) {
const params = []
for (const param of localParam) {

@ -165,7 +165,7 @@ export class EditorContextListener extends Plugin {
async _highlightExpressions(node, compilationResult) {
const highlights = async (id) => {
let refs = await this.call('codeParser', 'getDeclaration', id)
const refs = await this.call('codeParser', 'getDeclaration', id)
if (refs) {
for (const ref in refs) {
const node = refs[ref]

@ -14,6 +14,7 @@ export const etherscanAccessTokenText2 = 'Go to Etherscan api key page (link bel
export const ethereunVMText = 'Always use Javascript VM at load'
export const wordWrapText = 'Word wrap in editor'
export const enablePersonalModeText = ' Enable Personal Mode for web3 provider. Transaction sent over Web3 will use the web3.personal API.\n'
export const useAutoCompleteText = 'Enable code completion in editor.'
export const matomoAnalytics = 'Enable Matomo Analytics. We do not collect personally identifiable information (PII). The info is used to improve the site’s UX & UI. See more about '
export const swarmSettingsTitle = 'Swarm Settings'
export const swarmSettingsText = 'Swarm Settings'

@ -1,10 +1,10 @@
import React, { useState, useReducer, useEffect, useCallback } from 'react' // eslint-disable-line
import { CopyToClipboard } from '@remix-ui/clipboard' // eslint-disable-line
import { enablePersonalModeText, ethereunVMText, labels, generateContractMetadataText, matomoAnalytics, textDark, textSecondary, warnText, wordWrapText, swarmSettingsTitle, ipfsSettingsText } from './constants'
import { enablePersonalModeText, ethereunVMText, labels, generateContractMetadataText, matomoAnalytics, textDark, textSecondary, warnText, wordWrapText, swarmSettingsTitle, ipfsSettingsText, useAutoCompleteText } from './constants'
import './remix-ui-settings.css'
import { ethereumVM, generateContractMetadat, personal, textWrapEventAction, useMatomoAnalytics, saveTokenToast, removeTokenToast, saveSwarmSettingsToast, saveIpfsSettingsToast } from './settingsAction'
import { ethereumVM, generateContractMetadat, personal, textWrapEventAction, useMatomoAnalytics, saveTokenToast, removeTokenToast, saveSwarmSettingsToast, saveIpfsSettingsToast, useAutoCompletion } from './settingsAction'
import { initialState, toastInitialState, toastReducer, settingReducer } from './settingsReducer'
import { Toaster } from '@remix-ui/toaster'// eslint-disable-line
import { RemixUiThemeModule, ThemeModule } from '@remix-ui/theme-module'
@ -32,13 +32,15 @@ export const RemixUiSettings = (props: RemixUiSettingsProps) => {
const [ipfsProjectId, setipfsProjectId] = useState('')
const [ipfsProjectSecret, setipfsProjectSecret] = useState('')
const initValue = () => {
const metadataConfig = props.config.get('settings/generate-contract-metadata')
if (metadataConfig === undefined || metadataConfig === null) generateContractMetadat(props.config, true, dispatch)
const javascriptVM = props.config.get('settings/always-use-vm')
if (javascriptVM === null || javascriptVM === undefined) ethereumVM(props.config, true, dispatch)
const useAutoComplete = props.config.get('settings/use-auto-complete')
if (useAutoComplete === null || useAutoComplete === undefined) useAutoCompletion(props.config, true, dispatch)
}
useEffect(() => initValue(), [resetState, props.config])
useEffect(() => initValue(), [])
@ -87,7 +89,6 @@ export const RemixUiSettings = (props: RemixUiSettingsProps) => {
setipfsProjectSecret(configipfsProjectSecret)
}
}, [themeName, state.message])
useEffect(() => {
@ -114,6 +115,10 @@ export const RemixUiSettings = (props: RemixUiSettingsProps) => {
useMatomoAnalytics(props.config, event.target.checked, dispatch)
}
const onchangeUseAutoComplete = event => {
useAutoCompletion(props.config, event.target.checked, dispatch)
}
const getTextClass = (key) => {
if (props.config.get(key)) {
return textDark
@ -128,6 +133,7 @@ export const RemixUiSettings = (props: RemixUiSettingsProps) => {
const isEditorWrapChecked = props.config.get('settings/text-wrap') || false
const isPersonalChecked = props.config.get('settings/personal-mode') || false
const isMatomoChecked = props.config.get('settings/matomo-analytics') || false
const isAutoCompleteChecked = props.config.get('settings/auto-completion') === null ? true:props.config.get('settings/auto-completion')
return (
<div className="$border-top">
@ -164,6 +170,12 @@ export const RemixUiSettings = (props: RemixUiSettingsProps) => {
<input id="editorWrap" className="custom-control-input" type="checkbox" onChange={textWrapEvent} checked={isEditorWrapChecked} />
<label className={`form-check-label custom-control-label align-middle ${getTextClass('settings/text-wrap')}`} htmlFor="editorWrap">{wordWrapText}</label>
</div>
<div className='custom-control custom-checkbox mb-1'>
<input onChange={onchangeUseAutoComplete} id="settingsUseAutoComplete" type="checkbox" className="custom-control-input" checked={isAutoCompleteChecked} />
<label className={`form-check-label custom-control-label align-middle ${getTextClass('settings/use-auto-complete')}`} htmlFor="settingsUseAutoComplete">
<span>{useAutoCompleteText}</span>
</label>
</div>
<div className="custom-control custom-checkbox mb-1">
<input onChange={onchangePersonal} id="personal" type="checkbox" className="custom-control-input" checked={isPersonalChecked} />
<label className={`form-check-label custom-control-label align-middle ${getTextClass('settings/personal-mode')}`} htmlFor="personal">

@ -41,6 +41,11 @@ export const useMatomoAnalytics = (config, checked, dispatch) => {
}
}
export const useAutoCompletion = (config, checked, dispatch) => {
config.set('settings/auto-completion', checked)
dispatch({ type: 'useAutoCompletion', payload: { isChecked: checked, textClass: checked ? textDark : textSecondary } })
}
export const saveTokenToast = (config, dispatch, tokenValue, key) => {
config.set('settings/' + key, tokenValue)
dispatch({ type: 'save', payload: { message: 'Access token has been saved' } })

@ -26,6 +26,11 @@ export const initialState = {
name: 'useMatomoAnalytics',
isChecked: false,
textClass: textSecondary
},
{
name: 'useAutoCompletion',
isChecked: true,
textClass: textSecondary
}
]
}
@ -82,6 +87,16 @@ export const settingReducer = (state, action) => {
return {
...state
}
case 'useAutoCompletion':
state.elementState.map(element => {
if (element.name === 'useAutoCompletion') {
element.isChecked = action.payload.isChecked
element.textClass = action.payload.textClass
}
})
return {
...state
}
default:
return initialState
}

Loading…
Cancel
Save