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 235bf76e31..1c98641612 100644 --- a/apps/remix-ide/src/app/tabs/locales/en/udapp.json +++ b/apps/remix-ide/src/app/tabs/locales/en/udapp.json @@ -73,6 +73,8 @@ "udapp.savedContracts": "Saved Contracts", "udapp.NoSavedInstanceText": "Currently you have no saved contracts to interact with.", "udapp.tooltipTextUnsave": "Delete from saved list", + "udapp.savedOn": "Saved On", + diff --git a/apps/remix-ide/src/app/udapp/run-tab.js b/apps/remix-ide/src/app/udapp/run-tab.js index f1907e07fd..3cd767a689 100644 --- a/apps/remix-ide/src/app/udapp/run-tab.js +++ b/apps/remix-ide/src/app/udapp/run-tab.js @@ -84,8 +84,8 @@ export class RunTab extends ViewPlugin { this.emit('addInstanceReducer', address, abi, name) } - addSavedInstance(address, abi, name) { - this.emit('addSavedInstanceReducer', address, abi, name) + addSavedInstance(address, abi, name, savedOn) { + this.emit('addSavedInstanceReducer', address, abi, name, savedOn) } 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 469c0e0061..a6806e02ce 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 }) => { +export const addSavedInstance = (dispatch: React.Dispatch, instance: { contractData?: ContractData, address: string, name: string, abi?: any, decodedResponse?: Record, savedOn?: number }) => { 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 e72d746be7..39904dd650 100644 --- a/libs/remix-ui/run-tab/src/lib/actions/events.ts +++ b/libs/remix-ui/run-tab/src/lib/actions/events.ts @@ -83,8 +83,8 @@ export const setupEvents = (plugin: RunTab, dispatch: React.Dispatch) => { addInstance(dispatch, { abi, address, name }) }) - plugin.on('udapp', 'addSavedInstanceReducer', (address, abi, name) => { - addSavedInstance(dispatch, { abi, address, name }) + plugin.on('udapp', 'addSavedInstanceReducer', (address, abi, name, savedOn) => { + addSavedInstance(dispatch, { abi, address, name, savedOn }) }) plugin.on('filePanel', 'setWorkspace', () => { 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 44e3c5f375..d09af1882e 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 }) => { +export const addNewSavedInstance = (instance: { contractData?: ContractData, address: string, name: string, abi?: any, savedOn?: 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 a13e0efe5d..74f94eea10 100644 --- a/libs/remix-ui/run-tab/src/lib/components/instanceContainerUI.tsx +++ b/libs/remix-ui/run-tab/src/lib/components/instanceContainerUI.tsx @@ -19,7 +19,7 @@ export function InstanceContainerUI(props: InstanceContainerProps) { if (savedContracts[env] && savedContracts[env][network.id]) { const instances = savedContracts[env][network.id] for (const inst of instances) - if (inst) await props.plugin.call('udapp', 'addSavedInstance', inst.address, inst.contractData.abi, inst.name) + if (inst) await props.plugin.call('udapp', 'addSavedInstance', inst.address, inst.contractData.abi, inst.name, inst.savedOn) } } } 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 214ed40ca4..d92a4390bc 100644 --- a/libs/remix-ui/run-tab/src/lib/components/universalDappUI.tsx +++ b/libs/remix-ui/run-tab/src/lib/components/universalDappUI.tsx @@ -52,6 +52,7 @@ export function UniversalDappUI(props: UdappProps) { }, [props.instance.contractData]) useEffect(() => { + console.log('props====>', props) if (props.instance.balance) { setInstanceBalance(props.instance.balance) } @@ -142,10 +143,11 @@ export function UniversalDappUI(props: UdappProps) { objToSave[env][network.id] = [] } } + props.instance.savedOn = Date.now() objToSave[env][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) + await props.plugin.call('udapp', 'addSavedInstance', props.instance.address, props.instance.contractData.abi, props.instance.name, props.instance.savedOn) // Remove contract from deployed contracts list on UI props.removeInstance(props.index, false) } @@ -288,6 +290,13 @@ export function UniversalDappUI(props: UdappProps) { : {instanceBalance} ETH + { props.isSavedContract && props.instance.savedOn ? ( +
+ +
+ ) : null } {contractABI && contractABI.map((funcABI, index) => { if (funcABI.type !== 'function') return 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 6f39cdab21..f55fbe6ef6 100644 --- a/libs/remix-ui/run-tab/src/lib/reducers/runTab.ts +++ b/libs/remix-ui/run-tab/src/lib/reducers/runTab.ts @@ -492,8 +492,7 @@ export const runTabReducer = (state: RunTabState = runTabInitialState, action: A } case ADD_SAVED_INSTANCE: { - const payload: { contractData: ContractData, address: string, name: string, abi?: any, decodedResponse?: Record } = action.payload - + const payload: { contractData: ContractData, address: string, name: string, abi?: any, savedOn: 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 1f07b42ddc..390c8bd676 100644 --- a/libs/remix-ui/run-tab/src/lib/types/index.ts +++ b/libs/remix-ui/run-tab/src/lib/types/index.ts @@ -103,7 +103,8 @@ export interface RunTabState { balance?: number, name: string, decodedResponse?: Record, - abi?: any + abi?: any, + savedOn?: number }[], error: string }, @@ -313,7 +314,8 @@ export interface InstanceContainerProps { balance?: number, name: string, decodedResponse?: Record, - abi?: any + abi?: any, + savedOn?: number }[], error: string }, @@ -419,7 +421,8 @@ export interface UdappProps { balance?: number, name: string, decodedResponse?: Record, - abi?: any + abi?: any, + savedOn?: number }, context: 'memory' | 'blockchain', isSavedContract?: boolean