forked from trent_larson/crowd-funder-for-time-pwa
allow choice of no identity (for testing)
This commit is contained in:
@@ -22,17 +22,16 @@ export async function loadLandmarks(vue, world, scene, loop) {
|
|||||||
await accountsDB.open();
|
await accountsDB.open();
|
||||||
const accounts = await accountsDB.accounts.toArray();
|
const accounts = await accountsDB.accounts.toArray();
|
||||||
const account = R.find((acc) => acc.did === activeDid, accounts);
|
const account = R.find((acc) => acc.did === activeDid, accounts);
|
||||||
const identity = JSON.parse(account?.identity || "undefined");
|
|
||||||
if (!identity) {
|
|
||||||
throw new Error("No identity found.");
|
|
||||||
}
|
|
||||||
const token = await accessToken(identity);
|
|
||||||
|
|
||||||
const url = apiServer + "/api/v2/report/claims?claimType=GiveAction";
|
|
||||||
const headers = {
|
const headers = {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
Authorization: "Bearer " + token,
|
|
||||||
};
|
};
|
||||||
|
const identity = JSON.parse(account?.identity || "null");
|
||||||
|
if (identity) {
|
||||||
|
const token = await accessToken(identity);
|
||||||
|
headers["Authorization"] = "Bearer " + token;
|
||||||
|
}
|
||||||
|
|
||||||
|
const url = apiServer + "/api/v2/report/claims?claimType=GiveAction";
|
||||||
const resp = await axios.get(url, { headers: headers });
|
const resp = await axios.get(url, { headers: headers });
|
||||||
if (resp.status === 200) {
|
if (resp.status === 200) {
|
||||||
const landmarks = resp.data.data;
|
const landmarks = resp.data.data;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { IIdentifier } from "@veramo/core";
|
|||||||
import { accessToken, SimpleSigner } from "@/libs/crypto";
|
import { accessToken, SimpleSigner } from "@/libs/crypto";
|
||||||
import * as didJwt from "did-jwt";
|
import * as didJwt from "did-jwt";
|
||||||
import { Axios, AxiosResponse } from "axios";
|
import { Axios, AxiosResponse } from "axios";
|
||||||
|
import { Contact } from "@/db/tables/contacts";
|
||||||
|
|
||||||
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";
|
||||||
@@ -81,12 +82,15 @@ export function isHiddenDid(did) {
|
|||||||
/**
|
/**
|
||||||
always returns text, maybe UNNAMED_VISIBLE or UNKNOWN_ENTITY
|
always returns text, maybe UNNAMED_VISIBLE or UNKNOWN_ENTITY
|
||||||
**/
|
**/
|
||||||
export function didInfo(did, identifiers, contacts) {
|
export function didInfo(did, activeDid, identifiers, contacts) {
|
||||||
const myId = R.find((i) => i.did === did, identifiers);
|
const myId: IIdentifier | undefined = R.find(
|
||||||
|
(i) => i.did === did,
|
||||||
|
identifiers
|
||||||
|
);
|
||||||
if (myId) {
|
if (myId) {
|
||||||
return "You";
|
return "You" + (myId.did !== activeDid ? " (Alt ID)" : "");
|
||||||
} else {
|
} else {
|
||||||
const contact = R.find((c) => c.did === did, contacts);
|
const contact: Contact | undefined = R.find((c) => c.did === did, contacts);
|
||||||
if (contact) {
|
if (contact) {
|
||||||
return contact.name || "Someone Unnamed in Contacts";
|
return contact.name || "Someone Unnamed in Contacts";
|
||||||
} else if (!did) {
|
} else if (!did) {
|
||||||
|
|||||||
@@ -290,6 +290,11 @@
|
|||||||
|
|
||||||
<div v-if="numAccounts > 0" class="flex py-2">
|
<div v-if="numAccounts > 0" class="flex py-2">
|
||||||
Switch Identifier
|
Switch Identifier
|
||||||
|
<span>
|
||||||
|
<button class="text-blue-500 px-2" @click="switchAccount(0)">
|
||||||
|
None
|
||||||
|
</button>
|
||||||
|
</span>
|
||||||
<span v-for="accountNum in numAccounts" :key="accountNum">
|
<span v-for="accountNum in numAccounts" :key="accountNum">
|
||||||
<button class="text-blue-500 px-2" @click="switchAccount(accountNum)">
|
<button class="text-blue-500 px-2" @click="switchAccount(accountNum)">
|
||||||
#{{ accountNum }}
|
#{{ accountNum }}
|
||||||
@@ -403,7 +408,9 @@ export default class AccountViewView extends Vue {
|
|||||||
const account = R.find((acc) => acc.did === this.activeDid, accounts);
|
const account = R.find((acc) => acc.did === this.activeDid, accounts);
|
||||||
const identity = JSON.parse(account?.identity || "null");
|
const identity = JSON.parse(account?.identity || "null");
|
||||||
if (!identity) {
|
if (!identity) {
|
||||||
throw new Error("No identity found.");
|
this.limitsMessage = "No identity.";
|
||||||
|
this.loadingLimits = false;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
this.publicHex = identity.keys[0].publicKeyHex;
|
this.publicHex = identity.keys[0].publicKeyHex;
|
||||||
this.publicBase64 = Buffer.from(this.publicHex, "hex").toString("base64");
|
this.publicBase64 = Buffer.from(this.publicHex, "hex").toString("base64");
|
||||||
@@ -469,7 +476,9 @@ export default class AccountViewView extends Vue {
|
|||||||
const account = R.find((acc) => acc.did === this.activeDid, accounts);
|
const account = R.find((acc) => acc.did === this.activeDid, accounts);
|
||||||
const identity = JSON.parse(account?.identity || "null");
|
const identity = JSON.parse(account?.identity || "null");
|
||||||
if (!identity) {
|
if (!identity) {
|
||||||
throw new Error("No identity found.");
|
this.limitsMessage = "No identity.";
|
||||||
|
this.loadingLimits = false;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
const token = await accessToken(identity);
|
const token = await accessToken(identity);
|
||||||
const headers = {
|
const headers = {
|
||||||
@@ -497,6 +506,17 @@ export default class AccountViewView extends Vue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async switchAccount(accountNum: number) {
|
async switchAccount(accountNum: number) {
|
||||||
|
// 0 means none
|
||||||
|
if (accountNum === 0) {
|
||||||
|
await db.open();
|
||||||
|
db.settings.update(MASTER_SETTINGS_KEY, {
|
||||||
|
activeDid: undefined,
|
||||||
|
});
|
||||||
|
this.activeDid = "";
|
||||||
|
this.derivationPath = "";
|
||||||
|
this.publicHex = "";
|
||||||
|
this.publicBase64 = "";
|
||||||
|
} else {
|
||||||
await accountsDB.open();
|
await accountsDB.open();
|
||||||
const accounts = await accountsDB.accounts.toArray();
|
const accounts = await accountsDB.accounts.toArray();
|
||||||
const account = accounts[accountNum - 1];
|
const account = accounts[accountNum - 1];
|
||||||
@@ -511,6 +531,7 @@ export default class AccountViewView extends Vue {
|
|||||||
this.publicHex = account.publicKeyHex;
|
this.publicHex = account.publicKeyHex;
|
||||||
this.publicBase64 = Buffer.from(this.publicHex, "hex").toString("base64");
|
this.publicBase64 = Buffer.from(this.publicHex, "hex").toString("base64");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public showContactGivesClassNames() {
|
public showContactGivesClassNames() {
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -242,9 +242,10 @@ import { AxiosError } from "axios";
|
|||||||
import * as didJwt from "did-jwt";
|
import * as didJwt from "did-jwt";
|
||||||
import * as R from "ramda";
|
import * as R from "ramda";
|
||||||
import { IIdentifier } from "@veramo/core";
|
import { IIdentifier } from "@veramo/core";
|
||||||
|
|
||||||
import { Component, Vue } from "vue-facing-decorator";
|
import { Component, Vue } from "vue-facing-decorator";
|
||||||
|
|
||||||
import { accountsDB, db } from "@/db";
|
import { accountsDB, db } from "@/db";
|
||||||
|
import AlertMessage from "@/components/AlertMessage";
|
||||||
import { Contact } from "@/db/tables/contacts";
|
import { Contact } from "@/db/tables/contacts";
|
||||||
import { MASTER_SETTINGS_KEY } from "@/db/tables/settings";
|
import { MASTER_SETTINGS_KEY } from "@/db/tables/settings";
|
||||||
import { accessToken, SimpleSigner } from "@/libs/crypto";
|
import { accessToken, SimpleSigner } from "@/libs/crypto";
|
||||||
|
|||||||
@@ -241,16 +241,27 @@ 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 giverDid =
|
||||||
claim.agent?.identifier || claim.agent?.did || giveRecord.issuer;
|
claim.agent?.identifier || claim.agent?.did || giveRecord.issuer;
|
||||||
const giverInfo = didInfo(giver, this.allAccounts, this.allContacts);
|
const giverInfo = didInfo(
|
||||||
|
giverDid,
|
||||||
|
this.activeDid,
|
||||||
|
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.description || "something unknown";
|
: 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 " + didInfo(gaveRecipientId, this.allAccounts, this.allContacts)
|
? " to " +
|
||||||
|
didInfo(
|
||||||
|
gaveRecipientId,
|
||||||
|
this.activeDid,
|
||||||
|
this.allAccounts,
|
||||||
|
this.allContacts
|
||||||
|
)
|
||||||
: "";
|
: "";
|
||||||
return giverInfo + " gave " + gaveAmount + gaveRecipientInfo;
|
return giverInfo + " gave " + gaveAmount + gaveRecipientInfo;
|
||||||
}
|
}
|
||||||
@@ -284,7 +295,7 @@ export default class HomeView extends Vue {
|
|||||||
* @param hours may be 0
|
* @param hours may be 0
|
||||||
*/
|
*/
|
||||||
recordGive(giverDid, description, hours) {
|
recordGive(giverDid, description, hours) {
|
||||||
if (this.activeDid == null) {
|
if (!this.activeDid) {
|
||||||
this.alertTitle = "Error";
|
this.alertTitle = "Error";
|
||||||
this.alertMessage =
|
this.alertMessage =
|
||||||
"You must select an identity before you can record a give.";
|
"You must select an identity before you can record a give.";
|
||||||
|
|||||||
Reference in New Issue
Block a user