@b3dotfun/sdk 0.0.46 → 0.0.47-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/README.md +3 -222
  2. package/dist/cjs/anyspend/react/components/AnySpend.js +13 -14
  3. package/dist/cjs/anyspend/react/components/AnyspendDepositHype.js +14 -15
  4. package/dist/cjs/anyspend/react/components/common/OrderHistory.js +2 -2
  5. package/dist/cjs/anyspend/react/components/common/OrderHistoryItem.js +6 -3
  6. package/dist/cjs/anyspend/types/api.d.ts +176 -0
  7. package/dist/cjs/anyspend/utils/chain.js +1 -1
  8. package/dist/cjs/shared/react/hooks/__tests__/useCurrencyConversion.test.js +245 -0
  9. package/dist/cjs/shared/utils/index.d.ts +0 -1
  10. package/dist/cjs/shared/utils/index.js +0 -1
  11. package/dist/esm/anyspend/react/components/AnySpend.js +14 -15
  12. package/dist/esm/anyspend/react/components/AnyspendDepositHype.js +15 -16
  13. package/dist/esm/anyspend/react/components/common/OrderHistory.js +2 -2
  14. package/dist/esm/anyspend/react/components/common/OrderHistoryItem.js +8 -5
  15. package/dist/esm/anyspend/types/api.d.ts +176 -0
  16. package/dist/esm/anyspend/utils/chain.js +1 -1
  17. package/dist/esm/shared/react/hooks/__tests__/useCurrencyConversion.test.d.ts +1 -0
  18. package/dist/esm/shared/react/hooks/__tests__/useCurrencyConversion.test.js +243 -0
  19. package/dist/esm/shared/utils/index.d.ts +0 -1
  20. package/dist/esm/shared/utils/index.js +0 -1
  21. package/dist/styles/index.css +1 -1
  22. package/dist/types/anyspend/types/api.d.ts +176 -0
  23. package/dist/types/shared/react/hooks/__tests__/useCurrencyConversion.test.d.ts +1 -0
  24. package/dist/types/shared/utils/index.d.ts +0 -1
  25. package/package.json +2 -21
  26. package/src/anyspend/react/components/AnySpend.tsx +21 -19
  27. package/src/anyspend/react/components/AnyspendDepositHype.tsx +21 -21
  28. package/src/anyspend/react/components/common/OrderHistory.tsx +11 -11
  29. package/src/anyspend/react/components/common/OrderHistoryItem.tsx +124 -129
  30. package/src/anyspend/types/api.ts +176 -0
  31. package/src/anyspend/utils/chain.ts +1 -4
  32. package/src/shared/utils/index.ts +0 -1
  33. package/dist/cjs/anyspend/react/components/common/ErrorSection.d.ts +0 -6
  34. package/dist/cjs/anyspend/react/components/common/ErrorSection.js +0 -12
  35. package/dist/cjs/notifications/index.d.ts +0 -3
  36. package/dist/cjs/notifications/index.js +0 -25
  37. package/dist/cjs/notifications/react/hooks/index.d.ts +0 -1
  38. package/dist/cjs/notifications/react/hooks/index.js +0 -17
  39. package/dist/cjs/notifications/react/hooks/useNotifications.d.ts +0 -42
  40. package/dist/cjs/notifications/react/hooks/useNotifications.js +0 -148
  41. package/dist/cjs/notifications/react/index.d.ts +0 -1
  42. package/dist/cjs/notifications/react/index.js +0 -17
  43. package/dist/cjs/notifications/services/api.d.ts +0 -67
  44. package/dist/cjs/notifications/services/api.js +0 -184
  45. package/dist/cjs/notifications/services/index.d.ts +0 -1
  46. package/dist/cjs/notifications/services/index.js +0 -17
  47. package/dist/cjs/notifications/types/index.d.ts +0 -51
  48. package/dist/cjs/notifications/types/index.js +0 -2
  49. package/dist/cjs/shared/utils/auth-token.d.ts +0 -7
  50. package/dist/cjs/shared/utils/auth-token.js +0 -17
  51. package/dist/esm/anyspend/react/components/common/ErrorSection.d.ts +0 -6
  52. package/dist/esm/anyspend/react/components/common/ErrorSection.js +0 -9
  53. package/dist/esm/notifications/index.d.ts +0 -3
  54. package/dist/esm/notifications/index.js +0 -7
  55. package/dist/esm/notifications/react/hooks/index.d.ts +0 -1
  56. package/dist/esm/notifications/react/hooks/index.js +0 -1
  57. package/dist/esm/notifications/react/hooks/useNotifications.d.ts +0 -42
  58. package/dist/esm/notifications/react/hooks/useNotifications.js +0 -145
  59. package/dist/esm/notifications/react/index.d.ts +0 -1
  60. package/dist/esm/notifications/react/index.js +0 -1
  61. package/dist/esm/notifications/services/api.d.ts +0 -67
  62. package/dist/esm/notifications/services/api.js +0 -179
  63. package/dist/esm/notifications/services/index.d.ts +0 -1
  64. package/dist/esm/notifications/services/index.js +0 -1
  65. package/dist/esm/notifications/types/index.d.ts +0 -51
  66. package/dist/esm/shared/utils/auth-token.d.ts +0 -7
  67. package/dist/esm/shared/utils/auth-token.js +0 -11
  68. package/dist/types/anyspend/react/components/common/ErrorSection.d.ts +0 -6
  69. package/dist/types/notifications/index.d.ts +0 -3
  70. package/dist/types/notifications/react/hooks/index.d.ts +0 -1
  71. package/dist/types/notifications/react/hooks/useNotifications.d.ts +0 -42
  72. package/dist/types/notifications/react/index.d.ts +0 -1
  73. package/dist/types/notifications/services/api.d.ts +0 -67
  74. package/dist/types/notifications/services/index.d.ts +0 -1
  75. package/dist/types/notifications/types/index.d.ts +0 -51
  76. package/dist/types/shared/utils/auth-token.d.ts +0 -7
  77. package/src/anyspend/react/components/common/ErrorSection.tsx +0 -21
  78. package/src/notifications/index.ts +0 -9
  79. package/src/notifications/react/hooks/index.ts +0 -1
  80. package/src/notifications/react/hooks/useNotifications.ts +0 -153
  81. package/src/notifications/react/index.ts +0 -1
  82. package/src/notifications/services/api.ts +0 -217
  83. package/src/notifications/services/index.ts +0 -1
  84. package/src/notifications/types/index.ts +0 -58
  85. package/src/shared/utils/auth-token.ts +0 -13
  86. /package/dist/{esm/notifications/types/index.js → cjs/shared/react/hooks/__tests__/useCurrencyConversion.test.d.ts} +0 -0
