|
|
@ -11,46 +11,46 @@ export function InstanceContainerUI(props: InstanceContainerProps) { |
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
useEffect(() => { |
|
|
|
const fetchSavedContracts = async () => { |
|
|
|
const fetchSavedContracts = async () => { |
|
|
|
const { network } = await props.plugin.call('blockchain', 'getCurrentNetworkStatus') |
|
|
|
const { network } = await props.plugin.call('blockchain', 'getCurrentNetworkStatus') |
|
|
|
chainId.current = network.id |
|
|
|
chainId.current = network.id |
|
|
|
// Move contract saved in localstorage to Remix FE
|
|
|
|
// Move contract saved in localstorage to Remix FE
|
|
|
|
const allSavedContracts = localStorage.getItem('savedContracts') |
|
|
|
const allSavedContracts = localStorage.getItem('savedContracts') |
|
|
|
if (allSavedContracts) { |
|
|
|
if (allSavedContracts) { |
|
|
|
const savedContracts = JSON.parse(allSavedContracts) |
|
|
|
const savedContracts = JSON.parse(allSavedContracts) |
|
|
|
for (const networkId in savedContracts) { |
|
|
|
for (const networkId in savedContracts) { |
|
|
|
if (savedContracts[networkId].length > 0) { |
|
|
|
if (savedContracts[networkId].length > 0) { |
|
|
|
for (const contractDetails of savedContracts[networkId]) { |
|
|
|
for (const contractDetails of savedContracts[networkId]) { |
|
|
|
const objToSave = { |
|
|
|
const objToSave = { |
|
|
|
name: contractDetails.name, |
|
|
|
name: contractDetails.name, |
|
|
|
address: contractDetails.address, |
|
|
|
address: contractDetails.address, |
|
|
|
abi: contractDetails.abi || contractDetails.contractData.abi, |
|
|
|
abi: contractDetails.abi || contractDetails.contractData.abi, |
|
|
|
filePath: contractDetails.filePath, |
|
|
|
filePath: contractDetails.filePath, |
|
|
|
pinnedAt: contractDetails.savedOn |
|
|
|
pinnedAt: contractDetails.savedOn |
|
|
|
} |
|
|
|
|
|
|
|
await props.plugin.call('fileManager', 'writeFile', `.deploys/pinned-contracts/${networkId}/${contractDetails.address}.json`, JSON.stringify(objToSave, null, 2)) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
await props.plugin.call('fileManager', 'writeFile', `.deploys/pinned-contracts/${networkId}/${contractDetails.address}.json`, JSON.stringify(objToSave, null, 2)) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
localStorage.removeItem('savedContracts') |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
// Clear existing saved instance state
|
|
|
|
localStorage.removeItem('savedContracts') |
|
|
|
await props.plugin.call('udapp', 'clearAllSavedInstances') |
|
|
|
} |
|
|
|
// Load contracts from FE
|
|
|
|
// Clear existing saved instance state
|
|
|
|
const dirName = props.plugin.REACT_API.networkName === 'VM' ? props.plugin.REACT_API.selectExEnv : chainId.current |
|
|
|
await props.plugin.call('udapp', 'clearAllSavedInstances') |
|
|
|
const isPinnedAvailable = await props.plugin.call('fileManager', 'exists', `.deploys/pinned-contracts/${dirName}`) |
|
|
|
// Load contracts from FE
|
|
|
|
if (isPinnedAvailable) { |
|
|
|
const dirName = props.plugin.REACT_API.networkName === 'VM' ? props.plugin.REACT_API.selectExEnv : chainId.current |
|
|
|
try { |
|
|
|
const isPinnedAvailable = await props.plugin.call('fileManager', 'exists', `.deploys/pinned-contracts/${dirName}`) |
|
|
|
const list = await props.plugin.call('fileManager', 'readdir', `.deploys/pinned-contracts/${dirName}`) |
|
|
|
if (isPinnedAvailable) { |
|
|
|
const filePaths = Object.keys(list) |
|
|
|
try { |
|
|
|
for (const file of filePaths) { |
|
|
|
const list = await props.plugin.call('fileManager', 'readdir', `.deploys/pinned-contracts/${dirName}`) |
|
|
|
const pinnedContract = await props.plugin.call('fileManager', 'readFile', file) |
|
|
|
const filePaths = Object.keys(list) |
|
|
|
const pinnedContractObj = JSON.parse(pinnedContract) |
|
|
|
for (const file of filePaths) { |
|
|
|
if (pinnedContractObj) await props.plugin.call('udapp', 'addSavedInstance', pinnedContractObj.address, pinnedContractObj.abi, pinnedContractObj.name, pinnedContractObj.pinnedAt, pinnedContractObj.filePath) |
|
|
|
const pinnedContract = await props.plugin.call('fileManager', 'readFile', file) |
|
|
|
} |
|
|
|
const pinnedContractObj = JSON.parse(pinnedContract) |
|
|
|
} catch(err) { |
|
|
|
if (pinnedContractObj) await props.plugin.call('udapp', 'addSavedInstance', pinnedContractObj.address, pinnedContractObj.abi, pinnedContractObj.name, pinnedContractObj.pinnedAt, pinnedContractObj.filePath) |
|
|
|
console.log(err) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} catch(err) { |
|
|
|
|
|
|
|
console.log(err) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
fetchSavedContracts() |
|
|
|
fetchSavedContracts() |
|
|
|
}, [props.plugin.REACT_API.selectExEnv, props.plugin.REACT_API.networkName]) |
|
|
|
}, [props.plugin.REACT_API.selectExEnv, props.plugin.REACT_API.networkName]) |
|
|
@ -61,45 +61,45 @@ export function InstanceContainerUI(props: InstanceContainerProps) { |
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<div className="udapp_instanceContainer mt-3 border-0 list-group-item"> |
|
|
|
<div className="udapp_instanceContainer mt-3 border-0 list-group-item"> |
|
|
|
<div className="d-flex justify-content-between align-items-center pl-2"> |
|
|
|
<div className="d-flex justify-content-between align-items-center pl-2"> |
|
|
|
<CustomTooltip placement="top-start" tooltipClasses="text-nowrap" tooltipId="deployAndRunPinnedContractsTooltip" tooltipText={<FormattedMessage id="udapp.tooltipTextPinnedContracts" />}> |
|
|
|
<CustomTooltip placement="top-start" tooltipClasses="text-nowrap" tooltipId="deployAndRunPinnedContractsTooltip" tooltipText={<FormattedMessage id="udapp.tooltipTextPinnedContracts" />}> |
|
|
|
<label className="udapp_deployedContracts"> |
|
|
|
<label className="udapp_deployedContracts"> |
|
|
|
<FormattedMessage id="udapp.savedContracts" />
|
|
|
|
<FormattedMessage id="udapp.savedContracts" />
|
|
|
|
<span style={{fontSize: '0.75rem'}}> { props.plugin.REACT_API.networkName === 'VM' ? `(VM: ${props.plugin.REACT_API.selectExEnv})` : `(chain id: ${chainId.current})` }</span> |
|
|
|
<span style={{fontSize: '0.75rem'}}> { props.plugin.REACT_API.networkName === 'VM' ? `(VM: ${props.plugin.REACT_API.selectExEnv})` : `(chain id: ${chainId.current})` }</span> |
|
|
|
</label> |
|
|
|
</label> |
|
|
|
</CustomTooltip> |
|
|
|
</CustomTooltip> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
|
|
|
|
|
|
|
|
{props.savedInstances.instanceList.length > 0 ? ( |
|
|
|
{props.savedInstances.instanceList.length > 0 ? ( |
|
|
|
<div> |
|
|
|
<div> |
|
|
|
{' '} |
|
|
|
{' '} |
|
|
|
{props.savedInstances.instanceList.map((instance, index) => { |
|
|
|
{props.savedInstances.instanceList.map((instance, index) => { |
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<UniversalDappUI |
|
|
|
<UniversalDappUI |
|
|
|
key={index} |
|
|
|
key={index} |
|
|
|
instance={instance} |
|
|
|
instance={instance} |
|
|
|
isSavedContract={true} |
|
|
|
isSavedContract={true} |
|
|
|
context={props.getContext()} |
|
|
|
context={props.getContext()} |
|
|
|
removeInstance={props.removeInstance} |
|
|
|
removeInstance={props.removeInstance} |
|
|
|
index={index} |
|
|
|
index={index} |
|
|
|
gasEstimationPrompt={props.gasEstimationPrompt} |
|
|
|
gasEstimationPrompt={props.gasEstimationPrompt} |
|
|
|
passphrasePrompt={props.passphrasePrompt} |
|
|
|
passphrasePrompt={props.passphrasePrompt} |
|
|
|
mainnetPrompt={props.mainnetPrompt} |
|
|
|
mainnetPrompt={props.mainnetPrompt} |
|
|
|
runTransactions={props.runTransactions} |
|
|
|
runTransactions={props.runTransactions} |
|
|
|
sendValue={props.sendValue} |
|
|
|
sendValue={props.sendValue} |
|
|
|
getFuncABIInputs={props.getFuncABIInputs} |
|
|
|
getFuncABIInputs={props.getFuncABIInputs} |
|
|
|
plugin={props.plugin} |
|
|
|
plugin={props.plugin} |
|
|
|
exEnvironment={props.exEnvironment} |
|
|
|
exEnvironment={props.exEnvironment} |
|
|
|
editInstance={props.editInstance} |
|
|
|
editInstance={props.editInstance} |
|
|
|
/> |
|
|
|
/> |
|
|
|
) |
|
|
|
) |
|
|
|
})} |
|
|
|
})} |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
) : ( |
|
|
|
) : ( |
|
|
|
<span className="mx-2 mt-2 text-dark" data-id="NoSavedInstanceText"> |
|
|
|
<span className="mx-2 mt-2 text-dark" data-id="NoSavedInstanceText"> |
|
|
|
<FormattedMessage id="udapp.NoSavedInstanceText" /> |
|
|
|
<FormattedMessage id="udapp.NoSavedInstanceText" /> |
|
|
|
</span> |
|
|
|
</span> |
|
|
|
)} |
|
|
|
)} |
|
|
|
|
|
|
|
|
|
|
|
<div className="d-flex justify-content-between align-items-center pl-2 mb-2 mt-2"> |
|
|
|
<div className="d-flex justify-content-between align-items-center pl-2 mb-2 mt-2"> |
|
|
|
<CustomTooltip placement="top-start" tooltipClasses="text-nowrap" tooltipId="deployAndRunClearInstancesTooltip" tooltipText={<FormattedMessage id="udapp.tooltipText6" />}> |
|
|
|
<CustomTooltip placement="top-start" tooltipClasses="text-nowrap" tooltipId="deployAndRunClearInstancesTooltip" tooltipText={<FormattedMessage id="udapp.tooltipText6" />}> |
|
|
|