forked from trent_larson/crowd-funder-for-time-pwa
Compare commits
46 Commits
quicknav-c
...
identity-s
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ead37ede74 | ||
|
|
f428199228 | ||
|
|
1405b88323 | ||
|
|
44fc2850dd | ||
|
|
52d411470e | ||
|
|
ab678a900a | ||
|
|
efa59e170f | ||
|
|
7a4ceaa455 | ||
| 78b98bab5e | |||
| 2493f2ad39 | |||
| 00954693b5 | |||
| 2dd77f898f | |||
| c1f218c2f3 | |||
| b5e78e5dc8 | |||
| 47442655cb | |||
|
|
1d362c314b | ||
| 3eda246e85 | |||
|
|
3f13d3ea33 | ||
|
|
cef346e487 | ||
|
|
fed23a61ee | ||
|
|
b6b7c56157 | ||
| 3f8be3b4de | |||
| 21af37c2c2 | |||
| 0b7a35c9b8 | |||
| 0257901c5b | |||
| d9d6096275 | |||
| ed7d37c649 | |||
| 81dd6eb595 | |||
|
|
c61bb88788 | ||
|
|
3bd55f3ad2 | ||
|
|
3471afdf25 | ||
|
|
e25a83ff1b | ||
|
|
0fbdb45d3e | ||
|
|
dc23ba1375 | ||
|
|
08137eb000 | ||
|
|
5d49965166 | ||
| 8e8aa4356d | |||
| 59a354027e | |||
|
|
5dc80ce12a | ||
|
|
754bced2a9 | ||
|
|
e3f58bd593 | ||
|
|
3b41014083 | ||
| f568149745 | |||
| a27d035e9b | |||
| 16d0be681c | |||
| e42b3ff11d |
950
package-lock.json
generated
950
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
31
package.json
31
package.json
@@ -21,15 +21,15 @@
|
||||
"@veramo/did-provider-ethr": "^5.1.2",
|
||||
"@veramo/did-resolver": "^5.2.0",
|
||||
"@veramo/key-manager": "^5.1.2",
|
||||
"@vueuse/core": "^10.2.0",
|
||||
"@vueuse/core": "^10.2.1",
|
||||
"@zxing/text-encoding": "^0.9.0",
|
||||
"axios": "^1.4.0",
|
||||
"buffer": "^6.0.3",
|
||||
"class-transformer": "^0.5.1",
|
||||
"core-js": "^3.31.0",
|
||||
"core-js": "^3.31.1",
|
||||
"dexie": "^3.2.4",
|
||||
"dexie-export-import": "^4.0.7",
|
||||
"did-jwt": "^7.2.2",
|
||||
"did-jwt": "^7.2.4",
|
||||
"ethereum-cryptography": "^2.0.0",
|
||||
"ethereumjs-util": "^7.1.5",
|
||||
"ethr-did-resolver": "^8.0.0",
|
||||
@@ -43,23 +43,22 @@
|
||||
"pinia-plugin-persistedstate": "^3.1.0",
|
||||
"qr-code-generator-vue3": "^1.4.21",
|
||||
"ramda": "^0.29.0",
|
||||
"readable-stream": "^4.4.0",
|
||||
"readable-stream": "^4.4.2",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"register-service-worker": "^1.7.2",
|
||||
"three": "^0.153.0",
|
||||
"three": "^0.154.0",
|
||||
"vue": "^3.3.4",
|
||||
"vue-axios": "^3.5.2",
|
||||
"vue-class-component": "^8.0.0-0",
|
||||
"vue-facing-decorator": "^2.1.20",
|
||||
"vue-property-decorator": "^9.1.2",
|
||||
"vue-router": "^4.2.2",
|
||||
"web-did-resolver": "^2.0.24"
|
||||
"vue-router": "^4.2.3",
|
||||
"web-did-resolver": "^2.0.27"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/ramda": "^0.29.2",
|
||||
"@types/ramda": "^0.29.3",
|
||||
"@types/three": "^0.152.1",
|
||||
"@typescript-eslint/eslint-plugin": "^5.60.0",
|
||||
"@typescript-eslint/parser": "^5.60.0",
|
||||
"@typescript-eslint/eslint-plugin": "^5.61.0",
|
||||
"@typescript-eslint/parser": "^5.61.0",
|
||||
"@vue/cli-plugin-babel": "~5.0.8",
|
||||
"@vue/cli-plugin-eslint": "~5.0.8",
|
||||
"@vue/cli-plugin-pwa": "~5.0.8",
|
||||
@@ -69,13 +68,13 @@
|
||||
"@vue/cli-service": "~5.0.8",
|
||||
"@vue/eslint-config-typescript": "^11.0.3",
|
||||
"autoprefixer": "^10.4.14",
|
||||
"eslint": "^8.43.0",
|
||||
"eslint": "^8.44.0",
|
||||
"eslint-config-prettier": "^8.8.0",
|
||||
"eslint-plugin-prettier": "^4.2.1",
|
||||
"eslint-plugin-vue": "^9.15.0",
|
||||
"eslint-plugin-prettier": "^5.0.0-alpha.1",
|
||||
"eslint-plugin-vue": "^9.15.1",
|
||||
"postcss": "^8.4.24",
|
||||
"prettier": "^2.8.8",
|
||||
"prettier": "^3.0.0",
|
||||
"tailwindcss": "^3.3.2",
|
||||
"typescript": "~5.1.3"
|
||||
"typescript": "~5.1.6"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,50 +1,37 @@
|
||||
|
||||
tasks:
|
||||
- replace user-affecting console.log & console.error with error messages (eg. catches)
|
||||
- if there's no identity, handle it on pages which expect an identity (eg. project -- look for JSON.parse identity calls)
|
||||
- .1 show an appropriate message when there are no contacts
|
||||
|
||||
- 8 Move to vue-facing-decorator
|
||||
|
||||
- 01 design ideas for simple gives on the first page
|
||||
|
||||
- .1 remove commitments from ProjectView UI
|
||||
- 01 add list of 'give' records for a project on ProjectView UI
|
||||
|
||||
- 02 Discover page - display results (currently in console.log), spin when searching
|
||||
- 08 search by location, endpoint, etc assignee:trent
|
||||
- 01 add a location for a project via map pin :
|
||||
- give attribute to use assignee:trent
|
||||
- 01 design ideas for simple gives on the Home page
|
||||
- 02 Discover page - add infinite search
|
||||
- 01 add a location for a project via map pin
|
||||
- 04 search by a bounding box for local projects (see API by clicking on "Nearby")
|
||||
- 01 remove all the "form" fields (or at least investigate to see if that page refresh is desired)
|
||||
- 01 Replace Gifted/Give in ContactsView with GiftedDialog
|
||||
- 02 Fix images on projectview: allow choice of image from a pallete of images or a url image.
|
||||
|
||||
- 08 Scan QR code to import into contacts.
|
||||
|
||||
- contacts v1 :
|
||||
- 01 Import contact info a la QR code.
|
||||
- 01 Import all the non-sensitive data (ie. contacts & settings).
|
||||
- .2 move all "identity" references to temporary account access assignee:trent
|
||||
|
||||
- contacts v+ :
|
||||
- 01 Import all the non-sensitive data (ie. contacts & settings).
|
||||
- .2 show error to user when adding a duplicate contact
|
||||
- 01 parse input more robustly (with CSV lib and not commas)
|
||||
|
||||
- refactor UI :
|
||||
- .5 Alerts show at the top and can be missed, eg. account data download
|
||||
- 01 Change alert popup code a component (to cut down duplicate code; see "in many files")
|
||||
- 01 Change "nav" tabs across the bottom into a component (eliminating duplicate code).
|
||||
- .5 Fix how icons show on top of bottom bar on ContactAmounts page
|
||||
- .2 Hide "Advanced" section in Account page by default
|
||||
- .5 Alerts show at the top and can be missed if you've scrolled down on the page, eg. account data download
|
||||
- .2 Make alerts at the top more visible (because they're currently a similar color and sometimes aren't seen)
|
||||
|
||||
- show pop-up confirming that settings & contacts have been downloaded
|
||||
- Show pop-up or some message confirming that settings & contacts download has been initiated/finished
|
||||
|
||||
- Ensure each action sent to the server has a confirmation - registration
|
||||
- Ensure each action sent to the server has a confirmation - eg registration
|
||||
|
||||
- Home Feed & Quick Give screen :
|
||||
- 01 save the feed-viewed status in settings storage ("afterQuery")
|
||||
- 01 quick action - send action, maybe choose via canvas tool https://github.com/konvajs/vue-konva
|
||||
|
||||
- .5 customize favicon
|
||||
- .2 Hide "Advanced" section in Account page by default
|
||||
- 04 allow user to download claims, mine + ones I can see about me from others
|
||||
|
||||
- 24 Move to Vite
|
||||
@@ -55,17 +42,16 @@ tasks:
|
||||
- Discuss whether the remaining tasks are worthwhile before MVP release.
|
||||
|
||||
- 01 fix images on project page, on discovery page
|
||||
- .2 fix "Rotary" and static icon to the right on project page
|
||||
- .2 fix static icon to the right on project page (Matthew: I've made "Rotary" into issuer?)
|
||||
|
||||
- stats v1 :
|
||||
- 01 show numeric stats
|
||||
- 01 link to world for specific stats
|
||||
- .5 don't load another instance of a bush if it already exists
|
||||
- maybe - allow type annotations in World.js & landmarks.js (since we get this error - "Types are not supported by current JavaScript version")
|
||||
- 4-8 convert to cleaner implementation (maybe Drie -- https://github.com/janvorisek/drie)
|
||||
- 08 convert to cleaner implementation (maybe Drie -- https://github.com/janvorisek/drie)
|
||||
|
||||
- Do we want split first name & last name?
|
||||
- remove 'about' page
|
||||
|
||||
- Release Minimum Viable Product :
|
||||
- 08 thorough testing for errors & edge cases
|
||||
@@ -82,9 +68,10 @@ tasks:
|
||||
- pull, w/ scheduled runs
|
||||
|
||||
- linking between projects or plans :
|
||||
- terminology:
|
||||
- for subtasks: fulfills (is it really the same?), feeds, contributes to, supplies, boosts, advances
|
||||
- for blocking: blocks, precedes, comes before, is sought by -- vs follows, seeks, builds on ("contributes to" isn't specific enough, "succeeds" has different, possibly confusing meaning)
|
||||
- show total time given to & from a project
|
||||
- terminology:
|
||||
- for subtasks: fulfills (is it really the same?), feeds, contributes to, supplies, boosts, advances
|
||||
- for blocking: blocks, precedes, comes before, is sought by -- vs follows, seeks, builds on ("contributes to" isn't specific enough, "succeeds" has different, possibly confusing meaning)
|
||||
|
||||
- Stats :
|
||||
- 01 point out user's location on the world
|
||||
@@ -104,7 +91,6 @@ tasks:
|
||||
|
||||
- Peer DID
|
||||
|
||||
|
||||
- DIDComm
|
||||
|
||||
- Write to or read from a different ledger (eg. private ACDC, attest.sh)
|
||||
|
||||
@@ -1,150 +0,0 @@
|
||||
<template>
|
||||
<div class="hello">
|
||||
<h1>{{ msg }}</h1>
|
||||
<p>
|
||||
For a guide and recipes on how to configure / customize this project,<br />
|
||||
check out the
|
||||
<a href="https://cli.vuejs.org" target="_blank" rel="noopener"
|
||||
>vue-cli documentation</a
|
||||
>.
|
||||
</p>
|
||||
<h3>Installed CLI Plugins</h3>
|
||||
<ul>
|
||||
<li>
|
||||
<a
|
||||
href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-babel"
|
||||
target="_blank"
|
||||
rel="noopener"
|
||||
>babel</a
|
||||
>
|
||||
</li>
|
||||
<li>
|
||||
<a
|
||||
href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-pwa"
|
||||
target="_blank"
|
||||
rel="noopener"
|
||||
>pwa</a
|
||||
>
|
||||
</li>
|
||||
<li>
|
||||
<a
|
||||
href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-router"
|
||||
target="_blank"
|
||||
rel="noopener"
|
||||
>router</a
|
||||
>
|
||||
</li>
|
||||
<li>
|
||||
<a
|
||||
href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-vuex"
|
||||
target="_blank"
|
||||
rel="noopener"
|
||||
>vuex</a
|
||||
>
|
||||
</li>
|
||||
<li>
|
||||
<a
|
||||
href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-eslint"
|
||||
target="_blank"
|
||||
rel="noopener"
|
||||
>eslint</a
|
||||
>
|
||||
</li>
|
||||
<li>
|
||||
<a
|
||||
href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-typescript"
|
||||
target="_blank"
|
||||
rel="noopener"
|
||||
>typescript</a
|
||||
>
|
||||
</li>
|
||||
</ul>
|
||||
<h3>Essential Links</h3>
|
||||
<ul>
|
||||
<li>
|
||||
<a href="https://vuejs.org" target="_blank" rel="noopener">Core Docs</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="https://forum.vuejs.org" target="_blank" rel="noopener"
|
||||
>Forum</a
|
||||
>
|
||||
</li>
|
||||
<li>
|
||||
<a href="https://chat.vuejs.org" target="_blank" rel="noopener"
|
||||
>Community Chat</a
|
||||
>
|
||||
</li>
|
||||
<li>
|
||||
<a href="https://twitter.com/vuejs" target="_blank" rel="noopener"
|
||||
>Twitter</a
|
||||
>
|
||||
</li>
|
||||
<li>
|
||||
<a href="https://news.vuejs.org" target="_blank" rel="noopener">News</a>
|
||||
</li>
|
||||
</ul>
|
||||
<h3>Ecosystem</h3>
|
||||
<ul>
|
||||
<li>
|
||||
<a href="https://router.vuejs.org" target="_blank" rel="noopener"
|
||||
>vue-router</a
|
||||
>
|
||||
</li>
|
||||
<li>
|
||||
<a href="https://vuex.vuejs.org" target="_blank" rel="noopener">vuex</a>
|
||||
</li>
|
||||
<li>
|
||||
<a
|
||||
href="https://github.com/vuejs/vue-devtools#vue-devtools"
|
||||
target="_blank"
|
||||
rel="noopener"
|
||||
>vue-devtools</a
|
||||
>
|
||||
</li>
|
||||
<li>
|
||||
<a href="https://vue-loader.vuejs.org" target="_blank" rel="noopener"
|
||||
>vue-loader</a
|
||||
>
|
||||
</li>
|
||||
<li>
|
||||
<a
|
||||
href="https://github.com/vuejs/awesome-vue"
|
||||
target="_blank"
|
||||
rel="noopener"
|
||||
>awesome-vue</a
|
||||
>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { Options, Vue } from "vue-class-component";
|
||||
|
||||
@Options({
|
||||
props: {
|
||||
msg: String,
|
||||
},
|
||||
})
|
||||
export default class HelloWorld extends Vue {
|
||||
msg!: string;
|
||||
}
|
||||
</script>
|
||||
|
||||
<!-- Add "scoped" attribute to limit CSS to this component only -->
|
||||
<style scoped>
|
||||
h3 {
|
||||
margin: 40px 0 0;
|
||||
}
|
||||
ul {
|
||||
list-style-type: none;
|
||||
padding: 0;
|
||||
}
|
||||
li {
|
||||
display: inline-block;
|
||||
margin: 0 10px;
|
||||
}
|
||||
a {
|
||||
color: #42b983;
|
||||
}
|
||||
</style>
|
||||
@@ -24,7 +24,7 @@ export default class InfiniteScroll extends Vue {
|
||||
};
|
||||
this.observer = new IntersectionObserver(
|
||||
this.handleIntersection,
|
||||
options
|
||||
options,
|
||||
);
|
||||
this.observer.observe(this.$refs.sentinel as HTMLElement);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ function createCamera() {
|
||||
35, // fov = Field Of View
|
||||
1, // aspect ratio (dummy value)
|
||||
0.1, // near clipping plane
|
||||
350 // far clipping plane
|
||||
350, // far clipping plane
|
||||
);
|
||||
|
||||
// move the camera back so we can view the scene
|
||||
|
||||
@@ -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;
|
||||
@@ -63,7 +62,11 @@ export async function loadLandmarks(vue, world, scene, loop) {
|
||||
|
||||
// calculate positions for each claim, especially because some are random
|
||||
const locations = landmarks.map((claim) =>
|
||||
locForGive(claim, world.PLATFORM_SIZE, world.PLATFORM_EDGE_FOR_UNKNOWNS)
|
||||
locForGive(
|
||||
claim,
|
||||
world.PLATFORM_SIZE,
|
||||
world.PLATFORM_EDGE_FOR_UNKNOWNS,
|
||||
),
|
||||
);
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
||||
@@ -93,7 +96,7 @@ export async function loadLandmarks(vue, world, scene, loop) {
|
||||
undefined,
|
||||
function (error) {
|
||||
console.error(error);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
// calculate when lights shine on appearing claim area
|
||||
@@ -121,7 +124,7 @@ export async function loadLandmarks(vue, world, scene, loop) {
|
||||
.onComplete(() => {
|
||||
scene.remove(light);
|
||||
light.dispose();
|
||||
})
|
||||
}),
|
||||
)
|
||||
.start();
|
||||
world.lights = [...world.lights, light];
|
||||
@@ -130,18 +133,18 @@ export async function loadLandmarks(vue, world, scene, loop) {
|
||||
console.error(
|
||||
"Got bad server response status & data of",
|
||||
resp.status,
|
||||
resp.data
|
||||
resp.data,
|
||||
);
|
||||
vue.setAlert(
|
||||
"Error With Server",
|
||||
"There was an error retrieving your claims from the server."
|
||||
"There was an error retrieving your claims from the server.",
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Got exception contacting server:", error);
|
||||
vue.setAlert(
|
||||
"Error With Server",
|
||||
"There was a problem retrieving your claims from the server."
|
||||
"There was a problem retrieving your claims from the server.",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +54,6 @@ if (localStorage.getItem("secret") == null) {
|
||||
localStorage.setItem("secret", secret);
|
||||
}
|
||||
|
||||
//console.log("IndexedDB Encryption Secret:", secret);
|
||||
encrypted(accountsDB, { secretKey: secret });
|
||||
accountsDB.version(1).stores(SensitiveSchemas);
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ export const newIdentifier = (
|
||||
address: string,
|
||||
publicHex: string,
|
||||
privateHex: string,
|
||||
derivationPath: string
|
||||
derivationPath: string,
|
||||
): Omit<IIdentifier, keyof "provider"> => {
|
||||
return {
|
||||
did: DEFAULT_DID_PROVIDER_NAME + ":" + address,
|
||||
@@ -46,7 +46,7 @@ export const newIdentifier = (
|
||||
* @return {*} {[string, string, string, string]}
|
||||
*/
|
||||
export const deriveAddress = (
|
||||
mnemonic: string
|
||||
mnemonic: string,
|
||||
): [string, string, string, string] => {
|
||||
const UPORT_ROOT_DERIVATION_PATH = "m/7696500'/0'/0'/0'";
|
||||
mnemonic = mnemonic.trim().toLowerCase();
|
||||
@@ -134,7 +134,7 @@ export function fromJose(signature: string): {
|
||||
const signatureBytes: Uint8Array = didJwt.base64ToBytes(signature);
|
||||
if (signatureBytes.length < 64 || signatureBytes.length > 65) {
|
||||
throw new TypeError(
|
||||
`Wrong size for signature. Expected 64 or 65 bytes, but got ${signatureBytes.length}`
|
||||
`Wrong size for signature. Expected 64 or 65 bytes, but got ${signatureBytes.length}`,
|
||||
);
|
||||
}
|
||||
const r = bytesToHex(signatureBytes.slice(0, 32));
|
||||
|
||||
@@ -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) {
|
||||
@@ -116,7 +120,7 @@ export async function createAndSubmitGive(
|
||||
toDid: string,
|
||||
description: string,
|
||||
hours: number,
|
||||
fulfillsProjectHandleId?: string
|
||||
fulfillsProjectHandleId?: string,
|
||||
): Promise<AxiosResponse<ClaimResult> | InternalError> {
|
||||
// Make a claim
|
||||
const vcClaim: GiveVerifiableCredential = {
|
||||
@@ -193,3 +197,53 @@ export function isNumeric(str: string): boolean {
|
||||
export function numberOrZero(str: string): number {
|
||||
return isNumeric(str) ? +str : 0;
|
||||
}
|
||||
|
||||
export interface ErrorResponse {
|
||||
error?: {
|
||||
message?: string;
|
||||
};
|
||||
}
|
||||
|
||||
export interface RateLimits {
|
||||
doneClaimsThisWeek: string;
|
||||
doneRegistrationsThisMonth: string;
|
||||
maxClaimsPerWeek: string;
|
||||
maxRegistrationsPerMonth: string;
|
||||
nextMonthBeginDateTime: string;
|
||||
nextWeekBeginDateTime: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents data about a project
|
||||
**/
|
||||
export interface ProjectData {
|
||||
/**
|
||||
* Name of the project
|
||||
**/
|
||||
name: string;
|
||||
/**
|
||||
* Description of the project
|
||||
**/
|
||||
description: string;
|
||||
/**
|
||||
* URL referencing information about the project
|
||||
**/
|
||||
handleId: string;
|
||||
/**
|
||||
* The Identier of the project
|
||||
**/
|
||||
rowid: string;
|
||||
}
|
||||
|
||||
export interface VerifiableCredential {
|
||||
"@context": string;
|
||||
"@type": string;
|
||||
name: string;
|
||||
description: string;
|
||||
identifier?: string;
|
||||
}
|
||||
|
||||
export interface WorldProperties {
|
||||
startTime?: string;
|
||||
endTime?: string;
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ function didProviderName(netName: string) {
|
||||
const DEFAULT_DID_PROVIDER_NETWORK_NAME = "mainnet";
|
||||
|
||||
export const DEFAULT_DID_PROVIDER_NAME = didProviderName(
|
||||
DEFAULT_DID_PROVIDER_NETWORK_NAME
|
||||
DEFAULT_DID_PROVIDER_NETWORK_NAME,
|
||||
);
|
||||
|
||||
export const HANDY_APP = false;
|
||||
|
||||
@@ -19,6 +19,7 @@ import {
|
||||
faCircleUser,
|
||||
faClock,
|
||||
faCoins,
|
||||
faComment,
|
||||
faCopy,
|
||||
faEllipsisVertical,
|
||||
faEye,
|
||||
@@ -58,6 +59,7 @@ library.add(
|
||||
faCircleUser,
|
||||
faClock,
|
||||
faCoins,
|
||||
faComment,
|
||||
faCopy,
|
||||
faEllipsisVertical,
|
||||
faEye,
|
||||
@@ -84,7 +86,7 @@ library.add(
|
||||
faTrashCan,
|
||||
faUser,
|
||||
faUsers,
|
||||
faXmark
|
||||
faXmark,
|
||||
);
|
||||
|
||||
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
|
||||
|
||||
@@ -7,7 +7,7 @@ if (process.env.NODE_ENV === "production") {
|
||||
ready() {
|
||||
console.log(
|
||||
"App is being served from cache by a service worker.\n" +
|
||||
"For more details, visit https://goo.gl/AFskqB"
|
||||
"For more details, visit https://goo.gl/AFskqB",
|
||||
);
|
||||
},
|
||||
registered() {
|
||||
@@ -24,7 +24,7 @@ if (process.env.NODE_ENV === "production") {
|
||||
},
|
||||
offline() {
|
||||
console.log(
|
||||
"No internet connection found. App is running in offline mode."
|
||||
"No internet connection found. App is running in offline mode.",
|
||||
);
|
||||
},
|
||||
error(error) {
|
||||
|
||||
@@ -25,12 +25,6 @@ const routes: Array<RouteRecordRaw> = [
|
||||
import(/* webpackChunkName: "home" */ "../views/HomeView.vue"),
|
||||
beforeEnter: enterOrStart,
|
||||
},
|
||||
{
|
||||
path: "/about",
|
||||
name: "about",
|
||||
component: () =>
|
||||
import(/* webpackChunkName: "about" */ "../views/AboutView.vue"),
|
||||
},
|
||||
{
|
||||
path: "/account",
|
||||
name: "account",
|
||||
@@ -129,6 +123,14 @@ const routes: Array<RouteRecordRaw> = [
|
||||
/* webpackChunkName: "new-identifier" */ "../views/NewIdentifierView.vue"
|
||||
),
|
||||
},
|
||||
{
|
||||
path: "/identity-switcher",
|
||||
name: "identity-switcher",
|
||||
component: () =>
|
||||
import(
|
||||
/* webpackChunkName: "identity-switcher" */ "../views/IdentitySwitcherView.vue"
|
||||
),
|
||||
},
|
||||
{
|
||||
path: "/project",
|
||||
name: "project",
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
<template>
|
||||
<div class="about">
|
||||
<h1>This is an about page</h1>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { Options, Vue } from "vue-class-component";
|
||||
|
||||
@Options({
|
||||
components: {},
|
||||
})
|
||||
export default class AboutView extends Vue {}
|
||||
</script>
|
||||
@@ -3,10 +3,23 @@
|
||||
<!-- CONTENT -->
|
||||
<section id="Content" class="p-6 pb-24">
|
||||
<!-- Heading -->
|
||||
<h1 id="ViewHeading" class="text-4xl text-center font-light pt-4 mb-8">
|
||||
<h1 id="ViewHeading" class="text-4xl text-center font-light pt-4 mb-4">
|
||||
Your Identity
|
||||
</h1>
|
||||
|
||||
<div class="flex justify-between">
|
||||
<span />
|
||||
<span class="whitespace-nowrap">
|
||||
<router-link
|
||||
:to="{ name: 'contact-qr' }"
|
||||
class="text-xs uppercase bg-slate-500 text-white px-1.5 py-1 rounded-md"
|
||||
>
|
||||
<fa icon="qrcode" class="fa-fw"></fa>
|
||||
</router-link>
|
||||
</span>
|
||||
<span />
|
||||
</div>
|
||||
|
||||
<div class="flex justify-between py-2">
|
||||
<span />
|
||||
<span>
|
||||
@@ -53,14 +66,6 @@
|
||||
<fa icon="copy" class="text-slate-400 fa-fw"></fa>
|
||||
</button>
|
||||
<span v-show="showDidCopy">Copied!</span>
|
||||
<span class="whitespace-nowrap ml-4">
|
||||
<router-link
|
||||
:to="{ name: 'contact-qr' }"
|
||||
class="text-xs uppercase bg-slate-500 text-white px-1.5 py-1 rounded-md ml-1"
|
||||
>
|
||||
<fa icon="qrcode" class="fa-fw"></fa>
|
||||
</router-link>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="text-slate-500 text-sm font-bold">Public Key (base 64)</div>
|
||||
@@ -108,10 +113,16 @@
|
||||
|
||||
<router-link
|
||||
:to="{ name: 'new-edit-account' }"
|
||||
class="block text-center text-lg font-bold uppercase bg-blue-600 text-white px-2 py-3 rounded-md mb-8"
|
||||
class="block text-center text-lg font-bold uppercase bg-blue-600 text-white px-2 py-3 rounded-md mb-2"
|
||||
>
|
||||
Edit Identity
|
||||
</router-link>
|
||||
<router-link
|
||||
:to="{ name: 'identity-switcher' }"
|
||||
class="block text-center text-md uppercase bg-slate-500 text-white px-1.5 py-2 rounded-md mb-8"
|
||||
>
|
||||
Switch Identity / No Identity
|
||||
</router-link>
|
||||
|
||||
<h3 class="text-sm uppercase font-semibold mb-3">Data</h3>
|
||||
|
||||
@@ -153,112 +164,126 @@
|
||||
</form>
|
||||
</dialog>
|
||||
|
||||
<h3 class="text-sm uppercase font-semibold mb-3">Advanced</h3>
|
||||
|
||||
<label
|
||||
for="toggleShowAmounts"
|
||||
class="flex items-center cursor-pointer mb-6"
|
||||
@click="handleChange"
|
||||
<h3
|
||||
class="text-sm uppercase font-semibold mb-3"
|
||||
@click="showAdvanced = !showAdvanced"
|
||||
>
|
||||
<!-- toggle -->
|
||||
<div class="relative">
|
||||
<!-- input -->
|
||||
<input
|
||||
type="checkbox"
|
||||
v-model="showContactGives"
|
||||
name="showContactGives"
|
||||
class="sr-only"
|
||||
/>
|
||||
<!-- line -->
|
||||
<div class="block bg-slate-500 w-14 h-8 rounded-full"></div>
|
||||
<!-- dot -->
|
||||
<div
|
||||
class="dot absolute left-1 top-1 bg-slate-400 w-6 h-6 rounded-full transition"
|
||||
></div>
|
||||
</div>
|
||||
<!-- label -->
|
||||
<div class="ml-2">Show amounts given with contacts</div>
|
||||
</label>
|
||||
|
||||
<div class="flex py-2">
|
||||
<button class="text-center text-md text-blue-500" @click="checkLimits()">
|
||||
Check Limits
|
||||
</button>
|
||||
<!-- show spinner if loading limits -->
|
||||
<div v-if="loadingLimits" class="ml-2">
|
||||
Checking... <fa icon="spinner" class="fa-spin"></fa>
|
||||
</div>
|
||||
<div class="ml-2">
|
||||
{{ limitsMessage }}
|
||||
</div>
|
||||
<div v-if="!!limits?.nextWeekBeginDateTime" class="px-9">
|
||||
<span class="font-bold">Rate Limits</span>
|
||||
<p>
|
||||
You have done {{ limits.doneClaimsThisWeek }} claims out of
|
||||
{{ limits.maxClaimsPerWeek }} for this week. Your claims counter
|
||||
resets at {{ readableTime(limits.nextWeekBeginDateTime) }}
|
||||
</p>
|
||||
<p>
|
||||
You have done {{ limits.doneRegistrationsThisMonth }} registrations
|
||||
out of {{ limits.maxRegistrationsPerMonth }} for this month. Your
|
||||
registrations counter resets at
|
||||
{{ readableTime(limits.nextMonthBeginDateTime) }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex py-2">
|
||||
Claim Server
|
||||
<input
|
||||
type="text"
|
||||
class="block w-full rounded border border-slate-400 px-3 py-2"
|
||||
v-model="apiServerInput"
|
||||
/>
|
||||
<button
|
||||
v-if="apiServerInput != apiServer"
|
||||
class="px-4 rounded bg-red-500 border border-slate-400"
|
||||
@click="onClickSaveApiServer()"
|
||||
Advanced
|
||||
</h3>
|
||||
<div v-if="showAdvanced">
|
||||
<label
|
||||
for="toggleShowAmounts"
|
||||
class="flex items-center cursor-pointer mb-6"
|
||||
@click="handleChange"
|
||||
>
|
||||
<fa icon="floppy-disk" class="fa-fw" color="white"></fa>
|
||||
</button>
|
||||
<button
|
||||
class="px-4 rounded bg-slate-200 border border-slate-400"
|
||||
@click="setApiServerInput(Constants.PROD_ENDORSER_API_SERVER)"
|
||||
>
|
||||
Use Prod
|
||||
</button>
|
||||
<button
|
||||
class="px-4 rounded bg-slate-200 border border-slate-400"
|
||||
@click="setApiServerInput(Constants.TEST_ENDORSER_API_SERVER)"
|
||||
>
|
||||
Use Test
|
||||
</button>
|
||||
<button
|
||||
class="px-4 rounded bg-slate-200 border border-slate-400"
|
||||
@click="setApiServerInput(Constants.LOCAL_ENDORSER_API_SERVER)"
|
||||
>
|
||||
Use Local
|
||||
</button>
|
||||
</div>
|
||||
<!-- toggle -->
|
||||
<div class="relative">
|
||||
<!-- input -->
|
||||
<input
|
||||
type="checkbox"
|
||||
v-model="showContactGives"
|
||||
name="showContactGives"
|
||||
class="sr-only"
|
||||
/>
|
||||
<!-- line -->
|
||||
<div class="block bg-slate-500 w-14 h-8 rounded-full"></div>
|
||||
<!-- dot -->
|
||||
<div
|
||||
class="dot absolute left-1 top-1 bg-slate-400 w-6 h-6 rounded-full transition"
|
||||
></div>
|
||||
</div>
|
||||
<!-- label -->
|
||||
<div class="ml-2">Show amounts given with contacts</div>
|
||||
</label>
|
||||
|
||||
<div v-if="numAccounts > 0" class="flex py-2">
|
||||
Switch Identifier
|
||||
<span v-for="accountNum in numAccounts" :key="accountNum">
|
||||
<button class="text-blue-500 px-2" @click="switchAccount(accountNum)">
|
||||
#{{ accountNum }}
|
||||
</button>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<button class="text-blue-500">
|
||||
<router-link
|
||||
:to="{ name: 'statistics' }"
|
||||
class="block text-center py-3"
|
||||
<div class="flex py-2">
|
||||
<button
|
||||
class="text-center text-md text-blue-500"
|
||||
@click="checkLimits()"
|
||||
>
|
||||
See Achievements & Statistics
|
||||
</router-link>
|
||||
</button>
|
||||
Check Limits
|
||||
</button>
|
||||
<!-- show spinner if loading limits -->
|
||||
<div v-if="loadingLimits" class="ml-2">
|
||||
Checking... <fa icon="spinner" class="fa-spin"></fa>
|
||||
</div>
|
||||
<div class="ml-2">
|
||||
{{ limitsMessage }}
|
||||
</div>
|
||||
<div v-if="!!limits?.nextWeekBeginDateTime" class="px-9">
|
||||
<span class="font-bold">Rate Limits</span>
|
||||
<p>
|
||||
You have done {{ limits.doneClaimsThisWeek }} claims out of
|
||||
{{ limits.maxClaimsPerWeek }} for this week. Your claims counter
|
||||
resets at {{ readableTime(limits.nextWeekBeginDateTime) }}
|
||||
</p>
|
||||
<p>
|
||||
You have done {{ limits.doneRegistrationsThisMonth }} registrations
|
||||
out of {{ limits.maxRegistrationsPerMonth }} for this month. Your
|
||||
registrations counter resets at
|
||||
{{ readableTime(limits.nextMonthBeginDateTime) }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex py-2">
|
||||
Claim Server
|
||||
<input
|
||||
type="text"
|
||||
class="block w-full rounded border border-slate-400 px-3 py-2"
|
||||
v-model="apiServerInput"
|
||||
/>
|
||||
<button
|
||||
v-if="apiServerInput != apiServer"
|
||||
class="px-4 rounded bg-red-500 border border-slate-400"
|
||||
@click="onClickSaveApiServer()"
|
||||
>
|
||||
<fa icon="floppy-disk" class="fa-fw" color="white"></fa>
|
||||
</button>
|
||||
<button
|
||||
class="px-4 rounded bg-slate-200 border border-slate-400"
|
||||
@click="setApiServerInput(Constants.PROD_ENDORSER_API_SERVER)"
|
||||
>
|
||||
Use Prod
|
||||
</button>
|
||||
<button
|
||||
class="px-4 rounded bg-slate-200 border border-slate-400"
|
||||
@click="setApiServerInput(Constants.TEST_ENDORSER_API_SERVER)"
|
||||
>
|
||||
Use Test
|
||||
</button>
|
||||
<button
|
||||
class="px-4 rounded bg-slate-200 border border-slate-400"
|
||||
@click="setApiServerInput(Constants.LOCAL_ENDORSER_API_SERVER)"
|
||||
>
|
||||
Use Local
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<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 }}
|
||||
</button>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<button class="text-blue-500">
|
||||
<router-link
|
||||
:to="{ name: 'statistics' }"
|
||||
class="block text-center py-3"
|
||||
>
|
||||
See Achievements & Statistics
|
||||
</router-link>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<AlertMessage
|
||||
:alertTitle="alertTitle"
|
||||
@@ -269,12 +294,12 @@
|
||||
|
||||
<script lang="ts">
|
||||
import "dexie-export-import";
|
||||
import * as R from "ramda";
|
||||
import { Component, Vue } from "vue-facing-decorator";
|
||||
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";
|
||||
@@ -284,15 +309,6 @@ import QuickNav from "@/components/QuickNav";
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
const Buffer = require("buffer/").Buffer;
|
||||
|
||||
interface RateLimits {
|
||||
doneClaimsThisWeek: string;
|
||||
doneRegistrationsThisMonth: string;
|
||||
maxClaimsPerWeek: string;
|
||||
maxRegistrationsPerMonth: string;
|
||||
nextMonthBeginDateTime: string;
|
||||
nextWeekBeginDateTime: string;
|
||||
}
|
||||
|
||||
@Component({ components: { AlertMessage, QuickNav } })
|
||||
export default class AccountViewView extends Vue {
|
||||
Constants = AppString;
|
||||
@@ -310,12 +326,42 @@ 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;
|
||||
showB64Copy = false;
|
||||
showPubCopy = false;
|
||||
|
||||
showAdvanced = false;
|
||||
alertMessage = "";
|
||||
alertTitle = "";
|
||||
|
||||
public async getIdentity(activeDid) {
|
||||
await accountsDB.open();
|
||||
const account = await accountsDB.accounts
|
||||
.where("did")
|
||||
.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;
|
||||
}
|
||||
|
||||
public async getHeaders(identity) {
|
||||
const token = await accessToken(identity);
|
||||
const headers = {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: "Bearer " + token,
|
||||
};
|
||||
return headers;
|
||||
}
|
||||
|
||||
// call fn, copy text to the clipboard, then redo fn after 2 seconds
|
||||
doCopyTwoSecRedo(text, fn) {
|
||||
fn();
|
||||
@@ -333,7 +379,12 @@ export default class AccountViewView extends Vue {
|
||||
return timeStr.substring(0, timeStr.indexOf("T"));
|
||||
}
|
||||
|
||||
// 'created' hook runs when the Vue instance is first created
|
||||
async beforeCreate() {
|
||||
accountsDB.open();
|
||||
this.accounts = accountsDB.accounts;
|
||||
this.numAccounts = await this.accounts.count();
|
||||
}
|
||||
|
||||
async created() {
|
||||
// Uncomment this to register this user on the test server.
|
||||
// To manage within the vue devtools browser extension https://devtools.vuejs.org/
|
||||
@@ -351,14 +402,8 @@ export default class AccountViewView extends Vue {
|
||||
this.lastName = settings?.lastName || "";
|
||||
this.showContactGives = !!settings?.showContactGivesInline;
|
||||
|
||||
await accountsDB.open();
|
||||
const accounts = await accountsDB.accounts.toArray();
|
||||
this.numAccounts = accounts.length;
|
||||
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.");
|
||||
}
|
||||
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;
|
||||
@@ -368,10 +413,21 @@ export default class AccountViewView extends Vue {
|
||||
});
|
||||
this.checkLimits();
|
||||
} catch (err) {
|
||||
this.alertMessage =
|
||||
"Clear your cache and start over (after data backup).";
|
||||
console.error("Telling user to clear cache at page create because:", err);
|
||||
this.alertTitle = "Error Creating Account";
|
||||
if (
|
||||
err.message ===
|
||||
"Attempted to load account records with no identity available."
|
||||
) {
|
||||
this.limitsMessage = "No identity.";
|
||||
this.loadingLimits = false;
|
||||
} else {
|
||||
this.alertMessage =
|
||||
"Clear your cache and start over (after data backup).";
|
||||
console.error(
|
||||
"Telling user to clear cache at page create because:",
|
||||
err,
|
||||
);
|
||||
this.alertTitle = "Error Creating Account";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -386,7 +442,7 @@ export default class AccountViewView extends Vue {
|
||||
"Clear your cache and start over (after data backup).";
|
||||
console.error(
|
||||
"Telling user to clear cache after contact setting update because:",
|
||||
err
|
||||
err,
|
||||
);
|
||||
this.alertTitle = "Error Updating Contact Setting";
|
||||
}
|
||||
@@ -417,53 +473,66 @@ export default class AccountViewView extends Vue {
|
||||
this.loadingLimits = true;
|
||||
this.limitsMessage = "";
|
||||
|
||||
const url = this.apiServer + "/api/report/rateLimits";
|
||||
await accountsDB.open();
|
||||
const accounts = await accountsDB.accounts.toArray();
|
||||
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.");
|
||||
}
|
||||
const token = await accessToken(identity);
|
||||
const headers = {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: "Bearer " + token,
|
||||
};
|
||||
|
||||
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 });
|
||||
// axios throws an exception on a 400
|
||||
if (resp.status === 200) {
|
||||
this.limits = resp.data;
|
||||
}
|
||||
} catch (error: unknown) {
|
||||
const serverError = error as AxiosError;
|
||||
if (
|
||||
error.message ===
|
||||
"Attempted to load Give records with no identity available."
|
||||
) {
|
||||
this.limitsMessage = "No identity.";
|
||||
this.loadingLimits = false;
|
||||
} else {
|
||||
const serverError = error as AxiosError;
|
||||
console.error("Bad response retrieving limits: ", serverError);
|
||||
|
||||
console.error("Bad response retrieving limits: ", serverError);
|
||||
// Anybody know how to access items inside "response.data" without this?
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const data: any = serverError.response?.data;
|
||||
this.limitsMessage = data?.error?.message || "Bad server response.";
|
||||
const data: ErrorResponse | undefined =
|
||||
serverError.response && serverError.response.data;
|
||||
if (data && data.error && data.error.message) {
|
||||
this.limitsMessage = data.error.message;
|
||||
} else {
|
||||
this.limitsMessage = "Bad server response.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.loadingLimits = false;
|
||||
}
|
||||
|
||||
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() {
|
||||
@@ -484,9 +553,5 @@ export default class AccountViewView extends Vue {
|
||||
setApiServerInput(value) {
|
||||
this.apiServerInput = value;
|
||||
}
|
||||
|
||||
// This same popup code is in many files.
|
||||
alertMessage = "";
|
||||
alertTitle = "";
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -48,9 +48,9 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { Options, Vue } from "vue-class-component";
|
||||
import { Component, Vue } from "vue-facing-decorator";
|
||||
|
||||
@Options({
|
||||
@Component({
|
||||
components: {},
|
||||
})
|
||||
export default class ConfirmContactView extends Vue {}
|
||||
|
||||
@@ -1,48 +1,5 @@
|
||||
<template>
|
||||
<!-- QUICK NAV -->
|
||||
<nav id="QuickNav" class="fixed bottom-0 left-0 right-0 bg-slate-200 z-50">
|
||||
<ul class="flex text-2xl p-2 gap-2">
|
||||
<!-- Home Feed -->
|
||||
<li class="basis-1/5 rounded-md text-slate-500">
|
||||
<router-link :to="{ name: 'home' }" class="block text-center py-3 px-1"
|
||||
><fa icon="house-chimney" class="fa-fw"></fa
|
||||
></router-link>
|
||||
</li>
|
||||
<!-- Search -->
|
||||
<li class="basis-1/5 rounded-md text-slate-500">
|
||||
<router-link
|
||||
:to="{ name: 'discover' }"
|
||||
class="block text-center py-3 px-1"
|
||||
><fa icon="magnifying-glass" class="fa-fw"></fa
|
||||
></router-link>
|
||||
</li>
|
||||
<!-- Contacts -->
|
||||
<li class="basis-1/5 rounded-md text-slate-500">
|
||||
<router-link
|
||||
:to="{ name: 'projects' }"
|
||||
class="block text-center py-3 px-1"
|
||||
><fa icon="folder-open" class="fa-fw"></fa
|
||||
></router-link>
|
||||
</li>
|
||||
<!-- Contacts -->
|
||||
<li class="basis-1/5 rounded-md text-slate-500">
|
||||
<router-link
|
||||
:to="{ name: 'contacts' }"
|
||||
class="block text-center py-3 px-1"
|
||||
><fa icon="users" class="fa-fw"></fa
|
||||
></router-link>
|
||||
</li>
|
||||
<!-- Profile -->
|
||||
<li class="basis-1/5 rounded-md text-slate-500">
|
||||
<router-link
|
||||
:to="{ name: 'account' }"
|
||||
class="block text-center py-3 px-1"
|
||||
><fa icon="circle-user" class="fa-fw"></fa
|
||||
></router-link>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
<QuickNav selected="Contacts"></QuickNav>
|
||||
<section id="Content" class="p-6 pb-24">
|
||||
<h1 id="ViewHeading" class="text-4xl text-center font-light pt-4 mb-8">
|
||||
Given with {{ contact?.name }}
|
||||
@@ -121,6 +78,7 @@ 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";
|
||||
@@ -133,8 +91,9 @@ import {
|
||||
import * as didJwt from "did-jwt";
|
||||
import { AxiosError } from "axios";
|
||||
import AlertMessage from "@/components/AlertMessage";
|
||||
import QuickNav from "@/components/QuickNav";
|
||||
|
||||
@Component({ components: { AlertMessage } })
|
||||
@Component({ components: { AlertMessage, QuickNav } })
|
||||
export default class ContactsView extends Vue {
|
||||
activeDid = "";
|
||||
apiServer = "";
|
||||
@@ -142,8 +101,40 @@ 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();
|
||||
}
|
||||
|
||||
public async getIdentity(activeDid) {
|
||||
await accountsDB.open();
|
||||
const account = await accountsDB.accounts
|
||||
.where("did")
|
||||
.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;
|
||||
}
|
||||
|
||||
public async getHeaders(identity) {
|
||||
const token = await accessToken(identity);
|
||||
const headers = {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: "Bearer " + token,
|
||||
};
|
||||
return headers;
|
||||
}
|
||||
|
||||
// 'created' hook runs when the Vue instance is first created
|
||||
async created() {
|
||||
try {
|
||||
await db.open();
|
||||
@@ -166,30 +157,16 @@ export default class ContactsView extends Vue {
|
||||
}
|
||||
|
||||
async loadGives(activeDid: string, contact: Contact) {
|
||||
// only load the private keys temporarily when needed
|
||||
await accountsDB.open();
|
||||
const accounts = await accountsDB.accounts.toArray();
|
||||
const account = R.find((acc) => acc.did === activeDid, accounts);
|
||||
const identity = JSON.parse(account?.identity || "null");
|
||||
if (!identity) {
|
||||
throw new Error("No identity found.");
|
||||
}
|
||||
|
||||
// load all the time I have given to them
|
||||
try {
|
||||
const identity = await this.getIdentity(this.activeDid);
|
||||
let result = [];
|
||||
|
||||
const url =
|
||||
this.apiServer +
|
||||
"/api/v2/report/gives?agentDid=" +
|
||||
encodeURIComponent(identity.did) +
|
||||
"&recipientDid=" +
|
||||
encodeURIComponent(contact.did);
|
||||
const token = await accessToken(identity);
|
||||
const headers = {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: "Bearer " + token,
|
||||
};
|
||||
const headers = this.getHeaders(identity);
|
||||
const resp = await this.axios.get(url, { headers });
|
||||
if (resp.status === 200) {
|
||||
result = resp.data.data;
|
||||
@@ -197,7 +174,7 @@ export default class ContactsView extends Vue {
|
||||
console.error(
|
||||
"Got bad response status & data of",
|
||||
resp.status,
|
||||
resp.data
|
||||
resp.data,
|
||||
);
|
||||
this.alertTitle = "Error With Server";
|
||||
this.alertMessage =
|
||||
@@ -210,11 +187,7 @@ export default class ContactsView extends Vue {
|
||||
encodeURIComponent(contact.did) +
|
||||
"&recipientDid=" +
|
||||
encodeURIComponent(identity.did);
|
||||
const token2 = await accessToken(identity);
|
||||
const headers2 = {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: "Bearer " + token2,
|
||||
};
|
||||
const headers2 = await this.getHeaders(identity);
|
||||
const resp2 = await this.axios.get(url2, { headers: headers2 });
|
||||
if (resp2.status === 200) {
|
||||
result = R.concat(result, resp2.data.data);
|
||||
@@ -222,7 +195,7 @@ export default class ContactsView extends Vue {
|
||||
console.error(
|
||||
"Got bad response status & data of",
|
||||
resp2.status,
|
||||
resp2.data
|
||||
resp2.data,
|
||||
);
|
||||
this.alertTitle = "Error With Server";
|
||||
this.alertMessage =
|
||||
@@ -232,7 +205,7 @@ export default class ContactsView extends Vue {
|
||||
const sortedResult: Array<GiveServerRecord> = R.sort(
|
||||
(a, b) =>
|
||||
new Date(b.issuedAt).getTime() - new Date(a.issuedAt).getTime(),
|
||||
result
|
||||
result,
|
||||
);
|
||||
this.giveRecords = sortedResult;
|
||||
} catch (error) {
|
||||
@@ -266,13 +239,7 @@ export default class ContactsView extends Vue {
|
||||
};
|
||||
|
||||
// Create a signature using private key of identity
|
||||
await accountsDB.open();
|
||||
const accounts = await accountsDB.accounts.toArray();
|
||||
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.");
|
||||
}
|
||||
const identity = await this.getIdentity(this.activeDid);
|
||||
if (identity.keys[0].privateKeyHex !== null) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
const privateKeyHex: string = identity.keys[0].privateKeyHex!;
|
||||
@@ -296,7 +263,6 @@ export default class ContactsView extends Vue {
|
||||
|
||||
try {
|
||||
const resp = await this.axios.post(url, payload, { headers });
|
||||
//console.log("Got resp data:", resp.data);
|
||||
if (resp.data?.success) {
|
||||
record.amountConfirmed = origClaim.object?.amountOfThisGood || 1;
|
||||
}
|
||||
|
||||
@@ -37,6 +37,8 @@ import QuickNav from "@/components/QuickNav";
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
const Buffer = require("buffer/").Buffer;
|
||||
alertTitle = "";
|
||||
alertMessage = "";
|
||||
|
||||
@Component({
|
||||
components: {
|
||||
@@ -50,6 +52,29 @@ export default class ContactQRScanShow extends Vue {
|
||||
apiServer = "";
|
||||
qrValue = "";
|
||||
|
||||
public async getIdentity(activeDid) {
|
||||
await accountsDB.open();
|
||||
const accounts = await accountsDB.accounts.toArray();
|
||||
const account = R.find((acc) => acc.did === activeDid, accounts);
|
||||
const identity = JSON.parse(account?.identity || "null");
|
||||
|
||||
if (!identity) {
|
||||
throw new Error(
|
||||
"Attempted to load Give records with no identity available.",
|
||||
);
|
||||
}
|
||||
return identity;
|
||||
}
|
||||
|
||||
public async getHeaders(identity) {
|
||||
const token = await accessToken(identity);
|
||||
const headers = {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: "Bearer " + token,
|
||||
};
|
||||
return headers;
|
||||
}
|
||||
|
||||
async created() {
|
||||
await db.open();
|
||||
const settings = await db.settings.get(MASTER_SETTINGS_KEY);
|
||||
@@ -62,11 +87,7 @@ export default class ContactQRScanShow extends Vue {
|
||||
if (!account) {
|
||||
this.alertMessage = "You have no identity yet.";
|
||||
} else {
|
||||
const identity = JSON.parse(account?.identity || "null");
|
||||
if (!identity) {
|
||||
throw new Error("No identity found.");
|
||||
}
|
||||
|
||||
const identity = await this.getIdentity(this.activeDid);
|
||||
const publicKeyHex = identity.keys[0].publicKeyHex;
|
||||
const publicEncKey = Buffer.from(publicKeyHex, "hex").toString("base64");
|
||||
const contactInfo = {
|
||||
@@ -91,9 +112,5 @@ export default class ContactQRScanShow extends Vue {
|
||||
this.qrValue = viewPrefix + vcJwt;
|
||||
}
|
||||
}
|
||||
|
||||
// This same popup code is in many files.
|
||||
alertTitle = "";
|
||||
alertMessage = "";
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -87,9 +87,9 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { Options, Vue } from "vue-class-component";
|
||||
import { Component, Vue } from "vue-facing-decorator";
|
||||
|
||||
@Options({
|
||||
@Component({
|
||||
components: {},
|
||||
})
|
||||
export default class ContactScanView extends Vue {}
|
||||
|
||||
@@ -70,7 +70,7 @@
|
||||
</div>
|
||||
|
||||
<!-- Results List -->
|
||||
<ul class="">
|
||||
<ul v-if="contacts.length > 0">
|
||||
<li
|
||||
class="border-b border-slate-300"
|
||||
v-for="contact in contacts"
|
||||
@@ -187,6 +187,7 @@
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
<p v-else>This identity has no contacts.</p>
|
||||
<AlertMessage
|
||||
:alertTitle="alertTitle"
|
||||
:alertMessage="alertMessage"
|
||||
@@ -199,18 +200,16 @@ 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 { Contact } from "@/db/tables/contacts";
|
||||
import { MASTER_SETTINGS_KEY } from "@/db/tables/settings";
|
||||
import { accessToken, SimpleSigner } from "@/libs/crypto";
|
||||
import {
|
||||
GiveServerRecord,
|
||||
GiveVerifiableCredential,
|
||||
RegisterVerifiableCredential,
|
||||
SERVICE_ID,
|
||||
} from "@/libs/endorserServer";
|
||||
import { Component, Vue } from "vue-facing-decorator";
|
||||
import AlertMessage from "@/components/AlertMessage";
|
||||
import QuickNav from "@/components/QuickNav";
|
||||
|
||||
@@ -242,8 +241,9 @@ export default class ContactsView extends Vue {
|
||||
showGiveNumbers = false;
|
||||
showGiveTotals = true;
|
||||
showGiveConfirmed = true;
|
||||
alertTitle = "";
|
||||
alertMessage = "";
|
||||
|
||||
// 'created' hook runs when the Vue instance is first created
|
||||
async created() {
|
||||
await db.open();
|
||||
const settings = await db.settings.get(MASTER_SETTINGS_KEY);
|
||||
@@ -257,123 +257,116 @@ export default class ContactsView extends Vue {
|
||||
const allContacts = await db.contacts.toArray();
|
||||
this.contacts = R.sort(
|
||||
(a: Contact, b) => (a.name || "").localeCompare(b.name || ""),
|
||||
allContacts
|
||||
allContacts,
|
||||
);
|
||||
}
|
||||
|
||||
async loadGives() {
|
||||
public async getIdentity(activeDid) {
|
||||
await accountsDB.open();
|
||||
const accounts = await accountsDB.accounts.toArray();
|
||||
const account = R.find((acc) => acc.did === this.activeDid, accounts);
|
||||
const account = R.find((acc) => acc.did === activeDid, accounts);
|
||||
const identity = JSON.parse(account?.identity || "null");
|
||||
|
||||
if (!identity) {
|
||||
console.error(
|
||||
"Attempted to load Give records with no identity available."
|
||||
throw new Error(
|
||||
"Attempted to load Give records with no identity available.",
|
||||
);
|
||||
return;
|
||||
}
|
||||
return identity;
|
||||
}
|
||||
|
||||
public async getHeaders(identity) {
|
||||
const token = await accessToken(identity);
|
||||
const headers = {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: "Bearer " + token,
|
||||
};
|
||||
return headers;
|
||||
}
|
||||
|
||||
public async getHeadersAndIdentity(activeDid) {
|
||||
const identity = await this.getIdentity(activeDid);
|
||||
const headers = await this.getHeaders(identity);
|
||||
|
||||
return { headers, identity };
|
||||
}
|
||||
|
||||
async loadGives() {
|
||||
const handleResponse = (resp, descriptions, confirmed, unconfirmed) => {
|
||||
if (resp.status === 200) {
|
||||
const allData = resp.data.data;
|
||||
for (const give of allData) {
|
||||
if (give.unit === "HUR") {
|
||||
if (give.amountConfirmed) {
|
||||
const prevAmount = confirmed[give.agentDid] || 0;
|
||||
confirmed[give.agentDid] = prevAmount + give.amount;
|
||||
} else {
|
||||
const prevAmount = unconfirmed[give.agentDid] || 0;
|
||||
unconfirmed[give.agentDid] = prevAmount + give.amount;
|
||||
}
|
||||
if (!descriptions[give.agentDid] && give.description) {
|
||||
descriptions[give.agentDid] = give.description;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
console.error(
|
||||
"Got bad response status & data of",
|
||||
resp.status,
|
||||
resp.data,
|
||||
);
|
||||
this.alertTitle = "Error With Server";
|
||||
this.alertMessage =
|
||||
"Got an error retrieving your " +
|
||||
resp.config.url.includes("recipientDid")
|
||||
? "received"
|
||||
: "given" + " time from the server.";
|
||||
}
|
||||
};
|
||||
|
||||
// load all the time I have given
|
||||
try {
|
||||
const url =
|
||||
const { headers, identity } = await this.getHeadersAndIdentity(
|
||||
this.activeDid,
|
||||
);
|
||||
const givenByUrl =
|
||||
this.apiServer +
|
||||
"/api/v2/report/gives?agentDid=" +
|
||||
encodeURIComponent(identity.did);
|
||||
const token = await accessToken(identity);
|
||||
const headers = {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: "Bearer " + token,
|
||||
};
|
||||
const resp = await this.axios.get(url, { headers });
|
||||
//console.log("All gifts you've given:", resp.data);
|
||||
if (resp.status === 200) {
|
||||
const contactDescriptions: Record<string, string> = {};
|
||||
const contactConfirmed: Record<string, number> = {};
|
||||
const contactUnconfirmed: Record<string, number> = {};
|
||||
const allData: Array<GiveServerRecord> = resp.data.data;
|
||||
for (const give of allData) {
|
||||
if (give.unit == "HUR") {
|
||||
const recipDid: string = give.recipientDid;
|
||||
if (give.amountConfirmed) {
|
||||
const prevAmount = contactConfirmed[recipDid] || 0;
|
||||
contactConfirmed[recipDid] = prevAmount + give.amount;
|
||||
} else {
|
||||
const prevAmount = contactUnconfirmed[recipDid] || 0;
|
||||
contactUnconfirmed[recipDid] = prevAmount + give.amount;
|
||||
}
|
||||
if (!contactDescriptions[recipDid] && give.description) {
|
||||
// Since many make the tooltip too big, we'll just use the latest.
|
||||
contactDescriptions[recipDid] = give.description;
|
||||
}
|
||||
}
|
||||
}
|
||||
//console.log("Done retrieving gives", contactConfirmed);
|
||||
this.givenByMeDescriptions = contactDescriptions;
|
||||
this.givenByMeConfirmed = contactConfirmed;
|
||||
this.givenByMeUnconfirmed = contactUnconfirmed;
|
||||
} else {
|
||||
console.error(
|
||||
"Got bad response status & data of",
|
||||
resp.status,
|
||||
resp.data
|
||||
);
|
||||
this.alertTitle = "Error With Server";
|
||||
this.alertMessage =
|
||||
"Got an error retrieving your given time from the server.";
|
||||
}
|
||||
} catch (error) {
|
||||
this.alertTitle = "Error With Server";
|
||||
this.alertMessage = error as string;
|
||||
}
|
||||
|
||||
// load all the time I have received
|
||||
try {
|
||||
const url =
|
||||
const givenToUrl =
|
||||
this.apiServer +
|
||||
"/api/v2/report/gives?recipientDid=" +
|
||||
encodeURIComponent(identity.did);
|
||||
const token = await accessToken(identity);
|
||||
const headers = {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: "Bearer " + token,
|
||||
};
|
||||
const resp = await this.axios.get(url, { headers });
|
||||
//console.log("All gifts you've recieved:", resp.data);
|
||||
if (resp.status === 200) {
|
||||
const contactDescriptions: Record<string, string> = {};
|
||||
const contactConfirmed: Record<string, number> = {};
|
||||
const contactUnconfirmed: Record<string, number> = {};
|
||||
const allData: Array<GiveServerRecord> = resp.data.data;
|
||||
for (const give of allData) {
|
||||
if (give.unit == "HUR") {
|
||||
if (give.amountConfirmed) {
|
||||
const prevAmount = contactConfirmed[give.agentDid] || 0;
|
||||
contactConfirmed[give.agentDid] = prevAmount + give.amount;
|
||||
} else {
|
||||
const prevAmount = contactUnconfirmed[give.agentDid] || 0;
|
||||
contactUnconfirmed[give.agentDid] = prevAmount + give.amount;
|
||||
}
|
||||
if (!contactDescriptions[give.agentDid] && give.description) {
|
||||
// Since many make the tooltip too big, we'll just use the latest.
|
||||
contactDescriptions[give.agentDid] = give.description;
|
||||
}
|
||||
}
|
||||
}
|
||||
//console.log("Done retrieving receipts", contactConfirmed);
|
||||
this.givenToMeDescriptions = contactDescriptions;
|
||||
this.givenToMeConfirmed = contactConfirmed;
|
||||
this.givenToMeUnconfirmed = contactUnconfirmed;
|
||||
} else {
|
||||
console.error(
|
||||
"Got bad response status & data of",
|
||||
resp.status,
|
||||
resp.data
|
||||
);
|
||||
this.alertTitle = "Error With Server";
|
||||
this.alertMessage =
|
||||
"Got an error retrieving your received time from the server.";
|
||||
}
|
||||
|
||||
const [givenByMeResp, givenToMeResp] = await Promise.all([
|
||||
this.axios.get(givenByUrl, { headers }),
|
||||
this.axios.get(givenToUrl, { headers }),
|
||||
]);
|
||||
|
||||
const givenByMeDescriptions = {};
|
||||
const givenByMeConfirmed = {};
|
||||
const givenByMeUnconfirmed = {};
|
||||
handleResponse(
|
||||
givenByMeResp,
|
||||
givenByMeDescriptions,
|
||||
givenByMeConfirmed,
|
||||
givenByMeUnconfirmed,
|
||||
);
|
||||
this.givenByMeDescriptions = givenByMeDescriptions;
|
||||
this.givenByMeConfirmed = givenByMeConfirmed;
|
||||
this.givenByMeUnconfirmed = givenByMeUnconfirmed;
|
||||
|
||||
const givenToMeDescriptions = {};
|
||||
const givenToMeConfirmed = {};
|
||||
const givenToMeUnconfirmed = {};
|
||||
handleResponse(
|
||||
givenToMeResp,
|
||||
givenToMeDescriptions,
|
||||
givenToMeConfirmed,
|
||||
givenToMeUnconfirmed,
|
||||
);
|
||||
this.givenToMeDescriptions = givenToMeDescriptions;
|
||||
this.givenToMeConfirmed = givenToMeConfirmed;
|
||||
this.givenToMeUnconfirmed = givenToMeUnconfirmed;
|
||||
} catch (error) {
|
||||
this.alertTitle = "Error With Server";
|
||||
this.alertMessage = error as string;
|
||||
@@ -403,7 +396,7 @@ export default class ContactsView extends Vue {
|
||||
const allContacts = this.contacts.concat([newContact]);
|
||||
this.contacts = R.sort(
|
||||
(a: Contact, b) => (a.name || "").localeCompare(b.name || ""),
|
||||
allContacts
|
||||
allContacts,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -414,7 +407,7 @@ export default class ContactsView extends Vue {
|
||||
this.nameForDid(this.contacts, contact.did) +
|
||||
" with DID " +
|
||||
contact.did +
|
||||
" ?"
|
||||
" ?",
|
||||
)
|
||||
) {
|
||||
await db.open();
|
||||
@@ -428,18 +421,11 @@ export default class ContactsView extends Vue {
|
||||
confirm(
|
||||
"Are you sure you want to use one of your registrations for " +
|
||||
this.nameForDid(this.contacts, contact.did) +
|
||||
"?"
|
||||
"?",
|
||||
)
|
||||
) {
|
||||
await accountsDB.open();
|
||||
const accounts = await accountsDB.accounts.toArray();
|
||||
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.");
|
||||
}
|
||||
const identity = await this.getIdentity(this.activeDid);
|
||||
|
||||
// Make a claim
|
||||
const vcClaim: RegisterVerifiableCredential = {
|
||||
"@context": "https://schema.org",
|
||||
"@type": "RegisterAction",
|
||||
@@ -471,15 +457,10 @@ export default class ContactsView extends Vue {
|
||||
// Make the xhr request payload
|
||||
const payload = JSON.stringify({ jwtEncoded: vcJwt });
|
||||
const url = this.apiServer + "/api/v2/claim";
|
||||
const token = await accessToken(identity);
|
||||
const headers = {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: "Bearer " + token,
|
||||
};
|
||||
const headers = await this.getHeaders(identity);
|
||||
|
||||
try {
|
||||
const resp = await this.axios.post(url, payload, { headers });
|
||||
//console.log("Got resp data:", resp.data);
|
||||
if (resp.data?.success?.embeddedRecordError) {
|
||||
this.alertTitle = "Registration Still Unknown";
|
||||
let message = "There was some problem with the registration.";
|
||||
@@ -519,19 +500,8 @@ export default class ContactsView extends Vue {
|
||||
this.apiServer +
|
||||
"/api/report/" +
|
||||
(visibility ? "canSeeMe" : "cannotSeeMe");
|
||||
await accountsDB.open();
|
||||
const accounts = await accountsDB.accounts.toArray();
|
||||
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.");
|
||||
}
|
||||
|
||||
const token = await accessToken(identity);
|
||||
const headers = {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: "Bearer " + token,
|
||||
};
|
||||
const identity = await this.getIdentity(this.activeDid);
|
||||
const headers = await this.getHeaders(identity);
|
||||
const payload = JSON.stringify({ did: contact.did });
|
||||
|
||||
try {
|
||||
@@ -559,19 +529,6 @@ export default class ContactsView extends Vue {
|
||||
this.apiServer +
|
||||
"/api/report/canDidExplicitlySeeMe?did=" +
|
||||
encodeURIComponent(contact.did);
|
||||
await accountsDB.open();
|
||||
const accounts = await accountsDB.accounts.toArray();
|
||||
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.");
|
||||
}
|
||||
|
||||
const token = await accessToken(identity);
|
||||
const headers = {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: "Bearer " + token,
|
||||
};
|
||||
|
||||
try {
|
||||
const resp = await this.axios.get(url, { headers });
|
||||
@@ -616,13 +573,7 @@ export default class ContactsView extends Vue {
|
||||
}
|
||||
|
||||
async onClickAddGive(fromDid: string, toDid: string): Promise<void> {
|
||||
await accountsDB.open();
|
||||
const accounts = await accountsDB.accounts.toArray();
|
||||
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.");
|
||||
}
|
||||
const identity = await this.getIdentity(this.activeDid);
|
||||
|
||||
// if they have unconfirmed amounts, ask to confirm those first
|
||||
if (toDid == identity?.did && this.givenToMeUnconfirmed[fromDid] > 0) {
|
||||
@@ -631,7 +582,7 @@ export default class ContactsView extends Vue {
|
||||
"There are " +
|
||||
this.givenToMeUnconfirmed[fromDid] +
|
||||
" unconfirmed hours from them." +
|
||||
" Would you like to confirm some of those hours?"
|
||||
" Would you like to confirm some of those hours?",
|
||||
)
|
||||
) {
|
||||
this.$router.push({
|
||||
@@ -671,7 +622,7 @@ export default class ContactsView extends Vue {
|
||||
" hours " +
|
||||
toFrom +
|
||||
description +
|
||||
"?"
|
||||
"?",
|
||||
)
|
||||
) {
|
||||
this.createAndSubmitGive(
|
||||
@@ -679,7 +630,7 @@ export default class ContactsView extends Vue {
|
||||
fromDid,
|
||||
toDid,
|
||||
parseFloat(this.hourInput),
|
||||
this.hourDescriptionInput
|
||||
this.hourDescriptionInput,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -690,7 +641,7 @@ export default class ContactsView extends Vue {
|
||||
fromDid: string,
|
||||
toDid: string,
|
||||
amount: number,
|
||||
description: string
|
||||
description: string,
|
||||
): Promise<void> {
|
||||
// Make a claim
|
||||
const vcClaim: GiveVerifiableCredential = {
|
||||
@@ -728,15 +679,10 @@ export default class ContactsView extends Vue {
|
||||
|
||||
const payload = JSON.stringify({ jwtEncoded: vcJwt });
|
||||
const url = this.apiServer + "/api/v2/claim";
|
||||
const token = await accessToken(identity);
|
||||
const headers = {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: "Bearer " + token,
|
||||
};
|
||||
const headers = await this.getHeaders(identity);
|
||||
|
||||
try {
|
||||
const resp = await this.axios.post(url, payload, { headers });
|
||||
//console.log("Got resp data:", resp.data);
|
||||
if (resp.data?.success?.handleId) {
|
||||
this.alertTitle = "Done";
|
||||
this.alertMessage = "Successfully logged time to the server.";
|
||||
@@ -783,10 +729,6 @@ export default class ContactsView extends Vue {
|
||||
}
|
||||
}
|
||||
|
||||
// This same popup code is in many files.
|
||||
alertTitle = "";
|
||||
alertMessage = "";
|
||||
|
||||
public showGiveAmountsClassNames() {
|
||||
return {
|
||||
"bg-slate-500": this.showGiveTotals,
|
||||
|
||||
@@ -30,87 +30,76 @@
|
||||
<li>
|
||||
<a
|
||||
href="#"
|
||||
class="inline-block py-3 rounded-t-lg border-b-2 active text-blue-600 border-blue-600 font-semibold"
|
||||
@click="
|
||||
projects = [];
|
||||
searchLocal();
|
||||
"
|
||||
v-bind:class="computedLocalTabClassNames()"
|
||||
>
|
||||
Nearby
|
||||
<span
|
||||
class="font-semibold text-sm bg-slate-200 px-1.5 py-0.5 rounded-md"
|
||||
>20+</span
|
||||
>{{ localCount }}</span
|
||||
>
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a
|
||||
href="#"
|
||||
class="inline-block py-3 rounded-t-lg border-b-2 border-transparent hover:text-slate-600 hover:border-slate-300"
|
||||
v-bind:class="computedRemoteTabClassNames()"
|
||||
@click="
|
||||
projects = [];
|
||||
search();
|
||||
"
|
||||
>
|
||||
Remote
|
||||
<span
|
||||
class="font-semibold text-sm bg-slate-200 px-1.5 py-0.5 rounded-md"
|
||||
>13</span
|
||||
>{{ remoteCount }}</span
|
||||
>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<!-- Loading Animation -->
|
||||
<div
|
||||
class="fixed left-6 bottom-24 text-center text-4xl leading-none bg-slate-400 text-white w-14 py-2.5 rounded-full"
|
||||
v-if="isLoading"
|
||||
>
|
||||
<fa icon="spinner" class="fa-spin-pulse"></fa>
|
||||
</div>
|
||||
|
||||
<!-- Results List -->
|
||||
<ul class="">
|
||||
<li class="border-b border-slate-300">
|
||||
<a href="project-view.html" class="block py-4 flex gap-4">
|
||||
<div class="w-12">
|
||||
<img
|
||||
src="https://picsum.photos/200/200?random=1"
|
||||
class="w-full rounded"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="grow">
|
||||
<h2 class="text-base font-semibold">Canyon cleanup</h2>
|
||||
<div class="text-sm">
|
||||
<fa icon="user" class="fa-fw text-slate-400"></fa> Rotary
|
||||
<InfiniteScroll @reached-bottom="loadMoreData">
|
||||
<ul>
|
||||
<li
|
||||
class="border-b border-slate-300"
|
||||
v-for="project in projects"
|
||||
:key="project.handleId"
|
||||
>
|
||||
<a
|
||||
@click="onClickLoadProject(project.handleId)"
|
||||
class="block py-4 flex gap-4"
|
||||
>
|
||||
<div class="w-12">
|
||||
<img
|
||||
src="https://picsum.photos/200/200?random=1"
|
||||
class="w-full rounded"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="border-b border-slate-300">
|
||||
<a href="project-view.html" class="block py-4 flex gap-4">
|
||||
<div class="w-12">
|
||||
<img
|
||||
src="https://picsum.photos/200/200?random=2"
|
||||
class="w-full rounded"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="grow">
|
||||
<h2 class="text-base font-semibold">Potluck with neighbors</h2>
|
||||
<div class="text-sm">
|
||||
<fa icon="user" class="fa-fw text-slate-400"></fa> Andrew A.
|
||||
<div class="grow">
|
||||
<h2 class="text-base font-semibold">Canyon cleanup</h2>
|
||||
<div class="text-sm">
|
||||
<fa icon="user" class="fa-fw text-slate-400"></fa>
|
||||
{{ project.name }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="border-b border-slate-300">
|
||||
<a href="project-view.html" class="block py-4 flex gap-4">
|
||||
<div class="w-12">
|
||||
<img
|
||||
src="https://picsum.photos/200/200?random=3"
|
||||
class="w-full rounded"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="grow">
|
||||
<h2 class="text-base font-semibold">Historical site</h2>
|
||||
<div class="text-sm">
|
||||
<fa icon="user" class="fa-fw text-slate-400 mr-1"></fa>
|
||||
<em>Unknown</em>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</InfiniteScroll>
|
||||
<AlertMessage
|
||||
:alertTitle="alertTitle"
|
||||
:alertMessage="alertMessage"
|
||||
@@ -123,73 +112,224 @@ import { Component, Vue } from "vue-facing-decorator";
|
||||
|
||||
import { accountsDB, db } from "@/db";
|
||||
import { MASTER_SETTINGS_KEY } from "@/db/tables/settings";
|
||||
import * as R from "ramda";
|
||||
import { accessToken } from "@/libs/crypto";
|
||||
import AlertMessage from "@/components/AlertMessage";
|
||||
import QuickNav from "@/components/QuickNav";
|
||||
import InfiniteScroll from "@/components/InfiniteScroll";
|
||||
|
||||
@Component({
|
||||
components: { AlertMessage, QuickNav },
|
||||
components: { AlertMessage, QuickNav, InfiniteScroll },
|
||||
})
|
||||
export default class DiscoverView extends Vue {
|
||||
activeDid = "";
|
||||
apiServer = "";
|
||||
searchTerms = "";
|
||||
alertMessage = "";
|
||||
alertTitle = "";
|
||||
projects: ProjectData[] = [];
|
||||
isLocalActive = true;
|
||||
isRemoteActive = false;
|
||||
localCount = 0;
|
||||
remoteCount = 0;
|
||||
isLoading = false;
|
||||
|
||||
async mounted() {
|
||||
await db.open();
|
||||
const settings = await db.settings.get(MASTER_SETTINGS_KEY);
|
||||
this.activeDid = settings?.activeDid || "";
|
||||
this.apiServer = settings?.apiServer || "";
|
||||
this.searchLocal();
|
||||
}
|
||||
|
||||
public async search() {
|
||||
public async buildHeaders() {
|
||||
const headers = { "Content-Type": "application/json" };
|
||||
|
||||
if (this.activeDid) {
|
||||
await accountsDB.open();
|
||||
const allAccounts = await accountsDB.accounts.toArray();
|
||||
const account = R.find((acc) => acc.did === this.activeDid, allAccounts);
|
||||
//console.log("about to parse from", this.activeDid, account?.identity);
|
||||
const account = allAccounts.find((acc) => acc.did === this.activeDid);
|
||||
const identity = JSON.parse(account?.identity || "null");
|
||||
|
||||
if (!identity) {
|
||||
throw new Error("No identity found.");
|
||||
throw new Error(
|
||||
"An ID is chosen but there are no keys for it so it cannot be used to talk with the service.",
|
||||
);
|
||||
}
|
||||
const token = await accessToken(identity);
|
||||
headers["Authorization"] = "Bearer " + token;
|
||||
|
||||
headers["Authorization"] = "Bearer " + (await accessToken(identity));
|
||||
} else {
|
||||
// it's OK without auth... we just won't get any identifiers
|
||||
}
|
||||
const claimContents =
|
||||
"claimContents=" + encodeURIComponent(this.searchTerms);
|
||||
const claimType = "claimType=PlanAction";
|
||||
const queryParams = [claimContents, claimType].join("&");
|
||||
return fetch(this.apiServer + "/api/v2/report/claims?" + queryParams, {
|
||||
method: "GET",
|
||||
headers: headers,
|
||||
})
|
||||
.then(async (response) => {
|
||||
if (response.status !== 200) {
|
||||
const details = await response.text();
|
||||
throw details;
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.then((results) => {
|
||||
if (results.data) {
|
||||
console.log(results.data);
|
||||
} else {
|
||||
throw JSON.stringify(results);
|
||||
}
|
||||
})
|
||||
.catch((e) => {
|
||||
console.log("Error with feed load:", e);
|
||||
this.alertMessage =
|
||||
e.userMessage || "There was an error retrieving projects.";
|
||||
this.alertTitle = "Error";
|
||||
});
|
||||
return headers;
|
||||
}
|
||||
|
||||
alertMessage = "";
|
||||
alertTitle = "";
|
||||
public async search(beforeId?: string) {
|
||||
let queryParams = "claimContents=" + encodeURIComponent(this.searchTerms);
|
||||
|
||||
console.log(beforeId);
|
||||
if (beforeId) {
|
||||
queryParams = queryParams + `&beforeId=${beforeId}`;
|
||||
}
|
||||
|
||||
this.isRemoteActive = true;
|
||||
this.isLocalActive = false;
|
||||
|
||||
try {
|
||||
this.isLoading = true;
|
||||
const response = await fetch(
|
||||
this.apiServer + "/api/v2/report/plans?" + queryParams,
|
||||
{
|
||||
method: "GET",
|
||||
headers: await this.buildHeaders(),
|
||||
},
|
||||
);
|
||||
|
||||
if (response.status !== 200) {
|
||||
const details = await response.text();
|
||||
throw details;
|
||||
}
|
||||
|
||||
const results = await response.json();
|
||||
|
||||
const plans: ProjectData[] = results.data;
|
||||
if (plans) {
|
||||
for (const plan of plans) {
|
||||
const { name, description, handleId = plan.handleId, rowid } = plan;
|
||||
console.log("here");
|
||||
this.projects.push({ name, description, handleId, rowid });
|
||||
}
|
||||
this.remoteCount = this.projects.length;
|
||||
} else {
|
||||
throw JSON.stringify(results);
|
||||
}
|
||||
} catch (e) {
|
||||
console.log("Error with feed load:", e);
|
||||
this.alertMessage =
|
||||
e.userMessage || "There was an error retrieving projects.";
|
||||
this.alertTitle = "Error";
|
||||
} finally {
|
||||
this.isLoading = false;
|
||||
}
|
||||
}
|
||||
|
||||
public async searchLocal(beforeId?: string) {
|
||||
const claimContents =
|
||||
"claimContents=" + encodeURIComponent(this.searchTerms);
|
||||
let queryParams = [
|
||||
claimContents,
|
||||
"minLocLat=40.901000",
|
||||
"maxLocLat=40.904000",
|
||||
"westLocLon=-111.914000",
|
||||
"eastLocLon=-111.909000",
|
||||
].join("&");
|
||||
|
||||
if (beforeId) {
|
||||
queryParams = queryParams + `&beforeId=${beforeId}`;
|
||||
}
|
||||
|
||||
try {
|
||||
this.isLoading = true;
|
||||
this.isLocalActive = true;
|
||||
this.isRemoteActive = false;
|
||||
const response = await fetch(
|
||||
this.apiServer + "/api/v2/report/plansByLocation?" + queryParams,
|
||||
{
|
||||
method: "GET",
|
||||
headers: await this.buildHeaders(),
|
||||
},
|
||||
);
|
||||
|
||||
if (response.status !== 200) {
|
||||
throw await response.text();
|
||||
}
|
||||
|
||||
const results = await response.json();
|
||||
|
||||
if (results.data) {
|
||||
if (beforeId) {
|
||||
const plans: ProjectData[] = results.data;
|
||||
for (const plan of plans) {
|
||||
const { name, description, handleId = plan.handleId, rowid } = plan;
|
||||
if (beforeId !== plan["rowid"]) {
|
||||
this.projects.push({ name, description, handleId, rowid });
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.projects = results.data;
|
||||
}
|
||||
this.localCount = this.projects.length;
|
||||
} else {
|
||||
throw JSON.stringify(results);
|
||||
}
|
||||
} catch (e) {
|
||||
console.log("Error with feed load:", e);
|
||||
this.alertMessage =
|
||||
e.userMessage || "There was an error retrieving projects.";
|
||||
this.alertTitle = "Error";
|
||||
} finally {
|
||||
this.isLoading = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Data loader used by infinite scroller
|
||||
* @param payload is the flag from the InfiniteScroll indicating if it should load
|
||||
**/
|
||||
async loadMoreData(payload: boolean) {
|
||||
if (this.projects.length > 0 && payload) {
|
||||
const latestProject = this.projects[this.projects.length - 1];
|
||||
console.log("rowid", latestProject, payload);
|
||||
console.log(Object.keys(latestProject));
|
||||
if (this.isLocalActive) {
|
||||
this.searchLocal(latestProject["rowid"]);
|
||||
} else if (this.isRemoteActive) {
|
||||
this.search(latestProject["rowid"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle clicking on a project entry found in the list
|
||||
* @param id of the project
|
||||
**/
|
||||
onClickLoadProject(id: string) {
|
||||
localStorage.setItem("projectId", id);
|
||||
const route = {
|
||||
name: "project",
|
||||
};
|
||||
this.$router.push(route);
|
||||
}
|
||||
|
||||
public computedLocalTabClassNames() {
|
||||
return {
|
||||
"inline-block": true,
|
||||
"py-3": true,
|
||||
"rounded-t-lg": true,
|
||||
"border-b-2": true,
|
||||
active: this.isLocalActive,
|
||||
"text-blue-600": this.isLocalActive,
|
||||
"border-blue-600": this.isLocalActive,
|
||||
"font-semibold": this.isLocalActive,
|
||||
"border-transparent": !this.isLocalActive,
|
||||
"hover:text-slate-600": !this.isLocalActive,
|
||||
"hover:border-slate-300": !this.isLocalActive,
|
||||
};
|
||||
}
|
||||
|
||||
public computedRemoteTabClassNames() {
|
||||
return {
|
||||
"inline-block": true,
|
||||
"py-3": true,
|
||||
"rounded-t-lg": true,
|
||||
"border-b-2": true,
|
||||
active: this.isRemoteActive,
|
||||
"text-blue-600": this.isRemoteActive,
|
||||
"border-blue-600": this.isRemoteActive,
|
||||
"font-semibold": this.isRemoteActive,
|
||||
"border-transparent": !this.isRemoteActive,
|
||||
"hover:text-slate-600": !this.isRemoteActive,
|
||||
"hover:border-slate-300": !this.isRemoteActive,
|
||||
};
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
@click="openDialog(contact)"
|
||||
class="block w-full text-center text-md uppercase bg-slate-500 text-white px-1.5 py-2 rounded-md mb-2"
|
||||
>
|
||||
{{ contact.name }}
|
||||
{{ contact.name || "(no name)" }}
|
||||
</button>
|
||||
<span v-if="allContacts.length > 0"> or </span>
|
||||
<button @click="openDialog()" class="text-blue-500">
|
||||
@@ -62,19 +62,18 @@
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<AlertMessage
|
||||
:alertTitle="alertTitle"
|
||||
:alertMessage="alertMessage"
|
||||
></AlertMessage>
|
||||
</section>
|
||||
<AlertMessage
|
||||
:alertTitle="alertTitle"
|
||||
:alertMessage="alertMessage"
|
||||
></AlertMessage>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import * as R from "ramda";
|
||||
import { Options, Vue } from "vue-class-component";
|
||||
|
||||
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";
|
||||
@@ -83,7 +82,7 @@ import { Contact } from "@/db/tables/contacts";
|
||||
import AlertMessage from "@/components/AlertMessage";
|
||||
import QuickNav from "@/components/QuickNav";
|
||||
|
||||
@Options({
|
||||
@Component({
|
||||
components: { GiftedDialog, AlertMessage, QuickNav },
|
||||
})
|
||||
export default class HomeView extends Vue {
|
||||
@@ -98,8 +97,40 @@ 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();
|
||||
}
|
||||
|
||||
public async getIdentity(activeDid) {
|
||||
await accountsDB.open();
|
||||
const account = await accountsDB.accounts
|
||||
.where("did")
|
||||
.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;
|
||||
}
|
||||
|
||||
public async getHeaders(identity) {
|
||||
const token = await accessToken(identity);
|
||||
const headers = {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: "Bearer " + token,
|
||||
};
|
||||
return headers;
|
||||
}
|
||||
|
||||
// 'created' hook runs when the Vue instance is first created
|
||||
async created() {
|
||||
try {
|
||||
await accountsDB.open();
|
||||
@@ -119,14 +150,34 @@ export default class HomeView extends Vue {
|
||||
}
|
||||
}
|
||||
|
||||
updateAllFeed = async () => {
|
||||
this.isHiddenSpinner = false;
|
||||
public async buildHeaders() {
|
||||
const headers = { "Content-Type": "application/json" };
|
||||
|
||||
if (this.activeDid) {
|
||||
await accountsDB.open();
|
||||
const allAccounts = await accountsDB.accounts.toArray();
|
||||
const account = allAccounts.find((acc) => acc.did === this.activeDid);
|
||||
const identity = JSON.parse(account?.identity || "null");
|
||||
|
||||
if (!identity) {
|
||||
throw new Error(
|
||||
"An ID is chosen but there are no keys for it so it cannot be used to talk with the service.",
|
||||
);
|
||||
}
|
||||
|
||||
headers["Authorization"] = "Bearer " + (await accessToken(identity));
|
||||
} else {
|
||||
// it's OK without auth... we just won't get any identifiers
|
||||
}
|
||||
return headers;
|
||||
}
|
||||
|
||||
public async updateAllFeed() {
|
||||
this.isHiddenSpinner = false;
|
||||
await this.retrieveClaims(this.apiServer, null, this.feedPreviousOldestId)
|
||||
.then(async (results) => {
|
||||
if (results.data.length > 0) {
|
||||
this.feedData = this.feedData.concat(results.data);
|
||||
//console.log("Feed data:", this.feedData);
|
||||
this.feedAllLoaded = results.hitLimit;
|
||||
this.feedPreviousOldestId =
|
||||
results.data[results.data.length - 1].jwtId;
|
||||
@@ -134,7 +185,6 @@ export default class HomeView extends Vue {
|
||||
this.feedLastViewedId == null ||
|
||||
this.feedLastViewedId < results.data[0].jwtId
|
||||
) {
|
||||
// save it to storage
|
||||
await db.open();
|
||||
db.settings.update(MASTER_SETTINGS_KEY, {
|
||||
lastViewedClaimId: results.data[0].jwtId,
|
||||
@@ -151,64 +201,59 @@ export default class HomeView extends Vue {
|
||||
});
|
||||
|
||||
this.isHiddenSpinner = true;
|
||||
};
|
||||
}
|
||||
|
||||
retrieveClaims = async (endorserApiServer, identifier, beforeId) => {
|
||||
//const afterQuery = afterId == null ? "" : "&afterId=" + afterId;
|
||||
public async retrieveClaims(endorserApiServer, identifier, 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
|
||||
);
|
||||
const identity = JSON.parse(account?.identity || "null");
|
||||
if (!identity) {
|
||||
throw new Error("No identity found.");
|
||||
}
|
||||
const token = await accessToken(identity);
|
||||
headers["Authorization"] = "Bearer " + token;
|
||||
} else {
|
||||
// it's OK without auth... we just won't get any identifiers
|
||||
const response = await fetch(
|
||||
endorserApiServer + "/api/v2/report/gives?" + beforeQuery,
|
||||
{
|
||||
method: "GET",
|
||||
headers: await this.buildHeaders(),
|
||||
},
|
||||
);
|
||||
|
||||
if (response.status !== 200) {
|
||||
throw await response.text();
|
||||
}
|
||||
return fetch(this.apiServer + "/api/v2/report/gives?" + beforeQuery, {
|
||||
method: "GET",
|
||||
headers: headers,
|
||||
})
|
||||
.then(async (response) => {
|
||||
if (response.status !== 200) {
|
||||
const details = await response.text();
|
||||
throw details;
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.then((results) => {
|
||||
if (results.data) {
|
||||
return results;
|
||||
} else {
|
||||
throw JSON.stringify(results);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const results = await response.json();
|
||||
|
||||
if (results.data) {
|
||||
return results;
|
||||
} else {
|
||||
throw JSON.stringify(results);
|
||||
}
|
||||
}
|
||||
|
||||
giveDescription(giveRecord) {
|
||||
let claim = giveRecord.fullClaim;
|
||||
if (claim.claim) {
|
||||
// it's probably a Verified Credential
|
||||
claim = claim.claim;
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
@@ -224,6 +269,7 @@ export default class HomeView extends Vue {
|
||||
openDialog(giver) {
|
||||
this.$refs.customDialog.open(giver);
|
||||
}
|
||||
|
||||
handleDialogResult(result) {
|
||||
if (result.action === "confirm") {
|
||||
return new Promise((resolve) => {
|
||||
@@ -241,59 +287,71 @@ export default class HomeView extends Vue {
|
||||
* @param description may be an empty string
|
||||
* @param hours may be 0
|
||||
*/
|
||||
recordGive(giverDid, description, hours) {
|
||||
if (this.activeDid == null) {
|
||||
this.alertTitle = "Error";
|
||||
this.alertMessage =
|
||||
"You must select an identity before you can record a give.";
|
||||
public async recordGive(giverDid, description, hours) {
|
||||
if (!this.activeDid) {
|
||||
this.setAlert(
|
||||
"Error",
|
||||
"You must select an identity before you can record a give.",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!description && !hours) {
|
||||
this.alertTitle = "Error";
|
||||
this.alertMessage =
|
||||
"You must enter a description or some number of hours.";
|
||||
this.setAlert(
|
||||
"Error",
|
||||
"You must enter a description or some number of hours.",
|
||||
);
|
||||
return;
|
||||
}
|
||||
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 || "null");
|
||||
if (!identity) {
|
||||
throw new Error("No identity found.");
|
||||
|
||||
try {
|
||||
const identity = await this.getIdentity(this.activeDid);
|
||||
const result = await createAndSubmitGive(
|
||||
this.axios,
|
||||
this.apiServer,
|
||||
identity,
|
||||
giverDid,
|
||||
this.activeDid,
|
||||
description,
|
||||
hours,
|
||||
);
|
||||
|
||||
if (isGiveCreationError(result)) {
|
||||
const errorMessage = getGiveCreationErrorMessage(result);
|
||||
console.log("Error with give result:", result);
|
||||
this.setAlert(
|
||||
"Error",
|
||||
errorMessage || "There was an error recording the give.",
|
||||
);
|
||||
} else {
|
||||
this.setAlert("Success", "That gift was recorded.");
|
||||
}
|
||||
} catch (error) {
|
||||
console.log("Error with give caught:", error);
|
||||
this.setAlert(
|
||||
"Error",
|
||||
getGiveErrorMessage(error) || "There was an error recording the give.",
|
||||
);
|
||||
}
|
||||
createAndSubmitGive(
|
||||
this.axios,
|
||||
this.apiServer,
|
||||
identity,
|
||||
giverDid,
|
||||
this.activeDid,
|
||||
description,
|
||||
hours
|
||||
)
|
||||
.then((result) => {
|
||||
if (result.status != 201 || result.data?.error) {
|
||||
console.log("Error with give result:", result);
|
||||
this.alertTitle = "Error";
|
||||
this.alertMessage =
|
||||
result.data?.error?.message ||
|
||||
"There was an error recording the give.";
|
||||
} else {
|
||||
this.alertTitle = "Success";
|
||||
this.alertMessage = "That gift was recorded.";
|
||||
//this.updateAllFeed(); // full update is overkill but we should show something
|
||||
}
|
||||
})
|
||||
.catch((e) => {
|
||||
// axios throws errors on 400 responses
|
||||
console.log("Error with give caught:", e);
|
||||
this.alertTitle = "Error";
|
||||
this.alertMessage =
|
||||
e.userMessage ||
|
||||
e.response?.data?.error?.message ||
|
||||
"There was an error recording the give.";
|
||||
});
|
||||
}
|
||||
|
||||
private setAlert(title, message) {
|
||||
this.alertTitle = title;
|
||||
this.alertMessage = message;
|
||||
}
|
||||
|
||||
// Helper functions for readability
|
||||
|
||||
isGiveCreationError(result) {
|
||||
return result.status !== 201 || result.data?.error;
|
||||
}
|
||||
|
||||
getGiveCreationErrorMessage(result) {
|
||||
return result.data?.error?.message;
|
||||
}
|
||||
|
||||
getGiveErrorMessage(error) {
|
||||
return error.userMessage || error.response?.data?.error?.message;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
169
src/views/IdentitySwitcherView.vue
Normal file
169
src/views/IdentitySwitcherView.vue
Normal file
@@ -0,0 +1,169 @@
|
||||
<template>
|
||||
<QuickNav selected="Profile"></QuickNav>
|
||||
<section id="Content" class="p-6 pb-24">
|
||||
<!-- Breadcrumb -->
|
||||
<div id="ViewBreadcrumb" class="mb-8">
|
||||
<h1 class="text-lg text-center font-light relative px-7">
|
||||
<!-- Cancel -->
|
||||
<router-link
|
||||
:to="{ name: 'account' }"
|
||||
class="text-lg text-center px-2 py-1 absolute -left-2 -top-1"
|
||||
><fa icon="chevron-left" class="fa-fw"></fa>
|
||||
</router-link>
|
||||
|
||||
Switch Identity
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
<!-- Identity List -->
|
||||
|
||||
<!-- Current Identity - Display First! -->
|
||||
<div class="block bg-slate-100 rounded-md flex items-center px-4 py-3 mb-4">
|
||||
<fa icon="circle-check" class="fa-fw text-blue-600 text-xl mr-3"></fa>
|
||||
<span class="overflow-hidden">
|
||||
<h2 class="text-xl font-semibold mb-0">
|
||||
{{ firstName }} {{ lastName }}
|
||||
</h2>
|
||||
<div class="text-sm text-slate-500 truncate">
|
||||
<b>ID:</b> <code>{{ activeDid }}</code>
|
||||
</div>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<!-- Other Identity/ies -->
|
||||
<ul class="mb-4">
|
||||
<li
|
||||
class="block bg-slate-100 rounded-md flex items-center px-4 py-3 mb-2"
|
||||
v-for="ident in otherIdentities"
|
||||
:key="ident.did"
|
||||
@click="switchAccount(ident.did)"
|
||||
>
|
||||
<fa icon="circle" class="fa-fw text-slate-400 text-xl mr-3"></fa>
|
||||
<span class="overflow-hidden">
|
||||
<h2 class="text-xl font-semibold mb-0"></h2>
|
||||
<div class="text-sm text-slate-500 truncate">
|
||||
<b>ID:</b> <code>{{ ident.did }}</code>
|
||||
</div>
|
||||
</span>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<!-- Actions -->
|
||||
<router-link
|
||||
:to="{ name: 'start' }"
|
||||
class="block text-center text-lg font-bold uppercase bg-blue-600 text-white px-2 py-3 rounded-md mb-2"
|
||||
>
|
||||
Add Another Identity…
|
||||
</router-link>
|
||||
<a
|
||||
href="#"
|
||||
class="block w-full text-center text-md uppercase bg-slate-500 text-white px-1.5 py-2 rounded-md mb-8"
|
||||
@click="switchAccount('0')"
|
||||
>
|
||||
No Identity
|
||||
</a>
|
||||
|
||||
<AlertMessage
|
||||
:alertTitle="alertTitle"
|
||||
:alertMessage="alertMessage"
|
||||
></AlertMessage>
|
||||
</section>
|
||||
</template>
|
||||
<script lang="ts">
|
||||
import { Component, Vue } from "vue-facing-decorator";
|
||||
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 AlertMessage from "@/components/AlertMessage";
|
||||
import QuickNav from "@/components/QuickNav";
|
||||
|
||||
@Component({ components: { AlertMessage, QuickNav } })
|
||||
export default class IdentitySwitcherView extends Vue {
|
||||
Constants = AppString;
|
||||
public accounts: AccountsSchema;
|
||||
public activeDid;
|
||||
public firstName;
|
||||
public lastName;
|
||||
public alertTitle;
|
||||
public alertMessage;
|
||||
public otherIdentities = [];
|
||||
|
||||
public async getIdentity(activeDid) {
|
||||
await accountsDB.open();
|
||||
const account = await accountsDB.accounts
|
||||
.where("did")
|
||||
.equals(activeDid)
|
||||
.first();
|
||||
const identity = JSON.parse(account?.identity || "null");
|
||||
return identity;
|
||||
}
|
||||
|
||||
async created() {
|
||||
try {
|
||||
await db.open();
|
||||
const settings = await db.settings.get(MASTER_SETTINGS_KEY);
|
||||
this.activeDid = settings?.activeDid || "";
|
||||
this.apiServer = settings?.apiServer || "";
|
||||
this.apiServerInput = settings?.apiServer || "";
|
||||
this.firstName = settings?.firstName || "No";
|
||||
this.lastName = settings?.lastName || "Name";
|
||||
this.showContactGives = !!settings?.showContactGivesInline;
|
||||
|
||||
const identity = await this.getIdentity(this.activeDid);
|
||||
|
||||
if (identity) {
|
||||
db.settings.update(MASTER_SETTINGS_KEY, {
|
||||
activeDid: identity.did,
|
||||
});
|
||||
}
|
||||
await accountsDB.open();
|
||||
const accounts = await accountsDB.accounts.toArray();
|
||||
for (let n = 0; n < accounts.length; n++) {
|
||||
const did = JSON.parse(accounts[n].identity)["did"];
|
||||
if (did && this.activeDid !== did) {
|
||||
this.otherIdentities.push({ did: did });
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
if (
|
||||
err.message ===
|
||||
"Attempted to load account records with no identity available."
|
||||
) {
|
||||
this.limitsMessage = "No identity.";
|
||||
this.loadingLimits = false;
|
||||
} else {
|
||||
this.alertMessage =
|
||||
"Clear your cache and start over (after data backup).";
|
||||
console.error(
|
||||
"Telling user to clear cache at page create because:",
|
||||
err,
|
||||
);
|
||||
this.alertTitle = "Error Creating Account";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async switchAccount(did: string) {
|
||||
// 0 means none
|
||||
if (did === "0") {
|
||||
did = undefined;
|
||||
}
|
||||
await db.open();
|
||||
db.settings.update(MASTER_SETTINGS_KEY, {
|
||||
activeDid: did,
|
||||
});
|
||||
this.activeDid = did;
|
||||
this.otherIdentities = [];
|
||||
await accountsDB.open();
|
||||
const accounts = await accountsDB.accounts.toArray();
|
||||
for (let n = 0; n < accounts.length; n++) {
|
||||
const did = JSON.parse(accounts[n].identity)["did"];
|
||||
if (did && this.activeDid !== did) {
|
||||
this.otherIdentities.push({ did: did });
|
||||
}
|
||||
}
|
||||
this.$router.push({ name: "account" });
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -43,12 +43,12 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { Options, Vue } from "vue-class-component";
|
||||
import { Component, Vue } from "vue-facing-decorator";
|
||||
import { deriveAddress, newIdentifier } from "../libs/crypto";
|
||||
import { accountsDB, db } from "@/db";
|
||||
import { MASTER_SETTINGS_KEY } from "@/db/tables/settings";
|
||||
|
||||
@Options({
|
||||
@Component({
|
||||
components: {},
|
||||
})
|
||||
export default class ImportAccountView extends Vue {
|
||||
@@ -72,7 +72,7 @@ export default class ImportAccountView extends Vue {
|
||||
this.address,
|
||||
this.publicHex,
|
||||
this.privateHex,
|
||||
this.derivationPath
|
||||
this.derivationPath,
|
||||
);
|
||||
|
||||
try {
|
||||
|
||||
@@ -49,11 +49,11 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { Options, Vue } from "vue-class-component";
|
||||
import { Component, Vue } from "vue-facing-decorator";
|
||||
import { db } from "@/db";
|
||||
import { MASTER_SETTINGS_KEY } from "@/db/tables/settings";
|
||||
|
||||
@Options({
|
||||
@Component({
|
||||
components: {},
|
||||
})
|
||||
export default class NewEditAccountView extends Vue {
|
||||
|
||||
@@ -61,9 +61,9 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { Options, Vue } from "vue-class-component";
|
||||
import { Component, Vue } from "vue-facing-decorator";
|
||||
|
||||
@Options({
|
||||
@Component({
|
||||
components: {},
|
||||
})
|
||||
export default class NewEditCommitmentView extends Vue {}
|
||||
|
||||
@@ -73,24 +73,16 @@
|
||||
<script lang="ts">
|
||||
import { AxiosError } from "axios";
|
||||
import * as didJwt from "did-jwt";
|
||||
import * as R from "ramda";
|
||||
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";
|
||||
import { IIdentifier } from "@veramo/core";
|
||||
import AlertMessage from "@/components/AlertMessage";
|
||||
|
||||
interface VerifiableCredential {
|
||||
"@context": string;
|
||||
"@type": string;
|
||||
name: string;
|
||||
description: string;
|
||||
identifier?: string;
|
||||
}
|
||||
|
||||
@Component({
|
||||
components: { AlertMessage },
|
||||
})
|
||||
@@ -100,12 +92,46 @@ 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();
|
||||
}
|
||||
|
||||
public async getIdentity(activeDid) {
|
||||
await accountsDB.open();
|
||||
const account = await accountsDB.accounts
|
||||
.where("did")
|
||||
.equals(activeDid)
|
||||
.first();
|
||||
const identity = JSON.parse(account?.identity || "null");
|
||||
|
||||
if (!identity) {
|
||||
throw new Error(
|
||||
"Attempted to load project records with no identity available.",
|
||||
);
|
||||
}
|
||||
return identity;
|
||||
}
|
||||
|
||||
public async getHeaders(identity) {
|
||||
const token = await accessToken(identity);
|
||||
const headers = {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: "Bearer " + token,
|
||||
};
|
||||
return headers;
|
||||
}
|
||||
|
||||
projectId = localStorage.getItem("projectId") || "";
|
||||
isHiddenSave = false;
|
||||
isHiddenSpinner = true;
|
||||
|
||||
// 'created' hook runs when the Vue instance is first created
|
||||
async created() {
|
||||
await db.open();
|
||||
const settings = await db.settings.get(MASTER_SETTINGS_KEY);
|
||||
@@ -113,16 +139,14 @@ export default class NewEditProjectView extends Vue {
|
||||
this.apiServer = settings?.apiServer || "";
|
||||
|
||||
if (this.projectId) {
|
||||
await accountsDB.open();
|
||||
const num_accounts = await accountsDB.accounts.count();
|
||||
if (num_accounts === 0) {
|
||||
if (this.numAccounts === 0) {
|
||||
console.error("Error: no account was found.");
|
||||
} else {
|
||||
const accounts = await accountsDB.accounts.toArray();
|
||||
const account = R.find((acc) => acc.did === this.activeDid, accounts);
|
||||
const identity = JSON.parse(account?.identity || "null");
|
||||
const identity = await this.getIdentity(this.activeDid);
|
||||
if (!identity) {
|
||||
throw new Error("No identity found.");
|
||||
throw new Error(
|
||||
"An ID is chosen but there are no keys for it so it cannot be used to talk with the service.",
|
||||
);
|
||||
}
|
||||
this.LoadProject(identity);
|
||||
}
|
||||
@@ -205,7 +229,7 @@ export default class NewEditProjectView extends Vue {
|
||||
// handleId is new in server v release-1.6.0; remove fullIri when that
|
||||
// version shows up here: https://endorser.ch:3000/api-docs/
|
||||
useAppStore().setProjectId(
|
||||
resp.data.success.handleId || resp.data.success.fullIri
|
||||
resp.data.success.handleId || resp.data.success.fullIri,
|
||||
);
|
||||
setTimeout(
|
||||
function (that: Vue) {
|
||||
@@ -215,7 +239,7 @@ export default class NewEditProjectView extends Vue {
|
||||
that.$router.push(route);
|
||||
},
|
||||
2000,
|
||||
this
|
||||
this,
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
@@ -234,7 +258,7 @@ export default class NewEditProjectView extends Vue {
|
||||
} else {
|
||||
console.error(
|
||||
"Here's the full error trying to save the claim:",
|
||||
error
|
||||
error,
|
||||
);
|
||||
this.alertTitle = "Claim Error";
|
||||
this.alertMessage = error as string;
|
||||
@@ -248,17 +272,11 @@ export default class NewEditProjectView extends Vue {
|
||||
public async onSaveProjectClick() {
|
||||
this.isHiddenSave = true;
|
||||
this.isHiddenSpinner = false;
|
||||
await accountsDB.open();
|
||||
const num_accounts = await accountsDB.accounts.count();
|
||||
if (num_accounts === 0) {
|
||||
|
||||
if (this.numAccounts === 0) {
|
||||
console.error("Error: there is no account.");
|
||||
} else {
|
||||
const accounts = await accountsDB.accounts.toArray();
|
||||
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.");
|
||||
}
|
||||
const identity = await this.getIdentity(this.activeDid);
|
||||
this.SaveProject(identity);
|
||||
}
|
||||
}
|
||||
@@ -266,9 +284,5 @@ export default class NewEditProjectView extends Vue {
|
||||
public onCancelClick() {
|
||||
this.$router.back();
|
||||
}
|
||||
|
||||
// This same popup code is in many files.
|
||||
alertTitle = "";
|
||||
alertMessage = "";
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -23,16 +23,15 @@
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
{{ errorMessage }}
|
||||
</div>
|
||||
|
||||
<!-- Project Details -->
|
||||
<div class="bg-slate-100 rounded-md overflow-hidden px-4 py-3 mb-4">
|
||||
<div>
|
||||
<h2 class="text-xl font-semibold">{{ name }}</h2>
|
||||
<div class="flex justify-between gap-4 text-sm mb-3">
|
||||
<span><fa icon="user" class="fa-fw text-slate-400"></fa> Rotary</span>
|
||||
<span
|
||||
><fa icon="user" class="fa-fw text-slate-400"></fa>
|
||||
{{ issuer }}</span
|
||||
>
|
||||
<span
|
||||
><fa icon="calendar" class="fa-fw text-slate-400"></fa
|
||||
>{{ timeSince }}
|
||||
@@ -65,77 +64,90 @@
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<button
|
||||
@click="openDialog({ name: 'you', did: activeDid })"
|
||||
class="block text-center text-lg font-bold uppercase bg-blue-600 text-white px-2 py-3 rounded-md mb-8"
|
||||
>
|
||||
I gave...
|
||||
</button>
|
||||
|
||||
<div>
|
||||
<p>... or choose a contact who gave:</p>
|
||||
<!-- similar contact selection code is in multiple places -->
|
||||
<div class="px-4">
|
||||
<div v-if="activeDid">
|
||||
<button
|
||||
v-for="contact in allContacts"
|
||||
:key="contact.did"
|
||||
@click="openDialog(contact)"
|
||||
class="text-blue-500"
|
||||
@click="openDialog({ name: 'you', did: activeDid })"
|
||||
class="text-center text-lg font-bold uppercase bg-blue-600 text-white px-2 py-3 rounded-md"
|
||||
>
|
||||
{{ contact.name }},
|
||||
</button>
|
||||
<span v-if="allContacts.length > 0"> or </span>
|
||||
<button @click="openDialog()" class="text-blue-500">
|
||||
someone not specified
|
||||
I gave...
|
||||
</button>
|
||||
― or:
|
||||
</div>
|
||||
<!-- similar contact selection code is in multiple places -->
|
||||
Record a gift from
|
||||
<span v-for="contact in allContacts" :key="contact.did">
|
||||
<button @click="openDialog(contact)" class="text-blue-500">
|
||||
{{ contact.name }}</button
|
||||
>,
|
||||
</span>
|
||||
<span v-if="allContacts.length > 0"> or </span>
|
||||
<button @click="openDialog()" class="text-blue-500">
|
||||
someone not specified
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- Gifts to & from this -->
|
||||
<div class="mt-8 flex justify-around">
|
||||
<div>
|
||||
<h1 class="text-xl">Given to this Project</h1>
|
||||
</div>
|
||||
<div>
|
||||
<h1 class="text-xl">... and from this Project</h1>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex justify-around">
|
||||
<div class="w-1/2">
|
||||
<div v-for="give in givesToThis" :key="give.id">
|
||||
<div class="flex justify-between">
|
||||
<div class="flex gap-3">
|
||||
<div class="flex gap-2">
|
||||
<fa icon="user" class="fa-fw text-slate-400"></fa>
|
||||
<span>{{
|
||||
didInfo(give.agentDid, activeDid, accounts, allContacts)
|
||||
}}</span>
|
||||
</div>
|
||||
<div class="flex gap-2" v-if="give.amount">
|
||||
<fa icon="coins" class="fa-fw text-slate-400"></fa>
|
||||
<span>{{ give.amount }}</span>
|
||||
</div>
|
||||
<div class="flex gap-2" v-if="give.description">
|
||||
<fa icon="comment" class="fa-fw text-slate-400"></fa>
|
||||
<span>{{ give.description }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="w-1/2">
|
||||
<div v-for="give in givesByThis" :key="give.id">
|
||||
<div class="flex justify-between">
|
||||
<div class="flex gap-3">
|
||||
<div class="flex gap-2">
|
||||
<fa icon="user" class="fa-fw text-slate-400"></fa>
|
||||
<span>{{
|
||||
didInfo(give.agentDid, activeDid, accounts, allContacts)
|
||||
}}</span>
|
||||
</div>
|
||||
<div class="flex gap-2" v-if="give.amount">
|
||||
<fa icon="coins" class="fa-fw text-slate-400"></fa>
|
||||
<span>{{ give.amount }}</span>
|
||||
</div>
|
||||
<div class="flex gap-2">
|
||||
<fa icon="comment" class="fa-fw text-slate-400"></fa>
|
||||
<span>{{ give.description }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<GiftedDialog
|
||||
ref="customDialog"
|
||||
@dialog-result="handleDialogResult"
|
||||
message="Received from"
|
||||
>
|
||||
</GiftedDialog>
|
||||
|
||||
<!-- Commit -->
|
||||
<!--
|
||||
<router-link
|
||||
:to="{ name: 'new-edit-commitment' }"
|
||||
class="block text-center text-lg font-bold uppercase bg-blue-600 text-white px-2 py-3 rounded-md mb-8"
|
||||
>Make Commitment</router-link
|
||||
>
|
||||
-->
|
||||
|
||||
<!-- Commitments -->
|
||||
<!--
|
||||
<div class="bg-slate-100 px-4 py-3 rounded-md">
|
||||
<h3 class="text-sm uppercase font-semibold mb-3">Commitments</h3>
|
||||
|
||||
<ul class="text-sm border-t border-slate-300">
|
||||
<li class="flex justify-between gap-4 py-1.5 border-b border-slate-300">
|
||||
<span>[Username]</span>
|
||||
<span
|
||||
>5 hours <fa icon="spinner" class="fa-fw text-slate-400"></fa
|
||||
></span>
|
||||
</li>
|
||||
|
||||
<li class="flex justify-between gap-4 py-1.5 border-b border-slate-300">
|
||||
<span>[Username]</span>
|
||||
<span
|
||||
>US$ 20.00 <fa icon="circle-check" class="fa-fw text-lime-500"></fa
|
||||
></span>
|
||||
</li>
|
||||
|
||||
<li class="flex justify-between gap-4 py-1.5 border-b border-slate-300">
|
||||
<span>[Username]</span>
|
||||
<span
|
||||
>0.1 BTC <fa icon="spinner" class="fa-fw text-slate-400"></fa
|
||||
></span>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
-->
|
||||
<AlertMessage
|
||||
:alertTitle="alertTitle"
|
||||
:alertMessage="alertMessage"
|
||||
@@ -146,16 +158,20 @@
|
||||
<script lang="ts">
|
||||
import { AxiosError } from "axios";
|
||||
import * as moment from "moment";
|
||||
import * as R from "ramda";
|
||||
import { IIdentifier } from "@veramo/core";
|
||||
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 { createAndSubmitGive } from "@/libs/endorserServer";
|
||||
import { accessToken } from "@/libs/crypto";
|
||||
import { IIdentifier } from "@veramo/core";
|
||||
import {
|
||||
createAndSubmitGive,
|
||||
didInfo,
|
||||
GiveServerRecord,
|
||||
} from "@/libs/endorserServer";
|
||||
import AlertMessage from "@/components/AlertMessage";
|
||||
import QuickNav from "@/components/QuickNav";
|
||||
|
||||
@@ -163,17 +179,68 @@ import QuickNav from "@/components/QuickNav";
|
||||
components: { GiftedDialog, AlertMessage, QuickNav },
|
||||
})
|
||||
export default class ProjectViewView extends Vue {
|
||||
accounts: AccountsSchema;
|
||||
activeDid = "";
|
||||
alertMessage = "";
|
||||
alertTitle = "";
|
||||
allContacts: Array<Contact> = [];
|
||||
apiServer = "";
|
||||
expanded = false;
|
||||
name = "";
|
||||
description = "";
|
||||
expanded = false;
|
||||
givesToThis: Array<GiveServerRecord> = [];
|
||||
givesByThis: Array<GiveServerRecord> = [];
|
||||
name = "";
|
||||
issuer = "";
|
||||
numAccounts = 0;
|
||||
projectId = localStorage.getItem("projectId") || ""; // handle ID
|
||||
timeSince = "";
|
||||
truncatedDesc = "";
|
||||
truncateLength = 40;
|
||||
timeSince = "";
|
||||
projectId = localStorage.getItem("projectId") || ""; // handle ID
|
||||
errorMessage = "";
|
||||
|
||||
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);
|
||||
this.activeDid = settings?.activeDid || "";
|
||||
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);
|
||||
const identity = JSON.parse(account?.identity || "null");
|
||||
this.LoadProject(identity);
|
||||
}
|
||||
|
||||
public async getIdentity(activeDid) {
|
||||
await accountsDB.open();
|
||||
const account = await accountsDB.accounts
|
||||
.where("did")
|
||||
.equals(activeDid)
|
||||
.first();
|
||||
const identity = JSON.parse(account?.identity || "null");
|
||||
|
||||
if (!identity) {
|
||||
throw new Error(
|
||||
"Attempted to load project records with no identity available.",
|
||||
);
|
||||
}
|
||||
return identity;
|
||||
}
|
||||
|
||||
public async getHeaders(identity) {
|
||||
const token = await accessToken(identity);
|
||||
const headers = {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: "Bearer " + token,
|
||||
};
|
||||
return headers;
|
||||
}
|
||||
|
||||
onEditClick() {
|
||||
localStorage.setItem("projectId", this.projectId as string);
|
||||
@@ -183,6 +250,11 @@ export default class ProjectViewView extends Vue {
|
||||
this.$router.push(route);
|
||||
}
|
||||
|
||||
// Isn't there a better way to make this available to the template?
|
||||
didInfo(did, activeDid, identities, contacts) {
|
||||
return didInfo(did, activeDid, identities, contacts);
|
||||
}
|
||||
|
||||
expandText() {
|
||||
this.expanded = true;
|
||||
}
|
||||
@@ -196,11 +268,13 @@ export default class ProjectViewView extends Vue {
|
||||
this.apiServer +
|
||||
"/api/claim/byHandle/" +
|
||||
encodeURIComponent(this.projectId);
|
||||
const token = await accessToken(identity);
|
||||
const headers = {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: "Bearer " + token,
|
||||
};
|
||||
if (identity) {
|
||||
const token = await accessToken(identity);
|
||||
headers["Authorization"] = "Bearer " + token;
|
||||
}
|
||||
|
||||
try {
|
||||
const resp = await this.axios.get(url, { headers });
|
||||
@@ -211,52 +285,72 @@ export default class ProjectViewView extends Vue {
|
||||
const now = moment.now();
|
||||
this.timeSince = moment.utc(now).to(eventDate);
|
||||
}
|
||||
this.issuer = resp.data.issuer;
|
||||
this.name = resp.data.claim?.name || "(no name)";
|
||||
this.description = resp.data.claim?.description || "(no description)";
|
||||
this.truncatedDesc = this.description.slice(0, this.truncateLength);
|
||||
} else if (resp.status === 404) {
|
||||
// actually, axios throws an error so we never get here
|
||||
this.errorMessage = "That project does not exist.";
|
||||
this.alertMessage = "That project does not exist.";
|
||||
}
|
||||
} catch (error: unknown) {
|
||||
const serverError = error as AxiosError;
|
||||
if (serverError.response?.status === 404) {
|
||||
this.errorMessage = "That project does not exist.";
|
||||
this.alertMessage = "That project does not exist.";
|
||||
} else {
|
||||
this.errorMessage =
|
||||
this.alertMessage =
|
||||
"Something went wrong retrieving that project." +
|
||||
" See logs for more info.";
|
||||
console.error("Error retrieving project:", error);
|
||||
console.error("Error retrieving project:", serverError.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 'created' hook runs when the Vue instance is first created
|
||||
async created() {
|
||||
await db.open();
|
||||
const settings = await db.settings.get(MASTER_SETTINGS_KEY);
|
||||
this.activeDid = settings?.activeDid || "";
|
||||
this.apiServer = settings?.apiServer || "";
|
||||
this.allContacts = await db.contacts.toArray();
|
||||
|
||||
await accountsDB.open();
|
||||
const num_accounts = await accountsDB.accounts.count();
|
||||
if (num_accounts === 0) {
|
||||
console.error("Problem! Should have a profile!");
|
||||
} else {
|
||||
const accounts = await accountsDB.accounts.toArray();
|
||||
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.");
|
||||
const givesInUrl =
|
||||
this.apiServer +
|
||||
"/api/v2/report/givesForPlans?planIds=" +
|
||||
encodeURIComponent(JSON.stringify([this.projectId]));
|
||||
try {
|
||||
const resp = await this.axios.get(givesInUrl, { headers });
|
||||
if (resp.status === 200 && resp.data.data) {
|
||||
this.givesToThis = resp.data.data;
|
||||
} else {
|
||||
this.alertMessage = "Failed to retrieve gives to this project.";
|
||||
}
|
||||
this.LoadProject(identity);
|
||||
} catch (error: unknown) {
|
||||
const serverError = error as AxiosError;
|
||||
this.alertMessage =
|
||||
"Something went wrong retrieving gives to this project.";
|
||||
console.error(
|
||||
"Error retrieving gives to this project:",
|
||||
serverError.message,
|
||||
);
|
||||
}
|
||||
|
||||
const givesOutUrl =
|
||||
this.apiServer +
|
||||
"/api/v2/report/givesProvidedBy?providerId=" +
|
||||
encodeURIComponent(this.projectId);
|
||||
try {
|
||||
const resp = await this.axios.get(givesOutUrl, { headers });
|
||||
if (resp.status === 200 && resp.data.data) {
|
||||
this.givesByThis = resp.data.data;
|
||||
} else {
|
||||
this.alertMessage = "Failed to retrieve gives by this project.";
|
||||
}
|
||||
} catch (error: unknown) {
|
||||
const serverError = error as AxiosError;
|
||||
this.alertMessage = "Something went wrong retrieving gives by project.";
|
||||
console.error(
|
||||
"Error retrieving gives by this project:",
|
||||
serverError.message,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
openDialog(contact) {
|
||||
this.$refs.customDialog.open(contact);
|
||||
}
|
||||
|
||||
handleDialogResult(result) {
|
||||
if (result.action === "confirm") {
|
||||
return new Promise((resolve) => {
|
||||
@@ -275,60 +369,51 @@ export default class ProjectViewView extends Vue {
|
||||
* @param hours may be 0
|
||||
*/
|
||||
async 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.";
|
||||
return;
|
||||
}
|
||||
|
||||
if (!description && !hours) {
|
||||
this.alertTitle = "Error";
|
||||
this.alertMessage =
|
||||
"You must enter a description or some number of hours.";
|
||||
return;
|
||||
}
|
||||
const accounts = await accountsDB.accounts.toArray();
|
||||
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.");
|
||||
}
|
||||
createAndSubmitGive(
|
||||
this.axios,
|
||||
this.apiServer,
|
||||
identity,
|
||||
giverDid,
|
||||
this.activeDid,
|
||||
description,
|
||||
hours,
|
||||
this.projectId
|
||||
)
|
||||
.then((result) => {
|
||||
if (result.status != 201 || result.data?.error) {
|
||||
console.log("Error with give result:", result);
|
||||
this.alertTitle = "Error";
|
||||
this.alertMessage =
|
||||
result.data?.error?.message ||
|
||||
"There was an error recording the give.";
|
||||
} else {
|
||||
this.alertTitle = "Success";
|
||||
this.alertMessage = "That gift was recorded.";
|
||||
//this.updateAllFeed(); // full update is overkill but we should show something
|
||||
}
|
||||
})
|
||||
.catch((e) => {
|
||||
// axios throws errors on 400 responses
|
||||
console.log("Error with give caught:", e);
|
||||
|
||||
try {
|
||||
const identity = await this.getIdentity(this.activeDid);
|
||||
const result = await createAndSubmitGive(
|
||||
this.axios,
|
||||
this.apiServer,
|
||||
identity,
|
||||
giverDid,
|
||||
this.activeDid,
|
||||
description,
|
||||
hours,
|
||||
this.projectId,
|
||||
);
|
||||
|
||||
if (result.status !== 201 || result.data?.error) {
|
||||
console.log("Error with give result:", result);
|
||||
this.alertTitle = "Error";
|
||||
this.alertMessage =
|
||||
e.userMessage ||
|
||||
e.response?.data?.error?.message ||
|
||||
result.data?.error?.message ||
|
||||
"There was an error recording the give.";
|
||||
});
|
||||
} else {
|
||||
this.alertTitle = "Success";
|
||||
this.alertMessage = "That gift was recorded.";
|
||||
}
|
||||
} catch (e) {
|
||||
console.log("Error with give caught:", e);
|
||||
this.alertTitle = "Error";
|
||||
this.alertMessage =
|
||||
e.userMessage ||
|
||||
e.response?.data?.error?.message ||
|
||||
"There was an error recording the give.";
|
||||
}
|
||||
}
|
||||
|
||||
// This same popup code is in many files.
|
||||
alertMessage = "";
|
||||
alertTitle = "";
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -73,9 +73,9 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import * as R from "ramda";
|
||||
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";
|
||||
@@ -83,28 +83,6 @@ import InfiniteScroll from "@/components/InfiniteScroll";
|
||||
import AlertMessage from "@/components/AlertMessage";
|
||||
import QuickNav from "@/components/QuickNav";
|
||||
|
||||
/**
|
||||
* Represents data about a project
|
||||
**/
|
||||
interface ProjectData {
|
||||
/**
|
||||
* Name of the project
|
||||
**/
|
||||
name: string;
|
||||
/**
|
||||
* Description of the project
|
||||
**/
|
||||
description: string;
|
||||
/**
|
||||
* URL referencing information about the project
|
||||
**/
|
||||
handleId: string;
|
||||
/**
|
||||
* The Identier of the project
|
||||
**/
|
||||
rowid: string;
|
||||
}
|
||||
|
||||
@Component({
|
||||
components: { InfiniteScroll, AlertMessage, QuickNav },
|
||||
})
|
||||
@@ -115,6 +93,14 @@ 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* Core project data loader
|
||||
@@ -130,14 +116,15 @@ export default class ProjectsView extends Vue {
|
||||
try {
|
||||
this.isLoading = true;
|
||||
const resp = await this.axios.get(url, { headers });
|
||||
if (resp.status === 200) {
|
||||
if (resp.status === 200 || !resp.data.data) {
|
||||
const plans: ProjectData[] = resp.data.data;
|
||||
for (const plan of plans) {
|
||||
const { name, description, handleId = plan.fullIri, rowid } = plan;
|
||||
this.projects.push({ name, description, handleId, rowid });
|
||||
}
|
||||
} else {
|
||||
console.log(resp.status);
|
||||
console.log("Bad server response & data:", resp.status, resp.data);
|
||||
throw Error("Failed to get projects from the server.");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Got error loading projects:", error.message);
|
||||
@@ -183,6 +170,22 @@ export default class ProjectsView extends Vue {
|
||||
await this.dataLoader(url, token);
|
||||
}
|
||||
|
||||
public async getIdentity(activeDid) {
|
||||
await accountsDB.open();
|
||||
const account = await accountsDB.accounts
|
||||
.where("did")
|
||||
.equals(activeDid)
|
||||
.first();
|
||||
const identity = JSON.parse(account?.identity || "null");
|
||||
|
||||
if (!identity) {
|
||||
throw new Error(
|
||||
"Attempted to load project records with no identity available.",
|
||||
);
|
||||
}
|
||||
return identity;
|
||||
}
|
||||
|
||||
/**
|
||||
* 'created' hook runs when the Vue instance is first created
|
||||
**/
|
||||
@@ -193,26 +196,19 @@ export default class ProjectsView extends Vue {
|
||||
const activeDid = settings?.activeDid || "";
|
||||
this.apiServer = settings?.apiServer || "";
|
||||
|
||||
await accountsDB.open();
|
||||
const num_accounts = await accountsDB.accounts.count();
|
||||
if (num_accounts === 0) {
|
||||
console.error("Problem! You need a profile!");
|
||||
this.alertTitle = "Error!";
|
||||
this.alertMessage = "Problem! You need a profile!";
|
||||
if (this.numAccounts === 0) {
|
||||
console.error("No accounts found.");
|
||||
this.alertTitle = "Error";
|
||||
this.alertMessage = "You need an identity to load your projects.";
|
||||
} else {
|
||||
const accounts = await accountsDB.accounts.toArray();
|
||||
const account = R.find((acc) => acc.did === activeDid, accounts);
|
||||
const identity = JSON.parse(account?.identity || "null");
|
||||
if (!identity) {
|
||||
throw new Error("No identity found.");
|
||||
}
|
||||
const identity = await this.getIdentity(activeDid);
|
||||
this.current = identity;
|
||||
this.LoadProjects(identity);
|
||||
}
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
this.alertTitle = "Error!";
|
||||
this.alertMessage = "Problem! You need a profile!";
|
||||
console.log("Error initializing:", err);
|
||||
this.alertTitle = "Error";
|
||||
this.alertMessage = "Something went wrong loading your projects.";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,9 +28,9 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { Options, Vue } from "vue-class-component";
|
||||
import { Component, Vue } from "vue-facing-decorator";
|
||||
|
||||
@Options({
|
||||
@Component({
|
||||
components: {},
|
||||
})
|
||||
export default class StartView extends Vue {
|
||||
|
||||
@@ -39,15 +39,7 @@
|
||||
:alertMessage="alertMessage"
|
||||
></AlertMessage>
|
||||
</section>
|
||||
</template> /**
|
||||
// from https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob#examples
|
||||
// Adds a blank image const dataBlob = document
|
||||
.querySelector("#scene-container") .firstChild.toBlob((blob) => { const newImg =
|
||||
document.createElement("img"); const url = URL.createObjectURL(blob);
|
||||
newImg.onload = () => { // no longer need to read the blob so it's revoked
|
||||
URL.revokeObjectURL(url); }; newImg.src = url;
|
||||
document.body.appendChild(newImg); }); **/
|
||||
|
||||
</template>
|
||||
<script lang="ts">
|
||||
import { SVGRenderer } from "three/addons/renderers/SVGRenderer.js";
|
||||
import { Component, Vue } from "vue-facing-decorator";
|
||||
@@ -55,11 +47,6 @@ import { World } from "@/components/World/World.js";
|
||||
import AlertMessage from "@/components/AlertMessage";
|
||||
import QuickNav from "@/components/QuickNav";
|
||||
|
||||
interface WorldProperties {
|
||||
startTime?: string;
|
||||
endTime?: string;
|
||||
}
|
||||
|
||||
@Component({ components: { AlertMessage, World, QuickNav } })
|
||||
export default class StatisticsView extends Vue {
|
||||
world: World;
|
||||
@@ -70,7 +57,6 @@ export default class StatisticsView extends Vue {
|
||||
mounted() {
|
||||
try {
|
||||
const container = document.querySelector("#scene-container");
|
||||
console.log(container);
|
||||
const newWorld = new World(container, this);
|
||||
newWorld.start();
|
||||
this.world = newWorld;
|
||||
|
||||
Reference in New Issue
Block a user