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

This commit is contained in:
2023-06-12 20:29:55 -06:00
parent 6daa515d19
commit 07e7a70d56
5 changed files with 36 additions and 24 deletions

View File

@@ -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;
}