astra-sdk-web 1.1.2 → 1.1.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astra-sdk-web",
3
- "version": "1.1.2",
3
+ "version": "1.1.4",
4
4
  "description": "Official Astra SDK for JavaScript/TypeScript",
5
5
  "type": "module",
6
6
  "main": "./dist/astra-sdk.cjs.js",
@@ -1,8 +1,7 @@
1
- import React from 'react';
1
+ import React, { useState } from 'react';
2
2
  import { KycProvider } from '../contexts/KycContext';
3
3
  import MobileRoute from '../pages/MobileRoute';
4
4
  import QRCodePage from '../pages/QRCodePage';
5
- import { MemoryRouter, Routes, Route, Navigate } from 'react-router-dom';
6
5
 
7
6
  export interface KycFlowProps {
8
7
  apiBaseUrl: string;
@@ -11,8 +10,11 @@ export interface KycFlowProps {
11
10
  deviceType?: string;
12
11
  startAtQr?: boolean;
13
12
  onClose?: () => void;
13
+ mobileBaseUrl?: string;
14
14
  }
15
15
 
16
+ type KycFlowView = 'qr' | 'mobileroute';
17
+
16
18
  export const KycFlow: React.FC<KycFlowProps> = ({
17
19
  apiBaseUrl,
18
20
  sessionId,
@@ -20,7 +22,20 @@ export const KycFlow: React.FC<KycFlowProps> = ({
20
22
  deviceType,
21
23
  startAtQr = true,
22
24
  onClose,
25
+ mobileBaseUrl = 'https://astra-sdk-rebuild.vercel.app',
23
26
  }) => {
27
+ const [currentView, setCurrentView] = useState<KycFlowView>(startAtQr ? 'qr' : 'mobileroute');
28
+
29
+ const handleNavigate = (view: KycFlowView) => {
30
+ setCurrentView(view);
31
+ };
32
+
33
+ const handleClose = () => {
34
+ if (onClose) {
35
+ onClose();
36
+ }
37
+ };
38
+
24
39
  return (
25
40
  <KycProvider
26
41
  apiBaseUrl={apiBaseUrl}
@@ -28,13 +43,16 @@ export const KycFlow: React.FC<KycFlowProps> = ({
28
43
  serverKey={serverKey}
29
44
  deviceType={deviceType}
30
45
  >
31
- <MemoryRouter initialEntries={[startAtQr ? '/qr' : '/mobileroute']}>
32
- <Routes>
33
- <Route path="/" element={<Navigate to={startAtQr ? "/qr" : "/mobileroute"} replace />} />
34
- <Route path="/qr" element={<QRCodePage onClose={onClose} />} />
35
- <Route path="/mobileroute" element={<MobileRoute onClose={onClose} />} />
36
- </Routes>
37
- </MemoryRouter>
46
+ {currentView === 'qr' ? (
47
+ <QRCodePage
48
+ onClose={handleClose}
49
+ onNavigate={handleNavigate}
50
+ mobileBaseUrl={mobileBaseUrl}
51
+ sessionId={sessionId}
52
+ />
53
+ ) : (
54
+ <MobileRoute onClose={handleClose} onNavigate={handleNavigate} />
55
+ )}
38
56
  </KycProvider>
39
57
  );
40
58
  };
@@ -1,28 +1,24 @@
1
1
  import { useEffect } from 'react';
2
- import { useNavigate } from 'react-router-dom';
3
2
  import { isMobileDevice } from '../utils/deviceDetection';
4
3
  import FaceScanModal from './FaceScanModal';
5
4
  import '../index.css';
6
5
 
7
6
  interface MobileRouteProps {
8
7
  onClose?: () => void;
8
+ onNavigate?: (view: 'qr' | 'mobileroute') => void;
9
9
  }
10
10
 
11
- function MobileRoute({ onClose }: MobileRouteProps = {}) {
12
- const navigate = useNavigate();
13
-
11
+ function MobileRoute({ onClose, onNavigate }: MobileRouteProps = {}) {
14
12
  useEffect(() => {
15
- if (!isMobileDevice()) {
16
- navigate('/qr', { replace: true });
13
+ if (!isMobileDevice() && onNavigate) {
14
+ onNavigate('qr');
17
15
  return;
18
16
  }
19
- }, [navigate]);
17
+ }, [onNavigate]);
20
18
 
21
19
  const handleClose = () => {
22
20
  if (onClose) {
23
21
  onClose();
24
- } else {
25
- navigate(-1);
26
22
  }
27
23
  };
28
24
 
@@ -1,32 +1,33 @@
1
1
  import { useState, useEffect } from 'react';
2
2
  import { QRCodeSVG } from 'qrcode.react';
3
- import { useSearchParams, useNavigate } from 'react-router-dom';
4
3
  import '../index.css';
5
4
 
6
5
  interface QRCodePageProps {
7
6
  onClose?: () => void;
7
+ onNavigate?: (view: 'qr' | 'mobileroute') => void;
8
+ mobileBaseUrl?: string;
9
+ sessionId?: string;
8
10
  }
9
11
 
10
- function QRCodePage({ onClose }: QRCodePageProps = {}) {
11
- const [searchParams] = useSearchParams();
12
- const navigate = useNavigate();
12
+ function QRCodePage({ onClose, onNavigate, mobileBaseUrl = 'https://astra-sdk-rebuild.vercel.app', sessionId }: QRCodePageProps = {}) {
13
13
  const [qrUrl, setQrUrl] = useState<string>('');
14
14
  const [copied, setCopied] = useState<boolean>(false);
15
15
 
16
16
  useEffect(() => {
17
- const currentUrl = window.location.origin;
18
-
19
- const params: Record<string, string> = {};
20
- searchParams.forEach((value, key) => {
21
- params[key] = value;
22
- });
23
-
17
+ // Get search params from current URL
18
+ const searchParams = new URLSearchParams(window.location.search);
19
+
20
+ // Add sessionId to query params if provided
21
+ if (sessionId) {
22
+ searchParams.set('sessionId', sessionId);
23
+ }
24
+
24
25
  const mobileRoute = '/mobileroute';
25
- const queryString = new URLSearchParams(params).toString();
26
- const fullUrl = `${currentUrl}${mobileRoute}${queryString ? `?${queryString}` : ''}`;
26
+ const queryString = searchParams.toString();
27
+ const fullUrl = `${mobileBaseUrl}${mobileRoute}${queryString ? `?${queryString}` : ''}`;
27
28
 
28
29
  setQrUrl(fullUrl);
29
- }, [searchParams]);
30
+ }, [mobileBaseUrl, sessionId]);
30
31
 
31
32
  const handleCopyUrl = async () => {
32
33
  if (qrUrl) {
@@ -43,8 +44,6 @@ function QRCodePage({ onClose }: QRCodePageProps = {}) {
43
44
  const handleClose = () => {
44
45
  if (onClose) {
45
46
  onClose();
46
- } else {
47
- navigate(-1);
48
47
  }
49
48
  };
50
49
 
@@ -53,8 +52,14 @@ function QRCodePage({ onClose }: QRCodePageProps = {}) {
53
52
  };
54
53
 
55
54
  return (
56
- <div className="fixed inset-0 flex items-center justify-center bg-black p-4 sm:p-6 md:p-8 z-[1000]">
57
- <div className="relative bg-[rgba(20,20,20,0.95)] rounded-2xl p-5 sm:p-6 md:p-7 max-w-[450px] w-full h-[80vh] flex flex-col text-center shadow-[0_8px_32px_rgba(0,0,0,0.5)]">
55
+ <div className="fixed inset-0 flex items-center justify-center bg-gradient-to-br from-gray-900 via-gray-800 to-black p-4 sm:p-6 md:p-8 z-[1000]">
56
+ {/* Background pattern overlay */}
57
+ <div className="absolute inset-0 opacity-10" style={{
58
+ backgroundImage: `radial-gradient(circle at 2px 2px, rgba(255,255,255,0.15) 1px, transparent 0)`,
59
+ backgroundSize: '40px 40px'
60
+ }}></div>
61
+
62
+ <div className="relative bg-[rgba(20,20,20,0.95)] backdrop-blur-sm rounded-2xl p-5 sm:p-6 md:p-7 max-w-[450px] w-full h-[80vh] flex flex-col text-center shadow-[0_8px_32px_rgba(0,0,0,0.5)] border border-white/10">
58
63
  <button
59
64
  className="absolute top-5 right-5 bg-transparent border-none text-white cursor-pointer p-2 flex items-center justify-center rounded transition-colors hover:bg-white/10 active:bg-white/20"
60
65
  onClick={handleClose}