Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions components/layout/connect-wallet-button.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use client'

import { useState } from 'react'
import { Check, Copy, LogOut, Loader2, Wallet } from 'lucide-react'
import { Check, Copy, LogOut, Loader2, Wallet, ExternalLink } from 'lucide-react'
import { Button } from '@/components/ui/button'
import {
Dialog,
Expand All @@ -19,7 +19,7 @@
DropdownMenuTrigger,
} from '@/components/ui/dropdown-menu'
import { useWallet } from '@/hooks/use-wallet'
import { WALLET_OPTIONS } from '@/components/providers/wallet-provider'
import { WALLET_OPTIONS, ADAPTERS } from '@/components/providers/wallet-provider'
import { shortenAddress } from '@/lib/stream-utils'
import { cn } from '@/lib/utils'
import { toast } from 'sonner'
Expand Down Expand Up @@ -114,6 +114,7 @@
</div>
{WALLET_OPTIONS.map((wallet) => {
const isPending = connecting && pendingId === wallet.id
const available = ADAPTERS[wallet.id]?.isAvailable() ?? true

Check failure on line 117 in components/layout/connect-wallet-button.tsx

View workflow job for this annotation

GitHub Actions / build

__tests__/components/connect-wallet-button.test.tsx > ConnectWalletButton — disconnected > disables wallet buttons while connecting

Error: [vitest] No "ADAPTERS" export is defined on the "@/components/providers/wallet-provider" mock. Did you forget to return it from "vi.mock"? If you need to partially mock a module, you can use "importOriginal" helper inside: vi.mock(import("@/components/providers/wallet-provider"), async (importOriginal) => { const actual = await importOriginal() return { ...actual, // your mocked methods } }) ❯ components/layout/connect-wallet-button.tsx:117:31 ❯ ConnectWalletButton components/layout/connect-wallet-button.tsx:115:27 ❯ Object.react_stack_bottom_frame node_modules/react-dom/cjs/react-dom-client.development.js:25904:20 ❯ renderWithHooks node_modules/react-dom/cjs/react-dom-client.development.js:7662:22 ❯ updateFunctionComponent node_modules/react-dom/cjs/react-dom-client.development.js:10166:19 ❯ beginWork node_modules/react-dom/cjs/react-dom-client.development.js:11778:18 ❯ runWithFiberInDEV node_modules/react-dom/cjs/react-dom-client.development.js:874:13

Check failure on line 117 in components/layout/connect-wallet-button.tsx

View workflow job for this annotation

GitHub Actions / build

__tests__/components/connect-wallet-button.test.tsx > ConnectWalletButton — disconnected > calls connect with wallet id when option is clicked

Error: [vitest] No "ADAPTERS" export is defined on the "@/components/providers/wallet-provider" mock. Did you forget to return it from "vi.mock"? If you need to partially mock a module, you can use "importOriginal" helper inside: vi.mock(import("@/components/providers/wallet-provider"), async (importOriginal) => { const actual = await importOriginal() return { ...actual, // your mocked methods } }) ❯ components/layout/connect-wallet-button.tsx:117:31 ❯ ConnectWalletButton components/layout/connect-wallet-button.tsx:115:27 ❯ Object.react_stack_bottom_frame node_modules/react-dom/cjs/react-dom-client.development.js:25904:20 ❯ renderWithHooks node_modules/react-dom/cjs/react-dom-client.development.js:7662:22 ❯ updateFunctionComponent node_modules/react-dom/cjs/react-dom-client.development.js:10166:19 ❯ beginWork node_modules/react-dom/cjs/react-dom-client.development.js:11778:18 ❯ runWithFiberInDEV node_modules/react-dom/cjs/react-dom-client.development.js:874:13

Check failure on line 117 in components/layout/connect-wallet-button.tsx

View workflow job for this annotation

GitHub Actions / build

__tests__/components/connect-wallet-button.test.tsx > ConnectWalletButton — disconnected > lists wallet options in dialog

Error: [vitest] No "ADAPTERS" export is defined on the "@/components/providers/wallet-provider" mock. Did you forget to return it from "vi.mock"? If you need to partially mock a module, you can use "importOriginal" helper inside: vi.mock(import("@/components/providers/wallet-provider"), async (importOriginal) => { const actual = await importOriginal() return { ...actual, // your mocked methods } }) ❯ components/layout/connect-wallet-button.tsx:117:31 ❯ ConnectWalletButton components/layout/connect-wallet-button.tsx:115:27 ❯ Object.react_stack_bottom_frame node_modules/react-dom/cjs/react-dom-client.development.js:25904:20 ❯ renderWithHooks node_modules/react-dom/cjs/react-dom-client.development.js:7662:22 ❯ updateFunctionComponent node_modules/react-dom/cjs/react-dom-client.development.js:10166:19 ❯ beginWork node_modules/react-dom/cjs/react-dom-client.development.js:11778:18 ❯ runWithFiberInDEV node_modules/react-dom/cjs/react-dom-client.development.js:874:13

Check failure on line 117 in components/layout/connect-wallet-button.tsx

View workflow job for this annotation

GitHub Actions / build

__tests__/components/connect-wallet-button.test.tsx > ConnectWalletButton — disconnected > opens wallet selection dialog on click

Error: [vitest] No "ADAPTERS" export is defined on the "@/components/providers/wallet-provider" mock. Did you forget to return it from "vi.mock"? If you need to partially mock a module, you can use "importOriginal" helper inside: vi.mock(import("@/components/providers/wallet-provider"), async (importOriginal) => { const actual = await importOriginal() return { ...actual, // your mocked methods } }) ❯ components/layout/connect-wallet-button.tsx:117:31 ❯ ConnectWalletButton components/layout/connect-wallet-button.tsx:115:27 ❯ Object.react_stack_bottom_frame node_modules/react-dom/cjs/react-dom-client.development.js:25904:20 ❯ renderWithHooks node_modules/react-dom/cjs/react-dom-client.development.js:7662:22 ❯ updateFunctionComponent node_modules/react-dom/cjs/react-dom-client.development.js:10166:19 ❯ beginWork node_modules/react-dom/cjs/react-dom-client.development.js:11778:18 ❯ runWithFiberInDEV node_modules/react-dom/cjs/react-dom-client.development.js:874:13

Check failure on line 117 in components/layout/connect-wallet-button.tsx

View workflow job for this annotation

GitHub Actions / build

__tests__/components/connect-wallet-button.test.tsx > ConnectWalletButton — disconnected > renders "Connect wallet" button

Error: [vitest] No "ADAPTERS" export is defined on the "@/components/providers/wallet-provider" mock. Did you forget to return it from "vi.mock"? If you need to partially mock a module, you can use "importOriginal" helper inside: vi.mock(import("@/components/providers/wallet-provider"), async (importOriginal) => { const actual = await importOriginal() return { ...actual, // your mocked methods } }) ❯ components/layout/connect-wallet-button.tsx:117:31 ❯ ConnectWalletButton components/layout/connect-wallet-button.tsx:115:27 ❯ Object.react_stack_bottom_frame node_modules/react-dom/cjs/react-dom-client.development.js:25904:20 ❯ renderWithHooks node_modules/react-dom/cjs/react-dom-client.development.js:7662:22 ❯ updateFunctionComponent node_modules/react-dom/cjs/react-dom-client.development.js:10166:19 ❯ beginWork node_modules/react-dom/cjs/react-dom-client.development.js:11778:18 ❯ runWithFiberInDEV node_modules/react-dom/cjs/react-dom-client.development.js:874:13
return (
<button
key={wallet.id}
Expand All @@ -134,6 +135,24 @@
{isPending && (
<Loader2 className="size-4 animate-spin text-muted-foreground" />
)}
{!isPending && !available && (
wallet.installUrl ? (
<a
href={wallet.installUrl}
target="_blank"
rel="noopener noreferrer"
onClick={(e) => e.stopPropagation()}
className="flex items-center gap-1 rounded-full bg-muted px-2 py-0.5 text-xs text-muted-foreground hover:text-foreground"
>
Not installed
<ExternalLink className="size-3" />
</a>
) : (
<span className="rounded-full bg-muted px-2 py-0.5 text-xs text-muted-foreground">
Not installed
</span>
)
)}
</button>
)
})}
Expand Down
25 changes: 20 additions & 5 deletions components/layout/notification-bell.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
'use client'

import { useState, useRef, useEffect } from 'react'
import { Bell } from 'lucide-react'
import { Bell, X } from 'lucide-react'
import { formatTimeAgo } from '@/lib/stream-utils'
import { useWallet } from '@/hooks/use-wallet'
import { useNotifications, type AppNotification } from '@/hooks/use-notifications'

function NotificationItem({
notification,
onDismiss,
}: {
notification: AppNotification
onDismiss: (id: string) => void
itemRef,
}: {
notification: AppNotification
Expand All @@ -25,9 +29,18 @@ function NotificationItem({
>
<div className="flex items-start justify-between gap-2">
<p className="text-sm font-medium">{notification.title}</p>
{!notification.read && (
<span className="mt-1 size-2 shrink-0 rounded-full bg-primary" />
)}
<div className="flex shrink-0 items-center gap-1.5 mt-0.5">
{!notification.read && (
<span className="size-2 rounded-full bg-primary" />
)}
<button
onClick={() => onDismiss(notification.id)}
aria-label="Dismiss notification"
className="text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:rounded"
>
<X className="size-3.5" />
</button>
</div>
</div>
<p className="mt-0.5 text-xs text-muted-foreground">{notification.body}</p>
<p className="mt-1 text-xs text-muted-foreground">{formatTimeAgo(notification.timestamp)}</p>
Expand All @@ -37,7 +50,7 @@ function NotificationItem({

export function NotificationBell() {
const { address } = useWallet()
const { notifications, unreadCount, markAllRead, clearAll } = useNotifications(address)
const { notifications, unreadCount, markAllRead, clearAll, dismissNotification } = useNotifications(address)
const [open, setOpen] = useState(false)
const [activeIndex, setActiveIndex] = useState(-1)
const ref = useRef<HTMLDivElement>(null)
Expand Down Expand Up @@ -151,6 +164,8 @@ export function NotificationBell() {
No notifications yet
</p>
) : (
notifications.map((n) => (
<NotificationItem key={n.id} notification={n} onDismiss={dismissNotification} />
notifications.map((n, idx) => (
<NotificationItem
key={n.id}
Expand Down
11 changes: 9 additions & 2 deletions components/providers/wallet-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,22 @@ export interface WalletOption {
id: string;
name: string;
detail: string;
installUrl?: string;
}

export const WALLET_OPTIONS: WalletOption[] = [
{
id: "freighter",
name: "Freighter",
detail: "Browser extension · stellar.org",
installUrl: "https://www.freighter.app",
},
{
id: "xbull",
name: "xBull",
detail: "Extension & web",
installUrl: "https://xbull.app",
},
{ id: "xbull", name: "xBull", detail: "Extension & web" },
{ id: "lobstr", name: "LOBSTR", detail: "Mobile & extension" },
{ id: "albedo", name: "Albedo", detail: "Web signer" },
];
Expand Down Expand Up @@ -287,7 +294,7 @@ const albedoAdapter: WalletAdapter = {

// ─── Adapter registry ─────────────────────────────────────────────────────────

const ADAPTERS: Record<string, WalletAdapter> = {
export const ADAPTERS: Record<string, WalletAdapter> = {
freighter: freighterAdapter,
xbull: xbullAdapter,
lobstr: lobstrAdapter,
Expand Down
10 changes: 9 additions & 1 deletion hooks/use-notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,14 @@ export function useNotifications(walletAddress: string | null) {
saveNotifications([]);
}, []);

const dismissNotification = useCallback((id: string) => {
setNotifications((prev) => {
const updated = prev.filter((n) => n.id !== id);
saveNotifications(updated);
return updated;
});
}, []);

useEffect(() => {
const rpcUrl = config.rpcUrl;
const contractId = config.streamContractId;
Expand Down Expand Up @@ -388,5 +396,5 @@ export function useNotifications(walletAddress: string | null) {
network,
]);

return { notifications, unreadCount, markAllRead, clearAll };
return { notifications, unreadCount, markAllRead, clearAll, dismissNotification };
}
Loading