From 303c09d0cd107086b806e74245a005e9b75bfe12 Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Fri, 23 Feb 2024 12:38:05 +0530 Subject: [PATCH] save using network id --- .../lib/components/instanceContainerUI.tsx | 4 ++-- .../src/lib/components/universalDappUI.tsx | 21 +++++++------------ 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/libs/remix-ui/run-tab/src/lib/components/instanceContainerUI.tsx b/libs/remix-ui/run-tab/src/lib/components/instanceContainerUI.tsx index b96fef6645..c0544cec6f 100644 --- a/libs/remix-ui/run-tab/src/lib/components/instanceContainerUI.tsx +++ b/libs/remix-ui/run-tab/src/lib/components/instanceContainerUI.tsx @@ -17,8 +17,8 @@ export function InstanceContainerUI(props: InstanceContainerProps) { if (allSavedContracts) { const savedContracts = JSON.parse(allSavedContracts) const { network } = await props.plugin.call('blockchain', 'getCurrentNetworkStatus') - if (savedContracts[env.current] && savedContracts[env.current][network.id]) { - const instances = savedContracts[env.current][network.id] + if (savedContracts && savedContracts[network.id]) { + const instances = savedContracts[network.id] for (const inst of instances) if (inst) await props.plugin.call('udapp', 'addSavedInstance', inst.address, inst.contractData.abi, inst.name, inst.savedOn, inst.filePath) } diff --git a/libs/remix-ui/run-tab/src/lib/components/universalDappUI.tsx b/libs/remix-ui/run-tab/src/lib/components/universalDappUI.tsx index 16f97a4fdc..a2a0454f53 100644 --- a/libs/remix-ui/run-tab/src/lib/components/universalDappUI.tsx +++ b/libs/remix-ui/run-tab/src/lib/components/universalDappUI.tsx @@ -121,39 +121,34 @@ export function UniversalDappUI(props: UdappProps) { const remove = async() => { if (props.isSavedContract) { - const env = await props.plugin.call('blockchain', 'getProvider') const {network} = await props.plugin.call('blockchain', 'getCurrentNetworkStatus') const savedContracts = localStorage.getItem('savedContracts') const savedContractsJson = JSON.parse(savedContracts) - const instanceIndex = savedContractsJson[env][network.id].findIndex(instance => instance && instance.address === props.instance.address) - delete savedContractsJson[env][network.id][instanceIndex] - localStorage.setItem('savedContracts', JSON.stringify(savedContractsJson[env][network.id].filter(Boolean))) + const instanceIndex = savedContractsJson[network.id].findIndex(instance => instance && instance.address === props.instance.address) + delete savedContractsJson[network.id][instanceIndex] + savedContractsJson[network.id] = savedContractsJson[network.id].filter(Boolean) + localStorage.setItem('savedContracts', JSON.stringify(savedContractsJson)) } props.removeInstance(props.index, props.isSavedContract) } const saveContract = async() => { - const env = await props.plugin.call('blockchain', 'getProvider') const workspace = await props.plugin.call('filePanel', 'getCurrentWorkspace') const {network} = await props.plugin.call('blockchain', 'getCurrentNetworkStatus') const savedContracts = localStorage.getItem('savedContracts') let objToSave if (!savedContracts) { objToSave = {} - objToSave[env] = {} - objToSave[env][network.id] = [] + objToSave[network.id] = [] } else { objToSave = JSON.parse(savedContracts) - if (!objToSave[env]) { - objToSave[env] = {} - objToSave[env][network.id] = [] - } else if (!objToSave[env][network.id]) { - objToSave[env][network.id] = [] + if (!objToSave[network.id]) { + objToSave[network.id] = [] } } props.instance.savedOn = Date.now() props.instance.filePath = `${workspace.name}/${props.instance.contractData.contract.file}` - objToSave[env][network.id].push(props.instance) + objToSave[network.id].push(props.instance) localStorage.setItem('savedContracts', JSON.stringify(objToSave)) // Add contract to saved contracts list on UI await props.plugin.call('udapp', 'addSavedInstance', props.instance.address, props.instance.contractData.abi, props.instance.name, props.instance.savedOn, props.instance.filePath)