From 2bbc66701bfad6513c01a1cd0aa8e212f791d918 Mon Sep 17 00:00:00 2001 From: Tony Giorgio Date: Thu, 6 Jun 2024 16:16:26 -0500 Subject: [PATCH] Ask for diagnostic reporting on startup --- src/routes/setup/Root.tsx | 29 +++++++++++++- src/state/megaStore.tsx | 81 ++++++++++++++++++++++----------------- 2 files changed, 73 insertions(+), 37 deletions(-) diff --git a/src/routes/setup/Root.tsx b/src/routes/setup/Root.tsx index 8e9a79dd..3b3a9b96 100644 --- a/src/routes/setup/Root.tsx +++ b/src/routes/setup/Root.tsx @@ -1,5 +1,5 @@ import { useNavigate } from "@solidjs/router"; -import { createSignal } from "solid-js"; +import { createEffect, createSignal } from "solid-js"; import logo from "~/assets/mutiny-pixel-logo.png"; import { Button, DefaultMain, NiceP } from "~/components"; @@ -9,8 +9,22 @@ export function Setup() { const [_state, actions] = useMegaStore(); const [isCreatingNewWallet, setIsCreatingNewWallet] = createSignal(false); + const [isDiagnosticReportingEnabled, setIsDiagnosticReportingEnabled] = + createSignal(true); const navigate = useNavigate(); + // default is to set reporting + actions.setReportDiagnostics(); + + // set up a listener that toggles it + createEffect(() => { + if (isDiagnosticReportingEnabled()) { + actions.setReportDiagnostics(); + } else { + actions.disableReportDiagnostics(); + } + }); + async function handleNewWallet() { try { setIsCreatingNewWallet(true); @@ -67,6 +81,19 @@ export function Setup() {
+

+ + setIsDiagnosticReportingEnabled( + !isDiagnosticReportingEnabled() + ) + } + /> + Allow anonymous error reporting to help us improve the app. + You can opt out at any time. +

); diff --git a/src/state/megaStore.tsx b/src/state/megaStore.tsx index c8707245..3974da4a 100644 --- a/src/state/megaStore.tsx +++ b/src/state/megaStore.tsx @@ -48,41 +48,6 @@ const sentryenv = import.meta.env.VITE_SENTRY_ENVIRONMENT || (DEV ? "dev" : ""); export const makeMegaStoreContext = () => { const [searchParams] = useSearchParams(); const navigate = useNavigate(); - const reportDiagnostics = - localStorage.getItem("report_diagnostics") === "true"; - - // initialize both inside worker and outside - if (reportDiagnostics && sentryenv !== "") { - Sentry.init({ - dsn: "https://192c556849619517322719962a057376@sen.mutinywallet.com/2", - environment: sentryenv, - release: "mutiny-web@" + RELEASE_VERSION, - integrations: [ - Sentry.browserTracingIntegration(), - Sentry.replayIntegration() - ], - - initialScope: { - tags: { component: "main" } - }, - - // Set tracesSampleRate to 1.0 to capture 100% - // of transactions for performance monitoring. - // We recommend adjusting this value in production - tracesSampleRate: 1.0, - - // Set `tracePropagationTargets` to control for which URLs distributed tracing should be enabled - tracePropagationTargets: [ - "localhost", - /^https:\/\/mutinywallet\.com/ - ], - - // Capture Replay for 10% of all sessions, - // plus 100% of sessions with an error - replaysSessionSampleRate: 0.1, - replaysOnErrorSampleRate: 1.0 - }); - } // Not actually a shared worker, but it's the same code const sw = new ComlinkWorker( @@ -123,7 +88,8 @@ export const makeMegaStoreContext = () => { lang: localStorage.getItem("i18nexLng") || undefined, preferredInvoiceType: "unified" as "unified" | "lightning" | "onchain", should_zap_hodl: localStorage.getItem("should_zap_hodl") === "true", - report_diagnostics: reportDiagnostics, + report_diagnostics: + localStorage.getItem("report_diagnostics") === "true", testflightPromptDismissed: localStorage.getItem("testflightPromptDismissed") === "true", federations: undefined as MutinyFederationIdentity[] | undefined, @@ -208,6 +174,41 @@ export const makeMegaStoreContext = () => { const settings = await getSettings(); setState({ load_stage: "setup" }); + const reportDiagnostics = + localStorage.getItem("report_diagnostics") === "true"; + + if (reportDiagnostics && sentryenv !== "") { + Sentry.init({ + dsn: "https://192c556849619517322719962a057376@sen.mutinywallet.com/2", + environment: sentryenv, + release: "mutiny-web@" + RELEASE_VERSION, + integrations: [ + Sentry.browserTracingIntegration(), + Sentry.replayIntegration() + ], + + initialScope: { + tags: { component: "main" } + }, + + // Set tracesSampleRate to 1.0 to capture 100% + // of transactions for performance monitoring. + // We recommend adjusting this value in production + tracesSampleRate: 1.0, + + // Set `tracePropagationTargets` to control for which URLs distributed tracing should be enabled + tracePropagationTargets: [ + "localhost", + /^https:\/\/mutinywallet\.com/ + ], + + // Capture Replay for 10% of all sessions, + // plus 100% of sessions with an error + replaysSessionSampleRate: 0.1, + replaysOnErrorSampleRate: 1.0 + }); + } + // handle lsp settings if (searchParams.lsps) { settings.lsp = ""; @@ -559,6 +560,14 @@ export const makeMegaStoreContext = () => { ); setState({ report_diagnostics }); }, + setReportDiagnostics() { + localStorage.setItem("report_diagnostics", "true"); + setState({ report_diagnostics: true }); + }, + disableReportDiagnostics() { + localStorage.setItem("report_diagnostics", "false"); + setState({ report_diagnostics: false }); + }, async refreshFederations() { const federations = await sw.list_federations();