add flag for logging a contribution as a trade

This commit is contained in:
2024-01-08 21:28:04 -07:00
parent 525d3fc15a
commit 8a7ce0fe65
7 changed files with 50 additions and 20 deletions

View File

@@ -88,7 +88,7 @@ export interface GiveVerifiableCredential {
"@type": "GiveAction";
agent?: { identifier: string };
description?: string;
fulfills?: { "@type": string; identifier?: string; lastClaimId?: string };
fulfills?: { "@type": string; identifier?: string; lastClaimId?: string }[];
identifier?: string;
object?: { amountOfThisGood: number; unitCode: string };
recipient?: { identifier: string };
@@ -312,6 +312,7 @@ export async function createAndSubmitGive(
hours?: number,
unitCode?: string,
fulfillsProjectHandleId?: string,
isTrade: boolean = false,
): Promise<CreateAndSubmitClaimResult> {
const vcClaim: GiveVerifiableCredential = {
"@context": "https://schema.org",
@@ -322,10 +323,16 @@ export async function createAndSubmitGive(
object: hours
? { amountOfThisGood: hours, unitCode: unitCode || "HUR" }
: undefined,
fulfills: fulfillsProjectHandleId
? { "@type": "PlanAction", identifier: fulfillsProjectHandleId }
: undefined,
fulfills: [{ "@type": isTrade ? "TradeAction" : "DonateAction" }],
};
if (fulfillsProjectHandleId) {
vcClaim.fulfills = vcClaim.fulfills || []; // weird that it won't typecheck without this
vcClaim.fulfills.push({
"@type": "PlanAction",
identifier: fulfillsProjectHandleId,
});
}
console.log("createAndSubmitGive vcClaim", vcClaim);
return createAndSubmitClaim(
vcClaim as GenericServerRecord,
identity,