From 72503873c97345022a9840d1a65496c3fb86fabb Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Fri, 20 Dec 2024 18:27:26 +0530 Subject: [PATCH] fork instead of save --- apps/remix-dapp/src/locales/en/udapp.json | 8 +++--- .../src/app/providers/vm-provider.tsx | 2 +- .../src/app/tabs/locales/en/udapp.json | 8 +++--- apps/remix-ide/src/app/udapp/run-tab.tsx | 26 +++++++++---------- apps/remix-ide/src/blockchain/blockchain.tsx | 21 ++++++++------- .../components/environment-explorer-ui.tsx | 12 ++++----- .../src/lib/types/index.ts | 4 +-- .../src/lib/components/environment.tsx | 26 +++++++++---------- 8 files changed, 54 insertions(+), 53 deletions(-) diff --git a/apps/remix-dapp/src/locales/en/udapp.json b/apps/remix-dapp/src/locales/en/udapp.json index 92e2f362e5..b2792d4079 100644 --- a/apps/remix-dapp/src/locales/en/udapp.json +++ b/apps/remix-dapp/src/locales/en/udapp.json @@ -49,9 +49,10 @@ "udapp.enterAMessageToSign": "Enter a message to sign", "udapp.hash": "hash", "udapp.signature": "signature", - "udapp.saveVmStateTitle": "Save VM state", - "udapp.saveVmStateLabel": "State Name", - "udapp.saveVmStateTip": "VM state, saved for current workspace, can be pinned as an environment using Environment Explorer", + "udapp.forkStateTitle": "Fork VM state", + "udapp.forkStateLabel": "State Name", + "udapp.forkStateTip": "VM State, forked for current workspace, can be pinned as an environment using Environment Explorer", + "udapp.fork": "Fork", "udapp.resetVmStateTitle": "Reset VM state", "udapp.resetVmStateDesc1": "Resetting state of the selected environment will delete all your previously saved transaction details for current workspace.", "udapp.resetVmStateDesc2": "It will also delete the data for contracts deployed and pinned for this workspace.", @@ -71,7 +72,6 @@ "udapp._comment_environment.tsx": "libs/remix-ui/run-tab/src/lib/components/environment.tsx", "udapp.environment": "Environment", "udapp.environmentDocs": "Click for docs about Environment", - "udapp.saveVmState": "Save VM state", "udapp.resetVmStateTooltip": "Reset VM state", "udapp.tooltipText2": "Open chainlist.org and get the connection specs of the chain you want to interact with.", "udapp.tooltipText3": "Click to open a bridge for converting L1 mainnet ETH to the selected network currency.", diff --git a/apps/remix-ide/src/app/providers/vm-provider.tsx b/apps/remix-ide/src/app/providers/vm-provider.tsx index c978779b0d..3764948045 100644 --- a/apps/remix-ide/src/app/providers/vm-provider.tsx +++ b/apps/remix-ide/src/app/providers/vm-provider.tsx @@ -132,7 +132,7 @@ export class CancunVMProvider extends BasicVMProvider { } } -export class SavedVMStateProvider extends BasicVMProvider { +export class ForkedVMStateProvider extends BasicVMProvider { constructor(profile, blockchain, fork) { super(profile, blockchain) this.blockchain = blockchain diff --git a/apps/remix-ide/src/app/tabs/locales/en/udapp.json b/apps/remix-ide/src/app/tabs/locales/en/udapp.json index 6febd2d367..067ca16c42 100644 --- a/apps/remix-ide/src/app/tabs/locales/en/udapp.json +++ b/apps/remix-ide/src/app/tabs/locales/en/udapp.json @@ -49,9 +49,10 @@ "udapp.enterAMessageToSign": "Enter a message to sign and click `Sign`", "udapp.hash": "hash", "udapp.signature": "signature", - "udapp.saveVmStateTitle": "Save VM state", - "udapp.saveVmStateLabel": "State Name", - "udapp.saveVmStateTip": "VM state, saved for current workspace, can be pinned as an environment using Environment Explorer", + "udapp.forkStateTitle": "Fork VM state", + "udapp.forkStateLabel": "State Name", + "udapp.forkStateTip": "VM State, forked for current workspace, can be pinned as an environment using Environment Explorer", + "udapp.fork": "Fork", "udapp.resetVmStateTitle": "Reset VM state", "udapp.resetVmStateDesc1": "Resetting state of the selected environment will delete all your previously saved transaction details for current workspace.", "udapp.resetVmStateDesc2": "It will also delete the data for contracts deployed and pinned for this workspace.", @@ -70,7 +71,6 @@ "udapp._comment_environment.tsx": "libs/remix-ui/run-tab/src/lib/components/environment.tsx", "udapp.environment": "Environment", "udapp.environmentDocs": "Click for docs about Environment", - "udapp.saveVmState": "Save VM state", "udapp.resetVmStateTooltip": "Reset VM state", "udapp.reset": "Reset", "udapp.tooltipText2": "Open chainlist.org and get the connection specs of the chain you want to interact with.", diff --git a/apps/remix-ide/src/app/udapp/run-tab.tsx b/apps/remix-ide/src/app/udapp/run-tab.tsx index 50493830bd..55c06045b0 100644 --- a/apps/remix-ide/src/app/udapp/run-tab.tsx +++ b/apps/remix-ide/src/app/udapp/run-tab.tsx @@ -9,7 +9,7 @@ import * as packageJson from '../../../../../package.json' import { EventManager } from '@remix-project/remix-lib' import type { Blockchain } from '../../blockchain/blockchain' import type { CompilerArtefacts } from '@remix-project/core-plugin' -import { SavedVMStateProvider } from '../providers/vm-provider' +import { ForkedVMStateProvider } from '../providers/vm-provider' import { Recorder } from '../tabs/runTab/model/recorder' const _paq = (window._paq = window._paq || []) @@ -177,7 +177,7 @@ export class RunTab extends ViewPlugin { 'foundry-provider': ['assets/img/foundry.png'] } - const addProvider = async (position, name, displayName, isInjected, isVM, isSavedState, fork = '', dataId = '', title = '', forkedVM = false) => { + const addProvider = async (position, name, displayName, isInjected, isVM, isForkedState, fork = '', dataId = '', title = '', forkedVM = false) => { await this.call('blockchain', 'addProvider', { position, options: {}, @@ -190,7 +190,7 @@ export class RunTab extends ViewPlugin { isInjected, isForkedVM: forkedVM, isVM, - isSavedState, + isForkedState, title, init: async function () { const options = await udapp.call(name, 'init') @@ -257,18 +257,18 @@ export class RunTab extends ViewPlugin { await addProvider(3, 'vm-sepolia-fork', 'Remix VM - Sepolia fork', false, true, false, 'cancun', 'settingsVMSepoliaMode', titleVM, true) await addProvider(4, 'vm-custom-fork', 'Remix VM - Custom fork', false, true, false, '', 'settingsVMCustomMode', titleVM, true) - // Saved VM States - const addSVSProvider = async(stateFilePath, pos) => { + // Forked VM States + const addFVSProvider = async(stateFilePath, pos) => { let stateDetail = await this.call('fileManager', 'readFile', stateFilePath) stateDetail = JSON.parse(stateDetail) - const providerName = 'vm-svs-' + stateDetail.stateName + const providerName = 'vm-fs-' + stateDetail.stateName descriptions[providerName] = JSON.stringify({ name: providerName, latestBlock: stateDetail.latestBlockNumber, timestamp: stateDetail.savingTimestamp }) // Create and register provider plugin for saved states - const svsProvider = new SavedVMStateProvider({ + const fvsProvider = new ForkedVMStateProvider({ name: providerName, displayName: stateDetail.stateName, kind: 'provider', @@ -276,25 +276,25 @@ export class RunTab extends ViewPlugin { methods: ['sendAsync', 'init'], version: packageJson.version }, this.blockchain, stateDetail.forkName) - this.engine.register(svsProvider) + this.engine.register(fvsProvider) await addProvider(pos, providerName, stateDetail.stateName, false, false, true, stateDetail.forkName) } this.on('filePanel', 'workspaceInitializationCompleted', async () => { - const ssExists = await this.call('fileManager', 'exists', '.states/saved_states') + const ssExists = await this.call('fileManager', 'exists', '.states/forked_states') if (ssExists) { - const savedStatesDetails = await this.call('fileManager', 'readdir', '.states/saved_states') + const savedStatesDetails = await this.call('fileManager', 'readdir', '.states/forked_states') const savedStatesFiles = Object.keys(savedStatesDetails) let pos = 10 for (const filePath of savedStatesFiles) { pos += 1 - await addSVSProvider(filePath, pos) + await addFVSProvider(filePath, pos) } } }) - this.on('udapp', 'vmStateSaved', async (stateName) => { - await addSVSProvider(`.states/saved_states/${stateName}.json`, 20) + this.on('udapp', 'vmStateForked', async (stateName) => { + await addFVSProvider(`.states/forked_states/${stateName}.json`, 20) }) // wallet connect diff --git a/apps/remix-ide/src/blockchain/blockchain.tsx b/apps/remix-ide/src/blockchain/blockchain.tsx index f9af8540e3..8e5f00e890 100644 --- a/apps/remix-ide/src/blockchain/blockchain.tsx +++ b/apps/remix-ide/src/blockchain/blockchain.tsx @@ -55,7 +55,7 @@ export type Provider = { description?: string isInjected: boolean isVM: boolean - isSavedState: boolean + isForkedState: boolean isForkedVM: boolean title: string init: () => Promise @@ -700,11 +700,11 @@ export class Blockchain extends Plugin { const stateDb = await this.call('fileManager', 'readFile', `.states/${context}/state.json`) await this.getCurrentProvider().resetEnvironment(stateDb) } else { - // check if saved VM state is used as provider - const stateName = context.replace('vm-svs-', '') - const contextExists = await this.call('fileManager', 'exists', `.states/saved_states/${stateName}.json`) + // check if forked VM state is used as provider + const stateName = context.replace('vm-fs-', '') + const contextExists = await this.call('fileManager', 'exists', `.states/forked_states/${stateName}.json`) if (contextExists) { - const stateDb = await this.call('fileManager', 'readFile', `.states/saved_states/${stateName}.json`) + const stateDb = await this.call('fileManager', 'readFile', `.states/forked_states/${stateName}.json`) await this.getCurrentProvider().resetEnvironment(stateDb) } else await this.getCurrentProvider().resetEnvironment() } @@ -962,11 +962,12 @@ export class Blockchain extends Plugin { try { let state = await this.executionContext.getStateDetails() const provider = this.executionContext.getProvider() - if (provider.startsWith('vm-svs-')) { - const stateName = provider.replace('vm-svs-', '') - const stateFileExists = this.call('fileManager', 'exists', `.states/saved_states/${stateName}.json`) + // Check if provider is forked VM state + if (provider.startsWith('vm-fs-')) { + const stateName = provider.replace('vm-fs-', '') + const stateFileExists = this.call('fileManager', 'exists', `.states/forked_states/${stateName}.json`) if (stateFileExists) { - let stateDetails = await this.call('fileManager', 'readFile', `.states/saved_states/${stateName}.json`) + let stateDetails = await this.call('fileManager', 'readFile', `.states/forked_states/${stateName}.json`) stateDetails = JSON.parse(stateDetails) state = JSON.parse(state) state['stateName'] = stateDetails.stateName @@ -974,7 +975,7 @@ export class Blockchain extends Plugin { state['savingTimestamp'] = stateDetails.savingTimestamp state = JSON.stringify(state, null, 2) } - this.call('fileManager', 'writeFile', `.states/saved_states/${stateName}.json`, state) + this.call('fileManager', 'writeFile', `.states/forked_states/${stateName}.json`, state) } else this.call('fileManager', 'writeFile', `.states/${provider}/state.json`, state) } catch (e) { diff --git a/libs/remix-ui/environment-explorer/src/lib/components/environment-explorer-ui.tsx b/libs/remix-ui/environment-explorer/src/lib/components/environment-explorer-ui.tsx index 967d597a8e..acc392961c 100644 --- a/libs/remix-ui/environment-explorer/src/lib/components/environment-explorer-ui.tsx +++ b/libs/remix-ui/environment-explorer/src/lib/components/environment-explorer-ui.tsx @@ -17,11 +17,11 @@ const defaultSections: environmentExplorerUIGridSections = { providers: [], filterFn: (provider) => provider.isVM }, - 'Saved VM States': { - title: 'Deploy to an In-browser Saved VM State.', - keywords: ['Saved VM States'], + 'Forked States': { + title: 'Deploy to an In-browser Forked State.', + keywords: ['Forked State'], providers: [], - filterFn: (provider) => provider.isSavedState, + filterFn: (provider) => provider.isForkedState, descriptionFn: (provider) => { const { latestBlock, timestamp } = JSON.parse(provider.description) return ( @@ -30,7 +30,7 @@ const defaultSections: environmentExplorerUIGridSections = {
Saved at: {(new Date(timestamp)).toDateString()}
@@ -47,7 +47,7 @@ const defaultSections: environmentExplorerUIGridSections = { title: 'Deploy to an external Provider.', keywords: ['Externals'], providers: [], - filterFn: (provider) => (!provider.isInjected && !provider.isVM && !provider.isSavedState && !provider.isForkedVM) + filterFn: (provider) => (!provider.isInjected && !provider.isVM && !provider.isForkedState && !provider.isForkedVM) }, } export const EnvironmentExplorerUI = (props: environmentExplorerUIProps) => { diff --git a/libs/remix-ui/environment-explorer/src/lib/types/index.ts b/libs/remix-ui/environment-explorer/src/lib/types/index.ts index 6332084288..706e577edd 100644 --- a/libs/remix-ui/environment-explorer/src/lib/types/index.ts +++ b/libs/remix-ui/environment-explorer/src/lib/types/index.ts @@ -1,7 +1,7 @@ import { Plugin } from '@remixproject/engine' import { Profile } from '@remixproject/plugin-utils' -export type ProvidersSection = `Injected` | 'Remix VMs' | 'Externals' | 'Remix forked VMs' | 'Saved VM States' +export type ProvidersSection = `Injected` | 'Remix VMs' | 'Externals' | 'Remix forked VMs' | 'Forked States' export type environmentExplorerUIProps = { state: { @@ -36,7 +36,7 @@ export type Provider = { description?: string isInjected: boolean isVM: boolean - isSavedState: boolean + isForkedState: boolean isForkedVM: boolean title: string init: () => Promise diff --git a/libs/remix-ui/run-tab/src/lib/components/environment.tsx b/libs/remix-ui/run-tab/src/lib/components/environment.tsx index 590e9fb3f0..f38207e285 100644 --- a/libs/remix-ui/run-tab/src/lib/components/environment.tsx +++ b/libs/remix-ui/run-tab/src/lib/components/environment.tsx @@ -27,22 +27,22 @@ export function EnvironmentUI(props: EnvironmentProps) { const intl = useIntl() const isSaveEvmStateChecked = props.config.get('settings/save-evm-state') - const saveVmStatePrompt = (defaultName: string) => { + const forkStatePrompt = (defaultName: string) => { return (
vmStateName.current = e.target.value} />
- Tip: + Tip:
) @@ -60,24 +60,24 @@ export function EnvironmentUI(props: EnvironmentProps) { ) } - const saveVmState = async () => { + const forkState = async () => { const context = currentProvider.name vmStateName.current = `${context}_${Date.now()}` const contextExists = await props.runTabPlugin.call('fileManager', 'exists', `.states/${context}/state.json`) if (contextExists) { props.modal( - intl.formatMessage({ id: 'udapp.saveVmStateTitle' }), - saveVmStatePrompt(vmStateName.current), - intl.formatMessage({ id: 'udapp.save' }), + intl.formatMessage({ id: 'udapp.forkStateTitle' }), + forkStatePrompt(vmStateName.current), + intl.formatMessage({ id: 'udapp.fork' }), async () => { let currentStateDb = await props.runTabPlugin.call('fileManager', 'readFile', `.states/${context}/state.json`) currentStateDb = JSON.parse(currentStateDb) currentStateDb.stateName = vmStateName.current currentStateDb.forkName = currentProvider.fork currentStateDb.savingTimestamp = Date.now() - await props.runTabPlugin.call('fileManager', 'writeFile', `.states/saved_states/${vmStateName.current}.json`, JSON.stringify(currentStateDb, null, 2)) - props.runTabPlugin.emit('vmStateSaved', vmStateName.current) - props.runTabPlugin.call('notification', 'toast', `VM state ${vmStateName.current} saved.`) + await props.runTabPlugin.call('fileManager', 'writeFile', `.states/forked_states/${vmStateName.current}.json`, JSON.stringify(currentStateDb, null, 2)) + props.runTabPlugin.emit('vmStateForked', vmStateName.current) + props.runTabPlugin.call('notification', 'toast', `VM state ${vmStateName.current} forked successfully.`) }, intl.formatMessage({ id: 'udapp.cancel' }), null @@ -128,8 +128,8 @@ export function EnvironmentUI(props: EnvironmentProps) { - { currentProvider && currentProvider.isVM && isSaveEvmStateChecked && }> - + { currentProvider && currentProvider.isVM && isSaveEvmStateChecked && }> + } { currentProvider && currentProvider.isVM && isSaveEvmStateChecked && }>