Skip to content

Commit a76a14c

Browse files
authored
Merge pull request #1999 from ethereum/fix-parent
Use plugin calls for toaster and modal.
2 parents c58a252 + c21ec51 commit a76a14c

File tree

24 files changed

+228
-140
lines changed

24 files changed

+228
-140
lines changed

apps/remix-ide-e2e/src/local-plugin/src/app/app.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function App () {
3333

3434
useEffect(() => {
3535
client.onload(async () => {
36-
const customProfiles = ['menuicons', 'tabs', 'solidityUnitTesting', 'hardhat-provider']
36+
const customProfiles = ['menuicons', 'tabs', 'solidityUnitTesting', 'hardhat-provider', 'notification']
3737

3838
client.testCommand = async (data: any) => {
3939
console.log(data)

apps/remix-ide-e2e/src/tests/ballot.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ module.exports = {
8484
.openFile('Untitled.sol')
8585
.clickLaunchIcon('udapp')
8686
.click('*[data-id="settingsWeb3Mode"]')
87-
.waitForElementPresent('[data-id="udappNotify-modal-footer-ok-react"]')
87+
.waitForElementPresent('[data-id="envNotification-modal-footer-ok-react"]')
8888
.execute(function () {
89-
const modal = document.querySelector('[data-id="udappNotify-modal-footer-ok-react"]') as any
89+
const modal = document.querySelector('[data-id="envNotification-modal-footer-ok-react"]') as any
9090

9191
modal.click()
9292
})

apps/remix-ide-e2e/src/tests/ballot_0_4_11.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ module.exports = {
7979
.openFile('Untitled.sol')
8080
.clickLaunchIcon('udapp')
8181
.click('*[data-id="settingsWeb3Mode"]')
82-
.waitForElementPresent('[data-id="udappNotify-modal-footer-ok-react"]')
82+
.waitForElementPresent('[data-id="envNotification-modal-footer-ok-react"]')
8383
.execute(function () {
84-
const modal = document.querySelector('[data-id="udappNotify-modal-footer-ok-react"]') as any
84+
const modal = document.querySelector('[data-id="envNotification-modal-footer-ok-react"]') as any
8585

8686
modal.click()
8787
})

apps/remix-ide-e2e/src/tests/plugin_api.ts

Lines changed: 81 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,16 @@ const clearPayLoad = async (browser: NightwatchBrowser) => {
6464
})
6565
}
6666

67-
const clickButton = async (browser: NightwatchBrowser, buttonText: string) => {
67+
const clickButton = async (browser: NightwatchBrowser, buttonText: string, waitResult: boolean = true) => {
6868
return new Promise((resolve) => {
6969
browser.useXpath().waitForElementVisible(`//*[@data-id='${buttonText}']`).pause(100)
7070
.click(`//*[@data-id='${buttonText}']`, async () => {
7171
await checkForAcceptAndRemember(browser)
72-
browser.waitForElementContainsText('//*[@id="callStatus"]', 'stop').perform(() => resolve(true))
72+
if (waitResult) {
73+
browser.waitForElementContainsText('//*[@id="callStatus"]', 'stop').perform(() => resolve(true))
74+
} else {
75+
resolve(true)
76+
}
7377
})
7478
})
7579
}
@@ -103,7 +107,7 @@ const checkForAcceptAndRemember = async function (browser: NightwatchBrowser) {
103107
* @return {Promise}
104108
*/
105109

106-
const clickAndCheckLog = async (browser: NightwatchBrowser, buttonText: string, methodResult: any, eventResult: any, payload: any) => {
110+
const clickAndCheckLog = async (browser: NightwatchBrowser, buttonText: string, methodResult: any, eventResult: any, payload: any, waitResult: boolean = true) => {
107111
if (payload) {
108112
await setPayload(browser, payload)
109113
} else {
@@ -112,10 +116,14 @@ const clickAndCheckLog = async (browser: NightwatchBrowser, buttonText: string,
112116
if (methodResult && typeof methodResult !== 'string') { methodResult = JSON.stringify(methodResult) }
113117
if (eventResult && typeof eventResult !== 'string') { eventResult = JSON.stringify(eventResult) }
114118
if (buttonText) {
115-
await clickButton(browser, buttonText)
119+
await clickButton(browser, buttonText, waitResult)
120+
}
121+
if (methodResult) {
122+
await debugValues(browser, 'methods', methodResult)
123+
}
124+
if (eventResult) {
125+
await debugValues(browser, 'events', eventResult)
116126
}
117-
await debugValues(browser, 'methods', methodResult)
118-
await debugValues(browser, 'events', eventResult)
119127
}
120128

121129
const assertPluginIsActive = function (browser: NightwatchBrowser, id: string, shouldBeVisible: boolean) {
@@ -364,5 +372,72 @@ module.exports = {
364372
const result = '{"jsonrpc":"2.0","result":true,"id":9999}'
365373
await clickAndCheckLog(browser, 'hardhat-provider:sendAsync', result, null, request)
366374
})
375+
},
376+
377+
// MODAL
378+
379+
'Should open 2 alert in a row and trigger 2 toaster in between #group9': function (browser: NightwatchBrowser) {
380+
browser
381+
.frameParent()
382+
.useCss()
383+
.addFile('test_modal.js', { content: testModalToasterApi })
384+
.executeScript('remix.execute(\'test_modal.js\')')
385+
.clickLaunchIcon('localPlugin')
386+
.useXpath()
387+
// @ts-ignore
388+
.frame(0)
389+
.perform(async () => {
390+
await clickAndCheckLog(browser, 'notification:toast', null, null, 'message toast from local plugin', false) // create a toast on behalf of the localplugin
391+
await clickAndCheckLog(browser, 'notification:alert', null, null, { message: 'message from local plugin', id: 'test_id_1_local_plugin' }, false) // create an alert on behalf of the localplugin
392+
})
393+
.frameParent()
394+
.useCss()
395+
// check the local plugin notifications
396+
.waitForElementVisible('*[data-id="test_id_1_local_pluginModalDialogModalBody-react"]')
397+
.assert.containsText('*[data-id="test_id_1_local_pluginModalDialogModalBody-react"]', 'message from local plugin')
398+
.modalFooterOKClick('test_id_1_local_plugin')
399+
// check the script runner notifications
400+
.waitForElementVisible('*[data-id="test_id_1_ModalDialogModalBody-react"]')
401+
.assert.containsText('*[data-id="test_id_1_ModalDialogModalBody-react"]', 'message 1')
402+
.modalFooterOKClick('test_id_1_')
403+
.waitForElementVisible('*[data-id="test_id_2_ModalDialogModalBody-react"]')
404+
.assert.containsText('*[data-id="test_id_2_ModalDialogModalBody-react"]', 'message 2')
405+
.modalFooterOKClick('test_id_2_')
406+
.waitForElementVisible('*[data-id="test_id_3_ModalDialogModalBody-react"]')
407+
.modalFooterOKClick('test_id_3_')
408+
.journalLastChildIncludes('default value... ') // check the return value of the prompt
409+
// check the toasters
410+
.waitForElementVisible('*[data-shared="tooltipPopup"]')
411+
.waitForElementContainsText('*[data-shared="tooltipPopup"]', 'message toast from local plugin')
412+
.waitForElementContainsText('*[data-shared="tooltipPopup"]', 'I am a toast')
413+
.waitForElementContainsText('*[data-shared="tooltipPopup"]', 'I am a re-toast')
367414
}
368415
}
416+
417+
const testModalToasterApi = `
418+
// Right click on the script name and hit "Run" to execute
419+
(async () => {
420+
try {
421+
setTimeout(async () => {
422+
console.log('test .. ')
423+
remix.call('notification', 'alert', { message: 'message 1', id: 'test_id_1_' })
424+
remix.call('notification', 'toast', 'I am a toast')
425+
remix.call('notification', 'toast', 'I am a re-toast')
426+
remix.call('notification', 'alert', { message: 'message 2', id: 'test_id_2_' })
427+
428+
const modalContent = {
429+
id: 'test_id_3_',
430+
title: 'test with input title',
431+
message: 'test with input content',
432+
modalType: 'prompt',
433+
okLabel: 'OK',
434+
cancelLabel: 'Cancel',
435+
defaultValue: 'default value... '
436+
}
437+
const result = await remix.call('notification', 'modal', modalContent)
438+
console.log(result)
439+
}, 500)
440+
} catch (e) {
441+
console.log(e.message)
442+
}
443+
})() `

apps/remix-ide-e2e/src/tests/terminal.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ module.exports = {
5151
.click('*[data-id="terminalClearConsole"]') // clear the terminal
5252
.clickLaunchIcon('udapp')
5353
.click('*[data-id="settingsWeb3Mode"]')
54-
.modalFooterOKClick('udappNotify')
54+
.modalFooterOKClick('envNotification')
5555
.executeScript('web3.eth.getAccounts()')
5656
.waitForElementContainsText('*[data-id="terminalJournal"]', '["', 60000) // we check if an array is present, don't need to check for the content
5757
.waitForElementContainsText('*[data-id="terminalJournal"]', '"]', 60000)

apps/remix-ide/src/app.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { OffsetToLineColumnConverter, CompilerMetadata, CompilerArtefacts, Fetch
99
import Registry from './app/state/registry'
1010
import { ConfigPlugin } from './app/plugins/config'
1111
import { Layout } from './app/panels/layout'
12-
import { ModalPlugin } from './app/plugins/modal'
12+
import { NotificationPlugin } from './app/plugins/notification'
1313
import { Blockchain } from './blockchain/blockchain.js'
1414
import { HardhatProvider } from './app/tabs/hardhat-provider'
1515

@@ -177,7 +177,7 @@ class AppComponent {
177177
)
178178
const contextualListener = new EditorContextListener()
179179

180-
self.modal = new ModalPlugin()
180+
self.notification = new NotificationPlugin()
181181

182182
const configPlugin = new ConfigPlugin()
183183
self.layout = new Layout()
@@ -187,7 +187,7 @@ class AppComponent {
187187
self.engine.register([
188188
permissionHandler,
189189
self.layout,
190-
self.modal,
190+
self.notification,
191191
self.gistHandler,
192192
configPlugin,
193193
blockchain,

apps/remix-ide/src/app/plugins/modal.tsx renamed to apps/remix-ide/src/app/plugins/notification.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { AppModal } from '@remix-ui/app'
44
import { AlertModal } from 'libs/remix-ui/app/src/lib/remix-app/interface'
55
import { dispatchModalInterface } from 'libs/remix-ui/app/src/lib/remix-app/context/context'
66

7-
interface IModalApi {
7+
interface INotificationApi {
88
events: StatusEvents,
99
methods: {
1010
modal: (args: AppModal) => void
@@ -13,14 +13,14 @@ interface IModalApi {
1313
}
1414
}
1515

16-
const profile:LibraryProfile<IModalApi> = {
16+
const profile:LibraryProfile<INotificationApi> = {
1717
name: 'notification',
1818
displayName: 'Notification',
1919
description: 'Displays notifications',
2020
methods: ['modal', 'alert', 'toast']
2121
}
2222

23-
export class ModalPlugin extends Plugin implements MethodApi<IModalApi> {
23+
export class NotificationPlugin extends Plugin implements MethodApi<INotificationApi> {
2424
dispatcher: dispatchModalInterface
2525
constructor () {
2626
super(profile)
@@ -38,7 +38,7 @@ export class ModalPlugin extends Plugin implements MethodApi<IModalApi> {
3838
return this.dispatcher.alert(args)
3939
}
4040

41-
async toast (message: string) {
41+
async toast (message: string | JSX.Element) {
4242
this.dispatcher.toast(message)
4343
}
4444
}

apps/remix-ide/src/remixEngine.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export class RemixEngine extends Engine {
1414
if (name === 'slither') return { queueTimeout: 60000 * 4 } // Requires when a solc version is installed
1515
if (name === 'hardhat') return { queueTimeout: 60000 * 4 }
1616
if (name === 'localPlugin') return { queueTimeout: 60000 * 4 }
17+
if (name === 'notification') return { queueTimeout: 60000 * 4 }
1718
return { queueTimeout: 10000 }
1819
}
1920

libs/remix-ui/app/src/lib/remix-app/actions/modals.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ type ActionMap<M extends { [index: string]: any }> = {
1414
export const enum modalActionTypes {
1515
setModal = 'SET_MODAL',
1616
setToast = 'SET_TOAST',
17+
processQueue = 'PROCESS_QUEUEU',
1718
handleHideModal = 'HANDLE_HIDE_MODAL',
1819
handleToaster = 'HANDLE_HIDE_TOAST'
1920
}
@@ -22,7 +23,8 @@ type ModalPayload = {
2223
[modalActionTypes.setModal]: AppModal
2324
[modalActionTypes.handleHideModal]: any
2425
[modalActionTypes.setToast]: string | JSX.Element
25-
[modalActionTypes.handleToaster]: any
26+
[modalActionTypes.handleToaster]: any,
27+
[modalActionTypes.processQueue]: any
2628
}
2729

2830
export type ModalAction = ActionMap<ModalPayload>[keyof ActionMap<

libs/remix-ui/app/src/lib/remix-app/context/context.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ export const AppContext = React.createContext<any>(null)
77

88
export interface dispatchModalInterface {
99
modal: (data: AppModal) => void
10-
toast: (message: string) => void
10+
toast: (message: string | JSX.Element) => void
1111
alert: (data: AlertModal) => void
1212
handleHideModal: () => void,
1313
handleToaster: () => void
1414
}
1515

1616
export const dispatchModalContext = React.createContext<dispatchModalInterface>({
1717
modal: (data: AppModal) => { },
18-
toast: (message: string) => {},
18+
toast: (message: string | JSX.Element) => {},
1919
alert: (data: AlertModal) => {},
2020
handleHideModal: () => {},
2121
handleToaster: () => {}

0 commit comments

Comments
 (0)