Browse Source

fix all the lint warnings

kb/add-usage-guide
Trent Larson 1 year ago
parent
commit
4b9cbd0e9f
  1. 31
      src/libs/endorserServer.ts
  2. 1
      src/router/index.ts
  3. 2
      src/views/AccountViewView.vue
  4. 1
      src/views/ContactAmountsView.vue
  5. 15
      src/views/ContactGiftingView.vue
  6. 2
      src/views/DiscoverView.vue
  7. 28
      src/views/HomeView.vue
  8. 3
      src/views/NewEditProjectView.vue
  9. 21
      src/views/ProjectViewView.vue
  10. 14
      src/views/ProjectsView.vue

31
src/libs/endorserServer.ts

@ -65,6 +65,29 @@ export interface GiveVerifiableCredential {
recipient?: { identifier: string }; 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 { export interface RegisterVerifiableCredential {
"@context": string; "@context": string;
"@type": 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"; type: "success";
response: AxiosResponse<ClaimResult>; response: AxiosResponse<ClaimResult>;
} }
@ -242,7 +269,7 @@ export async function createAndSubmitGive(
type: "error", type: "error",
error: { error: {
error: errorMessage, error: errorMessage,
userMessage: "Failed to create and submit the claim", userMessage: "Failed to create and submit the claim.",
}, },
}; };
} }

1
src/router/index.ts

