diff --git a/src/components/GiftedDialog.vue b/src/components/GiftedDialog.vue
index 079116fa..1dfb153e 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 f80f88d6..d80cc833 100644
--- a/src/libs/endorserServer.ts
+++ b/src/libs/endorserServer.ts
@@ -310,6 +310,7 @@ export async function createAndSubmitGive(
toDid?: string,
description?: string,
hours?: number,
+ unitCode?: string,
fulfillsProjectHandleId?: string,
): Promise {
const vcClaim: GiveVerifiableCredential = {
@@ -318,7 +319,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,