diff --git a/project.task.yaml b/project.task.yaml index dbf4bbb..e23fb25 100644 --- a/project.task.yaml +++ b/project.task.yaml @@ -32,8 +32,7 @@ - Ensure each action sent to the server has a confirmation. - Feed screen - - 01 save the feed in settings storage - - .5 add user-specific data + - 01 save the feed-viewed status in settings storage ("afterQuery") - .5 customize favicon - .5 make advanced features harder to access; advanced build? diff --git a/src/db/tables/accounts.ts b/src/db/tables/accounts.ts index b42e55a..d31f160 100644 --- a/src/db/tables/accounts.ts +++ b/src/db/tables/accounts.ts @@ -3,6 +3,8 @@ export type Account = { dateCreated: string; derivationPath: string; did: string; + // stringified JSON containing underlying key material of type IIdentifier + // https://github.com/uport-project/veramo/blob/next/packages/core-types/src/types/IIdentifier.ts identity: string; publicKeyHex: string; mnemonic: string; diff --git a/src/libs/endorserServer.ts b/src/libs/endorserServer.ts index 20e04a6..1bfca84 100644 --- a/src/libs/endorserServer.ts +++ b/src/libs/endorserServer.ts @@ -1,3 +1,5 @@ +import * as R from "ramda"; + export const SCHEMA_ORG_CONTEXT = "https://schema.org"; export const SERVICE_ID = "endorser.ch"; @@ -52,9 +54,6 @@ export interface RegisterVerifiableCredential { // See https://github.com/trentlarson/endorser-ch/blob/0cb626f803028e7d9c67f095858a9fc8542e3dbd/server/api/services/util.js#L6 const HIDDEN_DID = "did:none:HIDDEN"; -const UNKNOWN_ENTITY = "Someone Unknown"; -const UNKNOWN_VISIBLE = "Someone Unnamed"; - export function isHiddenDid(did) { return did === HIDDEN_DID; } @@ -69,11 +68,11 @@ export function didInfo(did, identifiers, contacts) { } else { const contact = R.find((c) => c.did === did, contacts); if (contact) { - return contact.name || "(no name)"; + return contact.name || "Someone Unnamed in Contacts"; } else if (isHiddenDid(did)) { - return UNKNOWN_ENTITY; + return "Someone Not In Network"; } else { - return UNKNOWN_VISIBLE; + return "Someone Not In Contacts"; } } } diff --git a/src/views/HomeView.vue b/src/views/HomeView.vue index 11d2fdc..2c51e84 100644 --- a/src/views/HomeView.vue +++ b/src/views/HomeView.vue @@ -84,6 +84,7 @@ import { Options, Vue } from "vue-class-component"; import { db, accountsDB } from "@/db"; import { MASTER_SETTINGS_KEY } from "@/db/tables/settings"; +import { accessToken } from "@/libs/crypto"; import { didInfo } from "@/libs/endorserServer"; import { Account } from "@/db/tables/accounts"; import { Contact } from "@/db/tables/contacts"; @@ -93,9 +94,10 @@ import * as R from "ramda"; components: {}, }) export default class HomeView extends Vue { - accounts: Array = []; + activeDid = ""; + allAccounts: Array = []; + allContacts: Array = []; apiServer = ""; - contacts: Array = []; feedAllLoaded = false; feedData = []; feedPreviousOldestId = null; @@ -104,10 +106,11 @@ export default class HomeView extends Vue { // 'created' hook runs when the Vue instance is first created async created() { await accountsDB.open(); - this.accounts = await accountsDB.accounts.toArray(); - console.log("Accounts:", this.accounts); + this.allAccounts = await accountsDB.accounts.toArray(); await db.open(); - this.contacts = await db.contacts.toArray(); + const settings = await db.settings.get(MASTER_SETTINGS_KEY); + this.activeDid = settings?.activeDid || ""; + this.allContacts = await db.contacts.toArray(); } // 'mounted' hook runs after initial render @@ -116,6 +119,7 @@ export default class HomeView extends Vue { await db.open(); const settings = await db.settings.get(MASTER_SETTINGS_KEY); this.apiServer = settings?.apiServer || ""; + this.updateAllFeed(); } catch (err) { console.log("Error in mounted():", err); @@ -133,7 +137,7 @@ export default class HomeView extends Vue { .then(async (results) => { if (results.data.length > 0) { this.feedData = this.feedData.concat(results.data); - console.log("Feed data:", this.feedData); + //console.log("Feed data:", this.feedData); this.feedAllLoaded = results.hitLimit; this.feedPreviousOldestId = results.data[results.data.length - 1].id; } @@ -148,15 +152,22 @@ export default class HomeView extends Vue { }; retrieveClaims = async (endorserApiServer, identifier, beforeId) => { - //const token = await accessToken(identifier) //const afterQuery = afterId == null ? "" : "&afterId=" + afterId; const beforeQuery = beforeId == null ? "" : "&beforeId=" + beforeId; + const headers = { "Content-Type": "application/json" }; + if (this.activeDid) { + const account = R.find( + (acc) => acc.did === this.activeDid, + this.allAccounts + ); + console.log("about to parse from", this.activeDid, account?.identity); + const identity = JSON.parse(account?.identity || "undefined"); + const token = await accessToken(identity); + headers["Authorization"] = "Bearer " + token; + } return fetch(this.apiServer + "/api/v2/report/gives?" + beforeQuery, { method: "GET", - headers: { - "Content-Type": "application/json", - //"Uport-Push-Token": token, - }, + headers: headers, }) .then(async (response) => { if (response.status !== 200) { @@ -184,14 +195,14 @@ export default class HomeView extends Vue { // agent.did is for legacy data, before March 2023 const giver = claim.agent?.identifier || claim.agent?.did || giveRecord.issuer; - const giverInfo = giver; //didInfo(giver, identifiers, contacts); + const giverInfo = didInfo(giver, this.allAccounts, this.allContacts); const gaveAmount = claim.object?.amountOfThisGood ? this.displayAmount(claim.object.unitCode, claim.object.amountOfThisGood) - : claim.object; + : claim.description || "something unknown"; // recipient.did is for legacy data, before March 2023 const gaveRecipientId = claim.recipient?.identifier || claim.recipient?.did; const gaveRecipientInfo = gaveRecipientId - ? " to " + gaveRecipientId //didInfo(gaveRecipientId, identifiers, contacts) + ? " to " + didInfo(gaveRecipientId, this.allAccounts, this.allContacts) : ""; return giverInfo + " gave " + gaveAmount + gaveRecipientInfo; } diff --git a/src/views/NewEditProjectView.vue b/src/views/NewEditProjectView.vue index 6277195..af86bc8 100644 --- a/src/views/NewEditProjectView.vue +++ b/src/views/NewEditProjectView.vue @@ -49,8 +49,9 @@ Save Project - + + + Saving…