From 393d1583ae2a6f105f7876ce4eb3602289667531 Mon Sep 17 00:00:00 2001 From: Trent Larson Date: Tue, 5 Dec 2023 14:55:00 -0700 Subject: [PATCH] allow changing of units being given --- src/components/GiftedDialog.vue | 62 ++++++++++++++++++++++++++------- src/libs/endorserServer.ts | 5 ++- 2 files changed, 53 insertions(+), 14 deletions(-) diff --git a/src/components/GiftedDialog.vue b/src/components/GiftedDialog.vue index 079116f..1dfb153 100644 --- a/src/components/GiftedDialog.vue +++ b/src/components/GiftedDialog.vue @@ -13,18 +13,21 @@
Hours + {{ UNIT_SHORT[unitCode] }} +
= { + "BTC": "BTC", + "ETH": "ETH", + "HUR": "Hours", + "USD": "US $", + }; + /* eslint-enable prettier/prettier */ + + /* eslint-disable prettier/prettier */ + UNIT_LONG: Record = { + "BTC": "BTC", + "ETH": "ETH", + "HUR": "hours", + "USD": "dollars", + }; + /* eslint-enable prettier/prettier */ + async created() { try { await db.open(); @@ -115,7 +137,7 @@ export default class GiftedDialog extends Vue { this.giver = giver; // if we show "given to user" selection, default checkbox to true this.givenToUser = this.showGivenToUser; - this.hours = "0"; + this.amountInput = "0"; this.visible = true; } @@ -125,12 +147,21 @@ export default class GiftedDialog extends Vue { this.visible = false; } + changeUnitCode() { + const units = Object.keys(this.UNIT_SHORT); + const index = units.indexOf(this.unitCode); + this.unitCode = units[(index + 1) % units.length]; + } + increment() { - this.hours = `${(parseFloat(this.hours) || 0) + 1}`; + this.amountInput = `${(parseFloat(this.amountInput) || 0) + 1}`; } decrement() { - this.hours = `${Math.max(0, (parseFloat(this.hours) || 1) - 1)}`; + this.amountInput = `${Math.max( + 0, + (parseFloat(this.amountInput) || 1) - 1, + )}`; } cancel() { @@ -142,7 +173,7 @@ export default class GiftedDialog extends Vue { this.description = ""; this.giver = undefined; this.givenToUser = this.showGivenToUser; - this.hours = "0"; + this.amountInput = "0"; } async confirm() { @@ -160,7 +191,8 @@ export default class GiftedDialog extends Vue { await this.recordGive( this.giver?.did as string | undefined, this.description, - parseFloat(this.hours), + parseFloat(this.amountInput), + this.unitCode, ).then(() => { this.eraseValues(); }); @@ -186,12 +218,13 @@ export default class GiftedDialog extends Vue { * * @param giverDid may be null * @param description may be an empty string - * @param hours may be 0 + * @param amountInput may be 0 */ public async recordGive( giverDid?: string, description?: string, - hours?: number, + amountInput?: number, + unitCode?: string, ) { if (!this.activeDid) { this.$notify( @@ -206,13 +239,15 @@ export default class GiftedDialog extends Vue { return; } - if (!description && !hours) { + if (!description && !amountInput) { this.$notify( { group: "alert", type: "danger", title: "Error", - text: "You must enter a description or some number of hours.", + text: `You must enter a description or some number of ${ + this.UNIT_LONG[this.unitCode] + }.`, }, -1, ); @@ -228,7 +263,8 @@ export default class GiftedDialog extends Vue { giverDid, this.givenToUser ? this.activeDid : undefined, description, - hours, + amountInput, + unitCode, this.projectId, ); diff --git a/src/libs/endorserServer.ts b/src/libs/endorserServer.ts index 8db51eb..0c92fbf 100644 --- a/src/libs/endorserServer.ts +++ b/src/libs/endorserServer.ts @@ -194,6 +194,7 @@ export async function createAndSubmitGive( toDid?: string, description?: string, hours?: number, + unitCode?: string, fulfillsProjectHandleId?: string, ): Promise { const vcClaim: GiveVerifiableCredential = { @@ -202,7 +203,9 @@ export async function createAndSubmitGive( recipient: toDid ? { identifier: toDid } : undefined, agent: fromDid ? { identifier: fromDid } : undefined, description: description || undefined, - object: hours ? { amountOfThisGood: hours, unitCode: "HUR" } : undefined, + object: hours + ? { amountOfThisGood: hours, unitCode: unitCode || "HUR" } + : undefined, fulfills: fulfillsProjectHandleId ? { "@type": "PlanAction", identifier: fulfillsProjectHandleId } : undefined,