Browse Source

Merge remote-tracking branch 'origin/no-accounts-in-memory'

kb/add-usage-guide
Matthew Raymer 1 year ago
parent
commit
e8eae544f3
  1. 7
      src/libs/endorserServer.ts
  2. 40
      src/views/AccountViewView.vue
  3. 7
      src/views/ContactAmountsView.vue
  4. 26
      src/views/HomeView.vue
  5. 7
      src/views/NewEditProjectView.vue
  6. 3
      src/views/NewIdentifierView.vue
  7. 26
      src/views/ProjectViewView.vue
  8. 7
      src/views/ProjectsView.vue

7
src/libs/endorserServer.ts

@ -82,11 +82,8 @@ export function isHiddenDid(did) {
/**
always returns text, maybe UNNAMED_VISIBLE or UNKNOWN_ENTITY
**/
export function didInfo(did, activeDid, identifiers, contacts) {
const myId: IIdentifier | undefined = R.find(
(i) => i.did === did,
identifiers,
);
export function didInfo(did, activeDid, allMyDids, contacts) {
const myId: string | undefined = R.find(R.identity, allMyDids);
if (myId) {
return "You" + (myId.did !== activeDid ? " (Alt ID)" : "");
} else {

40
src/views/AccountViewView.vue

@ -283,12 +283,12 @@ import { useClipboard } from "@vueuse/core";
import { AppString } from "@/constants/app";
import { db, accountsDB } from "@/db";
import { AccountsSchema } from "@/db/tables/accounts";
import { MASTER_SETTINGS_KEY } from "@/db/tables/settings";
import { accessToken } from "@/libs/crypto";
import { AxiosError } from "axios/index";
import AlertMessage from "@/components/AlertMessage";
import QuickNav from "@/components/QuickNav";
import { IIdentifier } from "@veramo/core";
// eslint-disable-next-line @typescript-eslint/no-var-requires
const Buffer = require("buffer/").Buffer;
@ -310,7 +310,6 @@ export default class AccountViewView extends Vue {
limitsMessage = "";
loadingLimits = true; // might as well now that we do it on mount, to avoid flashing the registration message
showContactGives = false;
private accounts: AccountsSchema;
showDidCopy = false;
showDerCopy = false;
@ -328,12 +327,6 @@ export default class AccountViewView extends Vue {
.equals(activeDid)
.first();
const identity = JSON.parse(account?.identity || "null");
if (!identity) {
throw new Error(
"Attempted to load Give records with no identity available.",
);
}
return identity;
}
@ -364,9 +357,8 @@ export default class AccountViewView extends Vue {
}
async beforeCreate() {
accountsDB.open();
this.accounts = accountsDB.accounts;
this.numAccounts = await this.accounts.count();
await accountsDB.open();
this.numAccounts = await accountsDB.accounts.count();
}
async created() {
@ -388,14 +380,18 @@ export default class AccountViewView extends Vue {
const identity = await this.getIdentity(this.activeDid);
this.publicHex = identity.keys[0].publicKeyHex;
this.publicBase64 = Buffer.from(this.publicHex, "hex").toString("base64");
this.derivationPath = identity.keys[0].meta.derivationPath;
if (identity) {
this.publicHex = identity.keys[0].publicKeyHex;
this.publicBase64 = Buffer.from(this.publicHex, "hex").toString(
"base64",
);
this.derivationPath = identity.keys[0].meta.derivationPath;
db.settings.update(MASTER_SETTINGS_KEY, {
activeDid: identity.did,
});
this.checkLimits();
db.settings.update(MASTER_SETTINGS_KEY, {
activeDid: identity.did,
});
this.checkLimitsFor(identity);
}
} catch (err) {
if (
err.message ===
@ -454,12 +450,18 @@ export default class AccountViewView extends Vue {
}
async checkLimits() {
const identity = await this.getIdentity(this.activeDid);
if (identity) {
this.checkLimitsFor(identity);
}
}
async checkLimitsFor(identity: IIdentifier) {
this.loadingLimits = true;
this.limitsMessage = "";
try {
const url = this.apiServer + "/api/report/rateLimits";
const identity = await this.getIdentity(this.activeDid);
const headers = await this.getHeaders(identity);
const resp = await this.axios.get(url, { headers });

7
src/views/ContactAmountsView.vue

@ -78,7 +78,6 @@ import * as R from "ramda";
import { Component, Vue } from "vue-facing-decorator";
import { accountsDB, db } from "@/db";
import { AccountsSchema } from "@/db/tables/accounts";
import { Contact } from "@/db/tables/contacts";
import { MASTER_SETTINGS_KEY } from "@/db/tables/settings";
import { accessToken, SimpleSigner } from "@/libs/crypto";
@ -101,13 +100,11 @@ export default class ContactsView extends Vue {
giveRecords: Array<GiveServerRecord> = [];
alertTitle = "";
alertMessage = "";
accounts: AccountsSchema;
numAccounts = 0;
async beforeCreate() {
accountsDB.open();
this.accounts = accountsDB.accounts;
this.numAccounts = await this.accounts.count();
await accountsDB.open();
this.numAccounts = await accountsDB.accounts.count();
}
public async getIdentity(activeDid) {

26
src/views/HomeView.vue

@ -89,11 +89,9 @@
import { Component, Vue } from "vue-facing-decorator";
import GiftedDialog from "@/components/GiftedDialog.vue";
import { db, accountsDB } from "@/db";
import { AccountsSchema } from "@/db/tables/accounts";
import { MASTER_SETTINGS_KEY } from "@/db/tables/settings";
import { accessToken } from "@/libs/crypto";
import { createAndSubmitGive, didInfo } from "@/libs/endorserServer";
import { Account } from "@/db/tables/accounts";
import { Contact } from "@/db/tables/contacts";
import AlertMessage from "@/components/AlertMessage";
import QuickNav from "@/components/QuickNav";
@ -103,8 +101,8 @@ import QuickNav from "@/components/QuickNav";
})
export default class HomeView extends Vue {
activeDid = "";
allAccounts: Array<Account> = [];
allContacts: Array<Contact> = [];
allMyDids: Array<string> = [];
apiServer = "";
feedAllLoaded = false;
feedData = [];
@ -113,13 +111,11 @@ export default class HomeView extends Vue {
isHiddenSpinner = true;
alertTitle = "";
alertMessage = "";
accounts: AccountsSchema;
numAccounts = 0;
async beforeCreate() {
accountsDB.open();
this.accounts = accountsDB.accounts;
this.numAccounts = await this.accounts.count();
await accountsDB.open();
this.numAccounts = await accountsDB.accounts.count();
}
public async getIdentity(activeDid) {
@ -150,7 +146,9 @@ export default class HomeView extends Vue {
async created() {
try {
await accountsDB.open();
this.allAccounts = await accountsDB.accounts.toArray();
const allAccounts = await accountsDB.accounts.toArray();
this.allMyDids = allAccounts.map((acc) => acc.did);
await db.open();
const settings = await db.settings.get(MASTER_SETTINGS_KEY);
this.apiServer = settings?.apiServer || "";
@ -247,14 +245,13 @@ export default class HomeView extends Vue {
if (claim.claim) {
claim = claim.claim;
}
// agent.did is for legacy data, before March 2023
const giverDid =
claim.agent?.identifier || claim.agent?.did || giveRecord.issuer;
const giverInfo = didInfo(
giverDid,
this.activeDid,
this.allAccounts,
this.allMyDids,
this.allContacts,
);
const gaveAmount = claim.object?.amountOfThisGood
@ -267,7 +264,7 @@ export default class HomeView extends Vue {
didInfo(
gaveRecipientId,
this.activeDid,
this.allAccounts,
this.allMyDids,
this.allContacts,
)
: "";
@ -332,8 +329,8 @@ export default class HomeView extends Vue {
hours,
);
if (isGiveCreationError(result)) {
const errorMessage = getGiveCreationErrorMessage(result);
if (this.isGiveCreationError(result)) {
const errorMessage = this.getGiveCreationErrorMessage(result);
console.log("Error with give result:", result);
this.setAlert(
"Error",
@ -346,7 +343,8 @@ export default class HomeView extends Vue {
console.log("Error with give caught:", error);
this.setAlert(
"Error",
getGiveErrorMessage(error) || "There was an error recording the give.",
this.getGiveErrorMessage(error) ||
"There was an error recording the give.",
);
}
}

7
src/views/NewEditProjectView.vue

@ -76,7 +76,6 @@ import * as didJwt from "did-jwt";
import { Component, Vue } from "vue-facing-decorator";
import { accountsDB, db } from "@/db";
import { AccountsSchema } from "@/db/tables/accounts";
import { MASTER_SETTINGS_KEY } from "@/db/tables/settings";
import { accessToken, SimpleSigner } from "@/libs/crypto";
import { useAppStore } from "@/store/app";
@ -92,15 +91,13 @@ export default class NewEditProjectView extends Vue {
projectName = "";
description = "";
errorMessage = "";
accounts: AccountsSchema;
numAccounts = 0;
alertTitle = "";
alertMessage = "";
async beforeCreate() {
accountsDB.open();
this.accounts = accountsDB.accounts;
this.numAccounts = await this.accounts.count();
await accountsDB.open();
this.numAccounts = await accountsDB.accounts.count();
}
public async getIdentity(activeDid) {

3
src/views/NewIdentifierView.vue

@ -50,7 +50,6 @@ export default class AccountViewView extends Vue {
loading = true;
async mounted() {
await accountsDB.open();
const mnemonic = generateSeed();
// address is 0x... ETH address, without "did:eth:"
const [address, privateHex, publicHex, derivationPath] =
@ -58,6 +57,8 @@ export default class AccountViewView extends Vue {
const newId = newIdentifier(address, publicHex, privateHex, derivationPath);
const identity = JSON.stringify(newId);
await accountsDB.open();
await accountsDB.accounts.add({
dateCreated: new Date().toISOString(),
derivationPath: derivationPath,

26
src/views/ProjectViewView.vue

@ -104,7 +104,7 @@
<div class="flex gap-2">
<fa icon="user" class="fa-fw text-slate-400"></fa>
<span>{{
didInfo(give.agentDid, activeDid, accounts, allContacts)
didInfo(give.agentDid, activeDid, allMyDids, allContacts)
}}</span>
</div>
<div class="flex gap-2" v-if="give.amount">
@ -126,7 +126,7 @@
<div class="flex gap-2">
<fa icon="user" class="fa-fw text-slate-400"></fa>
<span>{{
didInfo(give.agentDid, activeDid, accounts, allContacts)
didInfo(give.agentDid, activeDid, allMyDids, allContacts)
}}</span>
</div>
<div class="flex gap-2" v-if="give.amount">
@ -163,7 +163,6 @@ import { Component, Vue } from "vue-facing-decorator";
import GiftedDialog from "@/components/GiftedDialog.vue";
import { accountsDB, db } from "@/db";
import { AccountsSchema } from "@/db/tables/accounts";
import { Contact } from "@/db/tables/contacts";
import { MASTER_SETTINGS_KEY } from "@/db/tables/settings";
import { accessToken } from "@/libs/crypto";
@ -179,10 +178,10 @@ import QuickNav from "@/components/QuickNav";
components: { GiftedDialog, AlertMessage, QuickNav },
})
export default class ProjectViewView extends Vue {
accounts: AccountsSchema;
activeDid = "";
alertMessage = "";
alertTitle = "";
allMyDids: Array<string> = [];
allContacts: Array<Contact> = [];
apiServer = "";
description = "";
@ -191,18 +190,11 @@ export default class ProjectViewView extends Vue {
givesByThis: Array<GiveServerRecord> = [];
name = "";
issuer = "";
numAccounts = 0;
projectId = localStorage.getItem("projectId") || ""; // handle ID
timeSince = "";
truncatedDesc = "";
truncateLength = 40;
async beforeCreate() {
accountsDB.open();
this.accounts = accountsDB.accounts;
this.numAccounts = (await this.accounts?.count()) || 0;
}
async created() {
await db.open();
const settings = await db.settings.get(MASTER_SETTINGS_KEY);
@ -210,9 +202,11 @@ export default class ProjectViewView extends Vue {
this.apiServer = settings?.apiServer || "";
this.allContacts = await db.contacts.toArray();
this.accounts = accountsDB.accounts;
const accountsArr = await this.accounts?.toArray();
const account = accountsArr.find((acc) => acc.did === this.activeDid);
await accountsDB.open();
const accounts = accountsDB.accounts;
const accountsArr = await accounts?.toArray();
this.allMyDids = accountsArr.map((acc) => acc.did);
const account = accountsArr?.find((acc) => acc.did === this.activeDid);
const identity = JSON.parse(account?.identity || "null");
this.LoadProject(identity);
}
@ -251,8 +245,8 @@ export default class ProjectViewView extends Vue {
}
// Isn't there a better way to make this available to the template?
didInfo(did, activeDid, identities, contacts) {
return didInfo(did, activeDid, identities, contacts);
didInfo(did, activeDid, dids, contacts) {
return didInfo(did, activeDid, dids, contacts);
}
expandText() {

7
src/views/ProjectsView.vue

@ -74,7 +74,6 @@
<script lang="ts">
import { Component, Vue } from "vue-facing-decorator";
import { accountsDB, db } from "@/db";
import { AccountsSchema } from "@/db/tables/accounts";
import { MASTER_SETTINGS_KEY } from "@/db/tables/settings";
import { accessToken } from "@/libs/crypto";
import { IIdentifier } from "@veramo/core";
@ -92,13 +91,11 @@ export default class ProjectsView extends Vue {
isLoading = false;
alertTitle = "";
alertMessage = "";
accounts: AccountsSchema;
numAccounts = 0;
async beforeCreate() {
accountsDB.open();
this.accounts = accountsDB.accounts;
this.numAccounts = await this.accounts.count();
await accountsDB.open();
this.numAccounts = await accountsDB.accounts.count();
}
/**

Loading…
Cancel
Save