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 3c2b581e03..469c0e0061 100644 --- a/libs/remix-ui/run-tab/src/lib/actions/actions.ts +++ b/libs/remix-ui/run-tab/src/lib/actions/actions.ts @@ -75,8 +75,8 @@ export const addSavedInstance = (dispatch: React.Dispatch, instance: { cont dispatch(addNewSavedInstance(instance)) } -export const removeInstance = (dispatch: React.Dispatch, index: number) => { - dispatch(removeExistingInstance(index)) +export const removeInstance = (dispatch: React.Dispatch, index: number, isSavedContract: boolean) => { + dispatch(removeExistingInstance(index, isSavedContract)) } export const clearInstances = (dispatch: React.Dispatch) => { diff --git a/libs/remix-ui/run-tab/src/lib/actions/index.ts b/libs/remix-ui/run-tab/src/lib/actions/index.ts index 012b765fbe..3746757184 100644 --- a/libs/remix-ui/run-tab/src/lib/actions/index.ts +++ b/libs/remix-ui/run-tab/src/lib/actions/index.ts @@ -48,7 +48,7 @@ export const setGasPriceStatus = (status: boolean) => updateGasPriceStatus(dispa export const setMaxFee = (fee: string) => updateMaxFee(dispatch, fee) export const setMaxPriorityFee = (fee: string) => updateMaxPriorityFee(dispatch, fee) export const removeInstances = () => clearInstances(dispatch) -export const removeSingleInstance = (index: number) => removeInstance(dispatch, index) +export const removeSingleInstance = (index: number, isSavedContract: boolean) => removeInstance(dispatch, index, isSavedContract) export const getExecutionContext = () => getContext(plugin) export const executeTransactions = (instanceIndex: number, isSavedContract: boolean, lookupOnly: boolean, funcABI: FuncABI, inputsValues: string, contractName: string, contractABI, contract, address, logMsg:string, mainnetPrompt: MainnetPrompt, gasEstimationPrompt: (msg: string) => JSX.Element, passphrasePrompt: (msg: string) => JSX.Element, funcIndex?: number) => runTransactions(plugin, dispatch, instanceIndex, isSavedContract, lookupOnly, funcABI, inputsValues, contractName, contractABI, contract, address, logMsg, mainnetPrompt, gasEstimationPrompt, passphrasePrompt, funcIndex) export const loadFromAddress = (contract: ContractData, address: string) => loadAddress(plugin, dispatch, contract, address) 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 e321101ebc..44e3c5f375 100644 --- a/libs/remix-ui/run-tab/src/lib/actions/payload.ts +++ b/libs/remix-ui/run-tab/src/lib/actions/payload.ts @@ -237,10 +237,13 @@ export const addNewSavedInstance = (instance: { contractData?: ContractData, add } } -export const removeExistingInstance = (index: number) => { +export const removeExistingInstance = (index: number, isSavedContract: boolean) => { return { type: REMOVE_INSTANCE, - payload: index + payload: { + index, + isSavedContract + } } } 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 88253d2ec3..1f374bca13 100644 --- a/libs/remix-ui/run-tab/src/lib/components/universalDappUI.tsx +++ b/libs/remix-ui/run-tab/src/lib/components/universalDappUI.tsx @@ -111,12 +111,17 @@ export function UniversalDappUI(props: UdappProps) { setToggleExpander(!toggleExpander) } - const remove = () => { - props.removeInstance(props.index) - } - - const unsave = () => { - console.log('unsave is clicked') + const remove = async() => { + if (props.isSavedContract) { + const env = await props.plugin.call('blockchain', 'getProvider') + const {network} = await props.plugin.call('blockchain', 'getCurrentNetworkStatus') + const savedContracts = localStorage.getItem('savedContracts') + const savedContractsJson = JSON.parse(savedContracts) + const instanceIndex = savedContractsJson[env][network.id].findIndex(instance => instance.address === props.instance.address) + delete savedContractsJson[env][network.id][instanceIndex] + localStorage.setItem('savedContracts', JSON.stringify(savedContractsJson)) + } + props.removeInstance(props.index, props.isSavedContract) } const saveContract = async() => { @@ -268,8 +273,8 @@ export function UniversalDappUI(props: UdappProps) { ( }> ) : - ( }> - + ( }> + )}
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 4a9c7d1732..6f39cdab21 100644 --- a/libs/remix-ui/run-tab/src/lib/reducers/runTab.ts +++ b/libs/remix-ui/run-tab/src/lib/reducers/runTab.ts @@ -516,15 +516,24 @@ export const runTabReducer = (state: RunTabState = runTabInitialState, action: A } case REMOVE_INSTANCE: { - const payload: number = action.payload + const payload: { index: number, isSavedContract: boolean } = action.payload - return { - ...state, - instances: { - ...state.instances, - instanceList: state.instances.instanceList.filter((_, index) => index !== payload) + if (payload.isSavedContract) + return { + ...state, + savedInstances: { + ...state.savedInstances, + instanceList: state.savedInstances.instanceList.filter((_, index) => index !== payload.index) + } + } + else + return { + ...state, + instances: { + ...state.instances, + instanceList: state.instances.instanceList.filter((_, index) => index !== payload.index) + } } - } } case CLEAR_INSTANCES: { 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 a046b51b55..1f07b42ddc 100644 --- a/libs/remix-ui/run-tab/src/lib/types/index.ts +++ b/libs/remix-ui/run-tab/src/lib/types/index.ts @@ -318,7 +318,7 @@ export interface InstanceContainerProps { error: string }, clearInstances: () => void, - removeInstance: (index: number) => void, + removeInstance: (index: number, isSavedContract:boolean) => void, getContext: () => 'memory' | 'blockchain', runTransactions: ( instanceIndex: number, @@ -423,7 +423,7 @@ export interface UdappProps { }, context: 'memory' | 'blockchain', isSavedContract?: boolean - removeInstance: (index: number) => void, + removeInstance: (index: number, isSavedContract: boolean) => void, index: number, gasEstimationPrompt: (msg: string) => JSX.Element, passphrasePrompt: (message: string) => JSX.Element,