Skip to content

Commit

Permalink
Toggle diagnostic reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyGiorgio committed Jun 6, 2024
1 parent 0caf222 commit 8df7a15
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 4 deletions.
6 changes: 5 additions & 1 deletion public/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,11 @@
"enable_zaps_to_hodl": "Enable zaps to hodl invoices?",
"zaps_to_hodl_desc": "Zaps to hodl invoices can result in channel force closes, which results in high on-chain fees. Use at your own risk!",
"zaps_to_hodl_enable": "Enable hodl zaps",
"zaps_to_hodl_disable": "Disable hodl zaps"
"zaps_to_hodl_disable": "Disable hodl zaps",
"enable_report_diagnostics": "Enable diagnostic reporting?",
"report_diagnostics_desc": "Automatically report critical errors to the developers. All transaction data or other personal information is scrubed and anonymized.",
"report_diagnostics_enable": "Enable diagnostics",
"report_diagnostics_disable": "Disable diagnostics"
}
},
"backup": {
Expand Down
3 changes: 3 additions & 0 deletions src/components/KitchenSink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
showToast,
SimpleErrorDisplay,
ToggleHodl,
ToggleReportDiagnostics,
VStack
} from "~/components";
import { useI18n } from "~/i18n/context";
Expand Down Expand Up @@ -572,6 +573,8 @@ export function KitchenSink() {
<Hr />
<Restart />
<Hr />
<ToggleReportDiagnostics />
<Hr />
</>
);
}
42 changes: 42 additions & 0 deletions src/components/ToggleReportDiagnostics.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Button, InnerCard, NiceP, VStack } from "~/components";
import { useI18n } from "~/i18n/context";
import { useMegaStore } from "~/state/megaStore";

export function ToggleReportDiagnostics() {
const i18n = useI18n();
const [state, actions] = useMegaStore();

async function toggle() {
try {
await actions.toggleReportDiagnostics();
window.location.href = "/";
} catch (e) {
console.error(e);
}
}

return (
<InnerCard
title={i18n.t("settings.admin.kitchen_sink.enable_report_diagnostics")}
>
<VStack>
<NiceP>
{i18n.t("settings.admin.kitchen_sink.report_diagnostics_desc")}
</NiceP>

<Button
intent={state.report_diagnostics ? "green" : "red"}
onClick={toggle}
>
{state.report_diagnostics
? i18n.t(
"settings.admin.kitchen_sink.report_diagnostics_disable"
)
: i18n.t(
"settings.admin.kitchen_sink.report_diagnostics_enable"
)}
</Button>
</VStack>
</InnerCard>
);
}
1 change: 1 addition & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export * from "./Toaster";
export * from "./NostrActivity";
export * from "./MutinyPlusCta";
export * from "./ToggleHodl";
export * from "./ToggleReportDiagnostics.tsx";

Check failure on line 42 in src/components/index.ts

View workflow job for this annotation

GitHub Actions / Build iOS

An import path can only end with a '.tsx' extension when 'allowImportingTsExtensions' is enabled.

Check failure on line 42 in src/components/index.ts

View workflow job for this annotation

GitHub Actions / Build APK

An import path can only end with a '.tsx' extension when 'allowImportingTsExtensions' is enabled.
export * from "./IOSbanner";
export * from "./HomePrompt";
export * from "./BigMoney";
Expand Down
12 changes: 10 additions & 2 deletions src/state/megaStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
MutinyWalletSettingStrings,
Network,
setSettings
// setupMutinyWallet
} from "~/logic/mutinyWalletSetup";
import { ParsedParams, toParsedParams } from "~/logic/waila";
import { MutinyFederationIdentity } from "~/routes/settings";
Expand Down Expand Up @@ -49,9 +48,10 @@ const sentryenv = import.meta.env.VITE_SENTRY_ENVIRONMENT || (DEV ? "dev" : "pro
export const makeMegaStoreContext = () => {
const [searchParams] = useSearchParams();
const navigate = useNavigate();
const reportDiagnostics = localStorage.getItem("report_diagnostics") === "true";

// initialize both inside worker and outside
// TODO figure out when to set or not
if (reportDiagnostics) {
Sentry.init({
dsn: "https://[email protected]/2",
environment: sentryenv,
Expand All @@ -78,6 +78,7 @@ export const makeMegaStoreContext = () => {
replaysSessionSampleRate: 0.1,
replaysOnErrorSampleRate: 1.0
});
}

// Not actually a shared worker, but it's the same code
const sw = new ComlinkWorker<typeof import("../workers/walletWorker")>(
Expand Down Expand Up @@ -118,6 +119,7 @@ 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,
testflightPromptDismissed:
localStorage.getItem("testflightPromptDismissed") === "true",
federations: undefined as MutinyFederationIdentity[] | undefined,
Expand Down Expand Up @@ -267,6 +269,7 @@ export const makeMegaStoreContext = () => {
password,
state.safe_mode,
state.should_zap_hodl,
state.report_diagnostics,
nsec
);

Expand Down Expand Up @@ -544,6 +547,11 @@ export const makeMegaStoreContext = () => {
localStorage.setItem("should_zap_hodl", should_zap_hodl.toString());
setState({ should_zap_hodl });
},
toggleReportDiagnostics() {
const report_diagnostics = !state.report_diagnostics;
localStorage.setItem("report_diagnostics", report_diagnostics.toString());
setState({ report_diagnostics });
},
async refreshFederations() {
const federations = await sw.list_federations();

Expand Down
4 changes: 3 additions & 1 deletion src/workers/walletWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,11 @@ export async function setupMutinyWallet(
password?: string,
safeMode?: boolean,
shouldZapHodl?: boolean,
reportDiagnostics?: boolean,
nsec?: string
): Promise<boolean> {
// initialize both inside worker and outside
// TODO figure out when to set or not
if (reportDiagnostics) {
Sentry.init({
dsn: "https://[email protected]/2",
environment: sentryenv,
Expand Down Expand Up @@ -145,6 +146,7 @@ export async function setupMutinyWallet(
replaysSessionSampleRate: 0.1,
replaysOnErrorSampleRate: 1.0
});
}

console.log("Starting setup...");

Expand Down

0 comments on commit 8df7a15

Please sign in to comment.