Browse Source

allow choice of no identity (for testing)

project-gives
Trent Larson 1 year ago
parent
commit
e42b3ff11d
  1. 15
      src/components/World/components/objects/landmarks.js
  2. 12
      src/libs/endorserServer.ts
  3. 47
      src/views/AccountViewView.vue
  4. 3
      src/views/ContactsView.vue
  5. 19
      src/views/HomeView.vue

15
src/components/World/components/objects/landmarks.js

@ -22,17 +22,16 @@ export async function loadLandmarks(vue, world, scene, loop) {
await accountsDB.open();
const accounts = await accountsDB.accounts.toArray();
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 = {
"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 });
if (resp.status === 200) {
const landmarks = resp.data.data;

12
src/libs/endorserServer.ts

@ -3,6 +3,7 @@ import { IIdentifier } from "@veramo/core";
import { accessToken, SimpleSigner } from "@/libs/crypto";
import * as didJwt from "did-jwt";
import { Axios, AxiosResponse } from "axios";
import { Contact } from "@/db/tables/contacts";
export const SCHEMA_ORG_CONTEXT = "https://schema.org";
export const SERVICE_ID = "endorser.ch";
@ -81,12 +82,15 @@ export function isHiddenDid(did) {
/**
always returns text, maybe UNNAMED_VISIBLE or UNKNOWN_ENTITY
**/
export function didInfo(did, identifiers, contacts) {
const myId = R.find((i) => i.did === did, identifiers);
export function didInfo(did, activeDid, identifiers, contacts) {
const myId: IIdentifier | undefined = R.find(
(i) => i.did === did,
identifiers
);
if (myId) {
return "You";
return "You" + (myId.did !== activeDid ? " (Alt ID)" : "");
} else {
const contact = R.find((c) => c.did === did, contacts);
const contact: Contact | undefined = R.find((c) => c.did === did, contacts);
if (contact) {
return contact.name || "Someone Unnamed in Contacts";
} else if (!did) {

47
src/views/AccountViewView.vue

@ -290,6 +290,11 @@
<div v-if="numAccounts > 0" class="flex py-2">
Switch Identifier
<span>
<button class="text-blue-500 px-2" @click="switchAccount(0)">
None
</button>
</span>
<span v-for="accountNum in numAccounts" :key="accountNum">
<button class="text-blue-500 px-2" @click="switchAccount(accountNum)">
#{{ accountNum }}
@ -403,7 +408,9 @@ export default class AccountViewView extends Vue {
const account = R.find((acc) => acc.did === this.activeDid, accounts);
const identity = JSON.parse(account?.identity || "null");
if (!identity) {
throw new Error("No identity found.");
this.limitsMessage = "No identity.";
this.loadingLimits = false;
return;
}
this.publicHex = identity.keys[0].publicKeyHex;
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 identity = JSON.parse(account?.identity || "null");
if (!identity) {
throw new Error("No identity found.");
this.limitsMessage = "No identity.";
this.loadingLimits = false;
return;
}
const token = await accessToken(identity);
const headers = {
@ -497,19 +506,31 @@ export default class AccountViewView extends Vue {
}
async switchAccount(accountNum: number) {
await accountsDB.open();
const accounts = await accountsDB.accounts.toArray();
const account = accounts[accountNum - 1];
// 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();
const accounts = await accountsDB.accounts.toArray();
const account = accounts[accountNum - 1];
await db.open();
db.settings.update(MASTER_SETTINGS_KEY, {
activeDid: account.did,
});
await db.open();
db.settings.update(MASTER_SETTINGS_KEY, {
activeDid: account.did,
});
this.activeDid = account.did;
this.derivationPath = account.derivationPath;
this.publicHex = account.publicKeyHex;
this.publicBase64 = Buffer.from(this.publicHex, "hex").toString("base64");
this.activeDid = account.did;
this.derivationPath = account.derivationPath;
this.publicHex = account.publicKeyHex;
this.publicBase64 = Buffer.from(this.publicHex, "hex").toString("base64");
}
}
public showContactGivesClassNames() {

3
src/views/ContactsView.vue

@ -242,9 +242,10 @@ import { AxiosError } from "axios";
import * as didJwt from "did-jwt";
import * as R from "ramda";
import { IIdentifier } from "@veramo/core";
import { Component, Vue } from "vue-facing-decorator";
import { accountsDB, db } from "@/db";
import AlertMessage from "@/components/AlertMessage";
import { Contact } from "@/db/tables/contacts";
import { MASTER_SETTINGS_KEY } from "@/db/tables/settings";
import { accessToken, SimpleSigner } from "@/libs/crypto";

19
src/views/HomeView.vue

@ -241,16 +241,27 @@ export default class HomeView extends Vue {
}
// agent.did is for legacy data, before March 2023
const giver =
const giverDid =
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
? this.displayAmount(claim.object.unitCode, claim.object.amountOfThisGood)
: 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 " + didInfo(gaveRecipientId, this.allAccounts, this.allContacts)
? " to " +
didInfo(
gaveRecipientId,
this.activeDid,
this.allAccounts,
this.allContacts
)
: "";
return giverInfo + " gave " + gaveAmount + gaveRecipientInfo;
}
@ -284,7 +295,7 @@ export default class HomeView extends Vue {
* @param hours may be 0
*/
recordGive(giverDid, description, hours) {
if (this.activeDid == null) {
if (!this.activeDid) {
this.alertTitle = "Error";
this.alertMessage =
"You must select an identity before you can record a give.";

Loading…
Cancel
Save