From 4b9cbd0e9f67e6ac9d3b71c0303e18c10e5e885c Mon Sep 17 00:00:00 2001 From: Trent Larson Date: Mon, 4 Sep 2023 15:17:32 -0600 Subject: [PATCH] fix all the lint warnings --- src/libs/endorserServer.ts | 31 ++++++++++++++++++++++++++++-- src/router/index.ts | 1 + src/views/AccountViewView.vue | 2 ++ src/views/ContactAmountsView.vue | 1 + src/views/ContactGiftingView.vue | 15 ++++++++------- src/views/DiscoverView.vue | 2 ++ src/views/HomeView.vue | 28 ++++++++++++++------------- src/views/NewEditProjectView.vue | 3 ++- src/views/ProjectViewView.vue | 33 ++++++++++++++++++-------------- src/views/ProjectsView.vue | 14 ++++++++++++-- 10 files changed, 91 insertions(+), 39 deletions(-) diff --git a/src/libs/endorserServer.ts b/src/libs/endorserServer.ts index ab22caa..4aab30a 100644 --- a/src/libs/endorserServer.ts +++ b/src/libs/endorserServer.ts @@ -65,6 +65,29 @@ export interface GiveVerifiableCredential { recipient?: { identifier: string }; } +export interface PlanVerifiableCredential { + "@context": "https://schema.org"; + "@type": "PlanAction"; + name: string; + description: string; + identifier?: string; + location?: { + geo: { "@type": "GeoCoordinates"; latitude: number; longitude: number }; + }; +} + +export interface PlanServerRecord { + agentDid?: string; // optional, if the issuer wants someone else to manage as well + description: string; + endTime?: string; + issuerDid: string; + handleId: string; + locLat?: number; + locLon?: number; + startTime?: string; + url?: string; +} + export interface RegisterVerifiableCredential { "@context": string; "@type": string; @@ -112,7 +135,11 @@ export function didInfo( } } -export interface SuccessResult { +export interface ResultWithType { + type: string; +} + +export interface SuccessResult extends ResultWithType { type: "success"; response: AxiosResponse; } @@ -242,7 +269,7 @@ export async function createAndSubmitGive( type: "error", error: { error: errorMessage, - userMessage: "Failed to create and submit the claim", + userMessage: "Failed to create and submit the claim.", }, }; } diff --git a/src/router/index.ts b/src/router/index.ts index 2bf1d7d..0fee166 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -201,6 +201,7 @@ const router = createRouter({ }); const errorHandler = ( + // eslint-disable-next-line @typescript-eslint/no-explicit-any error: any, to: RouteLocationNormalized, from: RouteLocationNormalized, diff --git a/src/views/AccountViewView.vue b/src/views/AccountViewView.vue index 99f15b0..f46b846 100644 --- a/src/views/AccountViewView.vue +++ b/src/views/AccountViewView.vue @@ -414,6 +414,7 @@ export default class AccountViewView extends Vue { }); this.checkLimitsFor(identity); } + // eslint-disable-next-line @typescript-eslint/no-explicit-any } catch (err: any) { if ( err.message === @@ -517,6 +518,7 @@ export default class AccountViewView extends Vue { if (resp.status === 200) { this.limits = resp.data; } + // eslint-disable-next-line @typescript-eslint/no-explicit-any } catch (error: any) { if ( error.message === diff --git a/src/views/ContactAmountsView.vue b/src/views/ContactAmountsView.vue index 366597c..385a285 100644 --- a/src/views/ContactAmountsView.vue +++ b/src/views/ContactAmountsView.vue @@ -172,6 +172,7 @@ export default class ContactsView extends Vue { if (this.activeDid && this.contact) { this.loadGives(this.activeDid, this.contact); } + // eslint-disable-next-line @typescript-eslint/no-explicit-any } catch (err: any) { this.$notify( { diff --git a/src/views/ContactGiftingView.vue b/src/views/ContactGiftingView.vue index b6d9afb..943fea9 100644 --- a/src/views/ContactGiftingView.vue +++ b/src/views/ContactGiftingView.vue @@ -154,6 +154,7 @@ export default class HomeView extends Vue { this.apiServer = settings?.apiServer || ""; this.activeDid = settings?.activeDid || ""; this.allContacts = await db.contacts.toArray(); + // eslint-disable-next-line @typescript-eslint/no-explicit-any } catch (err: any) { this.$notify( { @@ -261,16 +262,20 @@ export default class HomeView extends Vue { -1, ); } + // eslint-disable-next-line @typescript-eslint/no-explicit-any } catch (error: any) { console.log("Error with give caught:", error); + + const message = + error.userMessage || + error.response?.data?.error?.message || + "There was an error recording the Give."; this.$notify( { group: "alert", type: "danger", title: "Error", - text: - this.getGiveErrorMessage(error) || - "There was an error recording the give.", + text: message, }, -1, ); @@ -286,9 +291,5 @@ export default class HomeView extends Vue { getGiveCreationErrorMessage(result: CreateAndSubmitGiveResult) { return (result as ErrorResult).error?.userMessage; } - - getGiveErrorMessage(error: any) { - return error.userMessage || error.response?.data?.error?.message; - } } diff --git a/src/views/DiscoverView.vue b/src/views/DiscoverView.vue index 442704f..392cc95 100644 --- a/src/views/DiscoverView.vue +++ b/src/views/DiscoverView.vue @@ -337,6 +337,7 @@ export default class DiscoverView extends Vue { } else { throw JSON.stringify(results); } + // eslint-disable-next-line @typescript-eslint/no-explicit-any } catch (e: any) { console.log("Error with feed load:", e); this.$notify( @@ -415,6 +416,7 @@ export default class DiscoverView extends Vue { } else { throw JSON.stringify(results); } + // eslint-disable-next-line @typescript-eslint/no-explicit-any } catch (e: any) { console.log("Error with feed load:", e); this.$notify( diff --git a/src/views/HomeView.vue b/src/views/HomeView.vue index e7a12db..98a4d49 100644 --- a/src/views/HomeView.vue +++ b/src/views/HomeView.vue @@ -284,6 +284,7 @@ export default class HomeView extends Vue { this.allContacts = await db.contacts.toArray(); this.feedLastViewedId = settings?.lastViewedClaimId; this.updateAllFeed(); + // eslint-disable-next-line @typescript-eslint/no-explicit-any } catch (err: any) { this.$notify( { @@ -384,12 +385,11 @@ export default class HomeView extends Vue { } giveDescription(giveRecord: GiveServerRecord) { - let claim = giveRecord.fullClaim; - if ((claim as any).claim) { - // can happen for some claims wrapped in a Verifiable Credential - claim = (claim as any).claim; - } + // claim.claim happen for some claims wrapped in a Verifiable Credential + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const claim = (giveRecord.fullClaim as any).claim || giveRecord.fullClaim; // agent.did is for legacy data, before March 2023 + // eslint-disable-next-line @typescript-eslint/no-explicit-any const giverDid = claim.agent?.identifier || (claim.agent as any)?.did; const giverInfo = didInfo( giverDid, @@ -402,6 +402,7 @@ export default class HomeView extends Vue { : claim.description || "something unknown"; // recipient.did is for legacy data, before March 2023 const gaveRecipientId = + // eslint-disable-next-line @typescript-eslint/no-explicit-any claim.recipient?.identifier || (claim.recipient as any)?.did; const gaveRecipientInfo = gaveRecipientId ? " to " + @@ -515,16 +516,19 @@ export default class HomeView extends Vue { -1, ); } - } catch (error) { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + } catch (error: any) { console.log("Error with give caught:", error); + const message = + error.userMessage || + error.response?.data?.error?.message || + "There was an error recording the give."; this.$notify( { group: "alert", type: "danger", title: "Error", - text: - this.getGiveErrorMessage(error) || - "There was an error recording the give.", + text: message, }, -1, ); @@ -533,16 +537,14 @@ export default class HomeView extends Vue { // Helper functions for readability + // eslint-disable-next-line @typescript-eslint/no-explicit-any isGiveCreationError(result: any) { return result.status !== 201 || result.data?.error; } + // eslint-disable-next-line @typescript-eslint/no-explicit-any getGiveCreationErrorMessage(result: any) { return result.data?.error?.message; } - - getGiveErrorMessage(error: any) { - return error.userMessage || error.response?.data?.error?.message; - } } diff --git a/src/views/NewEditProjectView.vue b/src/views/NewEditProjectView.vue index 7ccbcf4..48bcd0f 100644 --- a/src/views/NewEditProjectView.vue +++ b/src/views/NewEditProjectView.vue @@ -112,6 +112,7 @@ import { MASTER_SETTINGS_KEY } from "@/db/tables/settings"; import { accessToken, SimpleSigner } from "@/libs/crypto"; import { useAppStore } from "@/store/app"; import { IIdentifier } from "@veramo/core"; +import { PlanVerifiableCredential } from "@/libs/endorserServer"; interface Notification { group: string; @@ -217,7 +218,7 @@ export default class NewEditProjectView extends Vue { private async SaveProject(identity: IIdentifier) { // Make a claim - const vcClaim: any = { + const vcClaim: PlanVerifiableCredential = { "@context": "https://schema.org", "@type": "PlanAction", name: this.projectName, diff --git a/src/views/ProjectViewView.vue b/src/views/ProjectViewView.vue index 76f8ea0..8c6b679 100644 --- a/src/views/ProjectViewView.vue +++ b/src/views/ProjectViewView.vue @@ -220,6 +220,7 @@ import { GiverInputInfo, GiverOutputInfo, GiveServerRecord, + ResultWithType, } from "@/libs/endorserServer"; import QuickNav from "@/components/QuickNav.vue"; import EntityIcon from "@/components/EntityIcon.vue"; @@ -547,22 +548,26 @@ export default class ProjectViewView extends Vue { }, -1, ); - } else if (result.type == "error") { - console.log("Error with give result:", result); - if ("data" in result) { - const data: any = result.data; - this.$notify( - { - group: "alert", - type: "danger", - title: "Error", - text: - data?.error?.message || - "There was an error recording the give.", - }, - -1, + } else { + console.log("Error with give creation:", result); + if (result.type != "error") { + console.log( + "... and it has an unexpected result type of", + (result as ResultWithType).type, ); } + const message = + result?.error?.userMessage || + "There was an error recording the Give."; + this.$notify( + { + group: "alert", + type: "danger", + title: "Error", + text: message, + }, + -1, + ); } } } diff --git a/src/views/ProjectsView.vue b/src/views/ProjectsView.vue index 5051b3e..d54b94d 100644 --- a/src/views/ProjectsView.vue +++ b/src/views/ProjectsView.vue @@ -129,16 +129,26 @@ export default class ProjectsView extends Vue { } } else { console.log("Bad server response & data:", resp.status, resp.data); - throw Error("Failed to get projects from the server."); + this.$notify( + { + group: "alert", + type: "danger", + title: "Error", + text: "Failed to get projects from the server. Try again later.", + }, + -1, + ); } + // eslint-disable-next-line @typescript-eslint/no-explicit-any } catch (error: any) { console.error("Got error loading projects:", error.message); + const additional = error.message ? " " + error.message : ""; this.$notify( { group: "alert", type: "danger", title: "Error", - text: "Got an error loading projects: " + error.message, + text: "Got an error loading projects." + additional, }, -1, );