Skip to content

refactor(core): eslint errors warns #938

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

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
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
3 changes: 3 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
"jest"
],
"rules": {
"@typescript-eslint/no-non-null-assertion": "off",
"react-hooks/exhaustive-deps": "off", // TODO: remove
"import/no-named-as-default-member": "off",
"@typescript-eslint/no-duplicate-enum-values": "error",
"react/no-unescaped-entities": 0,
"react/react-in-jsx-scope": "off",
Expand Down
10 changes: 8 additions & 2 deletions src/core/agent/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,9 +488,15 @@ class Agent {
instance: IonicSession | SqliteSession
) {
if (instance instanceof IonicSession) {
return new IonicStorage<T>(instance.session!);
if (!instance.session) {
throw new Error("IonicSession session is null or undefined");
}
return new IonicStorage<T>(instance.session);
}
if (!instance.session) {
throw new Error("SqliteSession session is null or undefined");
}
return new SqliteStorage<T>(instance.session!);
return new SqliteStorage<T>(instance.session);
}

getBranAndMnemonic(): BranAndMnemonic {
Expand Down
17 changes: 11 additions & 6 deletions src/core/agent/services/connectionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,12 @@ class ConnectionService extends AgentService {
onConnectionRemoved() {
this.props.eventEmitter.on(
EventTypes.ConnectionRemoved,
(data: ConnectionRemovedEvent) =>
this.deleteConnectionById(data.payload.connectionId!)
(data: ConnectionRemovedEvent) => {
const connectionId = data.payload.connectionId;
if (connectionId) {
this.deleteConnectionById(connectionId);
}
}
);
}

Expand All @@ -104,10 +108,11 @@ class ConnectionService extends AgentService {
}

const multiSigInvite = url.includes("groupId");
const connectionId = new URL(url).pathname
.split("/oobi/")
.pop()!
.split("/")[0];
const pathParts = new URL(url).pathname.split("/oobi/");
const connectionId = pathParts.length > 1 ? pathParts.pop()?.split("/")[0] : undefined;
if (!connectionId) {
throw new Error("Invalid OOBI URL: Unable to extract connection ID");
}

const alias = new URL(url).searchParams.get("name") ?? randomSalt();
const connectionDate = new Date().toISOString();
Expand Down
8 changes: 5 additions & 3 deletions src/core/agent/services/credentialService.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { CredentialFilter } from "signify-ts";
import { AgentServicesProps } from "../agent.types";
import { AgentService } from "./agentService";
import { CredentialMetadataRecordProps } from "../records/credentialMetadataRecord.types";
Expand Down Expand Up @@ -47,8 +46,11 @@ class CredentialService extends AgentService {
onCredentialRemoved() {
this.props.eventEmitter.on(
EventTypes.CredentialRemovedEvent,
(data: CredentialRemovedEvent) =>
this.deleteCredential(data.payload.credentialId!)
(data: CredentialRemovedEvent) => {
if (data.payload.credentialId) {
this.deleteCredential(data.payload.credentialId);
}
}
);
}

Expand Down
19 changes: 13 additions & 6 deletions src/core/agent/services/identifierService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ class IdentifierService extends AgentService {
this.props.eventEmitter.on(
EventTypes.IdentifierRemoved,
(data: IdentifierRemovedEvent) => {
this.deleteIdentifier(data.payload.id!);
if (data.payload.id) {
this.deleteIdentifier(data.payload.id);
}
}
);
}
Expand Down Expand Up @@ -255,7 +257,7 @@ class IdentifierService extends AgentService {
} catch (error) {
if (!(error instanceof Error)) throw error;

const [_, status, reason] = error.message.split(" - ");
const [, status, reason] = error.message.split(" - ");
if (!(/400/gi.test(status) && /already incepted/gi.test(reason))) {
throw error;
}
Expand All @@ -275,9 +277,12 @@ class IdentifierService extends AgentService {
.identifiers()
.get(identifier)) as HabState & { icp_dt: string };

if (!this.props.signifyClient.agent) {
throw new Error("Agent is not defined");
}
const addRoleOperation = await this.props.signifyClient
.identifiers()
.addEndRole(identifier, "agent", this.props.signifyClient.agent!.pre);
.addEndRole(identifier, "agent", this.props.signifyClient.agent.pre);
await addRoleOperation.op();

const isPending = true;
Expand Down Expand Up @@ -360,9 +365,11 @@ class IdentifierService extends AgentService {
localMember.displayName
}`,
});
await this.deleteGroupLinkedConnections(
localMember.groupMetadata!.groupId
);
if (localMember.groupMetadata) {
await this.deleteGroupLinkedConnections(
localMember.groupMetadata.groupId
);
}
}

await this.props.signifyClient.identifiers().update(identifier, {
Expand Down
9 changes: 6 additions & 3 deletions src/core/agent/services/ipexCommunicationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
Serder,
Siger,
} from "signify-ts";
import { ConfigurationService } from "../../configuration";
import {
ExchangeRoute,
ExnMessage,
Expand Down Expand Up @@ -705,12 +704,16 @@ class IpexCommunicationService extends AgentService {
.filter((signing: any) => signing.aid !== ourIdentifier.id)
.map((member: any) => member.aid);

const [_, acdc] = Saider.saidify(acdcDetail);
const [, acdc] = Saider.saidify(acdcDetail);

if (offerExnToJoin) {
const [, ked] = Saider.saidify(offerExnToJoin);
const offer = new Serder(ked);
const keeper = this.props.signifyClient.manager!.get(gHab);
const manager = this.props.signifyClient.manager;
if (!manager) {
throw new Error("Manager is not available");
}
const keeper = manager.get(gHab);
const sigs = await keeper.sign(b(new Serder(offerExnToJoin).raw));

const mstateNew = gHab["state"];
Expand Down
13 changes: 7 additions & 6 deletions src/core/cardano/walletConnect/identityWalletConnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
IWalletInfo,
} from "@fabianbormann/cardano-peer-connect/dist/src/types";
import { CardanoPeerConnect } from "@fabianbormann/cardano-peer-connect";
import { Signer } from "signify-ts";
import { Agent } from "../../agent/agent";
import {
PeerConnectSigningEvent,
Expand Down Expand Up @@ -97,13 +96,13 @@ class IdentityWalletConnect extends CardanoPeerConnect {
throw new Error("Method not implemented.");
}
protected getUtxos(
amount?: string | undefined,
paginate?: Paginate | undefined
amount?: string | undefined, // eslint-disable-line @typescript-eslint/no-unused-vars
paginate?: Paginate | undefined // eslint-disable-line @typescript-eslint/no-unused-vars
): Promise<string[] | null> {
throw new Error("Method not implemented.");
}
protected getCollateral(
params?: { amount?: string | undefined } | undefined
params?: { amount?: string | undefined } | undefined // eslint-disable-line @typescript-eslint/no-unused-vars
): Promise<string[] | null> {
throw new Error("Method not implemented.");
}
Expand All @@ -122,15 +121,17 @@ class IdentityWalletConnect extends CardanoPeerConnect {
protected async getRewardAddresses(): Promise<string[]> {
throw new Error("Method not implemented.");
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
protected signTx(tx: string, partialSign: boolean): Promise<string> {
throw new Error("Method not implemented.");
}
protected async signData(
addr: string,
payload: string
addr: string, // eslint-disable-line @typescript-eslint/no-unused-vars
payload: string // eslint-disable-line @typescript-eslint/no-unused-vars
): Promise<Cip30DataSignature> {
throw new Error("Method not implemented.");
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
protected submitTx(tx: string): Promise<string> {
throw new Error("Method not implemented.");
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/storage/ionicStorage/ionicStorage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Storage, Drivers } from "@ionic/storage";
import { Storage } from "@ionic/storage";
import {
Query,
BaseRecord,
Expand Down
15 changes: 11 additions & 4 deletions src/core/storage/sqliteStorage/sqliteSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { randomPasscode } from "signify-ts";
import { versionCompare } from "./utils";
import { MIGRATIONS } from "./migrations";
import { MigrationType } from "./migrations/migrations.types";
import { Agent } from "../../agent/agent";
import { KeyStoreKeys, SecureStorage } from "../secureStorage";

class SqliteSession {
Expand Down Expand Up @@ -99,8 +98,12 @@ class SqliteSession {
migrationStatements.push({ statement: sqlStatement });
}
} else {
const statements = await migration.migrationStatements(this.session!);
migrationStatements.push(...statements);
if (this.session) {
const statements = await migration.migrationStatements(this.session);
migrationStatements.push(...statements);
} else {
throw new Error("Session instance is not initialized.");
}
}

migrationStatements.push({
Expand All @@ -110,7 +113,11 @@ class SqliteSession {
JSON.stringify(migration.version),
],
});
await this.session!.executeTransaction(migrationStatements);
if (this.session) {
await this.session.executeTransaction(migrationStatements);
} else {
throw new Error("Session instance is not initialized.");
}
}
}
}
Expand Down
1 change: 0 additions & 1 deletion src/routes/nextRoute/nextRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
} from "../../store/reducers/seedPhraseCache";
import { DataProps, NextRoute, StoreState } from "./nextRoute.types";
import { RoutePath, TabsRoutePath } from "../paths";
import { OperationType } from "../../ui/globals/types";

const getNextRootRoute = (data: DataProps) => {
const authentication = data.store.stateCache.authentication;
Expand Down
2 changes: 1 addition & 1 deletion src/store/reducers/stateCache/stateCache.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { PeerConnectSigningEvent } from "../../../core/cardano/walletConnect/pee
import { OperationType, ToastMsgType } from "../../../ui/globals/types";
import { ConnectionData } from "../walletConnectionsCache";

interface PayloadData<T = any> {
interface PayloadData<T = unknown> {
[key: string]: T;
}
interface CurrentRouteCacheProps {
Expand Down
1 change: 1 addition & 0 deletions src/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ declare module "*.png";
declare module "*.svg";
declare module "*.gif";
declare module "*.yaml" {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const data: any;
export default data;
}
2 changes: 1 addition & 1 deletion src/ui/__mocks__/@capacitor/clipboard.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const Clipboard = {
// eslint-disable-next-line @typescript-eslint/no-empty-function
// eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-unused-vars
async write(text: string): Promise<void> {},
};
3 changes: 2 additions & 1 deletion src/ui/__mocks__/@capacitor/preferences.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
export const Preferences = {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
async get(data: { key: string }): Promise<{ value: string | undefined }> {
return { value: undefined };
},
// eslint-disable-next-line @typescript-eslint/no-empty-function
// eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-unused-vars
async set(data: { key: string; value: string }): Promise<void> {},
// eslint-disable-next-line @typescript-eslint/no-empty-function
async remove(): Promise<void> {},
Expand Down
3 changes: 1 addition & 2 deletions src/ui/components/CreateIdentifier/CreateIdentifier.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import {
IonGrid,
IonIcon,
IonModal,
IonRow,
IonSpinner,
IonRow
} from "@ionic/react";
import { informationCircleOutline } from "ionicons/icons";
import { useCallback, useEffect, useMemo, useState } from "react";
Expand Down
2 changes: 1 addition & 1 deletion src/ui/components/SeedPhraseModule/SeedPhraseModule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const SeedPhraseModule = forwardRef<SeedPhraseModuleRef, SeedPhraseModuleProps>(
const input = seedInputs.current.at(index);
if (!input) return;

(input as any).setFocus();
(input as HTMLElement & { setFocus: () => void }).setFocus();
},
}));

Expand Down
8 changes: 7 additions & 1 deletion src/ui/pages/Connections/Connections.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ interface ConnectionRequestData {
goal_code: string;
goal: string;
handshake_protocols: string[];
requestattach: any[];
requestattach: {
id: string;
mimetype: string;
data: {
base64: string;
};
}[];
service: {
id: string;
type: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { OptionItem, OptionModal } from "../../../components/OptionsModal";
import { NotificationOptionModalProps } from "./NotificationOptionsModal.types";
import { NotificationRoute } from "../../../../core/agent/agent.types";
import { showError } from "../../../utils/error";
import { ToastMsgType } from "../../../globals/types";

const NotificationOptionsModal = ({
optionsIsOpen,
Expand Down
Loading