send all info needed to create a Trustroots event

This commit is contained in:
2024-09-25 09:01:49 -06:00
parent 25d5e13029
commit d492ea9eeb
8 changed files with 201 additions and 20 deletions

View File

@@ -12,14 +12,18 @@ export enum AppString {
TEST_ENDORSER_API_SERVER = "https://test-api.endorser.ch",
LOCAL_ENDORSER_API_SERVER = "http://localhost:3000",
PROD_PUSH_SERVER = "https://timesafari.app",
TEST1_PUSH_SERVER = "https://test.timesafari.app",
TEST2_PUSH_SERVER = "https://timesafari-pwa.anomalistlabs.com",
PROD_IMAGE_API_SERVER = "https://image-api.timesafari.app",
TEST_IMAGE_API_SERVER = "https://test-image-api.timesafari.app",
LOCAL_IMAGE_API_SERVER = "http://localhost:3001",
PROD_PARTNER_API_SERVER = "https://endorser.ch",
TEST_PARTNER_API_SERVER = "https://test-partner.endorser.ch",
LOCAL_PARTNER_API_SERVER = LOCAL_ENDORSER_API_SERVER,
PROD_PUSH_SERVER = "https://timesafari.app",
TEST1_PUSH_SERVER = "https://test.timesafari.app",
TEST2_PUSH_SERVER = "https://timesafari-pwa.anomalistlabs.com",
NO_CONTACT_NAME = "(no name)",
}
@@ -31,6 +35,10 @@ export const DEFAULT_IMAGE_API_SERVER =
import.meta.env.VITE_DEFAULT_IMAGE_API_SERVER ||
AppString.TEST_IMAGE_API_SERVER;
export const DEFAULT_PARTNER_API_SERVER =
import.meta.env.VITE_DEFAULT_PARTNER_API_SERVER ||
AppString.TEST_PARTNER_API_SERVER;
export const DEFAULT_PUSH_SERVER =
window.location.protocol + "//" + window.location.host;

View File

@@ -588,11 +588,15 @@
</span>
<div id="sectionImageServerURL" class="mt-2">
<span class="text-slate-500 text-sm font-bold">Image Server URL</span>
&nbsp;
<span class="text-slate-500 text-sm font-bold">Image Server URL</span>&nbsp;
<span class="text-sm">{{ DEFAULT_IMAGE_API_SERVER }}</span>
</div>
<div id="sectionPartnerServerURL" class="mt-2">
<span class="text-slate-500 text-sm font-bold">Partner Server URL</span>&nbsp;
<span class="text-sm">{{ DEFAULT_PARTNER_API_SERVER }}</span>
</div>
<label
for="toggleHideRegisterPromptOnNewContact"
class="flex items-center justify-between cursor-pointer mt-4"
@@ -722,6 +726,7 @@ import UserNameDialog from "@/components/UserNameDialog.vue";
import {
AppString,
DEFAULT_IMAGE_API_SERVER,
DEFAULT_PARTNER_API_SERVER,
DEFAULT_PUSH_SERVER,
IMAGE_TYPE_PROFILE,
NotificationIface,
@@ -767,6 +772,7 @@ export default class AccountViewView extends Vue {
AppConstants = AppString;
DEFAULT_PUSH_SERVER = DEFAULT_PUSH_SERVER;
DEFAULT_IMAGE_API_SERVER = DEFAULT_IMAGE_API_SERVER;
DEFAULT_PARTNER_API_SERVER = DEFAULT_PARTNER_API_SERVER;
activeDid = "";
apiServer = "";

View File

@@ -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,
);