Browse Source

for BVC shortcut: send attend & give actions, and list actions to confirm

kb/add-usage-guide
Trent Larson 9 months ago
parent
commit
2058205150
  1. 4
      src/App.vue
  2. 19
      src/components/GiftedDialog.vue
  3. 27
      src/components/OfferDialog.vue
  4. 37
      src/libs/endorserServer.ts
  5. 30
      src/libs/util.ts
  6. 2
      src/views/AccountViewView.vue
  7. 2
      src/views/ContactAmountsView.vue
  8. 2
      src/views/ContactGiftingView.vue
  9. 3
      src/views/ContactQRScanShowView.vue
  10. 18
      src/views/ContactsView.vue
  11. 8
      src/views/DiscoverView.vue
  12. 8
      src/views/HomeView.vue
  13. 131
      src/views/QuickActionBvcBeginView.vue
  14. 71
      src/views/QuickActionBvcEndView.vue
  15. 2
      src/views/QuickActionBvcView.vue

4
src/App.vue

@ -582,7 +582,7 @@ export default class App extends Vue {
}
})
.catch((error) => {
console.log("Push provider server communication failed:", error);
console.error("Push provider server communication failed:", error);
return false;
});
@ -597,7 +597,7 @@ export default class App extends Vue {
return response.ok;
})
.catch((error) => {
console.log("Push server communication failed:", error);
console.error("Push server communication failed:", error);
return false;
});

19
src/components/GiftedDialog.vue

