forked from trent_larson/crowd-funder-for-time-pwa
in feed: add token for authorized request, plus better descriptions
This commit is contained in:
@@ -32,8 +32,7 @@
|
|||||||
- Ensure each action sent to the server has a confirmation.
|
- Ensure each action sent to the server has a confirmation.
|
||||||
|
|
||||||
- Feed screen
|
- Feed screen
|
||||||
- 01 save the feed in settings storage
|
- 01 save the feed-viewed status in settings storage ("afterQuery")
|
||||||
- .5 add user-specific data
|
|
||||||
|
|
||||||
- .5 customize favicon
|
- .5 customize favicon
|
||||||
- .5 make advanced features harder to access; advanced build?
|
- .5 make advanced features harder to access; advanced build?
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ export type Account = {
|
|||||||
dateCreated: string;
|
dateCreated: string;
|
||||||
derivationPath: string;
|
derivationPath: string;
|
||||||
did: 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;
|
identity: string;
|
||||||
publicKeyHex: string;
|
publicKeyHex: string;
|
||||||
mnemonic: string;
|
mnemonic: string;
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import * as R from "ramda";
|
||||||
|
|
||||||
export const SCHEMA_ORG_CONTEXT = "https://schema.org";
|
export const SCHEMA_ORG_CONTEXT = "https://schema.org";
|
||||||
export const SERVICE_ID = "endorser.ch";
|
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
|
// See https://github.com/trentlarson/endorser-ch/blob/0cb626f803028e7d9c67f095858a9fc8542e3dbd/server/api/services/util.js#L6
|
||||||
const HIDDEN_DID = "did:none:HIDDEN";
|
const HIDDEN_DID = "did:none:HIDDEN";
|
||||||
|
|
||||||
const UNKNOWN_ENTITY = "Someone Unknown";
|
|
||||||
const UNKNOWN_VISIBLE = "Someone Unnamed";
|
|
||||||
|
|
||||||
export function isHiddenDid(did) {
|
export function isHiddenDid(did) {
|
||||||
return did === HIDDEN_DID;
|
return did === HIDDEN_DID;
|
||||||
}
|
}
|
||||||
@@ -69,11 +68,11 @@ export function didInfo(did, identifiers, contacts) {
|
|||||||
} else {
|
} else {
|
||||||
const contact = R.find((c) => c.did === did, contacts);
|
const contact = R.find((c) => c.did === did, contacts);
|
||||||
if (contact) {
|
if (contact) {
|
||||||
return contact.name || "(no name)";
|
return contact.name || "Someone Unnamed in Contacts";
|
||||||
} else if (isHiddenDid(did)) {
|
} else if (isHiddenDid(did)) {
|
||||||
return UNKNOWN_ENTITY;
|
return "Someone Not In Network";
|
||||||
} else {
|
} else {
|
||||||
return UNKNOWN_VISIBLE;
|
return "Someone Not In Contacts";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,6 +84,7 @@ import { Options, Vue } from "vue-class-component";
|
|||||||
|
|
||||||
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 { didInfo } from "@/libs/endorserServer";
|
import { didInfo } 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";
|
||||||
@@ -93,9 +94,10 @@ import * as R from "ramda";
|
|||||||
components: {},
|
components: {},
|
||||||
})
|
})
|
||||||
export default class HomeView extends Vue {
|
export default class HomeView extends Vue {
|
||||||
accounts: Array<Account> = [];
|
activeDid = "";
|
||||||
|
allAccounts: Array<Account> = [];
|
||||||
|
allContacts: Array<Contact> = [];
|
||||||
apiServer = "";
|
apiServer = "";
|
||||||
contacts: Array<Contact> = [];
|
|
||||||
feedAllLoaded = false;
|
feedAllLoaded = false;
|
||||||
feedData = [];
|
feedData = [];
|
||||||
feedPreviousOldestId = null;
|
feedPreviousOldestId = null;
|
||||||
@@ -104,10 +106,11 @@ export default class HomeView extends Vue {
|
|||||||
// 'created' hook runs when the Vue instance is first created
|
// 'created' hook runs when the Vue instance is first created
|
||||||
async created() {
|
async created() {
|
||||||
await accountsDB.open();
|
await accountsDB.open();
|
||||||
this.accounts = await accountsDB.accounts.toArray();
|
this.allAccounts = await accountsDB.accounts.toArray();
|
||||||
console.log("Accounts:", this.accounts);
|
|
||||||
await db.open();
|
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
|
// 'mounted' hook runs after initial render
|
||||||
@@ -116,6 +119,7 @@ export default class HomeView extends Vue {
|
|||||||
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.updateAllFeed();
|
this.updateAllFeed();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log("Error in mounted():", err);
|
console.log("Error in mounted():", err);
|
||||||
@@ -133,7 +137,7 @@ export default class HomeView extends Vue {
|
|||||||
.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);
|
||||||
console.log("Feed data:", this.feedData);
|
//console.log("Feed data:", this.feedData);
|
||||||
this.feedAllLoaded = results.hitLimit;
|
this.feedAllLoaded = results.hitLimit;
|
||||||
this.feedPreviousOldestId = results.data[results.data.length - 1].id;
|
this.feedPreviousOldestId = results.data[results.data.length - 1].id;
|
||||||
}
|
}
|
||||||
@@ -148,15 +152,22 @@ export default class HomeView extends Vue {
|
|||||||
};
|
};
|
||||||
|
|
||||||
retrieveClaims = async (endorserApiServer, identifier, beforeId) => {
|
retrieveClaims = async (endorserApiServer, identifier, beforeId) => {
|
||||||
//const token = await accessToken(identifier)
|
|
||||||
//const afterQuery = afterId == null ? "" : "&afterId=" + afterId;
|
//const afterQuery = afterId == null ? "" : "&afterId=" + afterId;
|
||||||
const beforeQuery = beforeId == null ? "" : "&beforeId=" + beforeId;
|
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, {
|
return fetch(this.apiServer + "/api/v2/report/gives?" + beforeQuery, {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {
|
headers: headers,
|
||||||
"Content-Type": "application/json",
|
|
||||||
//"Uport-Push-Token": token,
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
.then(async (response) => {
|
.then(async (response) => {
|
||||||
if (response.status !== 200) {
|
if (response.status !== 200) {
|
||||||
@@ -184,14 +195,14 @@ export default class HomeView extends Vue {
|
|||||||
// agent.did is for legacy data, before March 2023
|
// agent.did is for legacy data, before March 2023
|
||||||
const giver =
|
const giver =
|
||||||
claim.agent?.identifier || claim.agent?.did || giveRecord.issuer;
|
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
|
const gaveAmount = claim.object?.amountOfThisGood
|
||||||
? this.displayAmount(claim.object.unitCode, 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
|
// recipient.did is for legacy data, before March 2023
|
||||||
const gaveRecipientId = claim.recipient?.identifier || claim.recipient?.did;
|
const gaveRecipientId = claim.recipient?.identifier || claim.recipient?.did;
|
||||||
const gaveRecipientInfo = gaveRecipientId
|
const gaveRecipientInfo = gaveRecipientId
|
||||||
? " to " + gaveRecipientId //didInfo(gaveRecipientId, identifiers, contacts)
|
? " to " + didInfo(gaveRecipientId, this.allAccounts, this.allContacts)
|
||||||
: "";
|
: "";
|
||||||
return giverInfo + " gave " + gaveAmount + gaveRecipientInfo;
|
return giverInfo + " gave " + gaveAmount + gaveRecipientInfo;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,8 +49,9 @@
|
|||||||
<span :class="{ hidden: isHiddenSave }">Save Project</span>
|
<span :class="{ hidden: isHiddenSave }">Save Project</span>
|
||||||
|
|
||||||
<!-- SHOW if in saving state; DISABLE button while in saving state -->
|
<!-- SHOW if in saving state; DISABLE button while in saving state -->
|
||||||
<span :class="{ hidden: isHiddenSpinner }"
|
<span :class="{ hidden: isHiddenSpinner }">
|
||||||
><i class="fa-solid fa-spinner fa-spin-pulse"></i>
|
<!-- icon no worky? -->
|
||||||
|
<i class="fa-solid fa-spinner fa-spin-pulse"></i>
|
||||||
Saving…</span
|
Saving…</span
|
||||||
>
|
>
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
Reference in New Issue
Block a user