Skip to content

Commit 90b3f91

Browse files
committed
fix vm state issue
1 parent 0142894 commit 90b3f91

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

libs/remix-ui/quick-dapp-v2/src/lib/utils/DappManager.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -266,12 +266,12 @@ export class DappManager {
266266
);
267267

268268
// Preserve VM state: the VM reads .states/{provider}/state.json per workspace.
269-
// Without copying, switching to a new workspace resets the VM and loses deployed contracts.
269+
// Without copying, switching to a new workspace resets the VM and loses deployed contracts.\
270270
let vmStateSnapshot: string | null = null;
271-
let vmProviderName: string | null = null;
272-
try {
273-
vmProviderName = await (this.plugin as any).call('blockchain', 'getProvider') as string;
274-
if (vmProviderName && vmProviderName.startsWith('vm-')) {
271+
const vmProviderName = contractData.chainId && String(contractData.chainId).startsWith('vm-')
272+
? String(contractData.chainId) : null;
273+
if (vmProviderName) {
274+
try {
275275
// Flush the latest in-memory state to disk first
276276
try { await (this.plugin as any).call('blockchain', 'dumpState'); } catch (_) { /* non-critical */ }
277277
await new Promise(resolve => setTimeout(resolve, 100));
@@ -281,26 +281,29 @@ export class DappManager {
281281
if (stateExists) {
282282
vmStateSnapshot = await this.plugin.call('fileManager', 'readFile', statePath) as string;
283283
}
284+
} catch (e) {
285+
console.warn('[DappManager] Could not capture VM state (non-critical):', e);
284286
}
285-
} catch (e) {
286-
console.warn('[DappManager] Could not capture VM state (non-critical):', e);
287287
}
288288

289289
await this.plugin.call('filePanel', 'createWorkspace', workspaceName, true);
290290

291291
await this.switchToWorkspace(workspaceName);
292292
await new Promise(resolve => setTimeout(resolve, 300));
293293

294-
// Restore VM state in the new DApp workspace
294+
// Restore VM state in the new DApp workspace.
295295
if (vmStateSnapshot && vmProviderName) {
296+
const foldersToWrite = new Set([vmProviderName, 'vm-osaka']);
296297
try {
297298
try { await this.plugin.call('fileManager', 'mkdir', '.states'); } catch (_) {}
298-
try { await this.plugin.call('fileManager', 'mkdir', `.states/${vmProviderName}`); } catch (_) {}
299-
await this.plugin.call(
300-
'fileManager', 'writeFile',
301-
`.states/${vmProviderName}/state.json`,
302-
vmStateSnapshot
303-
);
299+
for (const folder of foldersToWrite) {
300+
try { await this.plugin.call('fileManager', 'mkdir', `.states/${folder}`); } catch (_) {}
301+
await this.plugin.call(
302+
'fileManager', 'writeFile',
303+
`.states/${folder}/state.json`,
304+
vmStateSnapshot
305+
);
306+
}
304307
} catch (e) {
305308
console.warn('[DappManager] Failed to restore VM state (non-critical):', e);
306309
}

0 commit comments

Comments
 (0)