Browse Source

fix many, many more type errors

kb/add-usage-guide
Trent Larson 1 year ago
parent
commit
b05b602acd
  1. 5
      project.task.yaml
  2. 12
      src/components/GiftedDialog.vue
  3. 21
      src/libs/endorserServer.ts
  4. 20
      src/router/index.ts
  5. 13
      src/views/AccountViewView.vue
  6. 7
      src/views/ContactAmountsView.vue
  7. 35
      src/views/ContactGiftingView.vue
  8. 6
      src/views/ContactsView.vue
  9. 41
      src/views/HomeView.vue
  10. 12
      src/views/IdentitySwitcherView.vue
  11. 8
      src/views/ImportDerivedAccountView.vue
  12. 12
      src/views/NewEditProjectView.vue
  13. 58
      src/views/ProjectViewView.vue
  14. 7
      src/views/ProjectsView.vue
  15. 2
      src/views/StatisticsView.vue

5
project.task.yaml

@ -1,5 +1,8 @@
tasks: tasks:
- fix "any" warnings
- fix missing updateAllFeed in ContactGiftingView page
- check that Anonymous users jdenticon are nulls (not "Anonymous")
- test alerts on all pages -- or refactor to new "notify" (since AlertMessage refactoring may require a change, et. ContactQRScanShowView) - test alerts on all pages -- or refactor to new "notify" (since AlertMessage refactoring may require a change, et. ContactQRScanShowView)
- .2 bug - on contacts view, click on "to" & "from" and nothing happens - .2 bug - on contacts view, click on "to" & "from" and nothing happens
- 40 notifications : - 40 notifications :
@ -103,6 +106,8 @@ tasks:
- 40 notifications v+ : - 40 notifications v+ :
- pull, w/ scheduled runs - pull, w/ scheduled runs
- 01 On nearby search, if user starts changing their box but cancels and goes back to the map it is zoomed far out. Fix to fit the box better.
log: log:
- videos for multiple identities https://youtu.be/p8L87AeD76w and for adding time to contacts https://youtu.be/7Yylczevp10 done:2023-03-29 - videos for multiple identities https://youtu.be/p8L87AeD76w and for adding time to contacts https://youtu.be/7Yylczevp10 done:2023-03-29
- project lists, contact totals & actions, multiple identifiers, stats-world, activity feed, rename of this project file (use "--follow --") milestone:2 done:2023-06-27 - project lists, contact totals & actions, multiple identifiers, stats-world, activity feed, rename of this project file (use "--follow --") milestone:2 done:2023-06-27

12
src/components/GiftedDialog.vue