@@ -1,179 +0,0 @@
1
- import { getAuthToken } from "../../shared/utils/auth-token.js";
2
- const DEFAULT_API_URL = "https://notifications.b3.fun";
3
- let apiUrl = DEFAULT_API_URL;
4
- export function setApiUrl(url) {
5
- apiUrl = url;
6
- }
7
- export function getApiUrl() {
8
- return apiUrl;
9
- }
10
- function getHeaders(includeAuth = false) {
11
- const headers = {
12
- "Content-Type": "application/json",
13
- };
14
- if (includeAuth) {
15
- const token = getAuthToken();
16
- if (token) {
17
- headers["Authorization"] = `Bearer ${token}`;
18
- }
19
- }
20
- return headers;
21
- }
22
- export const notificationsAPI = {
23
- // ===== USER MANAGEMENT =====
24
- /**
25
- * Register the current user (userId extracted from JWT)
26
- */
27
- async registerUser() {
28
- const res = await fetch(`${apiUrl}/users`, {
29
- method: "POST",
30
- headers: getHeaders(true),
31
- });
32
- if (!res.ok) {
33
- const errorBody = await res.text().catch(() => "Could not read error body");
34
- throw new Error(`API Error: ${res.status} ${res.statusText} - ${errorBody}`);
35
- }
36
- return res.json();
37
- },
38
- /**
39
- * Get current user's profile and preferences
40
- */
41
- async getUser() {
42
- const res = await fetch(`${apiUrl}/users/me`, {
43
- headers: getHeaders(true),
44
- });
45
- return res.json();
46
- },
47
- /**
48
- * Get current user's notification history
49
- */
50
- async getHistory(appId, limit = 100) {
51
- const params = new URLSearchParams();
52
- if (appId)
53
- params.append("appId", appId);
54
- params.append("limit", limit.toString());
55
- const res = await fetch(`${apiUrl}/users/me/history?${params}`, {
56
- headers: getHeaders(true),
57
- });
58
- return res.json();
59
- },
60
- // ===== CHANNELS =====
61
- /**
62
- * Add a notification channel for current user
63
- */
64
- async addChannel(channelType, channelIdentifier, metadata) {
65
- const res = await fetch(`${apiUrl}/users/me/channels`, {
66
- method: "POST",
67
- headers: getHeaders(true),
68
- body: JSON.stringify({
69
- channelType,
70
- channelIdentifier,
71
- enabled: true,
72
- metadata,
73
- }),
74
- });
75
- return res.json();
76
- },
77
- /**
78
- * Connect email for current user
79
- */
80
- async connectEmail(email) {
81
- return this.addChannel("email", email);
82
- },
83
- /**
84
- * Update a notification channel
85
- */
86
- async updateChannel(channelId, updates) {
87
- const res = await fetch(`${apiUrl}/users/me/channels/${channelId}`, {
88
- method: "PUT",
89
- headers: getHeaders(true),
90
- body: JSON.stringify(updates),
91
- });
92
- return res.json();
93
- },
94
- /**
95
- * Delete a notification channel
96
- */
97
- async deleteChannel(channelId) {
98
- const res = await fetch(`${apiUrl}/users/me/channels/${channelId}`, {
99
- method: "DELETE",
100
- headers: getHeaders(true),
101
- });
102
- return res.json();
103
- },
104
- // ===== TELEGRAM =====
105
- /**
106
- * Get Telegram deep link for current user
107
- */
108
- async getTelegramLink() {
109
- const res = await fetch(`${apiUrl}/telegram/request-link`, {
110
- method: "POST",
111
- headers: getHeaders(true),
112
- });
113
- return res.json();
114
- },
115
- /**
116
- * Check current user's Telegram connection status
117
- */
118
- async checkTelegramStatus() {
119
- const res = await fetch(`${apiUrl}/telegram/status/me`, {
120
- headers: getHeaders(true),
121
- });
122
- return res.json();
123
- },
124
- // ===== APP PREFERENCES =====
125
- /**
126
- * Save notification preferences for an app
127
- * @param appId - The application ID
128
- * @param settings - Notification preferences including channels, type, and enabled status (defaults to true)
129
- */
130
- async savePreferences(appId, settings) {
131
- const res = await fetch(`${apiUrl}/users/me/apps/${appId}/settings`, {
132
- method: "POST",
133
- headers: getHeaders(true),
134
- body: JSON.stringify({ enabled: true, ...settings }),
135
- });
136
- return res.json();
137
- },
138
- /**
139
- * Get notification settings for an app
140
- */
141
- async getAppSettings(appId) {
142
- const res = await fetch(`${apiUrl}/users/me/apps/${appId}/settings`, {
143
- headers: getHeaders(true),
144
- });
145
- return res.json();
146
- },
147
- // ===== IN-APP NOTIFICATIONS =====
148
- /**
149
- * Get current user's in-app notifications
150
- */
151
- async getInAppNotifications() {
152
- const res = await fetch(`${apiUrl}/users/me/notifications`, {
153
- headers: getHeaders(true),
154
- });
155
- return res.json();
156
- },
157
- /**
158
- * Mark a notification as read
159
- */
160
- async markNotificationAsRead(notificationId) {
161
- const res = await fetch(`${apiUrl}/users/me/notifications/${notificationId}/read`, {
162
- method: "PUT",
163
- headers: getHeaders(true),
164
- });
165
- return res.json();
166
- },
167
- // ===== SENDING NOTIFICATIONS =====
168
- /**
169
- * Send a notification (requires auth)
170
- */
171
- async sendNotification(data) {
172
- const res = await fetch(`${apiUrl}/send`, {
173
- method: "POST",
174
- headers: getHeaders(true),
175
- body: JSON.stringify(data),
176
- });
177
- return res.json();
178
- },
179
- };
@@ -1 +0,0 @@
1
- export * from "./api";
@@ -1 +0,0 @@
1
- export * from "./api.js";
@@ -1,51 +0,0 @@
1
- export type ChannelType = "email" | "telegram" | "discord" | "sms" | "whatsapp" | "in_app";
2
- export interface NotificationChannel {
3
- id: number;
4
- channel_type: ChannelType;
5
- enabled: number;
6
- channel_identifier: string;
7
- }
8
- export interface UserData {
9
- user: {
10
- id: number;
11
- user_id: string;
12
- };
13
- channels: NotificationChannel[];
14
- appSettings: Array<{
15
- app_id: string;
16
- notification_type: string;
17
- enabled: number;
18
- channels: string;
19
- }>;
20
- }
21
- export interface NotificationHistory {
22
- id: string;
23
- app_id: string;
24
- notification_type: string;
25
- title: string;
26
- message: string;
27
- created_at: string;
28
- read: boolean;
29
- }
30
- export interface TelegramLinkResponse {
31
- deepLink: string;
32
- verificationCode: string;
33
- botUsername: string;
34
- }
35
- export interface TelegramStatusResponse {
36
- connected: boolean;
37
- chatId?: string;
38
- }
39
- export interface NotificationPreferences {
40
- notificationType: string;
41
- channels: string[];
42
- enabled?: boolean;
43
- }
44
- export interface SendNotificationRequest {
45
- userId: string;
46
- appId: string;
47
- notificationType: string;
48
- message: string;
49
- title?: string;
50
- data?: Record<string, any>;
51
- }
@@ -1,7 +0,0 @@
1
- /**
2
- * Get the authentication token from the B3 auth cookie
3
- * This token is managed by the B3 Global Account authentication system
4
- *
5
- * @returns The JWT token string or null if not found
6
- */
7
- export declare function getAuthToken(): string | null;
@@ -1,11 +0,0 @@
1
- import Cookies from "js-cookie";
2
- const B3_AUTH_COOKIE_NAME = "b3-auth";
3
- /**
4
- * Get the authentication token from the B3 auth cookie
5
- * This token is managed by the B3 Global Account authentication system
6
- *
7
- * @returns The JWT token string or null if not found
8
- */
9
- export function getAuthToken() {
10
- return Cookies.get(B3_AUTH_COOKIE_NAME) || null;
11
- }
@@ -1,6 +0,0 @@
1
- interface ErrorSectionProps {
2
- error?: Error | null;
3
- message?: string;
4
- }
5
- export declare function ErrorSection({ error, message }: ErrorSectionProps): import("react/jsx-runtime").JSX.Element | null;
6
- export {};
@@ -1,3 +0,0 @@
1
- export * from "./types";
2
- export * from "./services";
3
- export { getAuthToken } from "../shared/utils/auth-token";
@@ -1 +0,0 @@
1
- export * from "./useNotifications";
@@ -1,42 +0,0 @@
1
- import type { UserData } from "../../types";
2
- /**
3
- * React hook for managing B3 notifications
4
- * Automatically uses the authenticated user's ID from JWT
5
- *
6
- * @example
7
- * ```tsx
8
- * import { useNotifications } from '@b3dotfun/sdk/notifications/react';
9
- *
10
- * function NotificationSettings() {
11
- * const { user, loading, connectEmail, connectTelegram, isEmailConnected } = useNotifications();
12
- *
13
- * if (loading) return <div>Loading...</div>;
14
- *
15
- * return (
16
- * <div>
17
- * {!isEmailConnected && (
18
- * <button onClick={() => connectEmail('user@example.com')}>
19
- * Connect Email
20
- * </button>
21
- * )}
22
- * <button onClick={connectTelegram}>Connect Telegram</button>
23
- * </div>
24
- * );
25
- * }
26
- * ```
27
- */
28
- export declare function useNotifications(): {
29
- user: UserData | null;
30
- loading: boolean;
31
- error: Error | null;
32
- refresh: () => Promise<void>;
33
- connectEmail: (email: string) => Promise<void>;
34
- connectTelegram: () => Promise<void>;
35
- updateChannel: (channelId: string, updates: {
36
- enabled?: boolean;
37
- }) => Promise<void>;
38
- deleteChannel: (channelId: string) => Promise<void>;
39
- isEmailConnected: boolean;
40
- isTelegramConnected: boolean;
41
- isDiscordConnected: boolean;
42
- };
@@ -1 +0,0 @@
1
- export * from "./hooks";
@@ -1,67 +0,0 @@
1
- import type { NotificationHistory, NotificationPreferences, SendNotificationRequest, TelegramLinkResponse, TelegramStatusResponse, UserData } from "../types";
2
- export declare function setApiUrl(url: string): void;
3
- export declare function getApiUrl(): string;
4
- export declare const notificationsAPI: {
5
- /**
6
- * Register the current user (userId extracted from JWT)
7
- */
8
- registerUser(): Promise<any>;
9
- /**
10
- * Get current user's profile and preferences
11
- */
12
- getUser(): Promise<UserData>;
13
- /**
14
- * Get current user's notification history
15
- */
16
- getHistory(appId?: string, limit?: number): Promise<NotificationHistory[]>;
17
- /**
18
- * Add a notification channel for current user
19
- */
20
- addChannel(channelType: string, channelIdentifier: string, metadata?: Record<string, any>): Promise<any>;
21
- /**
22
- * Connect email for current user
23
- */
24
- connectEmail(email: string): Promise<any>;
25
- /**
26
- * Update a notification channel
27
- */
28
- updateChannel(channelId: string, updates: {
29
- enabled?: boolean;
30
- channelIdentifier?: string;
31
- metadata?: Record<string, any>;
32
- }): Promise<any>;
33
- /**
34
- * Delete a notification channel
35
- */
36
- deleteChannel(channelId: string): Promise<any>;
37
- /**
38
- * Get Telegram deep link for current user
39
- */
40
- getTelegramLink(): Promise<TelegramLinkResponse>;
41
- /**
42
- * Check current user's Telegram connection status
43
- */
44
- checkTelegramStatus(): Promise<TelegramStatusResponse>;
45
- /**
46
- * Save notification preferences for an app
47
- * @param appId - The application ID
48
- * @param settings - Notification preferences including channels, type, and enabled status (defaults to true)
49
- */
50
- savePreferences(appId: string, settings: NotificationPreferences): Promise<any>;
51
- /**
52
- * Get notification settings for an app
53
- */
54
- getAppSettings(appId: string): Promise<any>;
55
- /**
56
- * Get current user's in-app notifications
57
- */
58
- getInAppNotifications(): Promise<any>;
59
- /**
60
- * Mark a notification as read
61
- */
62
- markNotificationAsRead(notificationId: string): Promise<any>;
63
- /**
64
- * Send a notification (requires auth)
65
- */
66
- sendNotification(data: SendNotificationRequest): Promise<any>;
67
- };
@@ -1 +0,0 @@
1
- export * from "./api";
@@ -1,51 +0,0 @@
1
- export type ChannelType = "email" | "telegram" | "discord" | "sms" | "whatsapp" | "in_app";
2
- export interface NotificationChannel {
3
- id: number;
4
- channel_type: ChannelType;
5
- enabled: number;
6
- channel_identifier: string;
7
- }
8
- export interface UserData {
9
- user: {
10
- id: number;
11
- user_id: string;
12
- };
13
- channels: NotificationChannel[];
14
- appSettings: Array<{
15
- app_id: string;
16
- notification_type: string;
17
- enabled: number;
18
- channels: string;
19
- }>;
20
- }
21
- export interface NotificationHistory {
22
- id: string;
23
- app_id: string;
24
- notification_type: string;
25
- title: string;
26
- message: string;
27
- created_at: string;
28
- read: boolean;
29
- }
30
- export interface TelegramLinkResponse {
31
- deepLink: string;
32
- verificationCode: string;
33
- botUsername: string;
34
- }
35
- export interface TelegramStatusResponse {
36
- connected: boolean;
37
- chatId?: string;
38
- }
39
- export interface NotificationPreferences {
40
- notificationType: string;
41
- channels: string[];
42
- enabled?: boolean;
43
- }
44
- export interface SendNotificationRequest {
45
- userId: string;
46
- appId: string;
47
- notificationType: string;
48
- message: string;
49
- title?: string;
50
- data?: Record<string, any>;
51
- }
@@ -1,7 +0,0 @@
1
- /**
2
- * Get the authentication token from the B3 auth cookie
3
- * This token is managed by the B3 Global Account authentication system
4
- *
5
- * @returns The JWT token string or null if not found
6
- */
7
- export declare function getAuthToken(): string | null;
@@ -1,21 +0,0 @@
1
- import { CircleAlert } from "lucide-react";
2
-
3
- interface ErrorSectionProps {
4
- error?: Error | null;
5
- message?: string;
6
- }
7
-
8
- export function ErrorSection({ error, message }: ErrorSectionProps) {
9
- if (!error && !message) {
10
- return null;
11
- }
12
-
13
- const errorMessage = message || error?.message || "An error occurred";
14
-
15
- return (
16
- <div className="error-section bg-as-on-surface-1 flex w-full max-w-[460px] items-center gap-2 rounded-2xl px-4 py-2">
17
- <CircleAlert className="bg-as-red h-4 min-h-4 w-4 min-w-4 rounded-full p-0 text-sm font-medium text-white" />
18
- <div className="text-as-red text-sm">{errorMessage}</div>
19
- </div>
20
- );
21
- }
@@ -1,9 +0,0 @@
1
- // Export types
2
- export * from "./types";
3
-
4
- // Export services
5
- export * from "./services";
6
-
7
- // Re-export auth token getter from shared for convenience
8
- // Note: Auth token is managed by B3 Global Account authentication
9
- export { getAuthToken } from "../shared/utils/auth-token";
@@ -1 +0,0 @@
1
- export * from "./useNotifications";
@@ -1,153 +0,0 @@
1
- import { useEffect, useRef, useState } from "react";
2
- import { notificationsAPI } from "../../services/api";
3
- import type { UserData } from "../../types";
4
-
5
- /**
6
- * React hook for managing B3 notifications
7
- * Automatically uses the authenticated user's ID from JWT
8
- *
9
- * @example
10
- * ```tsx
11
- * import { useNotifications } from '@b3dotfun/sdk/notifications/react';
12
- *
13
- * function NotificationSettings() {
14
- * const { user, loading, connectEmail, connectTelegram, isEmailConnected } = useNotifications();
15
- *
16
- * if (loading) return <div>Loading...</div>;
17
- *
18
- * return (
19
- * <div>
20
- * {!isEmailConnected && (
21
- * <button onClick={() => connectEmail('user@example.com')}>
22
- * Connect Email
23
- * </button>
24
- * )}
25
- * <button onClick={connectTelegram}>Connect Telegram</button>
26
- * </div>
27
- * );
28
- * }
29
- * ```
30
- */
31
- export function useNotifications() {
32
- const [user, setUser] = useState<UserData | null>(null);
33
- const [loading, setLoading] = useState(true);
34
- const [error, setError] = useState<Error | null>(null);
35
-
36
- // Refs to track polling timers for cleanup
37
- const telegramPollIntervalRef = useRef<NodeJS.Timeout | null>(null);
38
- const telegramPollTimeoutRef = useRef<NodeJS.Timeout | null>(null);
39
-
40
- // Cleanup function for Telegram polling
41
- const cleanupTelegramPolling = () => {
42
- if (telegramPollIntervalRef.current) {
43
- clearInterval(telegramPollIntervalRef.current);
44
- telegramPollIntervalRef.current = null;
45
- }
46
- if (telegramPollTimeoutRef.current) {
47
- clearTimeout(telegramPollTimeoutRef.current);
48
- telegramPollTimeoutRef.current = null;
49
- }
50
- };
51
-
52
- // Load user data on mount
53
- useEffect(() => {
54
- loadUser();
55
- }, []);
56
-
57
- // Cleanup polling on unmount
58
- useEffect(() => {
59
- return () => {
60
- cleanupTelegramPolling();
61
- };
62
- }, []);
63
-
64
- const loadUser = async () => {
65
- try {
66
- setLoading(true);
67
- setError(null);
68
- const userData = await notificationsAPI.getUser();
69
- setUser(userData);
70
- } catch (err) {
71
- setError(err instanceof Error ? err : new Error("Failed to load user"));
72
- console.error("Failed to load user:", err);
73
- } finally {
74
- setLoading(false);
75
- }
76
- };
77
-
78
- const connectEmail = async (email: string) => {
79
- try {
80
- await notificationsAPI.connectEmail(email);
81
- await loadUser(); // Refresh user data
82
- } catch (err) {
83
- console.error("Failed to connect email:", err);
84
- throw err;
85
- }
86
- };
87
-
88
- const connectTelegram = async () => {
89
- try {
90
- // Clear any existing polling before starting new one
91
- cleanupTelegramPolling();
92
-
93
- const { deepLink } = await notificationsAPI.getTelegramLink();
94
- window.open(deepLink, "_blank");
95
-
96
- // Poll for connection status
97
- telegramPollIntervalRef.current = setInterval(async () => {
98
- try {
99
- const { connected } = await notificationsAPI.checkTelegramStatus();
100
- if (connected) {
101
- cleanupTelegramPolling();
102
- await loadUser(); // Refresh user data
103
- }
104
- } catch (err) {
105
- console.error("Failed to check Telegram status:", err);
106
- }
107
- }, 2000);
108
-
109
- // Stop polling after 2 minutes
110
- telegramPollTimeoutRef.current = setTimeout(() => {
111
- cleanupTelegramPolling();
112
- }, 120000);
113
- } catch (err) {
114
- console.error("Failed to connect Telegram:", err);
115
- throw err;
116
- }
117
- };
118
-
119
- const updateChannel = async (channelId: string, updates: { enabled?: boolean }) => {
120
- try {
121
- await notificationsAPI.updateChannel(channelId, updates);
122
- await loadUser(); // Refresh user data
123
- } catch (err) {
124
- console.error("Failed to update channel:", err);
125
- throw err;
126
- }
127
- };
128
-
129
- const deleteChannel = async (channelId: string) => {
130
- try {
131
- await notificationsAPI.deleteChannel(channelId);
132
- await loadUser(); // Refresh user data
133
- } catch (err) {
134
- console.error("Failed to delete channel:", err);
135
- throw err;
136
- }
137
- };
138
-
139
- return {
140
- user,
141
- loading,
142
- error,
143
- refresh: loadUser,
144
- connectEmail,
145
- connectTelegram,
146
- updateChannel,
147
- deleteChannel,
148
- // Convenience helpers
149
- isEmailConnected: user?.channels?.find(c => c.channel_type === "email")?.enabled === 1,
150
- isTelegramConnected: user?.channels?.find(c => c.channel_type === "telegram")?.enabled === 1,
151
- isDiscordConnected: user?.channels?.find(c => c.channel_type === "discord")?.enabled === 1,
152
- };
153
- }
@@ -1 +0,0 @@
1
- export * from "./hooks";