Browse Source

in feed: add token for authorized request, plus better descriptions

world-fix
Trent Larson 1 year ago
parent
commit
07e7a70d56
  1. 3
      project.task.yaml
  2. 2
      src/db/tables/accounts.ts
  3. 11
      src/libs/endorserServer.ts
  4. 39
      src/views/HomeView.vue
  5. 5
      src/views/NewEditProjectView.vue

3
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?

2
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;

11
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";
}
}
}

39
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<Account> = [];
activeDid = "";
allAccounts: Array<Account> = [];
allContacts: Array<Contact> = [];
apiServer = "";
contacts: Array<Contact> = [];
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;
}

5
src/views/NewEditProjectView.vue

@ -49,8 +49,9 @@
<span :class="{ hidden: isHiddenSave }">Save Project</span>
<!-- SHOW if in saving state; DISABLE button while in saving state -->
<span :class="{ hidden: isHiddenSpinner }"
><i class="fa-solid fa-spinner fa-spin-pulse"></i>
<span :class="{ hidden: isHiddenSpinner }">
<!-- icon no worky? -->
<i class="fa-solid fa-spinner fa-spin-pulse"></i>
Saving&hellip;</span
>
</button>

Loading…
Cancel
Save