@ -52,18 +52,18 @@
<script lang="ts"> <script lang="ts">
import { Vue, Component, Prop, Emit } from "vue-facing-decorator"; import { Vue, Component, Prop, Emit } from "vue-facing-decorator";
import { GiverInputInfo, GiverOutputInfo } from "@/libs/endorserServer";
@Component @Component
export default class GiftedDialog extends Vue { export default class GiftedDialog extends Vue {
@Prop message = ""; @Prop message = "";
giver = null; giver?: GiverInputInfo;
description = ""; description = "";
hours = "0"; hours = "0";
visible = false; visible = false;
open(giver) { open(giver: GiverInputInfo) {
// giver: GiverInputInfo
this.giver = giver; this.giver = giver;
this.visible = true; this.visible = true;
} }
@ -81,7 +81,7 @@ export default class GiftedDialog extends Vue {
} }
@Emit("dialog-result") @Emit("dialog-result")
confirm() { confirm(): GiverOutputInfo {
const result = { const result = {
action: "confirm", action: "confirm",
giver: this.giver, giver: this.giver,
@ -90,14 +90,14 @@ export default class GiftedDialog extends Vue {
}; };
this.close(); this.close();
this.description = ""; this.description = "";
this.giver = null; this.giver = undefined;
this.hours = "0"; this.hours = "0";
return result; return result;
} }
@Emit("dialog-result") @Emit("dialog-result")
cancel() { cancel(): GiverOutputInfo {
const result = { action: "cancel" }; const result = { action: "cancel" };
this.close(); this.close();
return result; return result;

21
src/libs/endorserServer.ts

@ -21,6 +21,13 @@ export interface GiverInputInfo {
name?: string; name?: string;
} }
export interface GiverOutputInfo {
action: string;
giver?: GiverInputInfo;
description?: string;
hours?: number;
}
export interface ClaimResult { export interface ClaimResult {
success: { claimId: string; handleId: string }; success: { claimId: string; handleId: string };
error: { code: string; message: string }; error: { code: string; message: string };
@ -55,7 +62,7 @@ export interface GiveVerifiableCredential {
fulfills?: { "@type": string; identifier: string }; fulfills?: { "@type": string; identifier: string };
identifier?: string; identifier?: string;
object?: { amountOfThisGood: number; unitCode: string }; object?: { amountOfThisGood: number; unitCode: string };
recipient: { identifier: string }; recipient?: { identifier: string };
} }
export interface RegisterVerifiableCredential { export interface RegisterVerifiableCredential {
@ -130,10 +137,10 @@ export async function createAndSubmitGive(
axios: Axios, axios: Axios,
apiServer: string, apiServer: string,
identity: IIdentifier, identity: IIdentifier,
fromDid: string, fromDid?: string,
toDid: string, toDid?: string,
description: string, description?: string,
hours: number, hours?: number,
fulfillsProjectHandleId?: string, fulfillsProjectHandleId?: string,
): Promise<CreateAndSubmitGiveResult> { ): Promise<CreateAndSubmitGiveResult> {
try { try {
@ -141,8 +148,10 @@ export async function createAndSubmitGive(
const vcClaim: GiveVerifiableCredential = { const vcClaim: GiveVerifiableCredential = {
"@context": "https://schema.org", "@context": "https://schema.org",
"@type": "GiveAction", "@type": "GiveAction",
recipient: { identifier: toDid },
}; };
if (toDid) {
vcClaim.recipient = { identifier: toDid };
}
if (fromDid) { if (fromDid) {
vcClaim.agent = { identifier: fromDid }; vcClaim.agent = { identifier: fromDid };
} }

20
src/router/index.ts

@ -1,4 +1,10 @@
import { createRouter, createWebHistory, RouteRecordRaw } from "vue-router"; import {
createRouter,
createWebHistory,
NavigationGuardNext,
RouteLocationNormalized,
RouteRecordRaw,
} from "vue-router";
import { accountsDB } from "@/db"; import { accountsDB } from "@/db";
/** /**
@ -7,7 +13,11 @@ import { accountsDB } from "@/db";
* @param from :RouteLocationNormalized * @param from :RouteLocationNormalized
* @param next :NavigationGuardNext * @param next :NavigationGuardNext
*/ */
const enterOrStart = async (to, from, next) => { const enterOrStart = async (
to: RouteLocationNormalized,
from: RouteLocationNormalized,
next: NavigationGuardNext,
) => {
await accountsDB.open(); await accountsDB.open();
const num_accounts = await accountsDB.accounts.count(); const num_accounts = await accountsDB.accounts.count();
if (num_accounts > 0) { if (num_accounts > 0) {
@ -190,7 +200,11 @@ const router = createRouter({
routes, routes,
}); });
const errorHandler = (error, to, from) => { const errorHandler = (
error: any,
to: RouteLocationNormalized,
from: RouteLocationNormalized,
) => {
// Handle the error here // Handle the error here
console.error("Caught in top level error handler:", error, to, from); console.error("Caught in top level error handler:", error, to, from);

13
src/views/AccountViewView.vue

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

7
src/views/ContactAmountsView.vue

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

35
src/views/ContactGiftingView.vue

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

6
src/views/ContactsView.vue

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

41
src/views/HomeView.vue

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

12
src/views/IdentitySwitcherView.vue

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

8
src/views/ImportDerivedAccountView.vue

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

12
src/views/NewEditProjectView.vue

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

58
src/views/ProjectViewView.vue

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

7
src/views/ProjectsView.vue

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

2
src/views/StatisticsView.vue

@ -37,7 +37,7 @@
</section> </section>
</template> </template>
<script lang="ts"> <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 { Component, Vue } from "vue-facing-decorator";
import { World } from "@/components/World/World.js"; import { World } from "@/components/World/World.js";
import QuickNav from "@/components/QuickNav.vue"; import QuickNav from "@/components/QuickNav.vue";

Loading…
Cancel
Save