send all info needed to create a Trustroots event
This commit is contained in:
@@ -188,19 +188,21 @@
|
||||
import "leaflet/dist/leaflet.css";
|
||||
import { AxiosError, AxiosRequestHeaders } from "axios";
|
||||
import { DateTime } from "luxon";
|
||||
import { accountFromSeedWords } from "nostr-tools/nip06";
|
||||
import { Component, Vue } from "vue-facing-decorator";
|
||||
import { LMap, LMarker, LTileLayer } from "@vue-leaflet/vue-leaflet";
|
||||
import { Router } from "vue-router";
|
||||
|
||||
import ImageMethodDialog from "@/components/ImageMethodDialog.vue";
|
||||
import QuickNav from "@/components/QuickNav.vue";
|
||||
import { DEFAULT_IMAGE_API_SERVER, NotificationIface } from "@/constants/app";
|
||||
import { DEFAULT_IMAGE_API_SERVER, DEFAULT_PARTNER_API_SERVER, NotificationIface } from "@/constants/app";
|
||||
import { accountsDB, retrieveSettingsForActiveAccount } from "@/db/index";
|
||||
import {
|
||||
createEndorserJwtVcFromClaim,
|
||||
getHeaders,
|
||||
PlanVerifiableCredential,
|
||||
} from "@/libs/endorserServer";
|
||||
import { getAccount } from "@/libs/util";
|
||||
|
||||
@Component({
|
||||
components: { ImageMethodDialog, LMap, LMarker, LTileLayer, QuickNav },
|
||||
@@ -431,36 +433,68 @@ export default class NewEditProjectView extends Vue {
|
||||
try {
|
||||
const resp = await this.axios.post(url, payload, { headers });
|
||||
if (resp.data?.success?.handleId) {
|
||||
console.log("Saved project with data", resp.data.success);
|
||||
this.errorMessage = "";
|
||||
|
||||
const projectPath = encodeURIComponent(resp.data.success.handleId);
|
||||
|
||||
if (this.sendToTrustroots) {
|
||||
const trustrootsUrl = "http://localhost:3000/api/partner/link";
|
||||
// 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/" + 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("localhost " + resp.data.success.claimId),
|
||||
inputJson: JSON.stringify(content),
|
||||
nostrPubKeyHex: nostrPubKey,
|
||||
});
|
||||
const fullTrustrootsUrl =
|
||||
trustrootsUrl + "?" + trustrootsParams.toString();
|
||||
const fullTrustrootsUrl = trustrootsUrl + "?" + trustrootsParams.toString();
|
||||
const headers = await getHeaders(issuerDid);
|
||||
try {
|
||||
const linkResp = await this.axios.post(
|
||||
fullTrustrootsUrl,
|
||||
{},
|
||||
{ headers },
|
||||
);
|
||||
console.log("Sent to Trustroots with data!!!!", linkResp.data);
|
||||
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) {
|
||||
console.error("Error sending to Trustroots", error);
|
||||
let errorMessage = "There was an error sending to Trustroots.";
|
||||
if (error.response?.data?.error?.message) {
|
||||
errorMessage = error.response.data.error.message;
|
||||
}
|
||||
this.$notify(
|
||||
{
|
||||
group: "alert",
|
||||
type: "danger",
|
||||
title: "Error Sending to Trustroots",
|
||||
text: "There was an error sending to Trustroots.",
|
||||
text: errorMessage,
|
||||
},
|
||||
5000,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user