From dffa007a74eb3c3456f46378c0cb527b0372db97 Mon Sep 17 00:00:00 2001 From: Trent Larson Date: Sat, 29 Jun 2024 10:18:56 -0600 Subject: [PATCH] add advanced page & flag for editing raw claims, and fix recipient assignment in detail screen --- src/db/tables/settings.ts | 1 + src/libs/endorserServer.ts | 63 +++++++++---- src/router/index.ts | 5 ++ src/views/AccountViewView.vue | 133 ++++++++++++++++++--------- src/views/ClaimAddRawView.vue | 133 +++++++++++++++++++++++++++ src/views/GiftedDetails.vue | 163 +++++++++++++++++++++++++--------- 6 files changed, 395 insertions(+), 103 deletions(-) create mode 100644 src/views/ClaimAddRawView.vue diff --git a/src/db/tables/settings.ts b/src/db/tables/settings.ts index f7ab6bf..ac5cde9 100644 --- a/src/db/tables/settings.ts +++ b/src/db/tables/settings.ts @@ -37,6 +37,7 @@ export type Settings = { }>; showContactGivesInline?: boolean; // Display contact inline or not + showGeneralAdvanced?: boolean; // Show advanced features which don't have their own flag showShortcutBvc?: boolean; // Show shortcut for Bountiful Voluntaryist Community actions vapid?: string; // VAPID (Voluntary Application Server Identification) field for web push warnIfProdServer?: boolean; // Warn if using a production server diff --git a/src/libs/endorserServer.ts b/src/libs/endorserServer.ts index 9dfb078..835fe5d 100644 --- a/src/libs/endorserServer.ts +++ b/src/libs/endorserServer.ts @@ -160,7 +160,7 @@ export interface OfferVerifiableCredential { // Note that previous VCs may have additional fields. // https://endorser.ch/doc/html/transactions.html#id7 export interface PlanVerifiableCredential { - "@context": "https://schema.org"; + "@context": SCHEMA_ORG_CONTEXT; "@type": "PlanAction"; name: string; agent?: { identifier: string }; @@ -518,19 +518,7 @@ export async function setPlanInCache( planCache.set(handleId, planSummary); } -/** - * For result, see https://api.endorser.ch/api-docs/#/claims/post_api_v2_claim - * - * @param identity - * @param fromDid may be null - * @param toDid - * @param description may be null; should have this or amount - * @param amount may be null; should have this or description - */ -export async function createAndSubmitGive( - axios: Axios, - apiServer: string, - identity: IIdentifier, +export function constructGive( fromDid?: string | null, toDid?: string, description?: string, @@ -540,9 +528,9 @@ export async function createAndSubmitGive( fulfillsOfferHandleId?: string, isTrade: boolean = false, imageUrl?: string, -): Promise { +): GiveVerifiableCredential { const vcClaim: GiveVerifiableCredential = { - "@context": "https://schema.org", + "@context": SCHEMA_ORG_CONTEXT, "@type": "GiveAction", recipient: toDid ? { identifier: toDid } : undefined, agent: fromDid ? { identifier: fromDid } : undefined, @@ -569,6 +557,43 @@ export async function createAndSubmitGive( if (imageUrl) { vcClaim.image = imageUrl; } + return vcClaim; +} + +/** + * For result, see https://api.endorser.ch/api-docs/#/claims/post_api_v2_claim + * + * @param identity + * @param fromDid may be null + * @param toDid + * @param description may be null; should have this or amount + * @param amount may be null; should have this or description + */ +export async function createAndSubmitGive( + axios: Axios, + apiServer: string, + identity: IIdentifier, + fromDid?: string | null, + toDid?: string, + description?: string, + amount?: number, + unitCode?: string, + fulfillsProjectHandleId?: string, + fulfillsOfferHandleId?: string, + isTrade: boolean = false, + imageUrl?: string, +): Promise { + const vcClaim = constructGive( + fromDid, + toDid, + description, + amount, + unitCode, + fulfillsProjectHandleId, + fulfillsOfferHandleId, + isTrade, + imageUrl, + ); return createAndSubmitClaim( vcClaim as GenericCredWrapper, identity, @@ -598,7 +623,7 @@ export async function createAndSubmitOffer( fulfillsProjectHandleId?: string, ): Promise { const vcClaim: OfferVerifiableCredential = { - "@context": "https://schema.org", + "@context": SCHEMA_ORG_CONTEXT, "@type": "Offer", offeredBy: { identifier: identity.did }, validThrough: expirationDate || undefined, @@ -645,7 +670,7 @@ export const createAndSubmitConfirmation = async ( ), ); const confirmationClaim: GenericVerifiableCredential = { - "@context": "https://schema.org", + "@context": SCHEMA_ORG_CONTEXT, "@type": "AgreeAction", object: goodClaim, }; @@ -928,7 +953,7 @@ export async function register( const identity = await getIdentity(activeDid); const vcClaim: RegisterVerifiableCredential = { - "@context": "https://schema.org", + "@context": SCHEMA_ORG_CONTEXT, "@type": "RegisterAction", agent: { identifier: identity.did }, object: SERVICE_ID, diff --git a/src/router/index.ts b/src/router/index.ts index c44739d..54850bf 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -38,6 +38,11 @@ const routes: Array = [ name: "claim", component: () => import("../views/ClaimView.vue"), }, + { + path: "/claim-add-raw/:id?", + name: "claim-add-raw", + component: () => import("../views/ClaimAddRawView.vue"), + }, { path: "/confirm-contact", name: "confirm-contact", diff --git a/src/views/AccountViewView.vue b/src/views/AccountViewView.vue index a1e1de2..98fbf5b 100644 --- a/src/views/AccountViewView.vue +++ b/src/views/AccountViewView.vue @@ -314,7 +314,7 @@ > Advanced -
+

Beware: the features here can be confusing and even change data in ways you do not expect. But we support your freedom! @@ -386,6 +386,27 @@ Switch Identifier +

+

+ Contacts & Settings Database +

+ +
+ Import + +
+ +
+
+
+ -
-

- Contacts & Settings Database -

- -
- Import - -
- -
-
-
-
+ +