Browse Source

support TripHopping on nostr as well

Trent Larson 2 months ago
parent
commit
011870e85f
  1. 152
      src/views/NewEditProjectView.vue

152
src/views/NewEditProjectView.vue

@ -145,14 +145,25 @@
</l-map> </l-map>
</div> </div>
<div v-if="showGeneralAdvanced" class="flex items-center mb-4"> <div v-if="showGeneralAdvanced && includeLocation" class="items-center mb-4">
<div class="flex">
<input <input
type="checkbox" type="checkbox"
class="mr-2" class="mr-2"
v-model="sendToTrustroots" v-model="sendToTrustroots"
@click="sendToTrustroots = !sendToTrustroots" @click="sendToTrustroots = !sendToTrustroots"
/> />
<label for="sendToTrustroots">Send to Trustroots</label> <label>Send to Trustroots</label>
</div>
<div class="flex">
<input
type="checkbox"
class="mr-2"
v-model="sendToTripHopping"
@click="sendToTripHopping = !sendToTripHopping"
/>
<label>Send to TripHopping</label>
</div>
</div> </div>
<div class="mt-8"> <div class="mt-8">
@ -237,6 +248,7 @@ export default class NewEditProjectView extends Vue {
projectId = ""; projectId = "";
projectIssuerDid = ""; projectIssuerDid = "";
sendToTrustroots = false; sendToTrustroots = false;
sendToTripHopping = false;
showGeneralAdvanced = false; showGeneralAdvanced = false;
startDateInput?: string; startDateInput?: string;
startTimeInput?: string; startTimeInput?: string;
@ -371,7 +383,7 @@ export default class NewEditProjectView extends Vue {
} }
} }
private async saveProject(issuerDid: string) { private async saveProject() {
// Make a claim // Make a claim
const vcClaim: PlanVerifiableCredential = this.fullClaim; const vcClaim: PlanVerifiableCredential = this.fullClaim;
if (this.projectId) { if (this.projectId) {
@ -422,13 +434,13 @@ export default class NewEditProjectView extends Vue {
} else { } else {
delete vcClaim.startTime; delete vcClaim.startTime;
} }
const vcJwt = await createEndorserJwtVcFromClaim(issuerDid, vcClaim); const vcJwt = await createEndorserJwtVcFromClaim(this.activeDid, vcClaim);
// Make the xhr request payload // Make the xhr request payload
const payload = JSON.stringify({ jwtEncoded: vcJwt }); const payload = JSON.stringify({ jwtEncoded: vcJwt });
const url = this.apiServer + "/api/v2/claim"; const url = this.apiServer + "/api/v2/claim";
const headers = await getHeaders(issuerDid); const headers = await getHeaders(this.activeDid);
try { try {
const resp = await this.axios.post(url, payload, { headers }); const resp = await this.axios.post(url, payload, { headers });
@ -438,68 +450,15 @@ export default class NewEditProjectView extends Vue {
const projectPath = encodeURIComponent(resp.data.success.handleId); const projectPath = encodeURIComponent(resp.data.success.handleId);
if (this.sendToTrustroots) { if (this.sendToTrustroots) {
// first, get the public key for nostr this.sendToNostrPartner(
const account = await getAccount(this.activeDid); "NOSTR-EVENT-TRUSTROOTS", "Trustroots", resp.data.success.claimId
// get the last number of the derivationPath
const finalDerNum = account?.derivationPath?.split?.("/")?.reverse()[0];
// remove any trailing '
const finalDerNumNoApostrophe = finalDerNum?.replace(/'/g, "");
const accountNum = Number(finalDerNumNoApostrophe || 0);
const pubPri = accountFromSeedWords(account?.mnemonic as string, "", accountNum);
const nostrPubKey = pubPri?.publicKey;
const trustrootsUrl = DEFAULT_PARTNER_API_SERVER + "/api/partner/link";
const timeSafariUrl = window.location.origin + "/claim/" + resp.data.success.claimId;
const content = this.fullClaim.name + " - see " + timeSafariUrl;
const trustrootsParams = new URLSearchParams({
jwtId: resp.data.success.claimId,
linkCode: "NOSTR-EVENT-TRUSTROOTS",
inputJson: JSON.stringify(content),
nostrPubKeyHex: nostrPubKey,
});
const fullTrustrootsUrl = trustrootsUrl + "?" + trustrootsParams.toString();
const headers = await getHeaders(issuerDid);
try {
const linkResp = await this.axios.post(fullTrustrootsUrl, {}, { headers });
if (linkResp.status === 201) {
this.$notify(
{
group: "alert",
type: "success",
title: "Sent to Trustroots",
text: "The project info was sent to Trustroots.",
},
5000,
);
} else {
// axios never gets here because it throws an error, but just in case
this.$notify(
{
group: "alert",
type: "danger",
title: "Failed Sending to Trustroots",
text: JSON.stringify(linkResp.data),
},
5000,
); );
} }
} catch (error) { if (this.sendToTripHopping) {
console.error("Error sending to Trustroots", error); this.sendToNostrPartner(
let errorMessage = "There was an error sending to Trustroots."; "NOSTR-EVENT-TRIPHOPPING", "TripHopping", resp.data.success.claimId
if (error.response?.data?.error?.message) {
errorMessage = error.response.data.error.message;
}
this.$notify(
{
group: "alert",
type: "danger",
title: "Error Sending to Trustroots",
text: errorMessage,
},
5000,
); );
} }
}
(this.$router as Router).push({ path: "/project/" + projectPath }); (this.$router as Router).push({ path: "/project/" + projectPath });
} else { } else {
@ -565,6 +524,71 @@ export default class NewEditProjectView extends Vue {
} }
} }
private async sendToNostrPartner(linkCode: string, serviceName: string, jwtId: string) {
// first, get the public key for nostr
const account = await getAccount(this.activeDid);
// get the last number of the derivationPath
const finalDerNum = account?.derivationPath?.split?.("/")?.reverse()[0];
// remove any trailing '
const finalDerNumNoApostrophe = finalDerNum?.replace(/'/g, "");
const accountNum = Number(finalDerNumNoApostrophe || 0);
const pubPri = accountFromSeedWords(account?.mnemonic as string, "", accountNum);
const nostrPubKey = pubPri?.publicKey;
const trustrootsUrl = DEFAULT_PARTNER_API_SERVER + "/api/partner/link";
const timeSafariUrl = window.location.origin + "/claim/" + jwtId;
const content = this.fullClaim.name + " - see " + timeSafariUrl;
const trustrootsParams = {
jwtId: jwtId,
linkCode: linkCode,
inputJson: JSON.stringify(content),
nostrPubKeyHex: nostrPubKey,
};
const fullTrustrootsUrl = trustrootsUrl;
const headers = await getHeaders(this.activeDid);
try {
const linkResp = await this.axios.post(fullTrustrootsUrl, trustrootsParams, { headers });
if (linkResp.status === 201) {
this.$notify(
{
group: "alert",
type: "success",
title: `Sent to ${serviceName}`,
text: `The project info was sent to ${serviceName}.`,
},
5000,
);
} else {
// axios never gets here because it throws an error, but just in case
this.$notify(
{
group: "alert",
type: "danger",
title: `Failed Sending to ${serviceName}`,
text: JSON.stringify(linkResp.data),
},
5000,
);
}
} catch (error) {
console.error(`Error sending to ${serviceName}`, error);
let errorMessage = `There was an error sending to ${serviceName}.`;
if (error.response?.data?.error?.message) {
errorMessage = error.response.data.error.message;
}
this.$notify(
{
group: "alert",
type: "danger",
title: `Error Sending to ${serviceName}`,
text: errorMessage,
},
5000,
);
}
}
public async onSaveProjectClick() { public async onSaveProjectClick() {
this.isHiddenSave = true; this.isHiddenSave = true;
this.isHiddenSpinner = false; this.isHiddenSpinner = false;
@ -572,7 +596,7 @@ export default class NewEditProjectView extends Vue {
if (this.numAccounts === 0) { if (this.numAccounts === 0) {
console.error("Error: there is no account."); console.error("Error: there is no account.");
} else { } else {
this.saveProject(this.activeDid); this.saveProject();
} }
} }

Loading…
Cancel
Save