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