Skip to content

Commit 74df73b

Browse files
authored
Merge pull request #5600 from ethereum/delFS
delete forked state environment from env explorer
2 parents 6b7131b + 7e1f2d5 commit 74df73b

File tree

9 files changed

+70
-39
lines changed

9 files changed

+70
-39
lines changed

apps/remix-dapp/src/locales/en/udapp.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,15 @@
5050
"udapp.hash": "hash",
5151
"udapp.signature": "signature",
5252
"udapp.forkStateTitle": "Fork VM state",
53-
"udapp.forkStateLabel": "State Name",
53+
"udapp.forkStateLabel": "New environment name",
54+
"udapp.forkVmStateDesc1":"Forking state will create a new environment with same state as selected environment",
55+
"udapp.forkVmStateDesc2":"New environment will be pinned, which can be unpinned or deleted using Envionment Explorer",
5456
"udapp.fork": "Fork",
55-
"udapp.deleteVmStateTitle": "Delete VM state",
56-
"udapp.deleteVmStateDesc1": "Deleting the state of this VM will delete the associated transaction details in this Workspace.",
57-
"udapp.deleteVmStateDesc2": "It will also delete the data of contracts deployed and pinned in this Workspace.",
58-
"udapp.deleteVmStateDesc3": "Do you want to continue?",
57+
"udapp.resetVmStateTitle": "Reset VM state",
58+
"udapp.resetVmStateDesc1": "Resetting the state of this VM will delete the associated transaction details in this Workspace.",
59+
"udapp.resetVmStateDesc2": "It will also delete the data of contracts deployed and pinned in this Workspace.",
60+
"udapp.resetVmStateDesc3": "Do you want to continue?",
61+
"udapp.reset": "Reset",
5962
"udapp.delete": "Delete",
6063
"udapp.injectedTitle": "Unfortunately it's not possible to create an account using injected provider. Please create the account directly from your provider (i.e metamask or other of the same type).",
6164
"udapp.createNewAccount": "Create a new account",

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const tests = {
3333
.click('*[data-id="delete-state-icon"]')
3434
.waitForElementVisible(
3535
{
36-
selector: "//*[@data-shared='tooltipPopup' and contains(.,'State not available to delete')]",
36+
selector: "//*[@data-shared='tooltipPopup' and contains(.,'State not available to reset')]",
3737
locateStrategy: 'xpath'
3838
}
3939
)
@@ -65,7 +65,7 @@ const tests = {
6565
// check toaster for forked state
6666
.waitForElementVisible(
6767
{
68-
selector: '//*[@data-shared="tooltipPopup" and contains(.,"VM state \'forkedState_1\' forked")]',
68+
selector: '//*[@data-shared="tooltipPopup" and contains(.,"New environment \'forkedState_1\' created with forked state.")]',
6969
locateStrategy: 'xpath'
7070
}
7171
)
@@ -105,7 +105,7 @@ const tests = {
105105
.setValue('input[data-id="modalDialogForkState"]', 'forkedState_2')
106106
.modalFooterOKClick('udappNotify')
107107
.waitForElementVisible('*[data-shared="tooltipPopup"]', 10000)
108-
.assert.textContains('*[data-shared="tooltipPopup"]', `VM state 'forkedState_2' forked and selected as current environment.`)
108+
.assert.textContains('*[data-shared="tooltipPopup"]', `New environment 'forkedState_2' created with forked state.`)
109109
// check if 'forkedState_2' is selected as current environment
110110
.assert.elementPresent('*[data-id="selected-provider-vm-fs-forkedState_2"]')
111111
// check if 'forkedState_2' is present in environment explorer
@@ -140,7 +140,7 @@ const tests = {
140140
.modalFooterOKClick('udappNotify')
141141
.waitForElementVisible('*[data-shared="tooltipPopup"]', 10000)
142142
// check if toaster is shown
143-
.assert.textContains('*[data-shared="tooltipPopup"]', `VM state deleted successfully.`)
143+
.assert.textContains('*[data-shared="tooltipPopup"]', `VM state reset successfully.`)
144144
// check that there are no instances
145145
.assert.textContains('*[data-id="deployedContractsBadge"]', '0')
146146
// check if state file is deleted

apps/remix-ide/src/app/providers/environment-explorer.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,15 @@ export class EnvironmentExplorer extends ViewPlugin {
7878
}
7979
}
8080

81+
async deleteForkedState (provider) {
82+
const providerName = await this.call('blockchain', 'getProvider')
83+
if (providerName !== provider.name) {
84+
await this.call('fileManager', 'remove', `.states/forked_states/${provider.displayName}.json`)
85+
await this.call('blockchain', 'removeProvider', provider.name)
86+
this.call('notification', 'toast', `Environment "${provider.displayName}" deleted successfully.`)
87+
} else this.call('notification', 'toast', 'Cannot delete the current selected environment')
88+
}
89+
8190
renderComponent() {
8291
this.dispatch({
8392
...this.state
@@ -86,7 +95,12 @@ export class EnvironmentExplorer extends ViewPlugin {
8695

8796
updateComponent(state: EnvironmentExplorerState) {
8897
return (<>
89-
<EnvironmentExplorerUI pinStateCallback={this.pinStateCallback.bind(this)} profile={profile} state={state} />
98+
<EnvironmentExplorerUI
99+
pinStateCallback={this.pinStateCallback.bind(this)}
100+
deleteForkedState={this.deleteForkedState.bind(this)}
101+
profile={profile}
102+
state={state}
103+
/>
90104
</>)
91105
}
92106
}

apps/remix-ide/src/app/tabs/locales/en/udapp.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,15 @@
5050
"udapp.hash": "hash",
5151
"udapp.signature": "signature",
5252
"udapp.forkStateTitle": "Fork VM state",
53-
"udapp.forkStateLabel": "State Name",
53+
"udapp.forkStateLabel": "New environment name",
54+
"udapp.forkVmStateDesc1":"Forking state will create a new environment with same state as selected environment",
55+
"udapp.forkVmStateDesc2":"After forking, new environment will be pinned and selected automatically. It can be unpinned or deleted using Envionment Explorer",
5456
"udapp.fork": "Fork",
55-
"udapp.deleteVmStateTitle": "Delete VM state",
56-
"udapp.deleteVmStateDesc1": "Deleting the state of this VM will delete the associated transaction details in this Workspace.",
57-
"udapp.deleteVmStateDesc2": "It will also delete the data of contracts deployed and pinned in this Workspace.",
58-
"udapp.deleteVmStateDesc3": "Do you want to continue?",
57+
"udapp.resetVmStateTitle": "Reset VM state",
58+
"udapp.resetVmStateDesc1": "Resetting the state of this VM will delete the associated transaction details in this Workspace.",
59+
"udapp.resetVmStateDesc2": "It will also delete the data of contracts deployed and pinned in this Workspace.",
60+
"udapp.resetVmStateDesc3": "Do you want to continue?",
61+
"udapp.reset": "Reset",
5962
"udapp.delete": "Delete",
6063
"udapp.injectedTitle": "Unfortunately it's not possible to create an account using injected provider. Please create the account directly from your provider (i.e metamask or other of the same type).",
6164
"udapp.createNewAccount": "Create new account",

apps/remix-ide/src/blockchain/blockchain.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ export class Blockchain extends Plugin {
157157
_paq.push(['trackEvent', 'blockchain', 'providerPinned', name])
158158
this.emit('providersChanged')
159159
this.changeExecutionContext({ context: name }, null, null, null)
160-
this.call('notification', 'toast', `VM state '${providerName}' forked and selected as current environment.`)
160+
this.call('notification', 'toast', `New environment '${providerName}' created with forked state.`)
161161
})
162162

163163
this.on('environmentExplorer', 'providerUnpinned', (name, provider) => {
@@ -687,6 +687,7 @@ export class Blockchain extends Plugin {
687687
}
688688

689689
removeProvider(name) {
690+
if (this.pinnedProviders.includes(name)) this.emit('shouldRemoveProviderFromUdapp', name, this.getProviderObjByName(name))
690691
this.executionContext.removeProvider(name)
691692
this.emit('providersChanged')
692693
}

libs/remix-simulator/src/provider.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ export class Provider {
5454
pendingRequests: Array<any>
5555

5656
constructor (options: ProviderOptions = {} as ProviderOptions) {
57-
console.log(options)
5857
this.options = options
5958
this.connected = true
6059
this.vmContext = new VMContext(options['fork'], options['nodeUrl'], options['blockNumber'], options['stateDb'], options['blocks'])

libs/remix-ui/environment-explorer/src/lib/components/environment-explorer-ui.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,19 @@ export const EnvironmentExplorerUI = (props: environmentExplorerUIProps) => {
102102
}}
103103
>
104104
<div data-id={`${provider.name}desc`}>{(section.descriptionFn && section.descriptionFn(provider)) || provider.description}</div>
105+
{ provider.isForkedState && <CustomTooltip
106+
placement="auto"
107+
tooltipId={`overlay-tooltip-${provider.name}`}
108+
tooltipText="Delete Environment Immediately"
109+
>
110+
<span
111+
onClick={async () => props.deleteForkedState(provider)}
112+
className="btn btn-sm mt-1 border border-danger"
113+
>
114+
Delete Environment
115+
</span>
116+
</CustomTooltip>
117+
}
105118
</RemixUIGridCell>
106119
))}
107120
</RemixUIGridSection>

libs/remix-ui/environment-explorer/src/lib/types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export type environmentExplorerUIProps = {
88
providersFlat: { [key: string]: Provider }
99
pinnedProviders: string[]
1010
}
11+
deleteForkedState (provider: Provider): Promise<void>
1112
pinStateCallback (provider: Provider, pinned: boolean): Promise<void>
1213
profile: Profile
1314
}

libs/remix-ui/run-tab/src/lib/components/environment.tsx

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ export function EnvironmentUI(props: EnvironmentProps) {
3131
const forkStatePrompt = (defaultName: string) => {
3232
return (
3333
<div data-id="forkVmStateModal">
34+
<ul className='ml-3'>
35+
<li><FormattedMessage id="udapp.forkVmStateDesc1"/></li>
36+
<li><FormattedMessage id="udapp.forkVmStateDesc2"/></li>
37+
</ul>
3438
<label id="stateName" className="form-check-label" style={{ fontWeight: 'bolder' }}>
3539
<FormattedMessage id="udapp.forkStateLabel" />
3640
</label>
@@ -49,10 +53,10 @@ export function EnvironmentUI(props: EnvironmentProps) {
4953
return (
5054
<div data-id="deleteVmStateModal">
5155
<ul className='ml-3'>
52-
<li><FormattedMessage id="udapp.deleteVmStateDesc1"/></li>
53-
<li><FormattedMessage id="udapp.deleteVmStateDesc2"/></li>
56+
<li><FormattedMessage id="udapp.resetVmStateDesc1"/></li>
57+
<li><FormattedMessage id="udapp.resetVmStateDesc2"/></li>
5458
</ul>
55-
<FormattedMessage id="udapp.deleteVmStateDesc3"/>
59+
<FormattedMessage id="udapp.resetVmStateDesc3"/>
5660
</div>
5761
)
5862
}
@@ -83,15 +87,15 @@ export function EnvironmentUI(props: EnvironmentProps) {
8387
} else props.runTabPlugin.call('notification', 'toast', `State not available to fork, as no transactions have been made for selected environment & selected workspace.`)
8488
}
8589

86-
const deleteVmState = async() => {
90+
const resetVmState = async() => {
8791
_paq.push(['trackEvent', 'udapp', 'deleteState', `deleteState clicked`])
8892
const context = currentProvider.name
8993
const contextExists = await props.runTabPlugin.call('fileManager', 'exists', `.states/${context}/state.json`)
9094
if (contextExists) {
9195
props.modal(
92-
intl.formatMessage({ id: 'udapp.deleteVmStateTitle' }),
96+
intl.formatMessage({ id: 'udapp.resetVmStateTitle' }),
9397
deleteVmStatePrompt(),
94-
intl.formatMessage({ id: 'udapp.delete' }),
98+
intl.formatMessage({ id: 'udapp.reset' }),
9599
async () => {
96100
const currentProvider = await props.runTabPlugin.call('blockchain', 'getCurrentProvider')
97101
// Reset environment blocks and account data
@@ -103,35 +107,28 @@ export function EnvironmentUI(props: EnvironmentProps) {
103107
// If there are pinned contracts, delete pinned contracts folder
104108
const isPinnedContracts = await props.runTabPlugin.call('fileManager', 'exists', `.deploys/pinned-contracts/${context}`)
105109
if (isPinnedContracts) await props.runTabPlugin.call('fileManager', 'remove', `.deploys/pinned-contracts/${context}`)
106-
props.runTabPlugin.call('notification', 'toast', `VM state deleted successfully.`)
107-
_paq.push(['trackEvent', 'udapp', 'deleteState', `VM state deleted`])
110+
props.runTabPlugin.call('notification', 'toast', `VM state reset successfully.`)
111+
_paq.push(['trackEvent', 'udapp', 'deleteState', `VM state reset`])
108112
},
109113
intl.formatMessage({ id: 'udapp.cancel' }),
110114
null
111115
)
112-
} else props.runTabPlugin.call('notification', 'toast', `State not available to delete, as no transactions have been made for selected environment & selected workspace.`)
116+
} else props.runTabPlugin.call('notification', 'toast', `State not available to reset, as no transactions have been made for selected environment & selected workspace.`)
113117
}
114118

115119
const isL2 = (providerDisplayName: string) => providerDisplayName && (providerDisplayName.startsWith('L2 - Optimism') || providerDisplayName.startsWith('L2 - Arbitrum'))
116120
return (
117121
<div className="udapp_crow">
118-
<label id="selectExEnv" className="udapp_settingsLabel">
122+
<label id="selectExEnv" className="udapp_settingsLabel w-100">
119123
<FormattedMessage id="udapp.environment" />
120-
<CustomTooltip placement={'auto-end'} tooltipClasses="text-nowrap" tooltipId="info-recorder" tooltipText={<FormattedMessage id="udapp.tooltipText2" />}>
121-
<a href="https://chainlist.org/" target="_blank">
122-
<i className={'ml-2 fas fa-plug'} aria-hidden="true"></i>
123-
</a>
124-
</CustomTooltip>
125-
<CustomTooltip placement={'auto-end'} tooltipClasses="text-wrap" tooltipId="runAndDeployAddresstooltip" tooltipText={<FormattedMessage id="udapp.environmentDocs" />}>
126-
<a href="https://remix-ide.readthedocs.io/en/latest/run.html#environment" target="_blank" rel="noreferrer">
127-
<i className="udapp_infoDeployAction ml-2 fas fa-info"></i>
128-
</a>
129-
</CustomTooltip>
130124
{ currentProvider && currentProvider.isVM && isSaveEvmStateChecked && <CustomTooltip placement={'auto-end'} tooltipClasses="text-wrap" tooltipId="forkStatetooltip" tooltipText={<FormattedMessage id="udapp.forkStateTitle" />}>
131125
<i className="udapp_infoDeployAction ml-2 fas fa-code-branch" style={{ cursor: 'pointer' }} onClick={forkState} data-id="fork-state-icon"></i>
132126
</CustomTooltip> }
133-
{ currentProvider && currentProvider.isVM && isSaveEvmStateChecked && <CustomTooltip placement={'auto-end'} tooltipClasses="text-wrap" tooltipId="deleteVMStatetooltip" tooltipText={<FormattedMessage id="udapp.deleteVmStateTitle" />}>
134-
<i className="udapp_infoDeployAction ml-2 fas fa-trash" style={{ cursor: 'pointer' }} onClick={deleteVmState} data-id="delete-state-icon"></i>
127+
{ currentProvider && currentProvider.isVM && isSaveEvmStateChecked && <CustomTooltip placement={'auto-end'} tooltipClasses="text-wrap" tooltipId="deleteVMStatetooltip" tooltipText={<FormattedMessage id="udapp.resetVmStateTitle" />}>
128+
<span onClick={resetVmState} style={{ cursor: 'pointer', float: 'right', textTransform: 'none' }}>
129+
<i className="udapp_infoDeployAction ml-2 fas fa-refresh" data-id="delete-state-icon"></i>
130+
<span className="ml-1" style = {{ textTransform: 'none', fontSize: '13px' }}>Reset State</span>
131+
</span>
135132
</CustomTooltip> }
136133
</label>
137134
<div className="udapp_environment" data-id={`selected-provider-${currentProvider && currentProvider.name}`}>

0 commit comments

Comments
 (0)