From baf36196b38875f633cde79415e62d034314ff68 Mon Sep 17 00:00:00 2001 From: yann300 Date: Thu, 6 Jan 2022 18:04:04 +0100 Subject: [PATCH] fix add and remove provider --- apps/remix-ide-e2e/src/tests/plugin_api.ts | 23 ++++++++++++++++++ .../src/app/tabs/hardhat-provider.tsx | 4 ++-- .../remix-ui/run-tab/src/lib/actions/index.ts | 2 +- .../run-tab/src/lib/reducers/runTab.ts | 24 ++++++++++++++----- 4 files changed, 44 insertions(+), 9 deletions(-) diff --git a/apps/remix-ide-e2e/src/tests/plugin_api.ts b/apps/remix-ide-e2e/src/tests/plugin_api.ts index 2ad4d82144..d3ce74a639 100644 --- a/apps/remix-ide-e2e/src/tests/plugin_api.ts +++ b/apps/remix-ide-e2e/src/tests/plugin_api.ts @@ -324,5 +324,28 @@ module.exports = { 'Should get compilationresults #group6': async function (browser: NightwatchBrowser) { await clickAndCheckLog(browser, 'solidity:getCompilationResult', 'contracts/1_Storage.sol', null, null) + }, + + // PROVIDER + + 'Should switch to hardhat provider (provider plugin)': async function (browser: NightwatchBrowser) { + browser + .clickLaunchIcon('udapp') + .click('*[data-id="Hardhat provider"]') + .modalFooterOKClick('hardhatprovider') + .waitForElementContainsText('*[data-id="settingsNetworkEnv"]', 'Custom') // e.g Custom (1337) network + .getValue('*[data-id="settingsNetworkEnv"]', (result) => { + browser.assert.ok((result.value as string).match(/^Custom \(\d+\) network$/) !== undefined, 'Expected to ') + }) + .perform(async () => { + const request = { + id: 9999, + jsonrpc: "2.0", + method: "net_listening", + params: [] + } + const result = true + await clickAndCheckLog(browser, 'hardhat-provider:sendAsync', {}, result, request) + }) } } diff --git a/apps/remix-ide/src/app/tabs/hardhat-provider.tsx b/apps/remix-ide/src/app/tabs/hardhat-provider.tsx index abb5eabddf..c84a6d09c2 100644 --- a/apps/remix-ide/src/app/tabs/hardhat-provider.tsx +++ b/apps/remix-ide/src/app/tabs/hardhat-provider.tsx @@ -66,7 +66,7 @@ export class HardhatProvider extends Plugin { value = await ((): Promise => { return new Promise((resolve, reject) => { const modalContent: AppModal = { - id: 'harrhatprovider', + id: 'hardhatprovider', title: 'Hardhat node request', message: this.hardhatProviderDialogBody(), modalType: ModalTypes.prompt, @@ -110,7 +110,7 @@ export class HardhatProvider extends Plugin { } catch (error) { this.blocked = true const modalContent: AlertModal = { - id: 'harrhatprovider', + id: 'hardhatprovider', title: 'Hardhat Provider', message: `Error while connecting to the hardhat provider: ${error.message}`, } diff --git a/libs/remix-ui/run-tab/src/lib/actions/index.ts b/libs/remix-ui/run-tab/src/lib/actions/index.ts index ea12ad7efa..97c5c4c7f9 100644 --- a/libs/remix-ui/run-tab/src/lib/actions/index.ts +++ b/libs/remix-ui/run-tab/src/lib/actions/index.ts @@ -237,7 +237,7 @@ export const setExecutionContext = (executionContext: { context: string, fork: s }, () => { setFinalContext() })) }, (alertMsg) => { dispatch(displayPopUp(alertMsg)) - }, setFinalContext()) + }, () => { setFinalContext() }) } export const setWeb3Endpoint = (endpoint: string) => { diff --git a/libs/remix-ui/run-tab/src/lib/reducers/runTab.ts b/libs/remix-ui/run-tab/src/lib/reducers/runTab.ts index c932202aa5..9f0624d561 100644 --- a/libs/remix-ui/run-tab/src/lib/reducers/runTab.ts +++ b/libs/remix-ui/run-tab/src/lib/reducers/runTab.ts @@ -171,6 +171,11 @@ export const runTabInitialState: RunTabState = { web3Dialog: null } +type AddProvider = { + name: string, + provider: any +} + export const runTabReducer = (state: RunTabState = runTabInitialState, action: Action) => { switch (action.type) { case 'FETCH_ACCOUNTS_LIST_REQUEST': { @@ -328,25 +333,32 @@ export const runTabReducer = (state: RunTabState = runTabInitialState, action: A } case 'ADD_PROVIDER': { - const payload: string = action.payload - + const payload: AddProvider = action.payload + const id = action.payload.name + state.providers.providerList.push({ + content: payload.name, + dataId: id, + id, + title: payload.name, + value: id + }) return { ...state, providers: { ...state.providers, - providerList: { ...state.providers.providerList, payload } + providerList: state.providers.providerList } } } case 'REMOVE_PROVIDER': { - const payload: string = action.payload - + const id: string = action.payload + const providers = state.providers.providerList.filter((el) => el.id !== id) return { ...state, providers: { ...state.providers, - providerList: delete state.providers.providerList[payload] ? state.providers.providerList : state.providers.providerList + providerList: providers } } }