@ -201,6 +201,7 @@ const router = createRouter({
}); });
const errorHandler = ( const errorHandler = (
// eslint-disable-next-line @typescript-eslint/no-explicit-any
error: any, error: any,
to: RouteLocationNormalized, to: RouteLocationNormalized,
from: RouteLocationNormalized, from: RouteLocationNormalized,

2
src/views/AccountViewView.vue

@ -414,6 +414,7 @@ export default class AccountViewView extends Vue {
}); });
this.checkLimitsFor(identity); this.checkLimitsFor(identity);
} }
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (err: any) { } catch (err: any) {
if ( if (
err.message === err.message ===
@ -517,6 +518,7 @@ export default class AccountViewView extends Vue {
if (resp.status === 200) { if (resp.status === 200) {
this.limits = resp.data; this.limits = resp.data;
} }
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (error: any) { } catch (error: any) {
if ( if (
error.message === error.message ===

1
src/views/ContactAmountsView.vue

@ -172,6 +172,7 @@ export default class ContactsView extends Vue {
if (this.activeDid && this.contact) { if (this.activeDid && this.contact) {
this.loadGives(this.activeDid, this.contact); this.loadGives(this.activeDid, this.contact);
} }
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (err: any) { } catch (err: any) {
this.$notify( this.$notify(
{ {

15
src/views/ContactGiftingView.vue

@ -154,6 +154,7 @@ export default class HomeView extends Vue {
this.apiServer = settings?.apiServer || ""; this.apiServer = settings?.apiServer || "";
this.activeDid = settings?.activeDid || ""; this.activeDid = settings?.activeDid || "";
this.allContacts = await db.contacts.toArray(); this.allContacts = await db.contacts.toArray();
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (err: any) { } catch (err: any) {
this.$notify( this.$notify(
{ {
@ -261,16 +262,20 @@ export default class HomeView extends Vue {
-1, -1,
); );
} }
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (error: any) { } catch (error: any) {
console.log("Error with give caught:", error); 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( this.$notify(
{ {
group: "alert", group: "alert",
type: "danger", type: "danger",
title: "Error", title: "Error",
text: text: message,
this.getGiveErrorMessage(error) ||
"There was an error recording the give.",
}, },
-1, -1,
); );
@ -286,9 +291,5 @@ export default class HomeView extends Vue {
getGiveCreationErrorMessage(result: CreateAndSubmitGiveResult) { getGiveCreationErrorMessage(result: CreateAndSubmitGiveResult) {
return (result as ErrorResult).error?.userMessage; return (result as ErrorResult).error?.userMessage;
} }
getGiveErrorMessage(error: any) {
return error.userMessage || error.response?.data?.error?.message;
}
} }
</script> </script>

2
src/views/DiscoverView.vue

@ -337,6 +337,7 @@ export default class DiscoverView extends Vue {
} else { } else {
throw JSON.stringify(results); throw JSON.stringify(results);
} }
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (e: any) { } catch (e: any) {
console.log("Error with feed load:", e); console.log("Error with feed load:", e);
this.$notify( this.$notify(
@ -415,6 +416,7 @@ export default class DiscoverView extends Vue {
} else { } else {
throw JSON.stringify(results); throw JSON.stringify(results);
} }
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (e: any) { } catch (e: any) {
console.log("Error with feed load:", e); console.log("Error with feed load:", e);
this.$notify( this.$notify(

28
src/views/HomeView.vue

@ -284,6 +284,7 @@ export default class HomeView extends Vue {
this.allContacts = await db.contacts.toArray(); this.allContacts = await db.contacts.toArray();
this.feedLastViewedId = settings?.lastViewedClaimId; this.feedLastViewedId = settings?.lastViewedClaimId;
this.updateAllFeed(); this.updateAllFeed();
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (err: any) { } catch (err: any) {
this.$notify( this.$notify(
{ {
@ -384,12 +385,11 @@ export default class HomeView extends Vue {
} }
giveDescription(giveRecord: GiveServerRecord) { giveDescription(giveRecord: GiveServerRecord) {
let claim = giveRecord.fullClaim; // claim.claim happen for some claims wrapped in a Verifiable Credential
if ((claim as any).claim) { // eslint-disable-next-line @typescript-eslint/no-explicit-any
// can happen for some claims wrapped in a Verifiable Credential const claim = (giveRecord.fullClaim as any).claim || giveRecord.fullClaim;
claim = (claim as any).claim;
}
// agent.did is for legacy data, before March 2023 // 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 giverDid = claim.agent?.identifier || (claim.agent as any)?.did;
const giverInfo = didInfo( const giverInfo = didInfo(
giverDid, giverDid,
@ -402,6 +402,7 @@ export default class HomeView extends Vue {
: claim.description || "something unknown"; : claim.description || "something unknown";
// recipient.did is for legacy data, before March 2023 // recipient.did is for legacy data, before March 2023
const gaveRecipientId = const gaveRecipientId =
// eslint-disable-next-line @typescript-eslint/no-explicit-any
claim.recipient?.identifier || (claim.recipient as any)?.did; claim.recipient?.identifier || (claim.recipient as any)?.did;
const gaveRecipientInfo = gaveRecipientId const gaveRecipientInfo = gaveRecipientId
? " to " + ? " to " +
@ -515,16 +516,19 @@ export default class HomeView extends Vue {
-1, -1,
); );
} }
} catch (error) { // eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (error: any) {
console.log("Error with give caught:", error); 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( this.$notify(
{ {
group: "alert", group: "alert",
type: "danger", type: "danger",
title: "Error", title: "Error",
text: text: message,
this.getGiveErrorMessage(error) ||
"There was an error recording the give.",
}, },
-1, -1,
); );
@ -533,16 +537,14 @@ export default class HomeView extends Vue {
// Helper functions for readability // Helper functions for readability
// eslint-disable-next-line @typescript-eslint/no-explicit-any
isGiveCreationError(result: any) { isGiveCreationError(result: any) {
return result.status !== 201 || result.data?.error; return result.status !== 201 || result.data?.error;
} }
// eslint-disable-next-line @typescript-eslint/no-explicit-any
getGiveCreationErrorMessage(result: any) { getGiveCreationErrorMessage(result: any) {
return result.data?.error?.message; return result.data?.error?.message;
} }
getGiveErrorMessage(error: any) {
return error.userMessage || error.response?.data?.error?.message;
}
} }
</script> </script>

3
src/views/NewEditProjectView.vue

@ -112,6 +112,7 @@ import { MASTER_SETTINGS_KEY } from "@/db/tables/settings";
import { accessToken, SimpleSigner } from "@/libs/crypto"; import { accessToken, SimpleSigner } from "@/libs/crypto";
import { useAppStore } from "@/store/app"; import { useAppStore } from "@/store/app";
import { IIdentifier } from "@veramo/core"; import { IIdentifier } from "@veramo/core";
import { PlanVerifiableCredential } from "@/libs/endorserServer";
interface Notification { interface Notification {
group: string; group: string;
@ -217,7 +218,7 @@ export default class NewEditProjectView extends Vue {
private async SaveProject(identity: IIdentifier) { private async SaveProject(identity: IIdentifier) {
// Make a claim // Make a claim
const vcClaim: any = { const vcClaim: PlanVerifiableCredential = {
"@context": "https://schema.org", "@context": "https://schema.org",
"@type": "PlanAction", "@type": "PlanAction",
name: this.projectName, name: this.projectName,

21
src/views/ProjectViewView.vue

@ -220,6 +220,7 @@ import {
GiverInputInfo, GiverInputInfo,
GiverOutputInfo, GiverOutputInfo,
GiveServerRecord, GiveServerRecord,
ResultWithType,
} from "@/libs/endorserServer"; } from "@/libs/endorserServer";
import QuickNav from "@/components/QuickNav.vue"; import QuickNav from "@/components/QuickNav.vue";
import EntityIcon from "@/components/EntityIcon.vue"; import EntityIcon from "@/components/EntityIcon.vue";
@ -547,18 +548,23 @@ export default class ProjectViewView extends Vue {
}, },
-1, -1,
); );
} else if (result.type == "error") { } else {
console.log("Error with give result:", result); console.log("Error with give creation:", result);
if ("data" in result) { if (result.type != "error") {
const data: any = result.data; 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( this.$notify(
{ {
group: "alert", group: "alert",
type: "danger", type: "danger",
title: "Error", title: "Error",
text: text: message,
data?.error?.message ||
"There was an error recording the give.",
}, },
-1, -1,
); );
@ -566,5 +572,4 @@ export default class ProjectViewView extends Vue {
} }
} }
} }
}
</script> </script>

14
src/views/ProjectsView.vue

@ -129,16 +129,26 @@ export default class ProjectsView extends Vue {
} }
} else { } else {
console.log("Bad server response & data:", resp.status, resp.data); 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) { } catch (error: any) {
console.error("Got error loading projects:", error.message); console.error("Got error loading projects:", error.message);
const additional = error.message ? " " + error.message : "";
this.$notify( this.$notify(
{ {
group: "alert", group: "alert",
type: "danger", type: "danger",
title: "Error", title: "Error",
text: "Got an error loading projects: " + error.message, text: "Got an error loading projects." + additional,
}, },
-1, -1,
); );

Loading…
Cancel
Save