Browse Source

Merge pull request 'allow changing the units being given' (#90) from other-units into master

Reviewed-on: https://gitea.anomalistdesign.com/trent_larson/crowd-funder-for-time-pwa/pulls/90
yml-fixes
trentlarson 12 months ago
parent
commit
8849e8806a
  1. 62
      src/components/GiftedDialog.vue
  2. 5
      src/libs/endorserServer.ts

62
src/components/GiftedDialog.vue

@ -13,18 +13,21 @@
<div class="flex flex-row"> <div class="flex flex-row">
<span <span
class="rounded-l border border-r-0 border-slate-400 bg-slate-200 w-1/3 text-center px-2 py-2" class="rounded-l border border-r-0 border-slate-400 bg-slate-200 w-1/3 text-center px-2 py-2"
>Hours</span @click="changeUnitCode()"
> >
{{ UNIT_SHORT[unitCode] }}
</span>
<div <div
class="border border-r-0 border-slate-400 bg-slate-200 px-4 py-2" class="border border-r-0 border-slate-400 bg-slate-200 px-4 py-2"
@click="decrement()" @click="decrement()"
v-if="amountInput !== '0'"
> >
<fa icon="chevron-left" /> <fa icon="chevron-left" />
</div> </div>
<input <input
type="text" type="text"
class="w-full border border-r-0 border-slate-400 px-2 py-2 text-center" class="w-full border border-r-0 border-slate-400 px-2 py-2 text-center"
v-model="hours" v-model="amountInput"
/> />
<div <div
class="rounded-r border border-slate-400 bg-slate-200 px-4 py-2" class="rounded-r border border-slate-400 bg-slate-200 px-4 py-2"
@ -81,12 +84,31 @@ export default class GiftedDialog extends Vue {
activeDid = ""; activeDid = "";
apiServer = ""; apiServer = "";
amountInput = "0";
giver?: GiverInputInfo; // undefined means no identified giver agent giver?: GiverInputInfo; // undefined means no identified giver agent
description = ""; description = "";
givenToUser = false; givenToUser = false;
hours = "0"; unitCode = "HUR";
visible = false; visible = false;
/* eslint-disable prettier/prettier */
UNIT_SHORT: Record<string, string> = {
"BTC": "BTC",
"ETH": "ETH",
"HUR": "Hours",
"USD": "US $",
};
/* eslint-enable prettier/prettier */
/* eslint-disable prettier/prettier */
UNIT_LONG: Record<string, string> = {
"BTC": "BTC",
"ETH": "ETH",
"HUR": "hours",
"USD": "dollars",
};
/* eslint-enable prettier/prettier */
async created() { async created() {
try { try {
await db.open(); await db.open();
@ -115,7 +137,7 @@ export default class GiftedDialog extends Vue {
this.giver = giver; this.giver = giver;
// if we show "given to user" selection, default checkbox to true // if we show "given to user" selection, default checkbox to true
this.givenToUser = this.showGivenToUser; this.givenToUser = this.showGivenToUser;
this.hours = "0"; this.amountInput = "0";
this.visible = true; this.visible = true;
} }
@ -125,12 +147,21 @@ export default class GiftedDialog extends Vue {
this.visible = false; 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() { increment() {
this.hours = `${(parseFloat(this.hours) || 0) + 1}`; this.amountInput = `${(parseFloat(this.amountInput) || 0) + 1}`;
} }
decrement() { decrement() {
this.hours = `${Math.max(0, (parseFloat(this.hours) || 1) - 1)}`; this.amountInput = `${Math.max(
0,
(parseFloat(this.amountInput) || 1) - 1,
)}`;
} }
cancel() { cancel() {
@ -142,7 +173,7 @@ export default class GiftedDialog extends Vue {
this.description = ""; this.description = "";
this.giver = undefined; this.giver = undefined;
this.givenToUser = this.showGivenToUser; this.givenToUser = this.showGivenToUser;
this.hours = "0"; this.amountInput = "0";
} }
async confirm() { async confirm() {
@ -160,7 +191,8 @@ export default class GiftedDialog extends Vue {
await this.recordGive( await this.recordGive(
this.giver?.did as string | undefined, this.giver?.did as string | undefined,
this.description, this.description,
parseFloat(this.hours), parseFloat(this.amountInput),
this.unitCode,
).then(() => { ).then(() => {
this.eraseValues(); this.eraseValues();
}); });
@ -186,12 +218,13 @@ export default class GiftedDialog extends Vue {
* *
* @param giverDid may be null * @param giverDid may be null
* @param description may be an empty string * @param description may be an empty string
* @param hours may be 0 * @param amountInput may be 0
*/ */
public async recordGive( public async recordGive(
giverDid?: string, giverDid?: string,
description?: string, description?: string,
hours?: number, amountInput?: number,
unitCode?: string,
) { ) {
if (!this.activeDid) { if (!this.activeDid) {
this.$notify( this.$notify(
@ -206,13 +239,15 @@ export default class GiftedDialog extends Vue {
return; return;
} }
if (!description && !hours) { if (!description && !amountInput) {
this.$notify( this.$notify(
{ {
group: "alert", group: "alert",
type: "danger", type: "danger",
title: "Error", 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, -1,
); );
@ -228,7 +263,8 @@ export default class GiftedDialog extends Vue {
giverDid, giverDid,
this.givenToUser ? this.activeDid : undefined, this.givenToUser ? this.activeDid : undefined,
description, description,
hours, amountInput,
unitCode,
this.projectId, this.projectId,
); );

5
src/libs/endorserServer.ts

@ -310,6 +310,7 @@ export async function createAndSubmitGive(
toDid?: string, toDid?: string,
description?: string, description?: string,
hours?: number, hours?: number,
unitCode?: string,
fulfillsProjectHandleId?: string, fulfillsProjectHandleId?: string,
): Promise<CreateAndSubmitClaimResult> { ): Promise<CreateAndSubmitClaimResult> {
const vcClaim: GiveVerifiableCredential = { const vcClaim: GiveVerifiableCredential = {
@ -318,7 +319,9 @@ export async function createAndSubmitGive(
recipient: toDid ? { identifier: toDid } : undefined, recipient: toDid ? { identifier: toDid } : undefined,
agent: fromDid ? { identifier: fromDid } : undefined, agent: fromDid ? { identifier: fromDid } : undefined,
description: description || undefined, description: description || undefined,
object: hours ? { amountOfThisGood: hours, unitCode: "HUR" } : undefined, object: hours
? { amountOfThisGood: hours, unitCode: unitCode || "HUR" }
: undefined,
fulfills: fulfillsProjectHandleId fulfills: fulfillsProjectHandleId
? { "@type": "PlanAction", identifier: fulfillsProjectHandleId } ? { "@type": "PlanAction", identifier: fulfillsProjectHandleId }
: undefined, : undefined,

Loading…
Cancel
Save