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

Add noUncheckedIndexedAccess TypeScript compiler flag #34

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions packages/controllers/src/plugins/PluginController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -487,16 +487,16 @@ export class PluginController extends BaseController<
}

try {
const { sourceCode } = await this.add({
const addedPlugin = await this.add({
name: pluginName,
manifestUrl: pluginName,
});

await this.authorize(pluginName);
await this.authorize(addedPlugin);

await this._startPlugin({
pluginName,
sourceCode,
sourceCode: addedPlugin.sourceCode,
});

return this.getSerializable(pluginName) as SerializablePlugin;
Expand Down Expand Up @@ -539,7 +539,7 @@ export class PluginController extends BaseController<

private async _startPlugin(pluginData: PluginData) {
const { pluginName } = pluginData;
if (this.get(pluginName).isRunning) {
if (this.get(pluginName)?.isRunning) {
throw new Error(`Plugin "${pluginName}" is already started.`);
}

Expand Down Expand Up @@ -646,11 +646,9 @@ export class PluginController extends BaseController<
* @param pluginName - The name of the plugin.
* @returns The plugin's approvedPermissions.
*/
async authorize(pluginName: string): Promise<string[]> {
async authorize(plugin: Plugin): Promise<string[]> {
const { name: pluginName, initialPermissions } = plugin;
console.log(`Authorizing plugin: ${pluginName}`);
const pluginsState = this.state.plugins;
const plugin = pluginsState[pluginName];
const { initialPermissions } = plugin;

// Don't prompt if there are no permissions requested:
if (Object.keys(initialPermissions).length === 0) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ethErrors } from 'eth-rpc-errors';
import { PLUGIN_PREFIX, InstallPluginsResult } from '@mm-snap/controllers';
import { IRequestedPermissions } from 'rpc-cap/dist/src/@types';
import { IOcapLdCapability } from 'rpc-cap/dist/src/@types/ocap-ld';
import { isPlainObject } from '../../utils';

export { InstallPluginsResult } from '@mm-snap/controllers';
Expand Down Expand Up @@ -51,11 +52,17 @@ export function preprocessRequestPermissions(
});
}

newRequestedPermissions[pluginKey] = requestedPlugins[pluginName];
// Typecast: TS doesn't understand that pluginName is an existing key
newRequestedPermissions[pluginKey] = requestedPlugins[
pluginName
] as Partial<IOcapLdCapability>;
});
} else {
// otherwise, leave things as we found them
newRequestedPermissions[permName] = requestedPermissions[permName];
// Typecast: TS doesn't understand that permName is an existing key
newRequestedPermissions[permName] = requestedPermissions[
permName
] as Partial<IOcapLdCapability>;
}

return newRequestedPermissions;
Expand Down
1 change: 1 addition & 0 deletions tsconfig.packages.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"esModuleInterop": true,
"module": "CommonJS",
"moduleResolution": "node",
"noUncheckedIndexedAccess": true,
"sourceMap": true,
"strict": true,
"target": "ES2017",
Expand Down