remove saved contract

pull/5370/head
aniket-engg 9 months ago committed by Aniket
parent 2ddc940d26
commit 72c72f8c39
  1. 4
      libs/remix-ui/run-tab/src/lib/actions/actions.ts
  2. 2
      libs/remix-ui/run-tab/src/lib/actions/index.ts
  3. 7
      libs/remix-ui/run-tab/src/lib/actions/payload.ts
  4. 21
      libs/remix-ui/run-tab/src/lib/components/universalDappUI.tsx
  5. 23
      libs/remix-ui/run-tab/src/lib/reducers/runTab.ts
  6. 4
      libs/remix-ui/run-tab/src/lib/types/index.ts

@ -75,8 +75,8 @@ export const addSavedInstance = (dispatch: React.Dispatch<any>, instance: { cont
dispatch(addNewSavedInstance(instance))
}
export const removeInstance = (dispatch: React.Dispatch<any>, index: number) => {
dispatch(removeExistingInstance(index))
export const removeInstance = (dispatch: React.Dispatch<any>, index: number, isSavedContract: boolean) => {
dispatch(removeExistingInstance(index, isSavedContract))
}
export const clearInstances = (dispatch: React.Dispatch<any>) => {

@ -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)

@ -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
}
}
}

@ -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) {
( <CustomTooltip placement="top" tooltipClasses="text-nowrap" tooltipId="udapp_udappCloseTooltip" tooltipText={<FormattedMessage id="udapp.tooltipText7" />}>
<i className="udapp_closeIcon m-1 fas fa-times align-self-center" aria-hidden="true" data-id="universalDappUiUdappClose" onClick={remove}></i>
</CustomTooltip> ) :
( <CustomTooltip placement="top" tooltipClasses="text-nowrap" tooltipId="udapp_udappDeleteTooltip" tooltipText={<FormattedMessage id="udapp.tooltipTextUnsave" />}>
<i className="udapp_closeIcon m-1 far fa-trash-alt align-self-center" aria-hidden="true" data-id="universalDappUiUdappClose" onClick={unsave}></i>
( <CustomTooltip placement="top" tooltipClasses="text-nowrap" tooltipId="udapp_udappUnsaveTooltip" tooltipText={<FormattedMessage id="udapp.tooltipTextUnsave" />}>
<i className="udapp_closeIcon m-1 far fa-trash-alt align-self-center" aria-hidden="true" data-id="universalDappUiUdappUnsave" onClick={remove}></i>
</CustomTooltip> )}
</div>
<div className="udapp_cActionsWrapper" data-id="universalDappUiContractActionWrapper">

@ -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: {

@ -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,

Loading…
Cancel
Save