|
|
|
@ -1,7 +1,7 @@ |
|
|
|
|
import { envChangeNotification } from "@remix-ui/helper" |
|
|
|
|
import { RunTab } from "../types/run-tab" |
|
|
|
|
import { setExecutionContext, setFinalContext, updateAccountBalances, fillAccountsList } from "./account" |
|
|
|
|
import { addExternalProvider, addInstance, addPinnedInstance, addNewProxyDeployment, removeExternalProvider, setNetworkNameFromProvider } from "./actions" |
|
|
|
|
import { addExternalProvider, addInstance, addPinnedInstance, addNewProxyDeployment, removeExternalProvider, setNetworkNameFromProvider, setPinnedChainId } from "./actions" |
|
|
|
|
import { addDeployOption, clearAllInstances, clearAllPinnedInstances, clearRecorderCount, fetchContractListSuccess, resetProxyDeployments, resetUdapp, setCurrentContract, setCurrentFile, setLoadType, setRecorderCount, setRemixDActivated, setSendValue, fetchAccountsListSuccess } from "./payload" |
|
|
|
|
import { updateInstanceBalance } from './deploy' |
|
|
|
|
import { CompilerAbstract } from '@remix-project/remix-solidity' |
|
|
|
@ -35,7 +35,7 @@ export const setupEvents = (plugin: RunTab, dispatch: React.Dispatch<any>) => { |
|
|
|
|
fillAccountsList(plugin, dispatch) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
plugin.blockchain.event.register('networkStatus', ({ error, network }) => { |
|
|
|
|
plugin.blockchain.event.register('networkStatus', async ({ error, network }) => { |
|
|
|
|
if (error) { |
|
|
|
|
const netUI = 'can\'t detect network' |
|
|
|
|
setNetworkNameFromProvider(dispatch, netUI) |
|
|
|
@ -44,8 +44,10 @@ export const setupEvents = (plugin: RunTab, dispatch: React.Dispatch<any>) => { |
|
|
|
|
} |
|
|
|
|
const networkProvider = plugin.networkModule.getNetworkProvider.bind(plugin.networkModule) |
|
|
|
|
const netUI = !networkProvider().startsWith('vm') ? `${network.name} (${network.id || '-'}) network` : 'VM' |
|
|
|
|
|
|
|
|
|
const pinnedChainId = !networkProvider().startsWith('vm') ? network.id : networkProvider() |
|
|
|
|
setNetworkNameFromProvider(dispatch, netUI) |
|
|
|
|
setPinnedChainId(dispatch, pinnedChainId) |
|
|
|
|
await loadPinnedContracts(plugin, dispatch, pinnedChainId) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
plugin.blockchain.event.register('addProvider', provider => addExternalProvider(dispatch, provider)) |
|
|
|
@ -94,7 +96,6 @@ export const setupEvents = (plugin: RunTab, dispatch: React.Dispatch<any>) => { |
|
|
|
|
plugin.on('filePanel', 'setWorkspace', async () => { |
|
|
|
|
dispatch(resetUdapp()) |
|
|
|
|
resetAndInit(plugin) |
|
|
|
|
await loadPinnedContracts(plugin, dispatch) |
|
|
|
|
await migrateSavedContracts(plugin) |
|
|
|
|
plugin.call('manager', 'isActive', 'remixd').then((activated) => { |
|
|
|
|
dispatch(setRemixDActivated(activated)) |
|
|
|
@ -165,46 +166,48 @@ export const setupEvents = (plugin: RunTab, dispatch: React.Dispatch<any>) => { |
|
|
|
|
}, 30000)
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const loadPinnedContracts = async (plugin, dispatch) => { |
|
|
|
|
const { network } = await plugin.call('blockchain', 'getCurrentNetworkStatus') |
|
|
|
|
const dirName = plugin.REACT_API.networkName === 'VM' ? plugin.REACT_API.selectExEnv : network.id |
|
|
|
|
const isPinnedAvailable = await plugin.call('fileManager', 'exists', `.deploys/pinned-contracts/${dirName}`) |
|
|
|
|
if (isPinnedAvailable) { |
|
|
|
|
try { |
|
|
|
|
const list = await plugin.call('fileManager', 'readdir', `.deploys/pinned-contracts/${dirName}`) |
|
|
|
|
const filePaths = Object.keys(list) |
|
|
|
|
for (const file of filePaths) { |
|
|
|
|
const pinnedContract = await plugin.call('fileManager', 'readFile', file) |
|
|
|
|
const pinnedContractObj = JSON.parse(pinnedContract) |
|
|
|
|
if (pinnedContractObj) addPinnedInstance(dispatch, pinnedContractObj) |
|
|
|
|
} |
|
|
|
|
} catch(err) { |
|
|
|
|
console.log(err) |
|
|
|
|
const loadPinnedContracts = async (plugin, dispatch, dirName) => { |
|
|
|
|
console.log('loadPinnedContracts---->') |
|
|
|
|
await plugin.call('udapp', 'clearAllPinnedInstances') |
|
|
|
|
// const { network } = await plugin.call('blockchain', 'getCurrentNetworkStatus')
|
|
|
|
|
// const dirName = plugin.REACT_API.networkName === 'VM' ? plugin.REACT_API.selectExEnv : network.id
|
|
|
|
|
const isPinnedAvailable = await plugin.call('fileManager', 'exists', `.deploys/pinned-contracts/${dirName}`) |
|
|
|
|
if (isPinnedAvailable) { |
|
|
|
|
try { |
|
|
|
|
const list = await plugin.call('fileManager', 'readdir', `.deploys/pinned-contracts/${dirName}`) |
|
|
|
|
const filePaths = Object.keys(list) |
|
|
|
|
for (const file of filePaths) { |
|
|
|
|
const pinnedContract = await plugin.call('fileManager', 'readFile', file) |
|
|
|
|
const pinnedContractObj = JSON.parse(pinnedContract) |
|
|
|
|
if (pinnedContractObj) addPinnedInstance(dispatch, pinnedContractObj) |
|
|
|
|
} |
|
|
|
|
} catch(err) { |
|
|
|
|
console.log(err) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const migrateSavedContracts = async (plugin) => { |
|
|
|
|
// Move contract saved in localstorage to Remix FE
|
|
|
|
|
const allSavedContracts = localStorage.getItem('savedContracts') |
|
|
|
|
if (allSavedContracts) { |
|
|
|
|
const savedContracts = JSON.parse(allSavedContracts) |
|
|
|
|
for (const networkId in savedContracts) { |
|
|
|
|
if (savedContracts[networkId].length > 0) { |
|
|
|
|
for (const contractDetails of savedContracts[networkId]) { |
|
|
|
|
const objToSave = { |
|
|
|
|
name: contractDetails.name, |
|
|
|
|
address: contractDetails.address, |
|
|
|
|
abi: contractDetails.abi || contractDetails.contractData.abi, |
|
|
|
|
filePath: contractDetails.filePath, |
|
|
|
|
pinnedAt: contractDetails.savedOn |
|
|
|
|
} |
|
|
|
|
await plugin.call('fileManager', 'writeFile', `.deploys/pinned-contracts/${networkId}/${contractDetails.address}.json`, JSON.stringify(objToSave, null, 2)) |
|
|
|
|
} |
|
|
|
|
// Move contract saved in localstorage to Remix FE
|
|
|
|
|
const allSavedContracts = localStorage.getItem('savedContracts') |
|
|
|
|
if (allSavedContracts) { |
|
|
|
|
const savedContracts = JSON.parse(allSavedContracts) |
|
|
|
|
for (const networkId in savedContracts) { |
|
|
|
|
if (savedContracts[networkId].length > 0) { |
|
|
|
|
for (const contractDetails of savedContracts[networkId]) { |
|
|
|
|
const objToSave = { |
|
|
|
|
name: contractDetails.name, |
|
|
|
|
address: contractDetails.address, |
|
|
|
|
abi: contractDetails.abi || contractDetails.contractData.abi, |
|
|
|
|
filePath: contractDetails.filePath, |
|
|
|
|
pinnedAt: contractDetails.savedOn |
|
|
|
|
} |
|
|
|
|
await plugin.call('fileManager', 'writeFile', `.deploys/pinned-contracts/${networkId}/${contractDetails.address}.json`, JSON.stringify(objToSave, null, 2)) |
|
|
|
|
} |
|
|
|
|
localStorage.removeItem('savedContracts') |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
localStorage.removeItem('savedContracts') |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const broadcastCompilationResult = async (compilerName: string, plugin: RunTab, dispatch: React.Dispatch<any>, file, source, languageVersion, data, input?) => { |
|
|
|
|