fix many, many more type errors

This commit is contained in:
2023-09-03 10:02:17 -06:00
parent b8aaffbf8d
commit b05b602acd
15 changed files with 170 additions and 97 deletions

View File

@@ -290,6 +290,7 @@
</template>
<script lang="ts">
import { AxiosError } from "axios/index";
import "dexie-export-import";
import { Component, Vue } from "vue-facing-decorator";
import { useClipboard } from "@vueuse/core";
@@ -298,9 +299,9 @@ import { AppString } from "@/constants/app";
import { db, accountsDB } from "@/db";
import { MASTER_SETTINGS_KEY } from "@/db/tables/settings";
import { accessToken } from "@/libs/crypto";
import { AxiosError } from "axios/index";
import QuickNav from "@/components/QuickNav";
import { IIdentifier } from "@veramo/core";
import { ErrorResponse, RateLimits } from "@/libs/endorserServer";
// eslint-disable-next-line @typescript-eslint/no-var-requires
const Buffer = require("buffer/").Buffer;
@@ -341,7 +342,7 @@ export default class AccountViewView extends Vue {
alertMessage = "";
alertTitle = "";
public async getIdentity(activeDid) {
public async getIdentity(activeDid: string) {
await accountsDB.open();
const account = await accountsDB.accounts
.where("did")
@@ -351,7 +352,7 @@ export default class AccountViewView extends Vue {
return identity;
}
public async getHeaders(identity) {
public async getHeaders(identity: IIdentifier) {
const token = await accessToken(identity);
const headers = {
"Content-Type": "application/json",
@@ -361,7 +362,7 @@ export default class AccountViewView extends Vue {
}
// call fn, copy text to the clipboard, then redo fn after 2 seconds
doCopyTwoSecRedo(text, fn) {
doCopyTwoSecRedo(text: string, fn: () => void) {
fn();
useClipboard()
.copy(text)
@@ -413,7 +414,7 @@ export default class AccountViewView extends Vue {
});
this.checkLimitsFor(identity);
}
} catch (err) {
} catch (err: any) {
if (
err.message ===
"Attempted to load account records with no identity available."
@@ -583,7 +584,7 @@ export default class AccountViewView extends Vue {
this.apiServer = this.apiServerInput;
}
setApiServerInput(value) {
setApiServerInput(value: string) {
this.apiServerInput = value;
}
}

View File

@@ -110,6 +110,7 @@ import {
import * as didJwt from "did-jwt";
import { AxiosError } from "axios";
import QuickNav from "@/components/QuickNav";
import { IIdentifier } from "@veramo/core";
interface Notification {
group: string;
@@ -133,7 +134,7 @@ export default class ContactsView extends Vue {
this.numAccounts = await accountsDB.accounts.count();
}
public async getIdentity(activeDid) {
public async getIdentity(activeDid: string) {
await accountsDB.open();
const account = await accountsDB.accounts
.where("did")
@@ -149,7 +150,7 @@ export default class ContactsView extends Vue {
return identity;
}
public async getHeaders(identity) {
public async getHeaders(identity: IIdentifier) {
const token = await accessToken(identity);
const headers = {
"Content-Type": "application/json",
@@ -171,7 +172,7 @@ export default class ContactsView extends Vue {
if (this.activeDid && this.contact) {
this.loadGives(this.activeDid, this.contact);
}
} catch (err) {
} catch (err: any) {
this.$notify(
{
group: "alert",

View File

@@ -86,11 +86,17 @@ import { db, accountsDB } from "@/db";
import { AccountsSchema } from "@/db/tables/accounts";
import { MASTER_SETTINGS_KEY } from "@/db/tables/settings";
import { accessToken } from "@/libs/crypto";
import { createAndSubmitGive } from "@/libs/endorserServer";
import {
createAndSubmitGive,
GiverInputInfo,
GiverOutputInfo,
} from "@/libs/endorserServer";
import { Account } from "@/db/tables/accounts";
import { Contact } from "@/db/tables/contacts";
import QuickNav from "@/components/QuickNav";
import EntityIcon from "@/components/EntityIcon";
import { IIdentifier } from "@veramo/core";
import { RawAxiosRequestHeaders } from "axios";
interface Notification {
group: string;
@@ -109,8 +115,9 @@ export default class HomeView extends Vue {
allAccounts: Array<Account> = [];
allContacts: Array<Contact> = [];
apiServer = "";
feedLastViewedId = "";
isHiddenSpinner = true;
accounts: AccountsSchema;
accounts: typeof AccountsSchema;
numAccounts = 0;
async beforeCreate() {
@@ -119,7 +126,7 @@ export default class HomeView extends Vue {
this.numAccounts = await this.accounts.count();
}
public async getIdentity(activeDid) {
public async getIdentity(activeDid: string) {
await accountsDB.open();
const account = await accountsDB.accounts
.where("did")
@@ -135,7 +142,7 @@ export default class HomeView extends Vue {
return identity;
}
public async getHeaders(identity) {
public async getHeaders(identity: IIdentifier) {
const token = await accessToken(identity);
const headers = {
"Content-Type": "application/json",
@@ -171,7 +178,9 @@ export default class HomeView extends Vue {
}
public async buildHeaders() {
const headers = { "Content-Type": "application/json" };
const headers: RawAxiosRequestHeaders = {
"Content-Type": "application/json",
};
if (this.activeDid) {
await accountsDB.open();
@@ -192,11 +201,11 @@ export default class HomeView extends Vue {
return headers;
}
openDialog(giver) {
openDialog(giver: GiverInputInfo) {
this.$refs.customDialog.open(giver);
}
handleDialogResult(result) {
handleDialogResult(result: GiverOutputInfo) {
if (result.action === "confirm") {
return new Promise((resolve) => {
this.recordGive(result.contact?.did, result.description, result.hours);
@@ -213,7 +222,11 @@ export default class HomeView extends Vue {
* @param description may be an empty string
* @param hours may be 0
*/
public async recordGive(giverDid, description, hours) {
public async recordGive(
giverDid?: string,
description?: string,
hours?: number,
) {
if (!this.activeDid) {
this.$notify(
{
@@ -252,8 +265,8 @@ export default class HomeView extends Vue {
hours,
);
if (isGiveCreationError(result)) {
const errorMessage = getGiveCreationErrorMessage(result);
if (this.isGiveCreationError(result)) {
const errorMessage = this.getGiveCreationErrorMessage(result);
console.log("Error with give result:", result);
this.$notify(
{
@@ -283,7 +296,7 @@ export default class HomeView extends Vue {
type: "danger",
title: "Error",
text:
getGiveErrorMessage(error) ||
this.getGiveErrorMessage(error) ||
"There was an error recording the give.",
},
-1,

View File

@@ -278,7 +278,7 @@ export default class ContactsView extends Vue {
);
}
public async getIdentity(activeDid) {
public async getIdentity(activeDid: string) {
await accountsDB.open();
const accounts = await accountsDB.accounts.toArray();
const account = R.find((acc) => acc.did === activeDid, accounts);
@@ -292,7 +292,7 @@ export default class ContactsView extends Vue {
return identity;
}
public async getHeaders(identity) {
public async getHeaders(identity: IIdentifier) {
const token = await accessToken(identity);
const headers = {
"Content-Type": "application/json",
@@ -301,7 +301,7 @@ export default class ContactsView extends Vue {
return headers;
}
public async getHeadersAndIdentity(activeDid) {
public async getHeadersAndIdentity(activeDid: string) {
const identity = await this.getIdentity(activeDid);
const headers = await this.getHeaders(identity);

View File

@@ -205,10 +205,17 @@ import GiftedDialog from "@/components/GiftedDialog.vue";
import { db, accountsDB } from "@/db";
import { MASTER_SETTINGS_KEY } from "@/db/tables/settings";
import { accessToken } from "@/libs/crypto";
import { createAndSubmitGive, didInfo } from "@/libs/endorserServer";
import {
createAndSubmitGive,
didInfo,
GiverInputInfo,
GiverOutputInfo,
} from "@/libs/endorserServer";
import { Contact } from "@/db/tables/contacts";
import QuickNav from "@/components/QuickNav";
import EntityIcon from "@/components/EntityIcon";
import { IIdentifier } from "@veramo/core";
import { RawAxiosRequestHeaders } from "axios";
interface Notification {
group: string;
@@ -230,7 +237,7 @@ export default class HomeView extends Vue {
feedAllLoaded = false;
feedData = [];
feedPreviousOldestId = null;
feedLastViewedId = null;
feedLastViewedId?: string;
isHiddenSpinner = true;
numAccounts = 0;
@@ -239,7 +246,7 @@ export default class HomeView extends Vue {
this.numAccounts = await accountsDB.accounts.count();
}
public async getIdentity(activeDid) {
public async getIdentity(activeDid: string) {
await accountsDB.open();
const account = await accountsDB.accounts
.where("did")
@@ -255,7 +262,7 @@ export default class HomeView extends Vue {
return identity;
}
public async getHeaders(identity) {
public async getHeaders(identity: IIdentifier) {
const token = await accessToken(identity);
const headers = {
"Content-Type": "application/json",
@@ -293,7 +300,9 @@ export default class HomeView extends Vue {
}
public async buildHeaders() {
const headers = { "Content-Type": "application/json" };
const headers: RawAxiosRequestHeaders = {
"Content-Type": "application/json",
};
if (this.activeDid) {
await accountsDB.open();
@@ -404,19 +413,19 @@ export default class HomeView extends Vue {
return giverInfo + " gave " + gaveAmount + gaveRecipientInfo;
}
displayAmount(code, amt) {
displayAmount(code: string, amt: number) {
return "" + amt + " " + this.currencyShortWordForCode(code, amt === 1);
}
currencyShortWordForCode(unitCode, single) {
currencyShortWordForCode(unitCode: string, single: number) {
return unitCode === "HUR" ? (single ? "hour" : "hours") : unitCode;
}
openDialog(giver) {
openDialog(giver: GiverInputInfo) {
this.$refs.customDialog.open(giver);
}
handleDialogResult(result) {
handleDialogResult(result: GiverInputInfo) {
if (result.action === "confirm") {
return new Promise((resolve) => {
this.recordGive(result.giver?.did, result.description, result.hours);
@@ -433,7 +442,11 @@ export default class HomeView extends Vue {
* @param description may be an empty string
* @param hours may be 0
*/
public async recordGive(giverDid, description, hours) {
public async recordGive(
giverDid?: string,
description?: string,
hours?: string,
) {
if (!this.activeDid) {
this.$notify(
{
@@ -469,7 +482,7 @@ export default class HomeView extends Vue {
giverDid,
this.activeDid,
description,
hours,
hours ? parseFloat(hours) : undefined,
);
if (this.isGiveCreationError(result)) {
@@ -513,15 +526,15 @@ export default class HomeView extends Vue {
// Helper functions for readability
isGiveCreationError(result) {
isGiveCreationError(result: any) {
return result.status !== 201 || result.data?.error;
}
getGiveCreationErrorMessage(result) {
getGiveCreationErrorMessage(result: any) {
return result.data?.error?.message;
}
getGiveErrorMessage(error) {
getGiveErrorMessage(error: any) {
return error.userMessage || error.response?.data?.error?.message;
}
}

View File

@@ -85,12 +85,12 @@ export default class IdentitySwitcherView extends Vue {
Constants = AppString;
public accounts: AccountsSchema;
public activeDid;
public firstName;
public lastName;
public activeDid = "";
public firstName = "";
public lastName = "";
public otherIdentities = [];
public async getIdentity(activeDid) {
public async getIdentity(activeDid: string) {
await accountsDB.open();
const account = await accountsDB.accounts
.where("did")
@@ -128,7 +128,7 @@ export default class IdentitySwitcherView extends Vue {
}
} catch (err) {
if (
err.message ===
err?.message ===
"Attempted to load account records with no identity available."
) {
this.limitsMessage = "No identity.";
@@ -151,7 +151,7 @@ export default class IdentitySwitcherView extends Vue {
}
}
async switchAccount(did: string) {
async switchAccount(did?: string) {
// 0 means none
if (did === "0") {
did = undefined;

View File

@@ -89,7 +89,7 @@ export default class ImportAccountView extends Vue {
const accounts = await accountsDB.accounts.toArray();
const seedDids = {};
accounts.forEach((account) => {
const prevDids = seedDids[account.mnemonic] || [];
const prevDids: Array<string> = seedDids[account.mnemonic] || [];
seedDids[account.mnemonic] = prevDids.concat([account.did]);
});
this.didArrays = Object.values(seedDids);
@@ -107,9 +107,9 @@ export default class ImportAccountView extends Vue {
public async incrementDerivation() {
await accountsDB.open();
// find the maximum derivation path for the selected DIDs
const selectedArray: Array<string> = this.didArrays.find(
(dids) => dids[0] === this.selectedArrayFirstDid,
);
const selectedArray: Array<string> =
this.didArrays.find((dids) => dids[0] === this.selectedArrayFirstDid) ||
[];
const allMatchingAccounts = await accountsDB.accounts
.where("did")
.anyOf(...selectedArray)

View File

@@ -142,7 +142,7 @@ export default class NewEditProjectView extends Vue {
this.numAccounts = await accountsDB.accounts.count();
}
public async getIdentity(activeDid) {
public async getIdentity(activeDid: string) {
await accountsDB.open();
const account = await accountsDB.accounts
.where("did")
@@ -158,7 +158,7 @@ export default class NewEditProjectView extends Vue {
return identity;
}
public async getHeaders(identity) {
public async getHeaders(identity: IIdentifier) {
const token = await accessToken(identity);
const headers = {
"Content-Type": "application/json",
@@ -217,7 +217,7 @@ export default class NewEditProjectView extends Vue {
private async SaveProject(identity: IIdentifier) {
// Make a claim
const vcClaim: VerifiableCredential = {
const vcClaim: any = {
"@context": "https://schema.org",
"@type": "PlanAction",
name: this.projectName,
@@ -291,11 +291,13 @@ export default class NewEditProjectView extends Vue {
}
} catch (error) {
let userMessage = "There was an error saving the project.";
const serverError = error as AxiosError;
const serverError = error as AxiosError<{
error?: { message?: string };
}>;
if (serverError) {
if (Object.prototype.hasOwnProperty.call(serverError, "message")) {
console.log(serverError);
userMessage = serverError.response.data.error.message; // This is info for the user.
userMessage = serverError.response?.data?.error?.message || ""; // This is info for the user.
this.$notify(
{
group: "alert",

View File

@@ -204,7 +204,7 @@
</template>
<script lang="ts">
import { AxiosError } from "axios";
import { AxiosError, RawAxiosRequestHeaders } from "axios";
import * as moment from "moment";
import { IIdentifier } from "@veramo/core";
import { Component, Vue } from "vue-facing-decorator";
@@ -217,6 +217,8 @@ import { accessToken } from "@/libs/crypto";
import {
createAndSubmitGive,
didInfo,
GiverInputInfo,
GiverOutputInfo,
GiveServerRecord,
} from "@/libs/endorserServer";
import QuickNav from "@/components/QuickNav";
@@ -268,7 +270,7 @@ export default class ProjectViewView extends Vue {
this.LoadProject(identity);
}
public async getIdentity(activeDid) {
public async getIdentity(activeDid: string) {
await accountsDB.open();
const account = await accountsDB.accounts
.where("did")
@@ -284,7 +286,7 @@ export default class ProjectViewView extends Vue {
return identity;
}
public async getHeaders(identity) {
public async getHeaders(identity: IIdentifier) {
const token = await accessToken(identity);
const headers = {
"Content-Type": "application/json",
@@ -302,7 +304,12 @@ export default class ProjectViewView extends Vue {
}
// Isn't there a better way to make this available to the template?
didInfo(did, activeDid, dids, contacts) {
didInfo(
did: string,
activeDid: string,
dids: Array<string>,
contacts: Array<Contact>,
) {
return didInfo(did, activeDid, dids, contacts);
}
@@ -319,7 +326,7 @@ export default class ProjectViewView extends Vue {
this.apiServer +
"/api/claim/byHandle/" +
encodeURIComponent(this.projectId);
const headers = {
const headers: RawAxiosRequestHeaders = {
"Content-Type": "application/json",
};
if (identity) {
@@ -453,8 +460,9 @@ export default class ProjectViewView extends Vue {
}
}
openDialog(contact) {
this.$refs.customDialog.open(contact);
openDialog(contact: GiverInputInfo) {
const dialog: GiftedDialog = this.$refs.customDialog as GiftedDialog;
dialog.open(contact);
}
getOpenStreetMapUrl() {
@@ -471,11 +479,16 @@ export default class ProjectViewView extends Vue {
);
}
handleDialogResult(result) {
handleDialogResult(result: GiverOutputInfo) {
if (result.action === "confirm") {
return new Promise((resolve) => {
this.recordGive(result.contact?.did, result.description, result.hours);
resolve();
this.recordGive(
result.giver?.did,
result.description,
result.hours,
).then(() => {
resolve(null);
});
});
} else {
// action was not "confirm" so do nothing
@@ -488,7 +501,7 @@ export default class ProjectViewView extends Vue {
* @param description may be an empty string
* @param hours may be 0
*/
async recordGive(giverDid, description: string, hours: number) {
async recordGive(giverDid?: string, description?: string, hours?: number) {
if (!this.activeDid) {
this.$notify(
{
@@ -525,21 +538,6 @@ export default class ProjectViewView extends Vue {
this.projectId,
);
if (result.type == "success") {
console.log("Error with give result:", result);
if ("data" in result) {
this.$notify(
{
group: "alert",
type: "danger",
title: "Error",
text:
result.data?.error?.message ||
"There was an error recording the give.",
},
-1,
);
}
} else if (result.type == "error") {
this.$notify(
{
group: "alert",
@@ -549,6 +547,22 @@ 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,
);
}
}
}
}

View File

@@ -79,6 +79,7 @@ import { IIdentifier } from "@veramo/core";
import InfiniteScroll from "@/components/InfiniteScroll";
import QuickNav from "@/components/QuickNav";
import EntityIcon from "@/components/EntityIcon";
import { ProjectData } from "@/libs/endorserServer";
interface Notification {
group: string;
@@ -123,14 +124,14 @@ export default class ProjectsView extends Vue {
if (resp.status === 200 || !resp.data.data) {
const plans: ProjectData[] = resp.data.data;
for (const plan of plans) {
const { name, description, handleId = plan.fullIri, rowid } = plan;
const { name, description, handleId, rowid } = plan;
this.projects.push({ name, description, handleId, rowid });
}
} else {
console.log("Bad server response & data:", resp.status, resp.data);
throw Error("Failed to get projects from the server.");
}
} catch (error) {
} catch (error: any) {
console.error("Got error loading projects:", error.message);
this.$notify(
{
@@ -181,7 +182,7 @@ export default class ProjectsView extends Vue {
await this.dataLoader(url, token);
}
public async getIdentity(activeDid) {
public async getIdentity(activeDid: string) {
await accountsDB.open();
const account = await accountsDB.accounts
.where("did")

View File

@@ -37,7 +37,7 @@
</section>
</template>
<script lang="ts">
import { SVGRenderer } from "three/addons/renderers/SVGRenderer.js";
import { SVGRenderer } from "three/examples/jsm/renderers/SVGRenderer.js";
import { Component, Vue } from "vue-facing-decorator";
import { World } from "@/components/World/World.js";
import QuickNav from "@/components/QuickNav.vue";