fix add and remove provider

pull/1910/head
yann300 3 years ago
parent 56f4ba8f90
commit baf36196b3
  1. 23
      apps/remix-ide-e2e/src/tests/plugin_api.ts
  2. 4
      apps/remix-ide/src/app/tabs/hardhat-provider.tsx
  3. 2
      libs/remix-ui/run-tab/src/lib/actions/index.ts
  4. 24
      libs/remix-ui/run-tab/src/lib/reducers/runTab.ts

@ -324,5 +324,28 @@ module.exports = {
'Should get compilationresults #group6': async function (browser: NightwatchBrowser) { 'Should get compilationresults #group6': async function (browser: NightwatchBrowser) {
await clickAndCheckLog(browser, 'solidity:getCompilationResult', 'contracts/1_Storage.sol', null, null) 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)
})
} }
} }

@ -66,7 +66,7 @@ export class HardhatProvider extends Plugin {
value = await ((): Promise<string> => { value = await ((): Promise<string> => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const modalContent: AppModal = { const modalContent: AppModal = {
id: 'harrhatprovider', id: 'hardhatprovider',
title: 'Hardhat node request', title: 'Hardhat node request',
message: this.hardhatProviderDialogBody(), message: this.hardhatProviderDialogBody(),
modalType: ModalTypes.prompt, modalType: ModalTypes.prompt,
@ -110,7 +110,7 @@ export class HardhatProvider extends Plugin {
} catch (error) { } catch (error) {
this.blocked = true this.blocked = true
const modalContent: AlertModal = { const modalContent: AlertModal = {
id: 'harrhatprovider', id: 'hardhatprovider',
title: 'Hardhat Provider', title: 'Hardhat Provider',
message: `Error while connecting to the hardhat provider: ${error.message}`, message: `Error while connecting to the hardhat provider: ${error.message}`,
} }

@ -237,7 +237,7 @@ export const setExecutionContext = (executionContext: { context: string, fork: s
}, () => { setFinalContext() })) }, () => { setFinalContext() }))
}, (alertMsg) => { }, (alertMsg) => {
dispatch(displayPopUp(alertMsg)) dispatch(displayPopUp(alertMsg))
}, setFinalContext()) }, () => { setFinalContext() })
} }
export const setWeb3Endpoint = (endpoint: string) => { export const setWeb3Endpoint = (endpoint: string) => {

@ -171,6 +171,11 @@ export const runTabInitialState: RunTabState = {
web3Dialog: null web3Dialog: null
} }
type AddProvider = {
name: string,
provider: any
}
export const runTabReducer = (state: RunTabState = runTabInitialState, action: Action) => { export const runTabReducer = (state: RunTabState = runTabInitialState, action: Action) => {
switch (action.type) { switch (action.type) {
case 'FETCH_ACCOUNTS_LIST_REQUEST': { case 'FETCH_ACCOUNTS_LIST_REQUEST': {
@ -328,25 +333,32 @@ export const runTabReducer = (state: RunTabState = runTabInitialState, action: A
} }
case 'ADD_PROVIDER': { 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 { return {
...state, ...state,
providers: { providers: {
...state.providers, ...state.providers,
providerList: { ...state.providers.providerList, payload } providerList: state.providers.providerList
} }
} }
} }
case 'REMOVE_PROVIDER': { case 'REMOVE_PROVIDER': {
const payload: string = action.payload const id: string = action.payload
const providers = state.providers.providerList.filter((el) => el.id !== id)
return { return {
...state, ...state,
providers: { providers: {
...state.providers, ...state.providers,
providerList: delete state.providers.providerList[payload] ? state.providers.providerList : state.providers.providerList providerList: providers
} }
} }
} }

Loading…
Cancel
Save