Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

delete forked state environment from env explorer #5600

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
16 changes: 15 additions & 1 deletion apps/remix-ide/src/app/providers/environment-explorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ export class EnvironmentExplorer extends ViewPlugin {
}
}

async deleteForkedState (provider) {
const providerName = await this.call('blockchain', 'getProvider')
if (providerName !== provider.name) {
await this.call('fileManager', 'remove', `.states/forked_states/${provider.displayName}.json`)
await this.call('blockchain', 'removeProvider', provider.name)
this.call('notification', 'toast', `Environment "${provider.displayName}" deleted successfully.`)
} else this.call('notification', 'toast', 'Cannot delete the current selected environment')
}

renderComponent() {
this.dispatch({
...this.state
Expand All @@ -86,7 +95,12 @@ export class EnvironmentExplorer extends ViewPlugin {

updateComponent(state: EnvironmentExplorerState) {
return (<>
<EnvironmentExplorerUI pinStateCallback={this.pinStateCallback.bind(this)} profile={profile} state={state} />
<EnvironmentExplorerUI
pinStateCallback={this.pinStateCallback.bind(this)}
deleteForkedState={this.deleteForkedState.bind(this)}
profile={profile}
state={state}
/>
</>)
}
}
1 change: 1 addition & 0 deletions apps/remix-ide/src/blockchain/blockchain.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,7 @@ export class Blockchain extends Plugin {
}

removeProvider(name) {
if (this.pinnedProviders.includes(name)) this.emit('shouldRemoveProviderFromUdapp', name, this.getProviderObjByName(name))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is already emitted by on('environmentExplorer', 'providerUnpinned'. Could you explain why you need this here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this, it doesn't remove provider from dropdown even after deletion. A similar check is there in addProvider too

this.executionContext.removeProvider(name)
this.emit('providersChanged')
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,19 @@ export const EnvironmentExplorerUI = (props: environmentExplorerUIProps) => {
}}
>
<div data-id={`${provider.name}desc`}>{(section.descriptionFn && section.descriptionFn(provider)) || provider.description}</div>
{ provider.isForkedState && <CustomTooltip
placement="auto"
tooltipId={`overlay-tooltip-${provider.name}`}
tooltipText="Delete Environment Immediately"
>
<span
onClick={async () => props.deleteForkedState(provider)}
className="btn btn-sm mt-1 border border-danger"
>
Delete Environment
</span>
</CustomTooltip>
}
</RemixUIGridCell>
))}
</RemixUIGridSection>
Expand Down
1 change: 1 addition & 0 deletions libs/remix-ui/environment-explorer/src/lib/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export type environmentExplorerUIProps = {
providersFlat: { [key: string]: Provider }
pinnedProviders: string[]
}
deleteForkedState (provider: Provider): Promise<void>
pinStateCallback (provider: Provider, pinned: boolean): Promise<void>
profile: Profile
}
Expand Down
Loading