forked from jsnbuchanan/crowd-funder-for-time-pwa
fix 'give' query and restore confirmClaim method
This commit is contained in:
@@ -99,6 +99,11 @@ export function numberOrZero(str: string): number {
|
|||||||
return isNumeric(str) ? +str : 0;
|
return isNumeric(str) ? +str : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* from https://tools.ietf.org/html/rfc3986#section-3
|
||||||
|
* also useful is https://en.wikipedia.org/wiki/Uniform_Resource_Identifier#Definition
|
||||||
|
**/
|
||||||
export const isGlobalUri = (uri: string) => {
|
export const isGlobalUri = (uri: string) => {
|
||||||
return uri && uri.match(new RegExp(/^[A-Za-z][A-Za-z0-9+.-]+:/));
|
return uri && uri.match(new RegExp(/^[A-Za-z][A-Za-z0-9+.-]+:/));
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -442,7 +442,7 @@ import { NotificationIface } from "../constants/app";
|
|||||||
import { db, retrieveSettingsForActiveAccount } from "../db/index";
|
import { db, retrieveSettingsForActiveAccount } from "../db/index";
|
||||||
import { Contact } from "../db/tables/contacts";
|
import { Contact } from "../db/tables/contacts";
|
||||||
import * as serverUtil from "../libs/endorserServer";
|
import * as serverUtil from "../libs/endorserServer";
|
||||||
import { GiveSummaryRecord } from "../interfaces";
|
import { GenericVerifiableCredential, GiveSummaryRecord } from "../interfaces";
|
||||||
import { displayAmount } from "../libs/endorserServer";
|
import { displayAmount } from "../libs/endorserServer";
|
||||||
import * as libsUtil from "../libs/util";
|
import * as libsUtil from "../libs/util";
|
||||||
import { retrieveAccountDids } from "../libs/util";
|
import { retrieveAccountDids } from "../libs/util";
|
||||||
@@ -621,7 +621,8 @@ export default class ConfirmGiftView extends Vue {
|
|||||||
* Fetches detailed give information
|
* Fetches detailed give information
|
||||||
*/
|
*/
|
||||||
private async fetchGiveDetails(claimId: string, userDid: string) {
|
private async fetchGiveDetails(claimId: string, userDid: string) {
|
||||||
const giveUrl = `${this.apiServer}/api/v2/report/gives?handleId=${encodeURIComponent(claimId)}`;
|
const param = libsUtil.isGlobalUri(claimId) ? "handleId" : "jwtId";
|
||||||
|
const giveUrl = `${this.apiServer}/api/v2/report/gives?${param}=${encodeURIComponent(claimId)}`;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const headers = await serverUtil.getHeaders(userDid);
|
const headers = await serverUtil.getHeaders(userDid);
|
||||||
@@ -645,15 +646,10 @@ export default class ConfirmGiftView extends Vue {
|
|||||||
if (!this.giveDetails) return;
|
if (!this.giveDetails) return;
|
||||||
|
|
||||||
this.urlForNewGive = "/gifted-details?";
|
this.urlForNewGive = "/gifted-details?";
|
||||||
this.addGiveDetailsToUrl();
|
|
||||||
this.processParticipantInfo();
|
|
||||||
this.processAdditionalDetails();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds basic give details to URL
|
* Add basic give details to URL
|
||||||
*/
|
*/
|
||||||
private addGiveDetailsToUrl() {
|
|
||||||
if (this.giveDetails?.amount) {
|
if (this.giveDetails?.amount) {
|
||||||
this.urlForNewGive += `&amountInput=${encodeURIComponent(String(this.giveDetails.amount))}`;
|
this.urlForNewGive += `&amountInput=${encodeURIComponent(String(this.giveDetails.amount))}`;
|
||||||
}
|
}
|
||||||
@@ -663,12 +659,10 @@ export default class ConfirmGiftView extends Vue {
|
|||||||
if (this.giveDetails?.description) {
|
if (this.giveDetails?.description) {
|
||||||
this.urlForNewGive += `&description=${encodeURIComponent(this.giveDetails.description)}`;
|
this.urlForNewGive += `&description=${encodeURIComponent(this.giveDetails.description)}`;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Processes participant (giver/recipient) information
|
* Add participant (giver/recipient) name & URL info
|
||||||
*/
|
*/
|
||||||
private processParticipantInfo() {
|
|
||||||
if (this.giveDetails?.agentDid) {
|
if (this.giveDetails?.agentDid) {
|
||||||
this.giverName = this.didInfo(this.giveDetails.agentDid);
|
this.giverName = this.didInfo(this.giveDetails.agentDid);
|
||||||
this.urlForNewGive += `&giverDid=${encodeURIComponent(this.giveDetails.agentDid)}&giverName=${encodeURIComponent(this.giverName)}`;
|
this.urlForNewGive += `&giverDid=${encodeURIComponent(this.giveDetails.agentDid)}&giverName=${encodeURIComponent(this.giverName)}`;
|
||||||
@@ -677,12 +671,10 @@ export default class ConfirmGiftView extends Vue {
|
|||||||
this.recipientName = this.didInfo(this.giveDetails.recipientDid);
|
this.recipientName = this.didInfo(this.giveDetails.recipientDid);
|
||||||
this.urlForNewGive += `&recipientDid=${encodeURIComponent(this.giveDetails.recipientDid)}&recipientName=${encodeURIComponent(this.recipientName)}`;
|
this.urlForNewGive += `&recipientDid=${encodeURIComponent(this.giveDetails.recipientDid)}&recipientName=${encodeURIComponent(this.recipientName)}`;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Processes additional give details (image, offer, plan)
|
* Add additional give details to URL (image, offer, plan)
|
||||||
*/
|
*/
|
||||||
private processAdditionalDetails() {
|
|
||||||
if (this.giveDetails?.fullClaim.image) {
|
if (this.giveDetails?.fullClaim.image) {
|
||||||
this.urlForNewGive += `&image=${encodeURIComponent(this.giveDetails.fullClaim.image)}`;
|
this.urlForNewGive += `&image=${encodeURIComponent(this.giveDetails.fullClaim.image)}`;
|
||||||
}
|
}
|
||||||
@@ -803,6 +795,53 @@ export default class ConfirmGiftView extends Vue {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// similar code is found in ProjectViewView
|
||||||
|
async confirmClaim() {
|
||||||
|
// similar logic is found in endorser-mobile
|
||||||
|
const goodClaim = serverUtil.removeSchemaContext(
|
||||||
|
serverUtil.removeVisibleToDids(
|
||||||
|
serverUtil.addLastClaimOrHandleAsIdIfMissing(
|
||||||
|
this.veriClaim.claim,
|
||||||
|
this.veriClaim.id,
|
||||||
|
this.veriClaim.handleId,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
const confirmationClaim: GenericVerifiableCredential = {
|
||||||
|
"@context": "https://schema.org",
|
||||||
|
"@type": "AgreeAction",
|
||||||
|
object: goodClaim,
|
||||||
|
};
|
||||||
|
const result = await serverUtil.createAndSubmitClaim(
|
||||||
|
confirmationClaim,
|
||||||
|
this.activeDid,
|
||||||
|
this.apiServer,
|
||||||
|
this.axios,
|
||||||
|
);
|
||||||
|
if (result.type === "success") {
|
||||||
|
this.$notify(
|
||||||
|
{
|
||||||
|
group: "alert",
|
||||||
|
type: "success",
|
||||||
|
title: "Success",
|
||||||
|
text: "Confirmation submitted.",
|
||||||
|
},
|
||||||
|
3000,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
console.error("Got error submitting the confirmation:", result);
|
||||||
|
this.$notify(
|
||||||
|
{
|
||||||
|
group: "alert",
|
||||||
|
type: "danger",
|
||||||
|
title: "Error",
|
||||||
|
text: "There was a problem submitting the confirmation.",
|
||||||
|
},
|
||||||
|
5000,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notifies user why they cannot confirm the gift
|
* Notifies user why they cannot confirm the gift
|
||||||
* Explains requirements or restrictions preventing confirmation
|
* Explains requirements or restrictions preventing confirmation
|
||||||
|
|||||||
Reference in New Issue
Block a user