load pinned contract on load

pull/5370/head
aniket-engg 8 months ago committed by Aniket
parent 25482fd95b
commit 67667f9446
  1. 2
      apps/remix-ide/src/app/tabs/locales/en/udapp.json
  2. 4
      apps/remix-ide/src/app/udapp/run-tab.js
  3. 2
      libs/remix-ui/run-tab/src/lib/actions/actions.ts
  4. 23
      libs/remix-ui/run-tab/src/lib/actions/events.ts
  5. 2
      libs/remix-ui/run-tab/src/lib/actions/payload.ts
  6. 8
      libs/remix-ui/run-tab/src/lib/components/instanceContainerUI.tsx
  7. 6
      libs/remix-ui/run-tab/src/lib/components/universalDappUI.tsx
  8. 2
      libs/remix-ui/run-tab/src/lib/reducers/runTab.ts
  9. 6
      libs/remix-ui/run-tab/src/lib/types/index.ts

@ -75,7 +75,7 @@
"udapp.NoSavedInstanceText": "No pinned contracts found for selected workspace & network", "udapp.NoSavedInstanceText": "No pinned contracts found for selected workspace & network",
"udapp.tooltipTextDelete": "Delete pinned contract", "udapp.tooltipTextDelete": "Delete pinned contract",
"udapp.tooltipTextUnpin": "Unpin contract", "udapp.tooltipTextUnpin": "Unpin contract",
"udapp.savedOn": "Pinned at", "udapp.pinnedAt": "Pinned at",
"udapp.filePath": "File path", "udapp.filePath": "File path",
"udapp._comment_recorderCardUI.tsx": "libs/remix-ui/run-tab/src/lib/components/recorderCardUI.tsx", "udapp._comment_recorderCardUI.tsx": "libs/remix-ui/run-tab/src/lib/components/recorderCardUI.tsx",

