@bytexbyte/nxtlinq-ai-agent-ui-react-development 0.1.1
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/dist/NxtlinqAgentChat.d.ts +26 -0
- package/dist/NxtlinqAgentChat.d.ts.map +1 -0
- package/dist/NxtlinqAgentChat.js +28 -0
- package/dist/components/AgentAssistantShell.d.ts +5 -0
- package/dist/components/AgentAssistantShell.d.ts.map +1 -0
- package/dist/components/AgentAssistantShell.js +52 -0
- package/dist/components/AgentComposer.d.ts +3 -0
- package/dist/components/AgentComposer.d.ts.map +1 -0
- package/dist/components/AgentComposer.js +60 -0
- package/dist/components/AgentMessageList.d.ts +3 -0
- package/dist/components/AgentMessageList.d.ts.map +1 -0
- package/dist/components/AgentMessageList.js +37 -0
- package/dist/components/AgentRemoteAudio.d.ts +4 -0
- package/dist/components/AgentRemoteAudio.d.ts.map +1 -0
- package/dist/components/AgentRemoteAudio.js +34 -0
- package/dist/components/AgentVoiceBar.d.ts +3 -0
- package/dist/components/AgentVoiceBar.d.ts.map +1 -0
- package/dist/components/AgentVoiceBar.js +91 -0
- package/dist/components/PresetMessageChips.d.ts +3 -0
- package/dist/components/PresetMessageChips.d.ts.map +1 -0
- package/dist/components/PresetMessageChips.js +23 -0
- package/dist/context/AgentAssistantContext.d.ts +32 -0
- package/dist/context/AgentAssistantContext.d.ts.map +1 -0
- package/dist/context/AgentAssistantContext.js +159 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -0
- package/dist/legacy/assets/images/adiSideItalicDataUri.d.ts +2 -0
- package/dist/legacy/assets/images/adiSideItalicDataUri.d.ts.map +1 -0
- package/dist/legacy/assets/images/adiSideItalicDataUri.js +1 -0
- package/dist/legacy/chatbot/ChatBot.d.ts +5 -0
- package/dist/legacy/chatbot/ChatBot.d.ts.map +1 -0
- package/dist/legacy/chatbot/ChatBot.js +35 -0
- package/dist/legacy/chatbot/context/ChatBotContext.d.ts +5 -0
- package/dist/legacy/chatbot/context/ChatBotContext.d.ts.map +1 -0
- package/dist/legacy/chatbot/context/ChatBotContext.js +2908 -0
- package/dist/legacy/chatbot/types/ChatBotTypes.d.ts +166 -0
- package/dist/legacy/chatbot/types/ChatBotTypes.d.ts.map +1 -0
- package/dist/legacy/chatbot/types/ChatBotTypes.js +1 -0
- package/dist/legacy/chatbot/ui/BerifyMeModal.d.ts +17 -0
- package/dist/legacy/chatbot/ui/BerifyMeModal.d.ts.map +1 -0
- package/dist/legacy/chatbot/ui/BerifyMeModal.js +110 -0
- package/dist/legacy/chatbot/ui/ChatBotUI.d.ts +3 -0
- package/dist/legacy/chatbot/ui/ChatBotUI.d.ts.map +1 -0
- package/dist/legacy/chatbot/ui/ChatBotUI.js +625 -0
- package/dist/legacy/chatbot/ui/MessageInput.d.ts +3 -0
- package/dist/legacy/chatbot/ui/MessageInput.d.ts.map +1 -0
- package/dist/legacy/chatbot/ui/MessageInput.js +321 -0
- package/dist/legacy/chatbot/ui/MessageList.d.ts +4 -0
- package/dist/legacy/chatbot/ui/MessageList.d.ts.map +1 -0
- package/dist/legacy/chatbot/ui/MessageList.js +455 -0
- package/dist/legacy/chatbot/ui/ModelSelector.d.ts +4 -0
- package/dist/legacy/chatbot/ui/ModelSelector.d.ts.map +1 -0
- package/dist/legacy/chatbot/ui/ModelSelector.js +122 -0
- package/dist/legacy/chatbot/ui/NotificationModal.d.ts +15 -0
- package/dist/legacy/chatbot/ui/NotificationModal.d.ts.map +1 -0
- package/dist/legacy/chatbot/ui/NotificationModal.js +53 -0
- package/dist/legacy/chatbot/ui/PermissionForm.d.ts +8 -0
- package/dist/legacy/chatbot/ui/PermissionForm.d.ts.map +1 -0
- package/dist/legacy/chatbot/ui/PermissionForm.js +465 -0
- package/dist/legacy/chatbot/ui/PresetMessages.d.ts +4 -0
- package/dist/legacy/chatbot/ui/PresetMessages.d.ts.map +1 -0
- package/dist/legacy/chatbot/ui/PresetMessages.js +33 -0
- package/dist/legacy/chatbot/ui/VoiceModePanel.d.ts +3 -0
- package/dist/legacy/chatbot/ui/VoiceModePanel.d.ts.map +1 -0
- package/dist/legacy/chatbot/ui/VoiceModePanel.js +95 -0
- package/dist/legacy/chatbot/ui/styles/isolatedStyles.d.ts +73 -0
- package/dist/legacy/chatbot/ui/styles/isolatedStyles.d.ts.map +1 -0
- package/dist/legacy/chatbot/ui/styles/isolatedStyles.js +985 -0
- package/dist/legacy/index.d.ts +14 -0
- package/dist/legacy/index.d.ts.map +1 -0
- package/dist/legacy/index.js +12 -0
- package/dist/theme/defaultTheme.d.ts +3 -0
- package/dist/theme/defaultTheme.d.ts.map +1 -0
- package/dist/theme/defaultTheme.js +20 -0
- package/dist/types.d.ts +62 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/dist/voice/useVoiceConnectOrchestration.d.ts +21 -0
- package/dist/voice/useVoiceConnectOrchestration.d.ts.map +1 -0
- package/dist/voice/useVoiceConnectOrchestration.js +86 -0
- package/dist/voice/useVoiceMicState.d.ts +15 -0
- package/dist/voice/useVoiceMicState.d.ts.map +1 -0
- package/dist/voice/useVoiceMicState.js +94 -0
- package/dist/voice/useVoiceSilenceCommit.d.ts +10 -0
- package/dist/voice/useVoiceSilenceCommit.d.ts.map +1 -0
- package/dist/voice/useVoiceSilenceCommit.js +67 -0
- package/dist/voice/useVoiceTranscriptMessages.d.ts +16 -0
- package/dist/voice/useVoiceTranscriptMessages.d.ts.map +1 -0
- package/dist/voice/useVoiceTranscriptMessages.js +129 -0
- package/dist/voice/useWsRealtimeAudio.d.ts +18 -0
- package/dist/voice/useWsRealtimeAudio.d.ts.map +1 -0
- package/dist/voice/useWsRealtimeAudio.js +102 -0
- package/dist/voice/voiceMicConstants.d.ts +4 -0
- package/dist/voice/voiceMicConstants.d.ts.map +1 -0
- package/dist/voice/voiceMicConstants.js +10 -0
- package/dist/voice/ws/BrowserWsPcmPlayer.d.ts +23 -0
- package/dist/voice/ws/BrowserWsPcmPlayer.d.ts.map +1 -0
- package/dist/voice/ws/BrowserWsPcmPlayer.js +137 -0
- package/dist/voice/ws/BrowserWsPcmRecorder.d.ts +17 -0
- package/dist/voice/ws/BrowserWsPcmRecorder.d.ts.map +1 -0
- package/dist/voice/ws/BrowserWsPcmRecorder.js +71 -0
- package/dist/voice/ws/float32ToPcm16.d.ts +2 -0
- package/dist/voice/ws/float32ToPcm16.d.ts.map +1 -0
- package/dist/voice/ws/float32ToPcm16.js +8 -0
- package/dist/voice/ws/voiceSilenceConstants.d.ts +5 -0
- package/dist/voice/ws/voiceSilenceConstants.d.ts.map +1 -0
- package/dist/voice/ws/voiceSilenceConstants.js +4 -0
- package/dist/voice/ws/wsRealtimeConstants.d.ts +2 -0
- package/dist/voice/ws/wsRealtimeConstants.d.ts.map +1 -0
- package/dist/voice/ws/wsRealtimeConstants.js +1 -0
- package/package.json +60 -0
- package/src/NxtlinqAgentChat.tsx +79 -0
- package/src/components/AgentAssistantShell.tsx +104 -0
- package/src/components/AgentComposer.tsx +134 -0
- package/src/components/AgentMessageList.tsx +78 -0
- package/src/components/AgentRemoteAudio.tsx +34 -0
- package/src/components/AgentVoiceBar.tsx +173 -0
- package/src/components/PresetMessageChips.tsx +41 -0
- package/src/context/AgentAssistantContext.tsx +276 -0
- package/src/index.ts +78 -0
- package/src/legacy/assets/images/adiSideItalicDataUri.ts +1 -0
- package/src/legacy/chatbot/ChatBot.tsx +61 -0
- package/src/legacy/chatbot/context/ChatBotContext.tsx +3227 -0
- package/src/legacy/chatbot/types/ChatBotTypes.ts +195 -0
- package/src/legacy/chatbot/ui/BerifyMeModal.tsx +145 -0
- package/src/legacy/chatbot/ui/ChatBotUI.tsx +949 -0
- package/src/legacy/chatbot/ui/MessageInput.tsx +517 -0
- package/src/legacy/chatbot/ui/MessageList.tsx +764 -0
- package/src/legacy/chatbot/ui/ModelSelector.tsx +190 -0
- package/src/legacy/chatbot/ui/NotificationModal.tsx +110 -0
- package/src/legacy/chatbot/ui/PermissionForm.tsx +632 -0
- package/src/legacy/chatbot/ui/PresetMessages.tsx +50 -0
- package/src/legacy/chatbot/ui/VoiceModePanel.tsx +168 -0
- package/src/legacy/chatbot/ui/styles/isolatedStyles.ts +1058 -0
- package/src/legacy/index.ts +26 -0
- package/src/theme/defaultTheme.ts +22 -0
- package/src/types.ts +65 -0
- package/src/voice/useVoiceConnectOrchestration.ts +117 -0
- package/src/voice/useVoiceMicState.ts +117 -0
- package/src/voice/useVoiceTranscriptMessages.ts +173 -0
- package/src/voice/voiceMicConstants.ts +13 -0
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import type { VoiceStatus, AIT, AITApi, Message, ServicePermission, Attachment } from '@bytexbyte/nxtlinq-ai-agent-core-development';
|
|
2
|
+
|
|
3
|
+
export interface PresetMessage {
|
|
4
|
+
text: string;
|
|
5
|
+
autoSend?: boolean;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface ToolUse {
|
|
9
|
+
name: string;
|
|
10
|
+
input: Record<string, any>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface ToolCall {
|
|
14
|
+
toolUse: ToolUse;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface NovaResponse {
|
|
18
|
+
result: string;
|
|
19
|
+
reply: Array<{ text: string }>;
|
|
20
|
+
toolCall?: ToolCall;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface NovaError {
|
|
24
|
+
error: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface AITMetadata {
|
|
28
|
+
permissions: string[];
|
|
29
|
+
issuedBy: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// AI Model related types
|
|
33
|
+
export interface AIModel {
|
|
34
|
+
label: string;
|
|
35
|
+
value: string;
|
|
36
|
+
}
|
|
37
|
+
export interface ChatBotProps {
|
|
38
|
+
onMessage?: (message: Message) => void;
|
|
39
|
+
onError?: (error: Error) => void;
|
|
40
|
+
onToolUse?: (
|
|
41
|
+
toolUse: ToolUse,
|
|
42
|
+
onProgress?: (update: {
|
|
43
|
+
status?: string;
|
|
44
|
+
progress?: number;
|
|
45
|
+
partialResult?: string;
|
|
46
|
+
steps?: string[];
|
|
47
|
+
partialContent?: string; // Token-level streaming - character-by-character content display
|
|
48
|
+
}) => void
|
|
49
|
+
) => Promise<Message | void>;
|
|
50
|
+
presetMessages?: PresetMessage[];
|
|
51
|
+
placeholder?: string;
|
|
52
|
+
className?: string;
|
|
53
|
+
maxRetries?: number;
|
|
54
|
+
retryDelay?: number;
|
|
55
|
+
serviceId: string;
|
|
56
|
+
apiKey: string;
|
|
57
|
+
apiSecret: string;
|
|
58
|
+
environment?: 'production' | 'staging'; // API environment (default: production)
|
|
59
|
+
onVerifyWallet?: () => Promise<{
|
|
60
|
+
token: string;
|
|
61
|
+
} | undefined>;
|
|
62
|
+
permissionGroup?: string;
|
|
63
|
+
children?: React.ReactNode;
|
|
64
|
+
// AI Model related properties
|
|
65
|
+
onModelChange?: (model: AIModel) => void;
|
|
66
|
+
// Storage mode configuration
|
|
67
|
+
storageMode?: "session-storage" | "local-storage"; // Choose storage type: "session-storage" (no cross-tab sync) or "local-storage" (cross-tab sync, default)
|
|
68
|
+
// Wallet verification configuration
|
|
69
|
+
requireWalletIDVVerification?: boolean; // Control whether to check wallet IDV verification status before AIT operations (default: true)
|
|
70
|
+
isSemiAutomaticMode?: boolean; // Enable semi-automatic mode for fix user activation issue (default: false)
|
|
71
|
+
// Custom user identity information - additional user identification data
|
|
72
|
+
customUserInfo?: Record<string, any>; // Custom user identity information object with flexible properties
|
|
73
|
+
// Custom username for wallet verification
|
|
74
|
+
customUsername?: string; // Custom username for wallet verification when using custom method
|
|
75
|
+
// IDV suggestion banner configuration
|
|
76
|
+
idvBannerDismissSeconds?: number; // Seconds to hide IDV suggestion banner after user dismisses it (default: 86400 = 24 hours)
|
|
77
|
+
// BerifyMe integration mode configuration
|
|
78
|
+
berifymeMode?: 'built-in' | 'external'; // BerifyMe integration mode: 'built-in' for SDK internal loading, 'external' for external SDK loading (default: 'built-in')
|
|
79
|
+
isStopRecordingOnSend?: boolean; // Stop recording automatically when sending message (default: false)
|
|
80
|
+
// Custom error message to display in chat
|
|
81
|
+
customError?: string; // Custom error message to display as a chat message when provided
|
|
82
|
+
/** PII display mode: how PII protection is visualized in chat messages
|
|
83
|
+
* - 'plain': No visualization, messages look like normal chat
|
|
84
|
+
* - 'redacted': Anonymized text with PII tokens displayed (default)
|
|
85
|
+
*/
|
|
86
|
+
piiDisplayMode?: 'plain' | 'redacted';
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export interface ChatBotContextType {
|
|
90
|
+
// State
|
|
91
|
+
messages: Message[];
|
|
92
|
+
inputValue: string;
|
|
93
|
+
isLoading: boolean;
|
|
94
|
+
isOpen: boolean;
|
|
95
|
+
hitAddress: string | null;
|
|
96
|
+
ait: AIT | null;
|
|
97
|
+
permissions: string[];
|
|
98
|
+
availablePermissions: ServicePermission[];
|
|
99
|
+
showPermissionForm: boolean;
|
|
100
|
+
isPermissionFormOpen: boolean;
|
|
101
|
+
isAITLoading: boolean;
|
|
102
|
+
isAITEnabling: boolean;
|
|
103
|
+
isDisabled: boolean;
|
|
104
|
+
walletInfo: any;
|
|
105
|
+
isWalletLoading: boolean;
|
|
106
|
+
isAutoConnecting: boolean;
|
|
107
|
+
notification: {
|
|
108
|
+
show: boolean;
|
|
109
|
+
type: 'success' | 'error' | 'warning' | 'info';
|
|
110
|
+
message: string;
|
|
111
|
+
autoHide?: boolean;
|
|
112
|
+
duration?: number;
|
|
113
|
+
};
|
|
114
|
+
isMicEnabled: boolean;
|
|
115
|
+
isAwaitingMicGesture: boolean;
|
|
116
|
+
transcript: string;
|
|
117
|
+
textInputRef: React.RefObject<HTMLInputElement>;
|
|
118
|
+
autoSendEnabled: boolean;
|
|
119
|
+
// Speech related state
|
|
120
|
+
textToSpeechEnabled: boolean;
|
|
121
|
+
speechingIndex: number | undefined;
|
|
122
|
+
isTtsProcessing: boolean;
|
|
123
|
+
requiresGesture?: boolean;
|
|
124
|
+
// AI Model related state
|
|
125
|
+
availableModels: AIModel[];
|
|
126
|
+
selectedModelIndex: number;
|
|
127
|
+
showModelSelector: boolean;
|
|
128
|
+
suggestions: PresetMessage[];
|
|
129
|
+
// PII Protection visualization
|
|
130
|
+
piiDisplayMode: 'plain' | 'redacted';
|
|
131
|
+
// Realtime voice mode (WebRTC)
|
|
132
|
+
isVoiceMode: boolean;
|
|
133
|
+
voiceStatus: VoiceStatus;
|
|
134
|
+
isVoiceConnecting: boolean;
|
|
135
|
+
isMicMuted: boolean;
|
|
136
|
+
remoteAudioRef: React.RefObject<HTMLAudioElement>;
|
|
137
|
+
|
|
138
|
+
// Actions
|
|
139
|
+
setInputValue: (value: string) => void;
|
|
140
|
+
setIsOpen: (open: boolean) => void;
|
|
141
|
+
setShowPermissionForm: (show: boolean) => void;
|
|
142
|
+
setIsPermissionFormOpen: (open: boolean) => void;
|
|
143
|
+
setPermissions: (permissions: string[]) => void;
|
|
144
|
+
setIsDisabled: (disabled: boolean) => void;
|
|
145
|
+
setIsWalletLoading: (loading: boolean) => void;
|
|
146
|
+
setNotification: (notification: any) => void;
|
|
147
|
+
// AI Model related actions
|
|
148
|
+
setSelectedModelIndex: (index: number) => void;
|
|
149
|
+
setSuggestions: (suggestions: PresetMessage[]) => void;
|
|
150
|
+
setAutoSendEnabled: (enabled: boolean) => void;
|
|
151
|
+
setTextToSpeechEnabled: (enabled: boolean) => void;
|
|
152
|
+
|
|
153
|
+
// Functions
|
|
154
|
+
connectWallet: (autoShowSignInMessage?: boolean) => Promise<string | false | undefined>;
|
|
155
|
+
signInWallet: (autoShowSuccessMessage?: boolean) => Promise<void>;
|
|
156
|
+
sendMessage: (content: string, retryCount?: number) => Promise<void>;
|
|
157
|
+
handleSubmit: (e: React.FormEvent, attachments?: Attachment[]) => Promise<void>;
|
|
158
|
+
handlePresetMessage: (message: PresetMessage) => void;
|
|
159
|
+
savePermissions: (newPermissions?: string[]) => Promise<void>;
|
|
160
|
+
enableAIT: (toolName: string) => Promise<boolean>;
|
|
161
|
+
handleVerifyWalletClick: (method: 'berifyme' | 'custom') => Promise<void>;
|
|
162
|
+
showSuccess: (message: string) => void;
|
|
163
|
+
showError: (message: string) => void;
|
|
164
|
+
showWarning: (message: string) => void;
|
|
165
|
+
showInfo: (message: string) => void;
|
|
166
|
+
refreshAIT: (forceUpdatePermissions?: boolean) => Promise<void>;
|
|
167
|
+
startRecording: () => Promise<void>;
|
|
168
|
+
stopRecording: () => void;
|
|
169
|
+
clearRecording: () => void;
|
|
170
|
+
// AI Model related functions
|
|
171
|
+
handleModelChange: (modelIndex: number) => void;
|
|
172
|
+
getCurrentModel: () => AIModel;
|
|
173
|
+
// Speech related functions
|
|
174
|
+
playTextToSpeech: (text: string) => Promise<void>;
|
|
175
|
+
stopTextToSpeech: () => void;
|
|
176
|
+
retryTtsWithGesture?: () => Promise<void>;
|
|
177
|
+
uploadAttachment: (file: File) => Promise<{ url: string } | { error: string }>;
|
|
178
|
+
enterVoiceMode: () => Promise<void>;
|
|
179
|
+
exitVoiceMode: () => Promise<void>;
|
|
180
|
+
toggleVoiceMicMute: () => void;
|
|
181
|
+
interruptVoice: () => void;
|
|
182
|
+
|
|
183
|
+
// Additional properties for PermissionForm
|
|
184
|
+
onSave: (newPermissions?: string[]) => Promise<void>;
|
|
185
|
+
onConnectWallet: () => Promise<string | false | undefined>;
|
|
186
|
+
onSignIn: () => Promise<void>;
|
|
187
|
+
isNeedSignInWithWallet: boolean;
|
|
188
|
+
onVerifyWallet: (method: 'berifyme' | 'custom') => Promise<void>;
|
|
189
|
+
serviceId: string;
|
|
190
|
+
permissionGroup?: string;
|
|
191
|
+
|
|
192
|
+
// Props
|
|
193
|
+
props: ChatBotProps;
|
|
194
|
+
nxtlinqApi: AITApi;
|
|
195
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/** @jsxImportSource @emotion/react */
|
|
2
|
+
import { css } from '@emotion/react';
|
|
3
|
+
import React, { useEffect, useRef } from 'react';
|
|
4
|
+
import { modalOverlay } from './styles/isolatedStyles';
|
|
5
|
+
|
|
6
|
+
interface BerifyMeModalProps {
|
|
7
|
+
isOpen: boolean;
|
|
8
|
+
onClose: () => void;
|
|
9
|
+
onVerificationComplete?: (token?: string) => void;
|
|
10
|
+
mode?: 'built-in' | 'external'; // BerifyMe integration mode
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// Built-in BerifyMe configuration
|
|
14
|
+
const BUILT_IN_BERIFYME_CONFIG = {
|
|
15
|
+
apiKeyId: 'idv_XjN7vvuQVfHnaUkVQAEhdTuxAsQeKoa9',
|
|
16
|
+
secretKey: 'aaa444b1-087c-4b17-821a-9a6974286905',
|
|
17
|
+
environment: 'idv' as const
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const BerifyMeModal: React.FC<BerifyMeModalProps> = ({
|
|
21
|
+
isOpen,
|
|
22
|
+
onClose,
|
|
23
|
+
onVerificationComplete,
|
|
24
|
+
mode = 'built-in'
|
|
25
|
+
}) => {
|
|
26
|
+
const modalRef = useRef<HTMLDivElement>(null);
|
|
27
|
+
const berifyMeModalRef = useRef<any>(null);
|
|
28
|
+
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
if (!isOpen) return;
|
|
31
|
+
|
|
32
|
+
if (mode === 'external') {
|
|
33
|
+
// External mode: This should not be called as BerifyMeModal is not rendered in external mode
|
|
34
|
+
console.warn('⚠️ BerifyMeModal should not be rendered in external mode');
|
|
35
|
+
onClose();
|
|
36
|
+
} else {
|
|
37
|
+
// Built-in mode: dynamically load BerifyMe SDK
|
|
38
|
+
const loadBerifyMeSDK = async () => {
|
|
39
|
+
try {
|
|
40
|
+
// Check if already loaded
|
|
41
|
+
if (window.BerifyMeSDK) {
|
|
42
|
+
renderBerifyMeModal();
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Dynamically load SDK
|
|
47
|
+
const script = document.createElement('script');
|
|
48
|
+
script.src = 'https://docs.nxtlinq.ai/sdk/umd/berifyme-sdk.umd.js';
|
|
49
|
+
script.onload = () => {
|
|
50
|
+
if (window.BerifyMeSDK) {
|
|
51
|
+
renderBerifyMeModal();
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
script.onerror = () => {
|
|
55
|
+
console.error('❌ Failed to load BerifyMe SDK');
|
|
56
|
+
onClose();
|
|
57
|
+
};
|
|
58
|
+
document.head.appendChild(script);
|
|
59
|
+
} catch (error) {
|
|
60
|
+
console.error('❌ Error loading BerifyMe SDK:', error);
|
|
61
|
+
onClose();
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
loadBerifyMeSDK();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return () => {
|
|
69
|
+
// Cleanup function
|
|
70
|
+
if (berifyMeModalRef.current) {
|
|
71
|
+
try {
|
|
72
|
+
berifyMeModalRef.current.unmount?.();
|
|
73
|
+
} catch (e) {
|
|
74
|
+
// Ignore cleanup errors
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
}, [isOpen]);
|
|
79
|
+
|
|
80
|
+
const renderBerifyMeModal = () => {
|
|
81
|
+
if (!window.BerifyMeSDK || !modalRef.current) return;
|
|
82
|
+
|
|
83
|
+
try {
|
|
84
|
+
// Build redirect URL - always redirect to current page
|
|
85
|
+
const currentUrl = window.location.href;
|
|
86
|
+
const redirectUrl = `${window.location.origin}${window.location.pathname}?isAutoConnect=true&method=berifyme&returnUrl=${encodeURIComponent(currentUrl)}`;
|
|
87
|
+
|
|
88
|
+
// Create BerifyMe modal using built-in config
|
|
89
|
+
const berifyMeModal = window.BerifyMeSDK.modal;
|
|
90
|
+
|
|
91
|
+
// Use React 18's createRoot
|
|
92
|
+
const { createRoot } = require('react-dom/client');
|
|
93
|
+
const root = createRoot(modalRef.current);
|
|
94
|
+
berifyMeModalRef.current = root;
|
|
95
|
+
|
|
96
|
+
root.render(React.createElement(berifyMeModal, {
|
|
97
|
+
environment: BUILT_IN_BERIFYME_CONFIG.environment,
|
|
98
|
+
apiKeyId: BUILT_IN_BERIFYME_CONFIG.apiKeyId,
|
|
99
|
+
secretKey: BUILT_IN_BERIFYME_CONFIG.secretKey,
|
|
100
|
+
redirectUrl,
|
|
101
|
+
onUpdate: (event: any) => {
|
|
102
|
+
if (event.detail.page.pageName === 'All Set') {
|
|
103
|
+
console.log('✅ BerifyMe wallet verification completed successfully!');
|
|
104
|
+
|
|
105
|
+
// Get token if available
|
|
106
|
+
const urlParams = new URLSearchParams(window.location.search);
|
|
107
|
+
const token = urlParams.get('token');
|
|
108
|
+
|
|
109
|
+
// Call completion callback
|
|
110
|
+
if (onVerificationComplete) {
|
|
111
|
+
onVerificationComplete(token || undefined);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Close modal
|
|
115
|
+
onClose();
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}));
|
|
119
|
+
} catch (error) {
|
|
120
|
+
console.error('❌ Error rendering BerifyMe modal:', error);
|
|
121
|
+
onClose();
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
if (!isOpen) return null;
|
|
126
|
+
|
|
127
|
+
return (
|
|
128
|
+
<div
|
|
129
|
+
ref={modalRef}
|
|
130
|
+
css={css`
|
|
131
|
+
${modalOverlay}
|
|
132
|
+
z-index: 9999 !important;
|
|
133
|
+
`}
|
|
134
|
+
/>
|
|
135
|
+
);
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
// Add global type declarations
|
|
139
|
+
declare global {
|
|
140
|
+
interface Window {
|
|
141
|
+
BerifyMeSDK?: {
|
|
142
|
+
modal: any;
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
}
|