add advanced page & flag for editing raw claims, and fix recipient assignment in detail screen

This commit is contained in:
2024-06-29 10:18:56 -06:00
parent 9c7b138d06
commit 053ee4a748
6 changed files with 395 additions and 103 deletions

View File

@@ -160,7 +160,7 @@ export interface OfferVerifiableCredential {
// Note that previous VCs may have additional fields.
// https://endorser.ch/doc/html/transactions.html#id7
export interface PlanVerifiableCredential {
"@context": "https://schema.org";
"@context": SCHEMA_ORG_CONTEXT;
"@type": "PlanAction";
name: string;
agent?: { identifier: string };
@@ -518,19 +518,7 @@ export async function setPlanInCache(
planCache.set(handleId, planSummary);
}
/**
* For result, see https://api.endorser.ch/api-docs/#/claims/post_api_v2_claim
*
* @param identity
* @param fromDid may be null
* @param toDid
* @param description may be null; should have this or amount
* @param amount may be null; should have this or description
*/
export async function createAndSubmitGive(
axios: Axios,
apiServer: string,
identity: IIdentifier,
export function constructGive(
fromDid?: string | null,
toDid?: string,
description?: string,
@@ -540,9 +528,9 @@ export async function createAndSubmitGive(
fulfillsOfferHandleId?: string,
isTrade: boolean = false,
imageUrl?: string,
): Promise<CreateAndSubmitClaimResult> {
): GiveVerifiableCredential {
const vcClaim: GiveVerifiableCredential = {
"@context": "https://schema.org",
"@context": SCHEMA_ORG_CONTEXT,
"@type": "GiveAction",
recipient: toDid ? { identifier: toDid } : undefined,
agent: fromDid ? { identifier: fromDid } : undefined,
@@ -569,6 +557,43 @@ export async function createAndSubmitGive(
if (imageUrl) {
vcClaim.image = imageUrl;
}
return vcClaim;
}
/**
* For result, see https://api.endorser.ch/api-docs/#/claims/post_api_v2_claim
*
* @param identity
* @param fromDid may be null
* @param toDid
* @param description may be null; should have this or amount
* @param amount may be null; should have this or description
*/
export async function createAndSubmitGive(
axios: Axios,
apiServer: string,
identity: IIdentifier,
fromDid?: string | null,
toDid?: string,
description?: string,
amount?: number,
unitCode?: string,
fulfillsProjectHandleId?: string,
fulfillsOfferHandleId?: string,
isTrade: boolean = false,
imageUrl?: string,
): Promise<CreateAndSubmitClaimResult> {
const vcClaim = constructGive(
fromDid,
toDid,
description,
amount,
unitCode,
fulfillsProjectHandleId,
fulfillsOfferHandleId,
isTrade,
imageUrl,
);
return createAndSubmitClaim(
vcClaim as GenericCredWrapper,
identity,
@@ -598,7 +623,7 @@ export async function createAndSubmitOffer(
fulfillsProjectHandleId?: string,
): Promise<CreateAndSubmitClaimResult> {
const vcClaim: OfferVerifiableCredential = {
"@context": "https://schema.org",
"@context": SCHEMA_ORG_CONTEXT,
"@type": "Offer",
offeredBy: { identifier: identity.did },
validThrough: expirationDate || undefined,
@@ -645,7 +670,7 @@ export const createAndSubmitConfirmation = async (
),
);
const confirmationClaim: GenericVerifiableCredential = {
"@context": "https://schema.org",
"@context": SCHEMA_ORG_CONTEXT,
"@type": "AgreeAction",
object: goodClaim,
};
@@ -928,7 +953,7 @@ export async function register(
const identity = await getIdentity(activeDid);
const vcClaim: RegisterVerifiableCredential = {
"@context": "https://schema.org",
"@context": SCHEMA_ORG_CONTEXT,
"@type": "RegisterAction",
agent: { identifier: identity.did },
object: SERVICE_ID,