@ -77,7 +77,6 @@ import {
import * as libsUtil from "@/libs/util";
import { accountsDB, db } from "@/db/index";
import { MASTER_SETTINGS_KEY, Settings } from "@/db/tables/settings";
import { Account } from "@/db/tables/accounts";
import { Contact } from "@/db/tables/contacts";
@Component
@ -206,22 +205,6 @@ export default class GiftedDialog extends Vue {
});
}
public async getIdentity(activeDid: string) {
await accountsDB.open();
const account = (await accountsDB.accounts
.where("did")
.equals(activeDid)
.first()) as Account;
const identity = JSON.parse(account?.identity || "null");
if (!identity) {
throw new Error(
"Attempted to load Give records for DID ${activeDid} but no identifier was found",
);
}
return identity;
}
/**
*
* @param giverDid may be null
@ -262,7 +245,7 @@ export default class GiftedDialog extends Vue {
}
try {
const identity = await this.getIdentity(this.activeDid);
const identity = await libsUtil.getIdentity(this.activeDid);
const result = await createAndSubmitGive(
this.axios,
this.apiServer,

27
src/components/OfferDialog.vue

@ -72,9 +72,8 @@ import { Vue, Component, Prop } from "vue-facing-decorator";
import { NotificationIface } from "@/constants/app";
import { createAndSubmitOffer } from "@/libs/endorserServer";
import * as libsUtil from "@/libs/util";
import { accountsDB, db } from "@/db/index";
import { db } from "@/db/index";
import { MASTER_SETTINGS_KEY, Settings } from "@/db/tables/settings";
import { Account } from "@/db/tables/accounts";
@Component
export default class OfferDialog extends Vue {
@ -102,7 +101,7 @@ export default class OfferDialog extends Vue {
this.activeDid = settings?.activeDid || "";
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (err: any) {
console.log("Error retrieving settings from database:", err);
console.error("Error retrieving settings from database:", err);
this.$notify(
{
group: "alert",
@ -173,22 +172,6 @@ export default class OfferDialog extends Vue {
});
}
public async getIdentity(activeDid: string) {
await accountsDB.open();
const account = (await accountsDB.accounts
.where("did")
.equals(activeDid)
.first()) as Account;
const identity = JSON.parse(account?.identity || "null");
if (!identity) {
throw new Error(
`Attempted to load Offer records for DID ${activeDid} but no identifier was found`,
);
}
return identity;
}
/**
*
* @param description may be an empty string
@ -228,7 +211,7 @@ export default class OfferDialog extends Vue {
}
try {
const identity = await this.getIdentity(this.activeDid);
const identity = await libsUtil.getIdentity(this.activeDid);
const result = await createAndSubmitOffer(
this.axios,
this.apiServer,
@ -245,7 +228,7 @@ export default class OfferDialog extends Vue {
this.isOfferCreationError(result.response)
) {
const errorMessage = this.getOfferCreationErrorMessage(result);
console.log("Error with offer creation result:", result);
console.error("Error with offer creation result:", result);
this.$notify(
{
group: "alert",
@ -268,7 +251,7 @@ export default class OfferDialog extends Vue {
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (error: any) {
console.log("Error with offer recordation caught:", error);
console.error("Error with offer recordation caught:", error);
const message =
error.userMessage ||
error.response?.data?.error?.message ||

37
src/libs/endorserServer.ts

@ -229,16 +229,16 @@ export interface ErrorResponse {
};
}
export interface ErrorResult {
type: "error";
error: InternalError;
}
export interface InternalError {
error: string; // for system logging
userMessage?: string; // for user display
}
export interface ErrorResult extends ResultWithType {
type: "error";
error: InternalError;
}
export type CreateAndSubmitClaimResult = SuccessResult | ErrorResult;
// This is used to check for hidden info.
@ -758,12 +758,23 @@ export const claimSpecialDescription = (
}
};
// from https://stackoverflow.com/a/175787/845494
//
export function isNumeric(str: string): boolean {
return !isNaN(+str);
}
export const BVC_MEETUPS_PROJECT_CLAIM_ID =
//"https://endorser.ch/entity/01GXYPFF7FA03NXKPYY142PY4H";
"https://endorser.ch/entity/01HNTZYJJXTGT0EZS3VEJGX7AK";
export function numberOrZero(str: string): number {
return isNumeric(str) ? +str : 0;
}
export const bvcMeetingJoinClaim = (did: string, startTime: string) => {
return {
"@context": SCHEMA_ORG_CONTEXT,
"@type": "JoinAction",
agent: {
identifier: did,
},
event: {
organizer: {
name: "Bountiful Voluntaryist Community",
},
name: "Saturday Morning Meeting",
startTime: startTime,
},
};
};

30
src/libs/util.ts

@ -1,14 +1,16 @@
// many of these are also found in endorser-mobile utility.ts
import axios, { AxiosResponse } from "axios";
import { IIdentifier } from "@veramo/core";
import { useClipboard } from "@vueuse/core";
import { DEFAULT_PUSH_SERVER } from "@/constants/app";
import { accountsDB, db } from "@/db/index";
import { Account } from "@/db/tables/accounts";
import { MASTER_SETTINGS_KEY } from "@/db/tables/settings";
import { deriveAddress, generateSeed, newIdentifier } from "@/libs/crypto";
import { GenericServerRecord, containsHiddenDid } from "@/libs/endorserServer";
import * as serverUtil from "@/libs/endorserServer";
import { useClipboard } from "@vueuse/core";
// eslint-disable-next-line @typescript-eslint/no-var-requires
const Buffer = require("buffer/").Buffer;
@ -55,6 +57,16 @@ export function iconForUnitCode(unitCode: string) {
return UNIT_CODES[unitCode]?.faIcon || "question";
}
// from https://stackoverflow.com/a/175787/845494
//
export function isNumeric(str: string): boolean {
return !isNaN(+str);
}
export function numberOrZero(str: string): number {
return isNumeric(str) ? +str : 0;
}
export const isGlobalUri = (uri: string) => {
return uri && uri.match(new RegExp(/^[A-Za-z][A-Za-z0-9+.-]+:/));
};
@ -180,6 +192,22 @@ export function findAllVisibleToDids(
*
**/
export const getIdentity = async (activeDid: string): Promise<IIdentifier> => {
await accountsDB.open();
const account = (await accountsDB.accounts
.where("did")
.equals(activeDid)
.first()) as Account;
const identity = JSON.parse(account?.identity || "null");
if (!identity) {
throw new Error(
`Attempted to load Offer records for DID ${activeDid} but no identifier was found`,
);
}
return identity;
};
/**
* Generates a new identity, saves it to the database, and sets it as the active identity.
* @return {Promise<string>} with the DID of the new identity

2
src/views/AccountViewView.vue

@ -446,7 +446,7 @@
>
<!-- label -->
<span class="text-slate-500 text-sm font-bold"
>Show Shortcut on Home Page</span
>Show BVC Shortcut on Home Page</span
>
<!-- toggle -->
<div class="relative ml-2">

2
src/views/ContactAmountsView.vue

@ -179,7 +179,7 @@ export default class ContactAmountssView extends Vue {
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (err: any) {
console.log("Error retrieving settings or gives.", err);
console.error("Error retrieving settings or gives.", err);
this.$notify(
{
group: "alert",

2
src/views/ContactGiftingView.vue

@ -119,7 +119,7 @@ export default class ContactGiftingView extends Vue {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (err: any) {
console.log("Error retrieving settings & contacts:", err);
console.error("Error retrieving settings & contacts:", err);
this.$notify(
{
group: "alert",

3
src/views/ContactQRScanShowView.vue

@ -180,7 +180,6 @@ export default class ContactQRScanShow extends Vue {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
onScanDetect(content: any) {
if (content[0]?.rawValue) {
//console.log("onDetect", content[0].rawValue);
localStorage.setItem("contactEndorserUrl", content[0].rawValue);
this.$router.push({ name: "contacts" });
} else {
@ -198,7 +197,7 @@ export default class ContactQRScanShow extends Vue {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
onScanError(error: any) {
console.log("Scan was invalid:", error);
console.error("Scan was invalid:", error);
this.$notify(
{
group: "alert",

18
src/views/ContactsView.vue

@ -284,6 +284,7 @@
<script lang="ts">
import { AxiosError } from "axios";
import { IndexableType } from "dexie";
import * as didJwt from "did-jwt";
import * as R from "ramda";
import { IIdentifier } from "@veramo/core";
@ -311,7 +312,6 @@ import * as libsUtil from "@/libs/util";
import QuickNav from "@/components/QuickNav.vue";
import EntityIcon from "@/components/EntityIcon.vue";
import { Account } from "@/db/tables/accounts";
import { IndexableType } from "dexie";
// eslint-disable-next-line @typescript-eslint/no-var-requires
const Buffer = require("buffer/").Buffer;
@ -497,7 +497,7 @@ export default class ContactsView extends Vue {
this.givenToMeConfirmed = givenToMeConfirmed;
this.givenToMeUnconfirmed = givenToMeUnconfirmed;
} catch (error) {
console.log("Error loading gives", error);
console.error("Error loading gives", error);
this.$notify(
{
group: "alert",
@ -1000,7 +1000,7 @@ export default class ContactsView extends Vue {
-1,
);
} else {
console.log("Got bad server response when checking visibility: ", resp);
console.error("Got bad server response checking visibility:", resp);
const message = resp.data.error?.message || "Got bad server response.";
this.$notify(
{
@ -1013,7 +1013,7 @@ export default class ContactsView extends Vue {
);
}
} catch (err) {
console.log("Caught error from request to check visibility:", err);
console.error("Caught error from request to check visibility:", err);
this.$notify(
{
group: "alert",
@ -1026,12 +1026,6 @@ export default class ContactsView extends Vue {
}
}
// from https://stackoverflow.com/a/175787/845494
//
private isNumeric(str: string): boolean {
return !isNaN(+str);
}
private nameForDid(contacts: Array<Contact>, did: string): string {
const contact = R.find((con) => con.did == did, contacts);
return this.nameForContact(contact);
@ -1067,7 +1061,7 @@ export default class ContactsView extends Vue {
return;
}
}
if (!this.isNumeric(this.hourInput)) {
if (!libsUtil.isNumeric(this.hourInput)) {
this.$notify(
{
group: "alert",
@ -1204,7 +1198,7 @@ export default class ContactsView extends Vue {
}
}
} catch (error) {
console.log("Error in createAndSubmitContactGive: ", error);
console.error("Error in createAndSubmitContactGive: ", error);
let userMessage = "There was an error. See logs for more info.";
const serverError = error as AxiosError;
if (serverError) {

8
src/views/DiscoverView.vue

@ -254,7 +254,7 @@ export default class DiscoverView extends Vue {
if (response.status !== 200) {
const details = await response.text();
console.log("Problem with full search:", details);
console.error("Problem with full search:", details);
this.$notify(
{
group: "alert",
@ -282,7 +282,7 @@ export default class DiscoverView extends Vue {
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (e: any) {
console.log("Error with feed load:", e);
console.error("Error with feed load:", e);
this.$notify(
{
group: "alert",
@ -337,7 +337,7 @@ export default class DiscoverView extends Vue {
if (response.status !== 200) {
const details = await response.text();
console.log("Problem with nearby search:", details);
console.error("Problem with nearby search:", details);
this.$notify(
{
group: "alert",
@ -374,7 +374,7 @@ export default class DiscoverView extends Vue {
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (e: any) {
console.log("Error with feed load:", e);
console.error("Error with feed load:", e);
this.$notify(
{
group: "alert",

8
src/views/HomeView.vue

@ -3,8 +3,8 @@
<TopMessage />
<!-- CONTENT -->
<section id="Content" class="p-6 pb-24 max-w-3xl mx-auto">
<h1 id="ViewHeading" class="text-4xl text-center font-light pt-4 mb-8">
<section id="Content" class="p-2 pb-24 max-w-3xl mx-auto">
<h1 id="ViewHeading" class="text-4xl text-center font-light px-4 mb-8">
Time Safari
</h1>
@ -346,7 +346,7 @@ export default class HomeView extends Vue {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (err: any) {
console.log("Error retrieving settings or feed.", err);
console.error("Error retrieving settings or feed.", err);
this.$notify(
{
group: "alert",
@ -452,7 +452,7 @@ export default class HomeView extends Vue {
}
})
.catch((e) => {
console.log("Error with feed load:", e);
console.error("Error with feed load:", e);
this.$notify(
{
group: "alert",

131
src/views/QuickActionBvcBeginView.vue

@ -15,20 +15,24 @@
</div>
<!-- Heading -->
<h1 id="ViewHeading" class="text-4xl text-center font-light pt-4 mb-4">
<h1 id="ViewHeading" class="text-4xl text-center font-light px-4 mb-4">
Beginning of BVC Saturday Meeting
</h1>
<div>
<h2 class="text-2xl m-4">You're Here</h2>
<div class="m-4 flex">
<input type="checkbox" v-model="gaveTime" class="h-6 w-6" />
<h2 class="text-2xl m-2">You're Here</h2>
<div class="m-2 flex">
<input type="checkbox" v-model="attended" class="h-6 w-6" />
<span class="pb-2 pl-2 pr-2">Attended</span>
</div>
<div class="m-2 flex">
<input type="checkbox" v-model="gaveTime" class="h-6 w-6" />
<span class="pb-2 pl-2 pr-2">Spent Time</span>
<span v-if="gaveTime">
<input
type="text"
placeholder="How much time"
v-model="hours"
v-model="hoursStr"
size="1"
class="border border-slate-400 h-6 px-2"
/>
@ -39,25 +43,44 @@
</div>
</div>
<div class="m-4" v-if="gaveTime && hours && hours != '0'">
<div
v-if="attended || (gaveTime && hoursStr && hoursStr != '0')"
class="flex justify-center mt-4"
>
<button
@click="record()"
class="block text-center text-md font-bold bg-blue-500 text-white px-2 py-3 rounded-md"
class="block text-center text-md font-bold bg-blue-500 text-white px-2 py-3 rounded-md w-56"
>
Sign & Send
</button>
</div>
<div v-else class="flex justify-center mt-4">
<button
class="block text-center text-md font-bold bg-slate-500 text-white px-2 py-3 rounded-md w-56"
>
Select Your Actions
</button>
</div>
</section>
</template>
<script lang="ts">
import axios from "axios";
import { DateTime } from "luxon";
import { Component, Vue } from "vue-facing-decorator";
import QuickNav from "@/components/QuickNav.vue";
import TopMessage from "@/components/TopMessage.vue";
import { NotificationIface } from "@/constants/app";
import { numberOrZero } from "@/libs/endorserServer";
import { db } from "@/db/index";
import {
BVC_MEETUPS_PROJECT_CLAIM_ID,
bvcMeetingJoinClaim,
createAndSubmitClaim,
createAndSubmitGive,
} from "@/libs/endorserServer";
import * as libsUtil from "@/libs/util";
import { MASTER_SETTINGS_KEY, Settings } from "@/db/tables/settings";
@Component({
components: {
@ -68,8 +91,11 @@ import { numberOrZero } from "@/libs/endorserServer";
export default class QuickActionBvcBeginView extends Vue {
$notify!: (notification: NotificationIface, timeout?: number) => void;
gaveTime = false;
hours = "1";
activeDid = "";
apiServer = "";
attended = true;
gaveTime = true;
hoursStr = "1";
todayOrPreviousStartDate = "";
async mounted() {
@ -91,9 +117,88 @@ export default class QuickActionBvcBeginView extends Vue {
}) || "";
}
record() {
const hoursNum = numberOrZero(this.hours);
alert("Nope" + hoursNum);
async record() {
await db.open();
const settings = (await db.settings.get(MASTER_SETTINGS_KEY)) as Settings;
const activeDid = settings?.activeDid || "";
const apiServer = settings?.apiServer || "";
try {
const hoursNum = libsUtil.numberOrZero(this.hoursStr);
const identity = await libsUtil.getIdentity(activeDid);
const result = await createAndSubmitGive(
axios,
apiServer,
identity,
activeDid,
undefined,
undefined,
hoursNum,
"HUR",
BVC_MEETUPS_PROJECT_CLAIM_ID,
);
if (result.type === "error") {
console.error("Error sending give:", result);
this.$notify(
{
group: "alert",
type: "danger",
title: "Error",
text:
result?.error?.userMessage ||
"There was an error sending the give.",
},
-1,
);
}
const result2 = await createAndSubmitClaim(
bvcMeetingJoinClaim(this.activeDid, this.todayOrPreviousStartDate),
identity,
apiServer,
axios,
);
if (result2.type === "error") {
console.error("Error sending give:", result2);
this.$notify(
{
group: "alert",
type: "danger",
title: "Error",
text:
result2?.error?.userMessage ||
"There was an error sending the attendance.",
},
-1,
);
}
if (result.type === "success" || result2.type === "success") {
this.$notify(
{
group: "alert",
type: "success",
title: "Success",
text: "Your actions have been recorded.",
},
-1,
);
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (error: any) {
console.error("Error sending claims.", error);
this.$notify(
{
group: "alert",
type: "danger",
title: "Error",
text: error.userMessage || "There was an error sending those claims.",
},
-1,
);
}
}
}
</script>

71
src/views/QuickActionBvcEndView.vue

@ -15,19 +15,26 @@
</div>
<!-- Heading -->
<h1 id="ViewHeading" class="text-4xl text-center font-light pt-4 mb-4">
<h1 id="ViewHeading" class="text-4xl text-center font-light px-4 mb-4">
End of BVC Saturday Meeting
</h1>
<div>
<h2 class="text-2xl m-4">Confirm</h2>
<div v-if="claimsToConfirm.length === 0">
There are no claims today yet for you to confirm.
<span v-if="claimCountWithHidden">
(There are {{ claimCountWithHidden }} hidden claims.)
<h2 class="text-2xl m-2">Confirm</h2>
<div v-if="loadingConfirms" class="flex justify-center">
<fa icon="spinner" class="animate-spin" />
</div>
<div v-else-if="claimsToConfirm.length === 0">
There are no claims yet today for you to confirm.
<span v-if="claimCountWithHidden > 0">
{{
claimCountWithHidden === 1
? "(There is 1 claim with hidden details.)"
: `(There are ${claimCountWithHidden} claims with hidden details.)`
}}
</span>
</div>
<ul class="border-t border-slate-300">
<ul class="border-t border-slate-300 m-2">
<li
class="border-b border-slate-300 py-2"
v-for="record in claimsToConfirm"
@ -36,7 +43,19 @@
<div class="grid grid-cols-12">
<span class="col-span-11 justify-self-start">
<span>
<input type="checkbox" class="mr-2 h-6 w-6" />
<input
type="checkbox"
:checked="claimsToConfirmSelected.includes(record.id)"
@click="
claimsToConfirmSelected.includes(record.id)
? claimsToConfirmSelected.splice(
claimsToConfirmSelected.indexOf(record.id),
1,
)
: claimsToConfirmSelected.push(record.id)
"
class="mr-2 h-6 w-6"
/>
</span>
{{
claimSpecialDescription(
@ -59,10 +78,10 @@
</div>
<div>
<h2 class="text-2xl m-4">Anything else?</h2>
<div class="m-4 flex">
<h2 class="text-2xl m-2">Anything else?</h2>
<div class="m-2 flex">
<input type="checkbox" v-model="someoneGave" class="h-6 w-6" />
<span class="pb-2 pl-2 pr-2">Someone gave</span>
<span class="pb-2 pl-2 pr-2">Someone else gave</span>
<span v-if="someoneGave">
<input
type="text"
@ -76,14 +95,24 @@
</div>
</div>
<div class="m-4" v-if="someoneGave && description">
<div
v-if="claimsToConfirmSelected.length || (someoneGave && description)"
class="flex justify-center mt-4"
>
<button
@click="record()"
class="block text-center text-md font-bold bg-blue-500 text-white px-2 py-3 rounded-md"
class="block text-center text-md font-bold bg-blue-500 text-white px-2 py-3 rounded-md w-56"
>
Sign & Send
</button>
</div>
<div v-else class="flex justify-center mt-4">
<button
class="block text-center text-md font-bold bg-slate-500 text-white px-2 py-3 rounded-md w-56"
>
Choose What To Confirm
</button>
</div>
</section>
</template>
@ -123,7 +152,9 @@ export default class QuickActionBvcBeginView extends Vue {
apiServer = "";
claimCountWithHidden = 0;
claimsToConfirm: GenericServerRecord[] = [];
description = "";
claimsToConfirmSelected: string[] = [];
description = "breakfast";
loadingConfirms = true;
someoneGave = false;
async created() {
@ -135,6 +166,7 @@ export default class QuickActionBvcBeginView extends Vue {
}
async mounted() {
this.loadingConfirms = true;
let currentOrPreviousSat = DateTime.now().setZone("America/Denver");
if (currentOrPreviousSat.weekday < 6) {
// it's not Saturday or Sunday,
@ -165,15 +197,7 @@ export default class QuickActionBvcBeginView extends Vue {
const headers = {
Authorization: "Bearer " + (await accessToken(identity)),
};
console.log("todayOrPreviousStartDate", todayOrPreviousStartDate);
try {
console.log(
this.apiServer +
"/api/claim/?" +
"issuedAt_greaterThanOrEqualTo=" +
encodeURIComponent(todayOrPreviousStartDate) +
"&excludeConfirmations=true",
);
const response = await fetch(
this.apiServer +
"/api/claim/?" +
@ -187,7 +211,7 @@ export default class QuickActionBvcBeginView extends Vue {
console.log("Bad response", response);
throw new Error("Bad response when retrieving claims.");
}
response.json().then((data) => {
await response.json().then((data) => {
const dataByOthers = R.reject(
(claim: GenericServerRecord) => claim.issuer === this.activeDid,
data,
@ -212,6 +236,7 @@ export default class QuickActionBvcBeginView extends Vue {
-1,
);
}
this.loadingConfirms = false;
}
onClickLoadClaim(jwtId: string) {

2
src/views/QuickActionBvcView.vue

@ -15,7 +15,7 @@
</div>
<!-- Heading -->
<h1 id="ViewHeading" class="text-4xl text-center font-light pt-4 mb-4">
<h1 id="ViewHeading" class="text-4xl text-center font-light px-4 mb-4">
Bountiful Voluntaryist Community Actions
</h1>

Loading…
Cancel
Save