@ -89,8 +89,8 @@ export class RunTab extends ViewPlugin {
this.emit('addInstanceReducer', address, abi, name, contractData) this.emit('addInstanceReducer', address, abi, name, contractData)
} }
addSavedInstance(address, abi, name, savedOn, filePath) { addSavedInstance(address, abi, name, pinnedAt, filePath) {
this.emit('addSavedInstanceReducer', address, abi, name, savedOn, filePath) this.emit('addSavedInstanceReducer', address, abi, name, pinnedAt, filePath)
} }
createVMAccount(newAccount) { createVMAccount(newAccount) {

@ -70,7 +70,7 @@ export const addInstance = (dispatch: React.Dispatch<any>, instance: { contractD
dispatch(addNewInstance(instance)) dispatch(addNewInstance(instance))
} }
export const addSavedInstance = (dispatch: React.Dispatch<any>, instance: { contractData?: ContractData, address: string, name: string, abi?: any, decodedResponse?: Record<number, any>, savedOn?: number, filePath?: string }) => { export const addSavedInstance = (dispatch: React.Dispatch<any>, instance: { contractData?: ContractData, address: string, name: string, abi?: any, decodedResponse?: Record<number, any>, pinnedAt?: number, filePath?: string }) => {
instance.decodedResponse = {} instance.decodedResponse = {}
dispatch(addNewSavedInstance(instance)) dispatch(addNewSavedInstance(instance))
} }

@ -87,13 +87,30 @@ export const setupEvents = (plugin: RunTab, dispatch: React.Dispatch<any>) => {
addInstance(dispatch, { contractData, abi, address, name }) addInstance(dispatch, { contractData, abi, address, name })
}) })
plugin.on('udapp', 'addSavedInstanceReducer', (address, abi, name, savedOn, filePath) => { plugin.on('udapp', 'addSavedInstanceReducer', (address, abi, name, pinnedAt, filePath) => {
addSavedInstance(dispatch, { abi, address, name, savedOn, filePath}) addSavedInstance(dispatch, { abi, address, name, pinnedAt, filePath})
}) })
plugin.on('filePanel', 'setWorkspace', () => { plugin.on('filePanel', 'setWorkspace', async () => {
dispatch(resetUdapp()) dispatch(resetUdapp())
resetAndInit(plugin) resetAndInit(plugin)
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}`)
console.log('isPinnedAvailable==in events===>', isPinnedAvailable)
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) addSavedInstance(dispatch, pinnedContractObj)
}
} catch(err) {
console.log(err)
}
}
plugin.call('manager', 'isActive', 'remixd').then((activated) => { plugin.call('manager', 'isActive', 'remixd').then((activated) => {
dispatch(setRemixDActivated(activated)) dispatch(setRemixDActivated(activated))
}) })

@ -230,7 +230,7 @@ export const addNewInstance = (instance: { contractData?: ContractData, address:
} }
} }
export const addNewSavedInstance = (instance: { contractData?: ContractData, address: string, name: string, abi?: any, savedOn?: number }) => { export const addNewSavedInstance = (instance: { contractData?: ContractData, address: string, name: string, abi?: any, pinnedAt?: number }) => {
return { return {
type: ADD_SAVED_INSTANCE, type: ADD_SAVED_INSTANCE,
payload: instance payload: instance

@ -37,14 +37,10 @@ export function InstanceContainerUI(props: InstanceContainerProps) {
await props.plugin.call('udapp', 'clearAllSavedInstances') await props.plugin.call('udapp', 'clearAllSavedInstances')
// Load contracts from FE // Load contracts from FE
const dirName = props.plugin.REACT_API.networkName === 'VM' ? props.plugin.REACT_API.selectExEnv : chainId.current const dirName = props.plugin.REACT_API.networkName === 'VM' ? props.plugin.REACT_API.selectExEnv : chainId.current
console.log('dirPath=====>', `.deploys/pinned-contracts/${dirName}`) const isPinnedAvailable = await props.plugin.call('fileManager', 'exists', `.deploys/pinned-contracts/${dirName}`)
const currentWorkspace = await props.plugin.call('filePanel', 'getCurrentWorkspace')
console.log('currentWorkspace=====>', currentWorkspace)
const isPinnedAvailable = await props.plugin.call('fileManager', 'exists', `.workspaces/${currentWorkspace}/.deploys/pinned-contracts/${dirName}`)
console.log('isPinnedAvailable=====>', isPinnedAvailable)
if (isPinnedAvailable) { if (isPinnedAvailable) {
try { try {
const list = await props.plugin.call('fileManager', 'readdir', `.workspaces/${currentWorkspace}/.deploys/pinned-contracts/${dirName}`) const list = await props.plugin.call('fileManager', 'readdir', `.deploys/pinned-contracts/${dirName}`)
const filePaths = Object.keys(list) const filePaths = Object.keys(list)
for (const file of filePaths) { for (const file of filePaths) {
const pinnedContract = await props.plugin.call('fileManager', 'readFile', file) const pinnedContract = await props.plugin.call('fileManager', 'readFile', file)

@ -263,7 +263,7 @@ export function UniversalDappUI(props: UdappProps) {
</span> </span>
<div className="input-group udapp_nameNbuts"> <div className="input-group udapp_nameNbuts">
<div className="udapp_titleText input-group-prepend"> <div className="udapp_titleText input-group-prepend">
{ props.isSavedContract ? ( <CustomTooltip placement="top" tooltipClasses="text-nowrap" tooltipId="udapp_udappUnpinTooltip" tooltipText={props.isSavedContract ? `Contract: ${props.instance.name}, Address: ${address}, Pinned at: ${new Date(props.instance.savedOn).toLocaleString()}` : '' }> { props.isSavedContract ? ( <CustomTooltip placement="top" tooltipClasses="text-nowrap" tooltipId="udapp_udappUnpinTooltip" tooltipText={props.isSavedContract ? `Contract: ${props.instance.name}, Address: ${address}, Pinned at: ${new Date(props.instance.pinnedAt).toLocaleString()}` : '' }>
<span className="input-group-text udapp_spanTitleText"> <span className="input-group-text udapp_spanTitleText">
{props.instance.name} at {shortenAddress(address)} {props.instance.name} at {shortenAddress(address)}
</span> </span>
@ -304,10 +304,10 @@ export function UniversalDappUI(props: UdappProps) {
</label> </label>
{props.exEnvironment === 'injected' && <i className="fas fa-edit btn btn-sm p-0" onClick={() => {props.editInstance(props.instance)}}></i>} {props.exEnvironment === 'injected' && <i className="fas fa-edit btn btn-sm p-0" onClick={() => {props.editInstance(props.instance)}}></i>}
</div> </div>
{ props.isSavedContract && props.instance.savedOn ? ( { props.isSavedContract && props.instance.pinnedAt ? (
<div className="d-flex" data-id="instanceContractSavedOn"> <div className="d-flex" data-id="instanceContractSavedOn">
<label> <label>
<b><FormattedMessage id="udapp.savedOn" />:</b> {(new Date(props.instance.savedOn)).toLocaleString()} <b><FormattedMessage id="udapp.pinnedAt" />:</b> {(new Date(props.instance.pinnedAt)).toLocaleString()}
</label> </label>
</div> </div>
) : null } ) : null }

@ -492,7 +492,7 @@ export const runTabReducer = (state: RunTabState = runTabInitialState, action: A
} }
case ADD_SAVED_INSTANCE: { case ADD_SAVED_INSTANCE: {
const payload: { contractData: ContractData, address: string, name: string, abi?: any, savedOn: number, decodedResponse?: Record<number, any> } = action.payload const payload: { contractData: ContractData, address: string, name: string, abi?: any, pinnedAt: number, decodedResponse?: Record<number, any> } = action.payload
return { return {
...state, ...state,
savedInstances: { savedInstances: {

@ -104,7 +104,7 @@ export interface RunTabState {
name: string, name: string,
decodedResponse?: Record<number, any>, decodedResponse?: Record<number, any>,
abi?: any, abi?: any,
savedOn?: number pinnedAt?: number
}[], }[],
error: string error: string
}, },
@ -315,7 +315,7 @@ export interface InstanceContainerProps {
name: string, name: string,
decodedResponse?: Record<number, any>, decodedResponse?: Record<number, any>,
abi?: any, abi?: any,
savedOn?: number, pinnedAt?: number,
filePath?: string filePath?: string
}[], }[],
error: string error: string
@ -425,7 +425,7 @@ export interface UdappProps {
name: string, name: string,
decodedResponse?: Record<number, any>, decodedResponse?: Record<number, any>,
abi?: any, abi?: any,
savedOn?: number, pinnedAt?: number,
filePath?: string filePath?: string
}, },
context: 'memory' | 'blockchain', context: 'memory' | 'blockchain',

Loading…
Cancel
Save