diff --git a/apps/remix-ide/src/app/tabs/locales/en/udapp.json b/apps/remix-ide/src/app/tabs/locales/en/udapp.json index 1db24ca378..4ab434c25f 100644 --- a/apps/remix-ide/src/app/tabs/locales/en/udapp.json +++ b/apps/remix-ide/src/app/tabs/locales/en/udapp.json @@ -75,7 +75,7 @@ "udapp.NoSavedInstanceText": "No pinned contracts found for selected workspace & network", "udapp.tooltipTextDelete": "Delete pinned contract", "udapp.tooltipTextUnpin": "Unpin contract", - "udapp.savedOn": "Pinned at", + "udapp.pinnedAt": "Pinned at", "udapp.filePath": "File path", "udapp._comment_recorderCardUI.tsx": "libs/remix-ui/run-tab/src/lib/components/recorderCardUI.tsx", diff --git a/apps/remix-ide/src/app/udapp/run-tab.js b/apps/remix-ide/src/app/udapp/run-tab.js index 7d65cae8de..f45e0ba67b 100644 --- a/apps/remix-ide/src/app/udapp/run-tab.js +++ b/apps/remix-ide/src/app/udapp/run-tab.js @@ -89,8 +89,8 @@ export class RunTab extends ViewPlugin { this.emit('addInstanceReducer', address, abi, name, contractData) } - addSavedInstance(address, abi, name, savedOn, filePath) { - this.emit('addSavedInstanceReducer', address, abi, name, savedOn, filePath) + addSavedInstance(address, abi, name, pinnedAt, filePath) { + this.emit('addSavedInstanceReducer', address, abi, name, pinnedAt, filePath) } createVMAccount(newAccount) { diff --git a/libs/remix-ui/run-tab/src/lib/actions/actions.ts b/libs/remix-ui/run-tab/src/lib/actions/actions.ts index 127993af20..318a72292d 100644 --- a/libs/remix-ui/run-tab/src/lib/actions/actions.ts +++ b/libs/remix-ui/run-tab/src/lib/actions/actions.ts @@ -70,7 +70,7 @@ export const addInstance = (dispatch: React.Dispatch, instance: { contractD dispatch(addNewInstance(instance)) } -export const addSavedInstance = (dispatch: React.Dispatch, instance: { contractData?: ContractData, address: string, name: string, abi?: any, decodedResponse?: Record, savedOn?: number, filePath?: string }) => { +export const addSavedInstance = (dispatch: React.Dispatch, instance: { contractData?: ContractData, address: string, name: string, abi?: any, decodedResponse?: Record, pinnedAt?: number, filePath?: string }) => { instance.decodedResponse = {} dispatch(addNewSavedInstance(instance)) } diff --git a/libs/remix-ui/run-tab/src/lib/actions/events.ts b/libs/remix-ui/run-tab/src/lib/actions/events.ts index ab2188847b..e01fdcd522 100644 --- a/libs/remix-ui/run-tab/src/lib/actions/events.ts +++ b/libs/remix-ui/run-tab/src/lib/actions/events.ts @@ -87,13 +87,30 @@ export const setupEvents = (plugin: RunTab, dispatch: React.Dispatch) => { addInstance(dispatch, { contractData, abi, address, name }) }) - plugin.on('udapp', 'addSavedInstanceReducer', (address, abi, name, savedOn, filePath) => { - addSavedInstance(dispatch, { abi, address, name, savedOn, filePath}) + plugin.on('udapp', 'addSavedInstanceReducer', (address, abi, name, pinnedAt, filePath) => { + addSavedInstance(dispatch, { abi, address, name, pinnedAt, filePath}) }) - plugin.on('filePanel', 'setWorkspace', () => { + plugin.on('filePanel', 'setWorkspace', async () => { dispatch(resetUdapp()) 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) => { dispatch(setRemixDActivated(activated)) }) diff --git a/libs/remix-ui/run-tab/src/lib/actions/payload.ts b/libs/remix-ui/run-tab/src/lib/actions/payload.ts index 8d2e9a8366..57095c4475 100644 --- a/libs/remix-ui/run-tab/src/lib/actions/payload.ts +++ b/libs/remix-ui/run-tab/src/lib/actions/payload.ts @@ -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 { type: ADD_SAVED_INSTANCE, payload: instance 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 1aced78696..d1d880771a 100644 --- a/libs/remix-ui/run-tab/src/lib/components/instanceContainerUI.tsx +++ b/libs/remix-ui/run-tab/src/lib/components/instanceContainerUI.tsx @@ -37,14 +37,10 @@ export function InstanceContainerUI(props: InstanceContainerProps) { await props.plugin.call('udapp', 'clearAllSavedInstances') // Load contracts from FE const dirName = props.plugin.REACT_API.networkName === 'VM' ? props.plugin.REACT_API.selectExEnv : chainId.current - console.log('dirPath=====>', `.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) + const isPinnedAvailable = await props.plugin.call('fileManager', 'exists', `.deploys/pinned-contracts/${dirName}`) if (isPinnedAvailable) { 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) for (const file of filePaths) { const pinnedContract = await props.plugin.call('fileManager', 'readFile', file) 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 165aa098bf..baa367ac72 100644 --- a/libs/remix-ui/run-tab/src/lib/components/universalDappUI.tsx +++ b/libs/remix-ui/run-tab/src/lib/components/universalDappUI.tsx @@ -263,7 +263,7 @@ export function UniversalDappUI(props: UdappProps) {
- { props.isSavedContract ? ( + { props.isSavedContract ? ( {props.instance.name} at {shortenAddress(address)} @@ -304,10 +304,10 @@ export function UniversalDappUI(props: UdappProps) { {props.exEnvironment === 'injected' && {props.editInstance(props.instance)}}>}
- { props.isSavedContract && props.instance.savedOn ? ( + { props.isSavedContract && props.instance.pinnedAt ? (
) : null } diff --git a/libs/remix-ui/run-tab/src/lib/reducers/runTab.ts b/libs/remix-ui/run-tab/src/lib/reducers/runTab.ts index d35175882b..287dfd2a2f 100644 --- a/libs/remix-ui/run-tab/src/lib/reducers/runTab.ts +++ b/libs/remix-ui/run-tab/src/lib/reducers/runTab.ts @@ -492,7 +492,7 @@ export const runTabReducer = (state: RunTabState = runTabInitialState, action: A } case ADD_SAVED_INSTANCE: { - const payload: { contractData: ContractData, address: string, name: string, abi?: any, savedOn: number, decodedResponse?: Record } = action.payload + const payload: { contractData: ContractData, address: string, name: string, abi?: any, pinnedAt: number, decodedResponse?: Record } = action.payload return { ...state, savedInstances: { diff --git a/libs/remix-ui/run-tab/src/lib/types/index.ts b/libs/remix-ui/run-tab/src/lib/types/index.ts index c8184d1890..8e5a379abe 100644 --- a/libs/remix-ui/run-tab/src/lib/types/index.ts +++ b/libs/remix-ui/run-tab/src/lib/types/index.ts @@ -104,7 +104,7 @@ export interface RunTabState { name: string, decodedResponse?: Record, abi?: any, - savedOn?: number + pinnedAt?: number }[], error: string }, @@ -315,7 +315,7 @@ export interface InstanceContainerProps { name: string, decodedResponse?: Record, abi?: any, - savedOn?: number, + pinnedAt?: number, filePath?: string }[], error: string @@ -425,7 +425,7 @@ export interface UdappProps { name: string, decodedResponse?: Record, abi?: any, - savedOn?: number, + pinnedAt?: number, filePath?: string }, context: 'memory' | 'blockchain',