@b3dotfun/sdk 0.0.44 → 0.0.46
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.
- package/README.md +222 -3
- package/dist/cjs/anyspend/react/components/common/OrderDetails.js +1 -6
- package/dist/cjs/anyspend/react/components/common/OrderHistoryItem.js +1 -6
- package/dist/cjs/anyspend/react/hooks/useAnyspendFlow.d.ts +1 -0
- package/dist/cjs/anyspend/react/hooks/useAnyspendFlow.js +3 -3
- package/dist/cjs/anyspend/react/hooks/useAnyspendOrderAndTransactions.d.ts +2 -0
- package/dist/cjs/anyspend/react/hooks/useAnyspendOrderHistory.d.ts +36 -0
- package/dist/cjs/anyspend/types/api.d.ts +13 -10
- package/dist/cjs/anyspend/utils/orderPayload.js +0 -4
- package/dist/cjs/notifications/index.d.ts +3 -0
- package/dist/cjs/notifications/index.js +25 -0
- package/dist/cjs/notifications/react/hooks/index.d.ts +1 -0
- package/dist/cjs/notifications/react/hooks/index.js +17 -0
- package/dist/cjs/notifications/react/hooks/useNotifications.d.ts +42 -0
- package/dist/cjs/notifications/react/hooks/useNotifications.js +148 -0
- package/dist/cjs/notifications/react/index.d.ts +1 -0
- package/dist/cjs/notifications/react/index.js +17 -0
- package/dist/cjs/notifications/services/api.d.ts +67 -0
- package/dist/cjs/notifications/services/api.js +184 -0
- package/dist/cjs/notifications/services/index.d.ts +1 -0
- package/dist/cjs/notifications/services/index.js +17 -0
- package/dist/cjs/notifications/types/index.d.ts +51 -0
- package/dist/cjs/notifications/types/index.js +2 -0
- package/dist/cjs/shared/utils/auth-token.d.ts +7 -0
- package/dist/cjs/shared/utils/auth-token.js +17 -0
- package/dist/cjs/shared/utils/index.d.ts +1 -0
- package/dist/cjs/shared/utils/index.js +1 -0
- package/dist/esm/anyspend/react/components/common/OrderDetails.js +1 -6
- package/dist/esm/anyspend/react/components/common/OrderHistoryItem.js +1 -6
- package/dist/esm/anyspend/react/hooks/useAnyspendFlow.d.ts +1 -0
- package/dist/esm/anyspend/react/hooks/useAnyspendFlow.js +3 -3
- package/dist/esm/anyspend/react/hooks/useAnyspendOrderAndTransactions.d.ts +2 -0
- package/dist/esm/anyspend/react/hooks/useAnyspendOrderHistory.d.ts +36 -0
- package/dist/esm/anyspend/types/api.d.ts +13 -10
- package/dist/esm/anyspend/utils/orderPayload.js +0 -4
- package/dist/esm/notifications/index.d.ts +3 -0
- package/dist/esm/notifications/index.js +7 -0
- package/dist/esm/notifications/react/hooks/index.d.ts +1 -0
- package/dist/esm/notifications/react/hooks/index.js +1 -0
- package/dist/esm/notifications/react/hooks/useNotifications.d.ts +42 -0
- package/dist/esm/notifications/react/hooks/useNotifications.js +145 -0
- package/dist/esm/notifications/react/index.d.ts +1 -0
- package/dist/esm/notifications/react/index.js +1 -0
- package/dist/esm/notifications/services/api.d.ts +67 -0
- package/dist/esm/notifications/services/api.js +179 -0
- package/dist/esm/notifications/services/index.d.ts +1 -0
- package/dist/esm/notifications/services/index.js +1 -0
- package/dist/esm/notifications/types/index.d.ts +51 -0
- package/dist/esm/shared/utils/auth-token.d.ts +7 -0
- package/dist/esm/shared/utils/auth-token.js +11 -0
- package/dist/esm/shared/utils/index.d.ts +1 -0
- package/dist/esm/shared/utils/index.js +1 -0
- package/dist/types/anyspend/react/hooks/useAnyspendFlow.d.ts +1 -0
- package/dist/types/anyspend/react/hooks/useAnyspendOrderAndTransactions.d.ts +2 -0
- package/dist/types/anyspend/react/hooks/useAnyspendOrderHistory.d.ts +36 -0
- package/dist/types/anyspend/types/api.d.ts +13 -10
- package/dist/types/notifications/index.d.ts +3 -0
- package/dist/types/notifications/react/hooks/index.d.ts +1 -0
- package/dist/types/notifications/react/hooks/useNotifications.d.ts +42 -0
- package/dist/types/notifications/react/index.d.ts +1 -0
- package/dist/types/notifications/services/api.d.ts +67 -0
- package/dist/types/notifications/services/index.d.ts +1 -0
- package/dist/types/notifications/types/index.d.ts +51 -0
- package/dist/types/shared/utils/auth-token.d.ts +7 -0
- package/dist/types/shared/utils/index.d.ts +1 -0
- package/package.json +21 -1
- package/src/anyspend/react/components/common/OrderDetails.tsx +1 -7
- package/src/anyspend/react/components/common/OrderHistoryItem.tsx +1 -7
- package/src/anyspend/react/hooks/useAnyspendFlow.ts +3 -3
- package/src/anyspend/types/api.ts +13 -10
- package/src/anyspend/utils/orderPayload.ts +0 -4
- package/src/notifications/index.ts +9 -0
- package/src/notifications/react/hooks/index.ts +1 -0
- package/src/notifications/react/hooks/useNotifications.ts +153 -0
- package/src/notifications/react/index.ts +1 -0
- package/src/notifications/services/api.ts +217 -0
- package/src/notifications/services/index.ts +1 -0
- package/src/notifications/types/index.ts +58 -0
- package/src/shared/utils/auth-token.ts +13 -0
- package/src/shared/utils/index.ts +1 -0
- package/dist/cjs/shared/react/hooks/__tests__/useCurrencyConversion.test.js +0 -245
- package/dist/esm/shared/react/hooks/__tests__/useCurrencyConversion.test.d.ts +0 -1
- package/dist/esm/shared/react/hooks/__tests__/useCurrencyConversion.test.js +0 -243
- package/dist/types/shared/react/hooks/__tests__/useCurrencyConversion.test.d.ts +0 -1
- /package/dist/{cjs/shared/react/hooks/__tests__/useCurrencyConversion.test.d.ts → esm/notifications/types/index.js} +0 -0
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useNotifications = useNotifications;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const api_1 = require("../../services/api");
|
|
6
|
+
/**
|
|
7
|
+
* React hook for managing B3 notifications
|
|
8
|
+
* Automatically uses the authenticated user's ID from JWT
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* import { useNotifications } from '../../../notifications/react';
|
|
13
|
+
*
|
|
14
|
+
* function NotificationSettings() {
|
|
15
|
+
* const { user, loading, connectEmail, connectTelegram, isEmailConnected } = useNotifications();
|
|
16
|
+
*
|
|
17
|
+
* if (loading) return <div>Loading...</div>;
|
|
18
|
+
*
|
|
19
|
+
* return (
|
|
20
|
+
* <div>
|
|
21
|
+
* {!isEmailConnected && (
|
|
22
|
+
* <button onClick={() => connectEmail('user@example.com')}>
|
|
23
|
+
* Connect Email
|
|
24
|
+
* </button>
|
|
25
|
+
* )}
|
|
26
|
+
* <button onClick={connectTelegram}>Connect Telegram</button>
|
|
27
|
+
* </div>
|
|
28
|
+
* );
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
function useNotifications() {
|
|
33
|
+
const [user, setUser] = (0, react_1.useState)(null);
|
|
34
|
+
const [loading, setLoading] = (0, react_1.useState)(true);
|
|
35
|
+
const [error, setError] = (0, react_1.useState)(null);
|
|
36
|
+
// Refs to track polling timers for cleanup
|
|
37
|
+
const telegramPollIntervalRef = (0, react_1.useRef)(null);
|
|
38
|
+
const telegramPollTimeoutRef = (0, react_1.useRef)(null);
|
|
39
|
+
// Cleanup function for Telegram polling
|
|
40
|
+
const cleanupTelegramPolling = () => {
|
|
41
|
+
if (telegramPollIntervalRef.current) {
|
|
42
|
+
clearInterval(telegramPollIntervalRef.current);
|
|
43
|
+
telegramPollIntervalRef.current = null;
|
|
44
|
+
}
|
|
45
|
+
if (telegramPollTimeoutRef.current) {
|
|
46
|
+
clearTimeout(telegramPollTimeoutRef.current);
|
|
47
|
+
telegramPollTimeoutRef.current = null;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
// Load user data on mount
|
|
51
|
+
(0, react_1.useEffect)(() => {
|
|
52
|
+
loadUser();
|
|
53
|
+
}, []);
|
|
54
|
+
// Cleanup polling on unmount
|
|
55
|
+
(0, react_1.useEffect)(() => {
|
|
56
|
+
return () => {
|
|
57
|
+
cleanupTelegramPolling();
|
|
58
|
+
};
|
|
59
|
+
}, []);
|
|
60
|
+
const loadUser = async () => {
|
|
61
|
+
try {
|
|
62
|
+
setLoading(true);
|
|
63
|
+
setError(null);
|
|
64
|
+
const userData = await api_1.notificationsAPI.getUser();
|
|
65
|
+
setUser(userData);
|
|
66
|
+
}
|
|
67
|
+
catch (err) {
|
|
68
|
+
setError(err instanceof Error ? err : new Error("Failed to load user"));
|
|
69
|
+
console.error("Failed to load user:", err);
|
|
70
|
+
}
|
|
71
|
+
finally {
|
|
72
|
+
setLoading(false);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
const connectEmail = async (email) => {
|
|
76
|
+
try {
|
|
77
|
+
await api_1.notificationsAPI.connectEmail(email);
|
|
78
|
+
await loadUser(); // Refresh user data
|
|
79
|
+
}
|
|
80
|
+
catch (err) {
|
|
81
|
+
console.error("Failed to connect email:", err);
|
|
82
|
+
throw err;
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
const connectTelegram = async () => {
|
|
86
|
+
try {
|
|
87
|
+
// Clear any existing polling before starting new one
|
|
88
|
+
cleanupTelegramPolling();
|
|
89
|
+
const { deepLink } = await api_1.notificationsAPI.getTelegramLink();
|
|
90
|
+
window.open(deepLink, "_blank");
|
|
91
|
+
// Poll for connection status
|
|
92
|
+
telegramPollIntervalRef.current = setInterval(async () => {
|
|
93
|
+
try {
|
|
94
|
+
const { connected } = await api_1.notificationsAPI.checkTelegramStatus();
|
|
95
|
+
if (connected) {
|
|
96
|
+
cleanupTelegramPolling();
|
|
97
|
+
await loadUser(); // Refresh user data
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
catch (err) {
|
|
101
|
+
console.error("Failed to check Telegram status:", err);
|
|
102
|
+
}
|
|
103
|
+
}, 2000);
|
|
104
|
+
// Stop polling after 2 minutes
|
|
105
|
+
telegramPollTimeoutRef.current = setTimeout(() => {
|
|
106
|
+
cleanupTelegramPolling();
|
|
107
|
+
}, 120000);
|
|
108
|
+
}
|
|
109
|
+
catch (err) {
|
|
110
|
+
console.error("Failed to connect Telegram:", err);
|
|
111
|
+
throw err;
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
const updateChannel = async (channelId, updates) => {
|
|
115
|
+
try {
|
|
116
|
+
await api_1.notificationsAPI.updateChannel(channelId, updates);
|
|
117
|
+
await loadUser(); // Refresh user data
|
|
118
|
+
}
|
|
119
|
+
catch (err) {
|
|
120
|
+
console.error("Failed to update channel:", err);
|
|
121
|
+
throw err;
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
const deleteChannel = async (channelId) => {
|
|
125
|
+
try {
|
|
126
|
+
await api_1.notificationsAPI.deleteChannel(channelId);
|
|
127
|
+
await loadUser(); // Refresh user data
|
|
128
|
+
}
|
|
129
|
+
catch (err) {
|
|
130
|
+
console.error("Failed to delete channel:", err);
|
|
131
|
+
throw err;
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
return {
|
|
135
|
+
user,
|
|
136
|
+
loading,
|
|
137
|
+
error,
|
|
138
|
+
refresh: loadUser,
|
|
139
|
+
connectEmail,
|
|
140
|
+
connectTelegram,
|
|
141
|
+
updateChannel,
|
|
142
|
+
deleteChannel,
|
|
143
|
+
// Convenience helpers
|
|
144
|
+
isEmailConnected: user?.channels?.find(c => c.channel_type === "email")?.enabled === 1,
|
|
145
|
+
isTelegramConnected: user?.channels?.find(c => c.channel_type === "telegram")?.enabled === 1,
|
|
146
|
+
isDiscordConnected: user?.channels?.find(c => c.channel_type === "discord")?.enabled === 1,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./hooks";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./hooks"), exports);
|
|
@@ -0,0 +1,67 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.notificationsAPI = void 0;
|
|
4
|
+
exports.setApiUrl = setApiUrl;
|
|
5
|
+
exports.getApiUrl = getApiUrl;
|
|
6
|
+
const auth_token_1 = require("../../shared/utils/auth-token");
|
|
7
|
+
const DEFAULT_API_URL = "https://notifications.b3.fun";
|
|
8
|
+
let apiUrl = DEFAULT_API_URL;
|
|
9
|
+
function setApiUrl(url) {
|
|
10
|
+
apiUrl = url;
|
|
11
|
+
}
|
|
12
|
+
function getApiUrl() {
|
|
13
|
+
return apiUrl;
|
|
14
|
+
}
|
|
15
|
+
function getHeaders(includeAuth = false) {
|
|
16
|
+
const headers = {
|
|
17
|
+
"Content-Type": "application/json",
|
|
18
|
+
};
|
|
19
|
+
if (includeAuth) {
|
|
20
|
+
const token = (0, auth_token_1.getAuthToken)();
|
|
21
|
+
if (token) {
|
|
22
|
+
headers["Authorization"] = `Bearer ${token}`;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return headers;
|
|
26
|
+
}
|
|
27
|
+
exports.notificationsAPI = {
|
|
28
|
+
// ===== USER MANAGEMENT =====
|
|
29
|
+
/**
|
|
30
|
+
* Register the current user (userId extracted from JWT)
|
|
31
|
+
*/
|
|
32
|
+
async registerUser() {
|
|
33
|
+
const res = await fetch(`${apiUrl}/users`, {
|
|
34
|
+
method: "POST",
|
|
35
|
+
headers: getHeaders(true),
|
|
36
|
+
});
|
|
37
|
+
if (!res.ok) {
|
|
38
|
+
const errorBody = await res.text().catch(() => "Could not read error body");
|
|
39
|
+
throw new Error(`API Error: ${res.status} ${res.statusText} - ${errorBody}`);
|
|
40
|
+
}
|
|
41
|
+
return res.json();
|
|
42
|
+
},
|
|
43
|
+
/**
|
|
44
|
+
* Get current user's profile and preferences
|
|
45
|
+
*/
|
|
46
|
+
async getUser() {
|
|
47
|
+
const res = await fetch(`${apiUrl}/users/me`, {
|
|
48
|
+
headers: getHeaders(true),
|
|
49
|
+
});
|
|
50
|
+
return res.json();
|
|
51
|
+
},
|
|
52
|
+
/**
|
|
53
|
+
* Get current user's notification history
|
|
54
|
+
*/
|
|
55
|
+
async getHistory(appId, limit = 100) {
|
|
56
|
+
const params = new URLSearchParams();
|
|
57
|
+
if (appId)
|
|
58
|
+
params.append("appId", appId);
|
|
59
|
+
params.append("limit", limit.toString());
|
|
60
|
+
const res = await fetch(`${apiUrl}/users/me/history?${params}`, {
|
|
61
|
+
headers: getHeaders(true),
|
|
62
|
+
});
|
|
63
|
+
return res.json();
|
|
64
|
+
},
|
|
65
|
+
// ===== CHANNELS =====
|
|
66
|
+
/**
|
|
67
|
+
* Add a notification channel for current user
|
|
68
|
+
*/
|
|
69
|
+
async addChannel(channelType, channelIdentifier, metadata) {
|
|
70
|
+
const res = await fetch(`${apiUrl}/users/me/channels`, {
|
|
71
|
+
method: "POST",
|
|
72
|
+
headers: getHeaders(true),
|
|
73
|
+
body: JSON.stringify({
|
|
74
|
+
channelType,
|
|
75
|
+
channelIdentifier,
|
|
76
|
+
enabled: true,
|
|
77
|
+
metadata,
|
|
78
|
+
}),
|
|
79
|
+
});
|
|
80
|
+
return res.json();
|
|
81
|
+
},
|
|
82
|
+
/**
|
|
83
|
+
* Connect email for current user
|
|
84
|
+
*/
|
|
85
|
+
async connectEmail(email) {
|
|
86
|
+
return this.addChannel("email", email);
|
|
87
|
+
},
|
|
88
|
+
/**
|
|
89
|
+
* Update a notification channel
|
|
90
|
+
*/
|
|
91
|
+
async updateChannel(channelId, updates) {
|
|
92
|
+
const res = await fetch(`${apiUrl}/users/me/channels/${channelId}`, {
|
|
93
|
+
method: "PUT",
|
|
94
|
+
headers: getHeaders(true),
|
|
95
|
+
body: JSON.stringify(updates),
|
|
96
|
+
});
|
|
97
|
+
return res.json();
|
|
98
|
+
},
|
|
99
|
+
/**
|
|
100
|
+
* Delete a notification channel
|
|
101
|
+
*/
|
|
102
|
+
async deleteChannel(channelId) {
|
|
103
|
+
const res = await fetch(`${apiUrl}/users/me/channels/${channelId}`, {
|
|
104
|
+
method: "DELETE",
|
|
105
|
+
headers: getHeaders(true),
|
|
106
|
+
});
|
|
107
|
+
return res.json();
|
|
108
|
+
},
|
|
109
|
+
// ===== TELEGRAM =====
|
|
110
|
+
/**
|
|
111
|
+
* Get Telegram deep link for current user
|
|
112
|
+
*/
|
|
113
|
+
async getTelegramLink() {
|
|
114
|
+
const res = await fetch(`${apiUrl}/telegram/request-link`, {
|
|
115
|
+
method: "POST",
|
|
116
|
+
headers: getHeaders(true),
|
|
117
|
+
});
|
|
118
|
+
return res.json();
|
|
119
|
+
},
|
|
120
|
+
/**
|
|
121
|
+
* Check current user's Telegram connection status
|
|
122
|
+
*/
|
|
123
|
+
async checkTelegramStatus() {
|
|
124
|
+
const res = await fetch(`${apiUrl}/telegram/status/me`, {
|
|
125
|
+
headers: getHeaders(true),
|
|
126
|
+
});
|
|
127
|
+
return res.json();
|
|
128
|
+
},
|
|
129
|
+
// ===== APP PREFERENCES =====
|
|
130
|
+
/**
|
|
131
|
+
* Save notification preferences for an app
|
|
132
|
+
* @param appId - The application ID
|
|
133
|
+
* @param settings - Notification preferences including channels, type, and enabled status (defaults to true)
|
|
134
|
+
*/
|
|
135
|
+
async savePreferences(appId, settings) {
|
|
136
|
+
const res = await fetch(`${apiUrl}/users/me/apps/${appId}/settings`, {
|
|
137
|
+
method: "POST",
|
|
138
|
+
headers: getHeaders(true),
|
|
139
|
+
body: JSON.stringify({ enabled: true, ...settings }),
|
|
140
|
+
});
|
|
141
|
+
return res.json();
|
|
142
|
+
},
|
|
143
|
+
/**
|
|
144
|
+
* Get notification settings for an app
|
|
145
|
+
*/
|
|
146
|
+
async getAppSettings(appId) {
|
|
147
|
+
const res = await fetch(`${apiUrl}/users/me/apps/${appId}/settings`, {
|
|
148
|
+
headers: getHeaders(true),
|
|
149
|
+
});
|
|
150
|
+
return res.json();
|
|
151
|
+
},
|
|
152
|
+
// ===== IN-APP NOTIFICATIONS =====
|
|
153
|
+
/**
|
|
154
|
+
* Get current user's in-app notifications
|
|
155
|
+
*/
|
|
156
|
+
async getInAppNotifications() {
|
|
157
|
+
const res = await fetch(`${apiUrl}/users/me/notifications`, {
|
|
158
|
+
headers: getHeaders(true),
|
|
159
|
+
});
|
|
160
|
+
return res.json();
|
|
161
|
+
},
|
|
162
|
+
/**
|
|
163
|
+
* Mark a notification as read
|
|
164
|
+
*/
|
|
165
|
+
async markNotificationAsRead(notificationId) {
|
|
166
|
+
const res = await fetch(`${apiUrl}/users/me/notifications/${notificationId}/read`, {
|
|
167
|
+
method: "PUT",
|
|
168
|
+
headers: getHeaders(true),
|
|
169
|
+
});
|
|
170
|
+
return res.json();
|
|
171
|
+
},
|
|
172
|
+
// ===== SENDING NOTIFICATIONS =====
|
|
173
|
+
/**
|
|
174
|
+
* Send a notification (requires auth)
|
|
175
|
+
*/
|
|
176
|
+
async sendNotification(data) {
|
|
177
|
+
const res = await fetch(`${apiUrl}/send`, {
|
|
178
|
+
method: "POST",
|
|
179
|
+
headers: getHeaders(true),
|
|
180
|
+
body: JSON.stringify(data),
|
|
181
|
+
});
|
|
182
|
+
return res.json();
|
|
183
|
+
},
|
|
184
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./api";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./api"), exports);
|
|
@@ -0,0 +1,51 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getAuthToken = getAuthToken;
|
|
7
|
+
const js_cookie_1 = __importDefault(require("js-cookie"));
|
|
8
|
+
const B3_AUTH_COOKIE_NAME = "b3-auth";
|
|
9
|
+
/**
|
|
10
|
+
* Get the authentication token from the B3 auth cookie
|
|
11
|
+
* This token is managed by the B3 Global Account authentication system
|
|
12
|
+
*
|
|
13
|
+
* @returns The JWT token string or null if not found
|
|
14
|
+
*/
|
|
15
|
+
function getAuthToken() {
|
|
16
|
+
return js_cookie_1.default.get(B3_AUTH_COOKIE_NAME) || null;
|
|
17
|
+
}
|
|
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
// Export utility functions
|
|
18
|
+
__exportStar(require("./auth-token"), exports);
|
|
18
19
|
__exportStar(require("./cn"), exports);
|
|
19
20
|
__exportStar(require("./formatNumber"), exports);
|
|
20
21
|
__exportStar(require("./formatUsername"), exports);
|
|
@@ -274,12 +274,7 @@ export const OrderDetails = memo(function OrderDetails({ mode = "modal", order,
|
|
|
274
274
|
? "0"
|
|
275
275
|
: order.payload.expectedDstAmount.toString();
|
|
276
276
|
const formattedExpectedDstAmount = formatTokenAmount(BigInt(expectedDstAmount), dstToken.decimals);
|
|
277
|
-
const actualDstAmount = order.
|
|
278
|
-
order.type === "join_tournament" ||
|
|
279
|
-
order.type === "fund_tournament" ||
|
|
280
|
-
order.type === "custom"
|
|
281
|
-
? undefined
|
|
282
|
-
: order.payload.actualDstAmount;
|
|
277
|
+
const actualDstAmount = order.settlement?.actualDstAmount;
|
|
283
278
|
const formattedActualDstAmount = actualDstAmount
|
|
284
279
|
? formatTokenAmount(BigInt(actualDstAmount), dstToken.decimals)
|
|
285
280
|
: undefined;
|
|
@@ -10,12 +10,7 @@ export function OrderHistoryItem({ order, onSelectOrder, mode }) {
|
|
|
10
10
|
const nft = order.type === "mint_nft" ? order.metadata.nft : undefined;
|
|
11
11
|
const tournament = order.type === "join_tournament" || order.type === "fund_tournament" ? order.metadata.tournament : undefined;
|
|
12
12
|
const dstToken = order.metadata.dstToken;
|
|
13
|
-
const actualDstAmount = order.
|
|
14
|
-
order.type === "join_tournament" ||
|
|
15
|
-
order.type === "fund_tournament" ||
|
|
16
|
-
order.type === "custom"
|
|
17
|
-
? undefined
|
|
18
|
-
: order.payload.actualDstAmount;
|
|
13
|
+
const actualDstAmount = order.settlement?.actualDstAmount;
|
|
19
14
|
const expectedDstAmount = order.type === "mint_nft" ||
|
|
20
15
|
order.type === "join_tournament" ||
|
|
21
16
|
order.type === "fund_tournament" ||
|
|
@@ -36,6 +36,7 @@ export declare function useAnyspendFlow({ paymentType, recipientAddress, loadOrd
|
|
|
36
36
|
relayTxs: components["schemas"]["RelayTx"][];
|
|
37
37
|
executeTx: components["schemas"]["ExecuteTx"] | null;
|
|
38
38
|
refundTxs: components["schemas"]["RefundTx"][];
|
|
39
|
+
points: number | null;
|
|
39
40
|
};
|
|
40
41
|
statusCode: number;
|
|
41
42
|
} | undefined;
|
|
@@ -188,8 +188,8 @@ export function useAnyspendFlow({ paymentType = "crypto", recipientAddress, load
|
|
|
188
188
|
// Handle order completion
|
|
189
189
|
useEffect(() => {
|
|
190
190
|
if (oat?.data?.order.status === "executed") {
|
|
191
|
-
// get the actualDstAmount if available from
|
|
192
|
-
const amount = oat.data.order.
|
|
191
|
+
// get the actualDstAmount if available from settlement
|
|
192
|
+
const amount = oat.data.order.settlement?.actualDstAmount;
|
|
193
193
|
const formattedActualDstAmount = amount
|
|
194
194
|
? formatTokenAmount(BigInt(amount), oat.data.order.metadata.dstToken.decimals)
|
|
195
195
|
: undefined;
|
|
@@ -197,7 +197,7 @@ export function useAnyspendFlow({ paymentType = "crypto", recipientAddress, load
|
|
|
197
197
|
}
|
|
198
198
|
}, [
|
|
199
199
|
oat?.data?.order.status,
|
|
200
|
-
oat?.data?.order.
|
|
200
|
+
oat?.data?.order.settlement?.actualDstAmount,
|
|
201
201
|
onTransactionSuccess,
|
|
202
202
|
oat?.data?.order.metadata.dstToken.decimals,
|
|
203
203
|
]);
|
|
@@ -8,6 +8,7 @@ export declare function useAnyspendOrderAndTransactions(orderId: string | undefi
|
|
|
8
8
|
relayTxs: import("../..").components["schemas"]["RelayTx"][];
|
|
9
9
|
executeTx: import("../..").components["schemas"]["ExecuteTx"] | null;
|
|
10
10
|
refundTxs: import("../..").components["schemas"]["RefundTx"][];
|
|
11
|
+
points: number | null;
|
|
11
12
|
};
|
|
12
13
|
statusCode: number;
|
|
13
14
|
} | undefined;
|
|
@@ -22,6 +23,7 @@ export declare function useAnyspendOrderAndTransactions(orderId: string | undefi
|
|
|
22
23
|
relayTxs: import("../..").components["schemas"]["RelayTx"][];
|
|
23
24
|
executeTx: import("../..").components["schemas"]["ExecuteTx"] | null;
|
|
24
25
|
refundTxs: import("../..").components["schemas"]["RefundTx"][];
|
|
26
|
+
points: number | null;
|
|
25
27
|
};
|
|
26
28
|
statusCode: number;
|
|
27
29
|
}, Error>>;
|