diff --git a/src/components/Toaster.tsx b/src/components/Toaster.tsx index d03abaf..07d0a8f 100644 --- a/src/components/Toaster.tsx +++ b/src/components/Toaster.tsx @@ -14,7 +14,7 @@ export function Toaster() { ); } -type ToastArg = { title: string; description: string } | Error; +export type ToastArg = { title: string; description: string } | Error; export function showToast(arg: ToastArg) { if (arg instanceof Error) { diff --git a/src/i18n/en/translations.ts b/src/i18n/en/translations.ts index 0211bc2..c8fa9a0 100644 --- a/src/i18n/en/translations.ts +++ b/src/i18n/en/translations.ts @@ -331,6 +331,9 @@ export default { open_app: "Open App", open_in_nostr_client: "Open in Nostr Client", open_in_primal: "Open in Primal", + nostr_client_not_found: "Nostr client not found", + client_not_found_description: + "Install a nostr client like Primal, Amethyst, or Damus to open this link.", relay: "Relay", authorize: "Authorize external services to request payments from your wallet. Pairs great with Nostr clients.", diff --git a/src/routes/settings/Connections.tsx b/src/routes/settings/Connections.tsx index 3df4c97..93c8d25 100644 --- a/src/routes/settings/Connections.tsx +++ b/src/routes/settings/Connections.tsx @@ -123,7 +123,12 @@ function NwcDetails(props: { async function openInNostrClient() { const uri = props.profile.nwc_uri; - await openLinkProgrammatically(uri); + await openLinkProgrammatically(uri, { + title: i18n.t("settings.connections.nostr_client_not_found"), + description: i18n.t( + "settings.connections.client_not_found_description" + ) + }); } return ( @@ -177,7 +182,11 @@ function NwcDetails(props: { props.profile.tag !== "Subscription" } > - diff --git a/src/utils/openLinkProgrammatically.ts b/src/utils/openLinkProgrammatically.ts index b5f925e..dd01c7b 100644 --- a/src/utils/openLinkProgrammatically.ts +++ b/src/utils/openLinkProgrammatically.ts @@ -1,17 +1,30 @@ +import { AppLauncher } from "@capacitor/app-launcher"; import { Capacitor } from "@capacitor/core"; -import { AppLauncher } from '@capacitor/app-launcher'; -export async function openLinkProgrammatically(url?: string) { +import { showToast, ToastArg } from "~/components"; + +// Have to pass in the failure text because i18n doesn't work in utils +export async function openLinkProgrammatically( + url?: string, + failureText?: ToastArg +) { if (!url) return; if (Capacitor.isNativePlatform()) { const { value } = await AppLauncher.canOpenUrl({ url }); if (!value) { + showToast( + failureText || { + title: "Client not found", + description: + "Please install a compatible client to open this link." + } + ); // Try to open in browser just in case that works glhf window.open(url || "", "_blank"); return; } else { - await AppLauncher.openUrl({ url}); + await AppLauncher.openUrl({ url }); } } else { window.open(url || "", "_blank");