async await modal

undo compiler

unde compiler

undo coompiler
awaitasyncmodals
bunsenstraat 3 years ago
parent bb960ab1df
commit 2b4e753b0e
  1. 4
      apps/remix-ide/src/app/plugins/modal.tsx
  2. 26
      apps/remix-ide/src/app/plugins/remixd-handle.tsx
  3. 25
      libs/remix-ui/app/src/lib/remix-app/components/modals/modal-wrapper.tsx
  4. 10
      libs/remix-ui/app/src/lib/remix-app/context/provider.tsx
  5. 7
      libs/remix-ui/app/src/lib/remix-app/interface/index.ts
  6. 6
      libs/remix-ui/app/src/lib/remix-app/reducer/modals.ts
  7. 3
      libs/remix-ui/modal-dialog/src/lib/types/index.ts
  8. 7
      libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx

@ -31,11 +31,11 @@ export class ModalPlugin extends Plugin implements MethodApi<IModalApi> {
}
async modal (args: AppModal) {
this.dispatcher.modal(args)
return this.dispatcher.modal(args)
}
async alert (args: AlertModal) {
this.dispatcher.alert(args)
return this.dispatcher.alert(args)
}
async toast (message: string) {

@ -30,7 +30,6 @@ enum State {
export class RemixdHandle extends WebsocketPlugin {
localhostProvider: any
appManager: PluginManager
state: State
constructor (localhostProvider, appManager) {
super(profile)
this.localhostProvider = localhostProvider
@ -48,7 +47,8 @@ export class RemixdHandle extends WebsocketPlugin {
}
async activate () {
await this.connectToLocalhost()
this.connectToLocalhost()
return true
}
async canceled () {
@ -95,13 +95,15 @@ export class RemixdHandle extends WebsocketPlugin {
this.deactivate()
} else if (!isElectron()) {
// warn the user only if he/she is in the browser context
this.state = State.new
const mod:AppModal = {
id: 'remixdConnect',
title: 'Connect to localhost',
message: remixdDialog(),
okFn: () => {
this.state = State.ok
okLabel: 'Connect',
cancelLabel: 'Cancel',
}
const result = await this.call('modal', 'modal', mod)
if(result) {
try {
this.localhostProvider.preInit()
super.activate()
@ -115,18 +117,10 @@ export class RemixdHandle extends WebsocketPlugin {
} catch (error) {
connection(error)
}
},
cancelFn: async () => {
this.state = State.cancel
await this.canceled()
},
okLabel: 'Connect',
cancelLabel: 'Cancel',
hideFn: async () => {
if (this.state === State.new) await this.canceled()
}
}
await this.call('modal', 'modal', mod)
else {
await this.canceled()
}
} else {
try {
super.activate()

@ -14,13 +14,21 @@ const ModalWrapper = (props: ModalWrapperProps) => {
const onFinishPrompt = async () => {
if (ref.current === undefined) {
props.okFn()
onOkFn()
} else {
// @ts-ignore: Object is possibly 'null'.
props.okFn(ref.current.value)
(props.resolve) ? props.resolve(ref.current.value) : props.okFn(ref.current.value)
}
}
const onOkFn = async () => {
(props.resolve) ? props.resolve(true) : props.okFn()
}
const onCancelFn = async () => {
(props.resolve) ? props.resolve(false) : props.cancelFn()
}
const createModalMessage = (defaultValue: string) => {
return (
<>
@ -37,15 +45,24 @@ const ModalWrapper = (props: ModalWrapperProps) => {
setState({
...props,
okFn: onFinishPrompt,
cancelFn: onCancelFn,
message: createModalMessage(props.defaultValue)
})
break
default:
setState({ ...props })
setState({
...props,
okFn: (onOkFn),
cancelFn: onCancelFn
})
break
}
} else {
setState({ ...props })
setState({
...props,
okFn: onOkFn,
cancelFn: onCancelFn
})
}
}, [props])

@ -11,14 +11,16 @@ export const ModalProvider = ({ children = [], reducer = modalReducer, initialSt
const modal = (data: AppModal) => {
const { id, title, message, okLabel, okFn, cancelLabel, cancelFn, modalType, defaultValue, hideFn } = data
dispatch({
type: modalActionTypes.setModal,
payload: { id, title, message, okLabel, okFn, cancelLabel, cancelFn, modalType: modalType || ModalTypes.default, defaultValue: defaultValue, hideFn }
return new Promise((resolve, reject) => {
dispatch({
type: modalActionTypes.setModal,
payload: { id, title, message, okLabel, okFn, cancelLabel, cancelFn, modalType: modalType || ModalTypes.default, defaultValue: defaultValue, hideFn, resolve }
})
})
}
const alert = (data: AlertModal) => {
modal({ id: data.id, title: data.title || 'Alert', message: data.message || data.title, okLabel: 'OK', okFn: (value?:any) => {}, cancelLabel: '', cancelFn: () => {} })
return modal({ id: data.id, title: data.title || 'Alert', message: data.message || data.title, okLabel: 'OK', okFn: (value?:any) => {}, cancelLabel: '', cancelFn: () => {} })
}
const handleHideModal = () => {

@ -7,12 +7,13 @@ export interface AppModal {
// eslint-disable-next-line no-undef
message: string | JSX.Element
okLabel: string
okFn: (value?:any) => void
okFn?: (value?:any) => void
cancelLabel: string
cancelFn: () => void,
cancelFn?: () => void,
modalType?: ModalTypes,
defaultValue?: string
hideFn?: () => void
hideFn?: () => void,
resolve?: (value?:any) => void
}
export interface AlertModal {

@ -19,7 +19,8 @@ export const modalReducer = (state: ModalState = ModalInitialState, action: Moda
cancelFn: modalList[0].cancelFn,
modalType: modalList[0].modalType,
defaultValue: modalList[0].defaultValue,
hideFn: modalList[0].hideFn
hideFn: modalList[0].hideFn,
resolve: modalList[0].resolve
}
modalList = modalList.slice()
@ -29,6 +30,9 @@ export const modalReducer = (state: ModalState = ModalInitialState, action: Moda
return { ...state, modals: modalList }
}
case modalActionTypes.handleHideModal:
if (state.focusModal.resolve) {
state.focusModal.resolve(undefined)
} else
if (state.focusModal.hideFn) {
state.focusModal.hideFn()
}

@ -11,5 +11,6 @@ export interface ModalDialogProps {
showCancelIcon?: boolean,
hide?: boolean,
handleHide: (hideState?: boolean) => void,
children?: React.ReactNode
children?: React.ReactNode,
resolve?: (value?:any) => void,
}

@ -356,13 +356,12 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
return console.log('loading ' + selectedVersion + ' not allowed, version should start with "soljson"')
}
}
// Workers cannot load js on "file:"-URLs and we get a
// "Uncaught RangeError: Maximum call stack size exceeded" error on Chromium,
// resort to non-worker version in that case.
if (selectedVersion === 'builtin') {
selectedVersion = state.defaultVersion
compileTabLogic.compiler.loadVersion(false, url)
} else if (canUseWorker(selectedVersion)) {
if (selectedVersion === 'builtin') selectedVersion = state.defaultVersion
if (selectedVersion !== 'builtin' && canUseWorker(selectedVersion)) {
compileTabLogic.compiler.loadVersion(true, url)
} else {
compileTabLogic.compiler.loadVersion(false, url)

Loading…
Cancel
Save