From b1593ab08ba7d67bafff3c860c0504cf626ee7e2 Mon Sep 17 00:00:00 2001 From: Roland Bewick Date: Wed, 18 Dec 2024 19:30:24 +0700 Subject: [PATCH 1/3] fix: gracefully handle missing permissions --- pages/settings/wallets/SetupWallet.tsx | 42 +++++++++++++++++++------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/pages/settings/wallets/SetupWallet.tsx b/pages/settings/wallets/SetupWallet.tsx index 8b8b404..be5ade0 100644 --- a/pages/settings/wallets/SetupWallet.tsx +++ b/pages/settings/wallets/SetupWallet.tsx @@ -7,11 +7,22 @@ import React from "react"; import { Pressable, TouchableOpacity, View } from "react-native"; import Toast from "react-native-toast-message"; import DismissableKeyboardView from "~/components/DismissableKeyboardView"; -import { ClipboardPaste, HelpCircle, X } from "~/components/Icons"; +import { + ClipboardPaste, + HelpCircle, + TriangleAlert, + X, +} from "~/components/Icons"; import Loading from "~/components/Loading"; import QRCodeScanner from "~/components/QRCodeScanner"; import Screen from "~/components/Screen"; import { Button } from "~/components/ui/button"; +import { + Card, + CardContent, + CardDescription, + CardTitle, +} from "~/components/ui/card"; import { Dialog, DialogClose, @@ -68,16 +79,6 @@ export function SetupWallet() { if (info.notifications?.length) { capabilities.push("notifications"); } - if ( - !REQUIRED_CAPABILITIES.every((capability) => - capabilities.includes(capability), - ) - ) { - const missing = REQUIRED_CAPABILITIES.filter( - (capability) => !capabilities.includes(capability), - ); - throw new Error(`Missing required capabilities: ${missing.join(", ")}`); - } console.info("NWC connected", info); @@ -214,6 +215,25 @@ export function SetupWallet() { returnKeyType="done" /> + {capabilities && + !REQUIRED_CAPABILITIES.every((capability) => + capabilities.includes(capability), + ) && ( + + + + + Alby Go might not work as expected + + Missing capabilities:  + {REQUIRED_CAPABILITIES.filter( + (capability) => !capabilities.includes(capability), + ).join(", ")} + + + + + )} From b1a19ec68e513eec122ba8c093060c5c31800bb8 Mon Sep 17 00:00:00 2001 From: im-adithya Date: Thu, 19 Dec 2024 12:49:29 +0530 Subject: [PATCH 2/3] chore: change card in wallet settings --- pages/settings/wallets/EditWallet.tsx | 38 ++++++++++++++------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/pages/settings/wallets/EditWallet.tsx b/pages/settings/wallets/EditWallet.tsx index b56abf9..f6d4f52 100644 --- a/pages/settings/wallets/EditWallet.tsx +++ b/pages/settings/wallets/EditWallet.tsx @@ -1,8 +1,7 @@ import { Link, router } from "expo-router"; -import { Alert, Pressable, Text, View } from "react-native"; +import { Alert, Pressable, View } from "react-native"; import Toast from "react-native-toast-message"; -import { Nip47Capability } from "@getalby/sdk/dist/NWCClient"; import * as Clipboard from "expo-clipboard"; import { ArchiveRestore, @@ -18,7 +17,7 @@ import { CardDescription, CardTitle, } from "~/components/ui/card"; -import { DEFAULT_WALLET_NAME } from "~/lib/constants"; +import { DEFAULT_WALLET_NAME, REQUIRED_CAPABILITIES } from "~/lib/constants"; import { useAppStore } from "~/lib/state/appStore"; export function EditWallet() { @@ -27,21 +26,24 @@ export function EditWallet() { return ( - {(["notifications", "list_transactions"] as Nip47Capability[]).map( - (capability) => - (wallets[selectedWalletId].nwcCapabilities || []).indexOf( - capability, - ) < 0 && ( - - - - - Your wallet does not support {capability} - - - - ), - )} + {/* TODO: Do not allow notifications to be toggled without notifications capability */} + + + + + This wallet might not work as expected + + Missing capabilities:  + {REQUIRED_CAPABILITIES.filter( + (capability) => + !(wallets[selectedWalletId].nwcCapabilities || []).includes( + capability, + ), + ).join(", ")} + + + + From 985509391f4c9740bf2c78da41097d57850d95b1 Mon Sep 17 00:00:00 2001 From: im-adithya Date: Tue, 24 Dec 2024 16:37:09 +0530 Subject: [PATCH 3/3] chore: stylize warning toasts --- components/ui/card.tsx | 2 +- pages/settings/wallets/EditWallet.tsx | 12 +++++++----- pages/settings/wallets/SetupWallet.tsx | 10 ++++++---- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/components/ui/card.tsx b/components/ui/card.tsx index b657d66..87cb6a4 100644 --- a/components/ui/card.tsx +++ b/components/ui/card.tsx @@ -56,7 +56,7 @@ const CardDescription = React.forwardRef< >(({ className, ...props }, ref) => ( )); diff --git a/pages/settings/wallets/EditWallet.tsx b/pages/settings/wallets/EditWallet.tsx index f6d4f52..a70a2b1 100644 --- a/pages/settings/wallets/EditWallet.tsx +++ b/pages/settings/wallets/EditWallet.tsx @@ -24,15 +24,17 @@ export function EditWallet() { const selectedWalletId = useAppStore((store) => store.selectedWalletId); const wallets = useAppStore((store) => store.wallets); return ( - + {/* TODO: Do not allow notifications to be toggled without notifications capability */} - + - + - This wallet might not work as expected - + + This wallet might not work as expected + + Missing capabilities:  {REQUIRED_CAPABILITIES.filter( (capability) => diff --git a/pages/settings/wallets/SetupWallet.tsx b/pages/settings/wallets/SetupWallet.tsx index a47cefb..047c055 100644 --- a/pages/settings/wallets/SetupWallet.tsx +++ b/pages/settings/wallets/SetupWallet.tsx @@ -248,12 +248,14 @@ export function SetupWallet() { !REQUIRED_CAPABILITIES.every((capability) => capabilities.includes(capability), ) && ( - + - + - Alby Go might not work as expected - + + Alby Go might not work as expected + + Missing capabilities:  {REQUIRED_CAPABILITIES.filter( (capability) => !capabilities.includes(capability),