show toast if can't open nostr client

This commit is contained in:
Paul Miller
2023-11-15 14:38:25 -06:00
committed by Tony Giorgio
parent 2c4c37c23f
commit 1271b66399
4 changed files with 31 additions and 6 deletions

View File

@@ -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) {

View File

@@ -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.",

View File

@@ -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"
}
>
<Button layout="small" intent="blue" onClick={openInNostrClient}>
<Button
layout="small"
intent="blue"
onClick={openInNostrClient}
>
{i18n.t("settings.connections.open_in_nostr_client")}
</Button>
</Show>

View File

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