From bba183dc466fffa392d6505c92771b8d2a95e975 Mon Sep 17 00:00:00 2001 From: Trent Larson Date: Sun, 21 Apr 2024 07:38:59 -0600 Subject: [PATCH] add 'offer' on contact screen --- src/components/OfferDialog.vue | 10 +++++++--- src/libs/endorserServer.ts | 5 +++++ src/views/ClaimView.vue | 3 +-- src/views/ContactsView.vue | 23 +++++++++++++++++++---- 4 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/components/OfferDialog.vue b/src/components/OfferDialog.vue index efbe7d78..980a61f1 100644 --- a/src/components/OfferDialog.vue +++ b/src/components/OfferDialog.vue @@ -81,8 +81,7 @@ import { MASTER_SETTINGS_KEY, Settings } from "@/db/tables/settings"; export default class OfferDialog extends Vue { $notify!: (notification: NotificationIface, timeout?: number) => void; - @Prop message = ""; - @Prop projectId = ""; + @Prop projectId? = ""; activeDid = ""; apiServer = ""; @@ -91,16 +90,20 @@ export default class OfferDialog extends Vue { amountUnitCode = "HUR"; description = ""; expirationDateInput = ""; + recipientDid? = ""; visible = false; libsUtil = libsUtil; - async open() { + async open(recipientDid?: string) { try { + this.recipientDid = recipientDid; + await db.open(); const settings = (await db.settings.get(MASTER_SETTINGS_KEY)) as Settings; this.apiServer = settings?.apiServer || ""; this.activeDid = settings?.activeDid || ""; + // eslint-disable-next-line @typescript-eslint/no-explicit-any } catch (err: any) { console.error("Error retrieving settings from database:", err); @@ -222,6 +225,7 @@ export default class OfferDialog extends Vue { amount, unitCode, expirationDateInput, + this.recipientDid, this.projectId, ); diff --git a/src/libs/endorserServer.ts b/src/libs/endorserServer.ts index 65371ef8..a51467f9 100644 --- a/src/libs/endorserServer.ts +++ b/src/libs/endorserServer.ts @@ -143,6 +143,7 @@ export interface OfferVerifiableCredential { isPartOf?: { identifier?: string; lastClaimId?: string; "@type"?: string }; }; offeredBy?: { identifier: string }; + recipient?: { identifier: string }; validThrough?: string; } @@ -582,6 +583,7 @@ export async function createAndSubmitOffer( amount?: number, unitCode?: string, expirationDate?: string, + recipientDid?: string, fulfillsProjectHandleId?: string, ): Promise { const vcClaim: OfferVerifiableCredential = { @@ -599,6 +601,9 @@ export async function createAndSubmitOffer( if (description) { vcClaim.itemOffered = { description }; } + if (recipientDid) { + vcClaim.recipient = { identifier: recipientDid }; + } if (fulfillsProjectHandleId) { vcClaim.itemOffered = vcClaim.itemOffered || {}; vcClaim.itemOffered.isPartOf = { diff --git a/src/views/ClaimView.vue b/src/views/ClaimView.vue index e47e40ef..e1ba5489 100644 --- a/src/views/ClaimView.vue +++ b/src/views/ClaimView.vue @@ -406,7 +406,6 @@ import { Component, Vue } from "vue-facing-decorator"; import { useClipboard } from "@vueuse/core"; import GiftedDialog from "@/components/GiftedDialog.vue"; -import OfferDialog from "@/components/OfferDialog.vue"; import { NotificationIface } from "@/constants/app"; import { accountsDB, db } from "@/db/index"; import { Contact } from "@/db/tables/contacts"; @@ -419,7 +418,7 @@ import { Account } from "@/db/tables/accounts"; import { GiverInputInfo } from "@/libs/endorserServer"; @Component({ - components: { GiftedDialog, OfferDialog, QuickNav }, + components: { GiftedDialog, QuickNav }, }) export default class ClaimView extends Vue { $notify!: (notification: NotificationIface, timeout?: number) => void; diff --git a/src/views/ContactsView.vue b/src/views/ContactsView.vue index 6f1119d4..aecd2339 100644 --- a/src/views/ContactsView.vue +++ b/src/views/ContactsView.vue @@ -177,7 +177,7 @@ + + @@ -241,6 +248,9 @@

There are no contacts.

+ + +
void; @@ -1131,6 +1142,10 @@ export default class ContactsView extends Vue { } } + openOfferDialog(recipientDid: string) { + (this.$refs.customOfferDialog as OfferDialog).open(recipientDid); + } + // similar function is in endorserServer.ts private async createAndSubmitContactGive( identity: IIdentifier,