Skip to content

Commit

Permalink
fix: validate capabilities in connection secret during setup
Browse files Browse the repository at this point in the history
  • Loading branch information
im-adithya committed Oct 1, 2024
1 parent 25c3e3a commit fcf4ad1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Nip47Capability } from "@getalby/sdk/dist/NWCClient";

export const NAV_THEME = {
light: {
background: "hsl(210 20% 98%)", // background
Expand Down Expand Up @@ -26,3 +28,5 @@ export const TRANSACTIONS_PAGE_SIZE = 20;
export const DEFAULT_CURRENCY = "USD";
export const DEFAULT_WALLET_NAME = "Default Wallet";
export const ALBY_LIGHTNING_ADDRESS = "[email protected]";

export const REQUIRED_CAPABILITIES: Nip47Capability[] = ["get_info", "get_balance", "make_invoice", "pay_invoice", "list_transactions"];
5 changes: 5 additions & 0 deletions pages/settings/wallets/WalletConnection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import Loading from "~/components/Loading";
import QRCodeScanner from "~/components/QRCodeScanner";
import Screen from "~/components/Screen";
import { Dialog, DialogTrigger, DialogContent, DialogHeader, DialogTitle, DialogFooter, DialogClose } from "~/components/ui/dialog";
import { REQUIRED_CAPABILITIES } from "~/lib/constants";

export function WalletConnection() {
const hasConnection = useAppStore((store) => !!store.nwcClient);
Expand Down Expand Up @@ -54,6 +55,10 @@ export function WalletConnection() {
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.log("NWC connected", info);
useAppStore.getState().setNostrWalletConnectUrl(nostrWalletConnectUrl);
useAppStore.getState().updateCurrentWallet({
Expand Down

0 comments on commit fcf4ad1

Please sign in to comment.