Browse Source

fix many more typescript errors

search-bbox
Trent Larson 1 year ago
parent
commit
b59bcf249a
  1. 4
      src/libs/endorserServer.ts
  2. 12
      src/views/AccountViewView.vue
  3. 2
      src/views/ContactAmountsView.vue
  4. 57
      src/views/ContactGiftingView.vue
  5. 2
      src/views/ContactQRScanShowView.vue
  6. 18
      src/views/ContactsView.vue
  7. 11
      src/views/DiscoverView.vue
  8. 38
      src/views/HomeView.vue
  9. 24
      src/views/IdentitySwitcherView.vue
  10. 2
      src/views/ImportDerivedAccountView.vue

4
src/libs/endorserServer.ts

@ -70,7 +70,7 @@ export interface RegisterVerifiableCredential {
"@type": string; "@type": string;
agent: { identifier: string }; agent: { identifier: string };
object: string; object: string;
recipient: { identifier: string }; participant: { identifier: string };
} }
export interface InternalError { export interface InternalError {
@ -122,7 +122,7 @@ interface ErrorResult {
error: InternalError; error: InternalError;
} }
type CreateAndSubmitGiveResult = SuccessResult | ErrorResult; export type CreateAndSubmitGiveResult = SuccessResult | ErrorResult;
/** /**
* For result, see https://api.endorser.ch/api-docs/#/claims/post_api_v2_claim * For result, see https://api.endorser.ch/api-docs/#/claims/post_api_v2_claim

12
src/views/AccountViewView.vue

@ -517,7 +517,7 @@ export default class AccountViewView extends Vue {
if (resp.status === 200) { if (resp.status === 200) {
this.limits = resp.data; this.limits = resp.data;
} }
} catch (error: unknown) { } catch (error: any) {
if ( if (
error.message === error.message ===
"Attempted to load Give records with no identity available." "Attempted to load Give records with no identity available."
@ -528,13 +528,9 @@ export default class AccountViewView extends Vue {
const serverError = error as AxiosError; const serverError = error as AxiosError;
console.error("Bad response retrieving limits: ", serverError); console.error("Bad response retrieving limits: ", serverError);
const data: ErrorResponse | undefined = const data = (serverError.response &&
serverError.response && serverError.response.data; serverError.response.data) as ErrorResponse;
if (data && data.error && data.error.message) { this.limitsMessage = data?.error?.message || "Bad server response.";
this.limitsMessage = data.error.message;
} else {
this.limitsMessage = "Bad server response.";
}
} }
} }

2
src/views/ContactAmountsView.vue

@ -190,7 +190,7 @@ export default class ContactsView extends Vue {
async loadGives(activeDid: string, contact: Contact) { async loadGives(activeDid: string, contact: Contact) {
try { try {
const identity = await this.getIdentity(this.activeDid); const identity = await this.getIdentity(this.activeDid);
let result = []; let result: Array<GiveServerRecord> = [];
const url = const url =
this.apiServer + this.apiServer +
"/api/v2/report/gives?agentDid=" + "/api/v2/report/gives?agentDid=" +

57
src/views/ContactGiftingView.vue

@ -88,10 +88,10 @@ import { MASTER_SETTINGS_KEY } from "@/db/tables/settings";
import { accessToken } from "@/libs/crypto"; import { accessToken } from "@/libs/crypto";
import { import {
createAndSubmitGive, createAndSubmitGive,
CreateAndSubmitGiveResult,
GiverInputInfo, GiverInputInfo,
GiverOutputInfo, GiverOutputInfo,
} from "@/libs/endorserServer"; } from "@/libs/endorserServer";
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";
@ -112,18 +112,14 @@ export default class HomeView extends Vue {
$notify!: (notification: Notification, timeout?: number) => void; $notify!: (notification: Notification, timeout?: number) => void;
activeDid = ""; activeDid = "";
allAccounts: Array<Account> = [];
allContacts: Array<Contact> = []; allContacts: Array<Contact> = [];
apiServer = ""; apiServer = "";
feedLastViewedId = "";
isHiddenSpinner = true;
accounts: typeof AccountsSchema; accounts: typeof AccountsSchema;
numAccounts = 0; numAccounts = 0;
async beforeCreate() { async beforeCreate() {
accountsDB.open(); accountsDB.open();
this.accounts = accountsDB.accounts; this.numAccounts = await accountsDB.accounts.count();
this.numAccounts = await this.accounts.count();
} }
public async getIdentity(activeDid: string) { public async getIdentity(activeDid: string) {
@ -153,15 +149,11 @@ export default class HomeView extends Vue {
async created() { async created() {
try { try {
await accountsDB.open();
this.allAccounts = await accountsDB.accounts.toArray();
await db.open(); await db.open();
const settings = await db.settings.get(MASTER_SETTINGS_KEY); const settings = await db.settings.get(MASTER_SETTINGS_KEY);
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();
this.feedLastViewedId = settings?.lastViewedClaimId;
this.updateAllFeed();
} catch (err) { } catch (err) {
this.$notify( this.$notify(
{ {
@ -177,30 +169,6 @@ export default class HomeView extends Vue {
} }
} }
public async buildHeaders() {
const headers: RawAxiosRequestHeaders = {
"Content-Type": "application/json",
};
if (this.activeDid) {
await accountsDB.open();
const allAccounts = await accountsDB.accounts.toArray();
const account = allAccounts.find((acc) => acc.did === this.activeDid);
const identity = JSON.parse(account?.identity || "null");
if (!identity) {
throw new Error(
"An ID is chosen but there are no keys for it so it cannot be used to talk with the service.",
);
}
headers["Authorization"] = "Bearer " + (await accessToken(identity));
} else {
// it's OK without auth... we just won't get any identifiers
}
return headers;
}
openDialog(giver: GiverInputInfo) { openDialog(giver: GiverInputInfo) {
this.$refs.customDialog.open(giver); this.$refs.customDialog.open(giver);
} }
@ -208,8 +176,13 @@ export default class HomeView extends Vue {
handleDialogResult(result: GiverOutputInfo) { 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 "cancel" so do nothing // action was "cancel" so do nothing
@ -288,7 +261,7 @@ export default class HomeView extends Vue {
-1, -1,
); );
} }
} catch (error) { } catch (error: any) {
console.log("Error with give caught:", error); console.log("Error with give caught:", error);
this.$notify( this.$notify(
{ {
@ -306,15 +279,15 @@ export default class HomeView extends Vue {
// Helper functions for readability // Helper functions for readability
isGiveCreationError(result) { isGiveCreationError(result: CreateAndSubmitGiveResult) {
return result.status !== 201 || result.data?.error; return result.response?.status !== 201 || result.response?.data?.error;
} }
getGiveCreationErrorMessage(result) { getGiveCreationErrorMessage(result: CreateAndSubmitGiveResult) {
return result.data?.error?.message; return result.response?.data?.error?.message;
} }
getGiveErrorMessage(error) { getGiveErrorMessage(error: any) {
return error.userMessage || error.response?.data?.error?.message; return error.userMessage || error.response?.data?.error?.message;
} }
} }

2
src/views/ContactQRScanShowView.vue

@ -54,7 +54,7 @@ export default class ContactQRScanShow extends Vue {
apiServer = ""; apiServer = "";
qrValue = ""; qrValue = "";
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: Account | undefined = R.find( const account: Account | undefined = R.find(

18
src/views/ContactsView.vue

@ -215,6 +215,7 @@ import { Contact } from "@/db/tables/contacts";
import { MASTER_SETTINGS_KEY } from "@/db/tables/settings"; import { MASTER_SETTINGS_KEY } from "@/db/tables/settings";
import { accessToken, SimpleSigner } from "@/libs/crypto"; import { accessToken, SimpleSigner } from "@/libs/crypto";
import { import {
GiveServerRecord,
GiveVerifiableCredential, GiveVerifiableCredential,
RegisterVerifiableCredential, RegisterVerifiableCredential,
SERVICE_ID, SERVICE_ID,
@ -310,11 +311,11 @@ export default class ContactsView extends Vue {
async loadGives() { async loadGives() {
const handleResponse = ( const handleResponse = (
resp, resp: { status: number; data: { data: GiveServerRecord[] } },
descriptions, descriptions: Record<string, string>,
confirmed, confirmed: Record<string, number>,
unconfirmed, unconfirmed: Record<string, number>,
useRecipient, useRecipient: boolean,
) => { ) => {
if (resp.status === 200) { if (resp.status === 200) {
const allData = resp.data.data; const allData = resp.data.data;
@ -346,9 +347,8 @@ export default class ContactsView extends Vue {
title: "Error With Server", title: "Error With Server",
text: text:
"Got an error retrieving your " + "Got an error retrieving your " +
resp.config.url.includes("recipientDid") (useRecipient ? "given" : "received") +
? "received" " time from the server.",
: "given" + " time from the server.",
}, },
-1, -1,
); );
@ -610,6 +610,8 @@ export default class ContactsView extends Vue {
this.apiServer + this.apiServer +
"/api/report/canDidExplicitlySeeMe?did=" + "/api/report/canDidExplicitlySeeMe?did=" +
encodeURIComponent(contact.did); encodeURIComponent(contact.did);
const identity = await this.getIdentity(this.activeDid);
const headers = await this.getHeaders(identity);
try { try {
const resp = await this.axios.get(url, { headers }); const resp = await this.axios.get(url, { headers });

11
src/views/DiscoverView.vue

@ -202,6 +202,7 @@ import { didInfo, ProjectData } from "@/libs/endorserServer";
import QuickNav from "@/components/QuickNav"; import QuickNav from "@/components/QuickNav";
import InfiniteScroll from "@/components/InfiniteScroll"; import InfiniteScroll from "@/components/InfiniteScroll";
import EntityIcon from "@/components/EntityIcon"; import EntityIcon from "@/components/EntityIcon";
import { RawAxiosRequestHeaders } from "axios";
const DEFAULT_LAT_LONG_DIFF = 0.01; const DEFAULT_LAT_LONG_DIFF = 0.01;
const WORLD_ZOOM = 2; const WORLD_ZOOM = 2;
@ -268,8 +269,10 @@ export default class DiscoverView extends Vue {
this.searchLocal(); this.searchLocal();
} }
public async buildHeaders() { public async buildHeaders(): Promise<HeadersInit> {
const headers = { "Content-Type": "application/json" }; const headers: HeadersInit = {
"Content-Type": "application/json",
};
if (this.activeDid) { if (this.activeDid) {
await accountsDB.open(); await accountsDB.open();
@ -327,8 +330,8 @@ export default class DiscoverView extends Vue {
const plans: ProjectData[] = results.data; const plans: ProjectData[] = results.data;
if (plans) { if (plans) {
for (const plan of plans) { for (const plan of plans) {
const { name, description, handleId, rowid, issuerDid } = plan; const { name, description, handleId, rowid } = plan;
this.projects.push({ name, description, handleId, rowid, issuerDid }); this.projects.push({ name, description, handleId, rowid });
} }
this.remoteCount = this.projects.length; this.remoteCount = this.projects.length;
} else { } else {

38
src/views/HomeView.vue

@ -210,6 +210,7 @@ import {
didInfo, didInfo,
GiverInputInfo, GiverInputInfo,
GiverOutputInfo, GiverOutputInfo,
GiveServerRecord,
} from "@/libs/endorserServer"; } 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";
@ -236,7 +237,7 @@ export default class HomeView extends Vue {
apiServer = ""; apiServer = "";
feedAllLoaded = false; feedAllLoaded = false;
feedData = []; feedData = [];
feedPreviousOldestId = null; feedPreviousOldestId?: string;
feedLastViewedId?: string; feedLastViewedId?: string;
isHiddenSpinner = true; isHiddenSpinner = true;
numAccounts = 0; numAccounts = 0;
@ -300,7 +301,7 @@ export default class HomeView extends Vue {
} }
public async buildHeaders() { public async buildHeaders() {
const headers: RawAxiosRequestHeaders = { const headers: HeadersInit = {
"Content-Type": "application/json", "Content-Type": "application/json",
}; };
@ -325,7 +326,7 @@ export default class HomeView extends Vue {
public async updateAllFeed() { public async updateAllFeed() {
this.isHiddenSpinner = false; this.isHiddenSpinner = false;
await this.retrieveClaims(this.apiServer, null, this.feedPreviousOldestId) await this.retrieveClaims(this.apiServer, this.feedPreviousOldestId)
.then(async (results) => { .then(async (results) => {
if (results.data.length > 0) { if (results.data.length > 0) {
this.feedData = this.feedData.concat(results.data); this.feedData = this.feedData.concat(results.data);
@ -360,7 +361,7 @@ export default class HomeView extends Vue {
this.isHiddenSpinner = true; this.isHiddenSpinner = true;
} }
public async retrieveClaims(endorserApiServer, identifier, beforeId) { public async retrieveClaims(endorserApiServer: string, beforeId?: string) {
const beforeQuery = beforeId == null ? "" : "&beforeId=" + beforeId; const beforeQuery = beforeId == null ? "" : "&beforeId=" + beforeId;
const response = await fetch( const response = await fetch(
endorserApiServer + "/api/v2/report/gives?" + beforeQuery, endorserApiServer + "/api/v2/report/gives?" + beforeQuery,
@ -383,13 +384,14 @@ export default class HomeView extends Vue {
} }
} }
giveDescription(giveRecord) { giveDescription(giveRecord: GiveServerRecord) {
let claim = giveRecord.fullClaim; let claim = giveRecord.fullClaim;
if (claim.claim) { if ((claim as any).claim) {
claim = claim.claim; // can happen for some claims wrapped in a Verifiable Credential
claim = (claim as any).claim;
} }
// agent.did is for legacy data, before March 2023 // agent.did is for legacy data, before March 2023
const giverDid = claim.agent?.identifier || claim.agent?.did; const giverDid = claim.agent?.identifier || (claim.agent as any)?.did;
const giverInfo = didInfo( const giverInfo = didInfo(
giverDid, giverDid,
this.activeDid, this.activeDid,
@ -400,7 +402,8 @@ export default class HomeView extends Vue {
? this.displayAmount(claim.object.unitCode, claim.object.amountOfThisGood) ? this.displayAmount(claim.object.unitCode, claim.object.amountOfThisGood)
: 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 = claim.recipient?.identifier || claim.recipient?.did; const gaveRecipientId =
claim.recipient?.identifier || (claim.recipient as any)?.did;
const gaveRecipientInfo = gaveRecipientId const gaveRecipientInfo = gaveRecipientId
? " to " + ? " to " +
didInfo( didInfo(
@ -417,7 +420,7 @@ export default class HomeView extends Vue {
return "" + amt + " " + this.currencyShortWordForCode(code, amt === 1); return "" + amt + " " + this.currencyShortWordForCode(code, amt === 1);
} }
currencyShortWordForCode(unitCode: string, single: number) { currencyShortWordForCode(unitCode: string, single: boolean) {
return unitCode === "HUR" ? (single ? "hour" : "hours") : unitCode; return unitCode === "HUR" ? (single ? "hour" : "hours") : unitCode;
} }
@ -425,11 +428,16 @@ export default class HomeView extends Vue {
this.$refs.customDialog.open(giver); this.$refs.customDialog.open(giver);
} }
handleDialogResult(result: GiverInputInfo) { handleDialogResult(result: GiverOutputInfo) {
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(
resolve(); result.giver?.did,
result.description,
result.hours,
).then(() => {
resolve(null);
});
}); });
} else { } else {
// action was "cancel" so do nothing // action was "cancel" so do nothing
@ -445,7 +453,7 @@ export default class HomeView extends Vue {
public async recordGive( public async recordGive(
giverDid?: string, giverDid?: string,
description?: string, description?: string,
hours?: string, hours?: number,
) { ) {
if (!this.activeDid) { if (!this.activeDid) {
this.$notify( this.$notify(
@ -482,7 +490,7 @@ export default class HomeView extends Vue {
giverDid, giverDid,
this.activeDid, this.activeDid,
description, description,
hours ? parseFloat(hours) : undefined, hours,
); );
if (this.isGiveCreationError(result)) { if (this.isGiveCreationError(result)) {

24
src/views/IdentitySwitcherView.vue

@ -84,11 +84,14 @@ export default class IdentitySwitcherView extends Vue {
$notify!: (notification: Notification, timeout?: number) => void; $notify!: (notification: Notification, timeout?: number) => void;
Constants = AppString; Constants = AppString;
public accounts: AccountsSchema; public accounts: typeof AccountsSchema;
public activeDid = ""; public activeDid = "";
public apiServer = "";
public apiServerInput = "";
public firstName = ""; public firstName = "";
public lastName = ""; public lastName = "";
public otherIdentities = []; public otherIdentities: Array<{ did: string }> = [];
public showContactGives = false;
public async getIdentity(activeDid: string) { public async getIdentity(activeDid: string) {
await accountsDB.open(); await accountsDB.open();
@ -127,27 +130,16 @@ export default class IdentitySwitcherView extends Vue {
} }
} }
} catch (err) { } catch (err) {
if (
err?.message ===
"Attempted to load account records with no identity available."
) {
this.limitsMessage = "No identity.";
this.loadingLimits = false;
} else {
this.$notify( this.$notify(
{ {
group: "alert", group: "alert",
type: "danger", type: "danger",
title: "Error Creating Account", title: "Error Loading Accounts",
text: "Clear your cache and start over (after data backup).", text: "Clear your cache and start over (after data backup).",
}, },
-1, -1,
); );
console.error( console.error("Telling user to clear cache at page create because:", err);
"Telling user to clear cache at page create because:",
err,
);
}
} }
} }
@ -160,7 +152,7 @@ export default class IdentitySwitcherView extends Vue {
db.settings.update(MASTER_SETTINGS_KEY, { db.settings.update(MASTER_SETTINGS_KEY, {
activeDid: did, activeDid: did,
}); });
this.activeDid = did; this.activeDid = did || "";
this.otherIdentities = []; this.otherIdentities = [];
await accountsDB.open(); await accountsDB.open();
const accounts = await accountsDB.accounts.toArray(); const accounts = await accountsDB.accounts.toArray();

2
src/views/ImportDerivedAccountView.vue

@ -87,7 +87,7 @@ export default class ImportAccountView extends Vue {
async mounted() { async mounted() {
await accountsDB.open(); await accountsDB.open();
const accounts = await accountsDB.accounts.toArray(); const accounts = await accountsDB.accounts.toArray();
const seedDids = {}; const seedDids: Record<string, Array<string>> = {};
accounts.forEach((account) => { accounts.forEach((account) => {
const prevDids: Array<string> = seedDids[account.mnemonic] || []; const prevDids: Array<string> = seedDids[account.mnemonic] || [];
seedDids[account.mnemonic] = prevDids.concat([account.did]); seedDids[account.mnemonic] = prevDids.concat([account.did]);

Loading…
Cancel
Save