@swype-org/react-sdk 0.1.15 → 0.1.17

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/index.cjs CHANGED
@@ -18,52 +18,52 @@ var __export = (target, all) => {
18
18
 
19
19
  // src/theme.ts
20
20
  var darkTheme = {
21
- bg: "#0a0a0a",
22
- bgCard: "#141414",
23
- bgInput: "#1e1e1e",
24
- bgHover: "#252525",
25
- bgOverlay: "rgba(0, 0, 0, 0.6)",
26
- text: "#f5f5f5",
27
- textSecondary: "#a1a1aa",
28
- textMuted: "#71717a",
29
- textInverse: "#09090b",
30
- border: "#27272a",
31
- borderFocus: "#3b82f6",
32
- accent: "#3b82f6",
33
- accentHover: "#2563eb",
21
+ bg: "#071216",
22
+ bgCard: "#101c22",
23
+ bgInput: "#17272f",
24
+ bgHover: "#20343d",
25
+ bgOverlay: "rgba(3, 10, 13, 0.7)",
26
+ text: "#ecfeff",
27
+ textSecondary: "#b7d3dd",
28
+ textMuted: "#7fa4b0",
29
+ textInverse: "#052027",
30
+ border: "#2b4551",
31
+ borderFocus: "#2ec4cf",
32
+ accent: "#2eb6c2",
33
+ accentHover: "#239ba6",
34
34
  accentText: "#ffffff",
35
- success: "#22c55e",
36
- successBg: "#052e16",
37
- error: "#ef4444",
38
- errorBg: "#450a0a",
39
- shadow: "0 1px 3px rgba(0,0,0,0.4)",
40
- shadowLg: "0 8px 32px rgba(0,0,0,0.5)",
41
- radius: "10px",
42
- radiusLg: "16px"
35
+ success: "#0f9d73",
36
+ successBg: "#0f2f2a",
37
+ error: "#d46a72",
38
+ errorBg: "#301d21",
39
+ shadow: "0 1px 4px rgba(0,0,0,0.35)",
40
+ shadowLg: "0 18px 44px rgba(0,0,0,0.42)",
41
+ radius: "14px",
42
+ radiusLg: "24px"
43
43
  };
44
44
  var lightTheme = {
45
- bg: "#f8fafc",
46
- bgCard: "#ffffff",
47
- bgInput: "#f1f5f9",
48
- bgHover: "#e2e8f0",
49
- bgOverlay: "rgba(0, 0, 0, 0.3)",
50
- text: "#0f172a",
51
- textSecondary: "#475569",
52
- textMuted: "#94a3b8",
45
+ bg: "#ebf9fb",
46
+ bgCard: "#f9fdff",
47
+ bgInput: "#f1f8fb",
48
+ bgHover: "#e7f4f7",
49
+ bgOverlay: "rgba(7, 18, 22, 0.18)",
50
+ text: "#12222b",
51
+ textSecondary: "#4b6772",
52
+ textMuted: "#7d97a1",
53
53
  textInverse: "#ffffff",
54
- border: "#e2e8f0",
55
- borderFocus: "#3b82f6",
56
- accent: "#3b82f6",
57
- accentHover: "#2563eb",
54
+ border: "#d2e4ea",
55
+ borderFocus: "#2eb6c2",
56
+ accent: "#2eb6c2",
57
+ accentHover: "#259da7",
58
58
  accentText: "#ffffff",
59
- success: "#16a34a",
60
- successBg: "#f0fdf4",
61
- error: "#dc2626",
62
- errorBg: "#fef2f2",
63
- shadow: "0 1px 3px rgba(0,0,0,0.08)",
64
- shadowLg: "0 8px 32px rgba(0,0,0,0.12)",
65
- radius: "10px",
66
- radiusLg: "16px"
59
+ success: "#0f9d73",
60
+ successBg: "#e6f7f1",
61
+ error: "#ce6670",
62
+ errorBg: "#fdf1f2",
63
+ shadow: "0 1px 3px rgba(12, 31, 39, 0.08)",
64
+ shadowLg: "0 20px 48px rgba(19, 61, 75, 0.14)",
65
+ radius: "14px",
66
+ radiusLg: "24px"
67
67
  };
68
68
  function getTheme(mode) {
69
69
  return mode === "dark" ? darkTheme : lightTheme;
@@ -738,6 +738,28 @@ async function createPasskeyCredential(userIdentifier) {
738
738
  publicKey: publicKeyBytes ? toBase64(publicKeyBytes) : ""
739
739
  };
740
740
  }
741
+ async function deviceHasPasskey(credentialId) {
742
+ try {
743
+ const challenge = new Uint8Array(32);
744
+ crypto.getRandomValues(challenge);
745
+ await waitForDocumentFocus();
746
+ const assertion = await navigator.credentials.get({
747
+ publicKey: {
748
+ challenge,
749
+ rpId: resolvePasskeyRpId(),
750
+ allowCredentials: [{
751
+ type: "public-key",
752
+ id: base64ToBytes(credentialId)
753
+ }],
754
+ userVerification: "required",
755
+ timeout: 3e4
756
+ }
757
+ });
758
+ return assertion != null;
759
+ } catch {
760
+ return false;
761
+ }
762
+ }
741
763
  function useTransferPolling(intervalMs = 3e3) {
742
764
  const { apiBaseUrl } = useSwypeConfig();
743
765
  const { getAccessToken } = reactAuth.usePrivy();
@@ -1268,10 +1290,12 @@ function Spinner({ size = 40, label }) {
1268
1290
  style: {
1269
1291
  width: size,
1270
1292
  height: size,
1271
- border: `3px solid ${tokens.border}`,
1293
+ border: `4px solid ${tokens.bgInput}`,
1272
1294
  borderTopColor: tokens.accent,
1295
+ borderRightColor: tokens.accent + "66",
1273
1296
  borderRadius: "50%",
1274
- animation: "swype-spin 0.8s linear infinite"
1297
+ boxShadow: "inset 0 0 0 1px rgba(255,255,255,0.1)",
1298
+ animation: "swype-spin 0.9s linear infinite"
1275
1299
  }
1276
1300
  }
1277
1301
  ),
@@ -1302,7 +1326,7 @@ function ProviderCard({ provider, selected, onClick }) {
1302
1326
  padding: "14px 16px",
1303
1327
  background: selected ? tokens.accent + "18" : hovered ? tokens.bgHover : tokens.bgInput,
1304
1328
  border: `1.5px solid ${selected ? tokens.accent : tokens.border}`,
1305
- borderRadius: tokens.radius,
1329
+ borderRadius: tokens.radiusLg,
1306
1330
  cursor: "pointer",
1307
1331
  transition: "all 0.15s ease",
1308
1332
  color: tokens.text,
@@ -1321,7 +1345,7 @@ function ProviderCard({ provider, selected, onClick }) {
1321
1345
  style: {
1322
1346
  width: 32,
1323
1347
  height: 32,
1324
- borderRadius: "8px",
1348
+ borderRadius: "50%",
1325
1349
  objectFit: "contain"
1326
1350
  }
1327
1351
  }
@@ -1331,7 +1355,7 @@ function ProviderCard({ provider, selected, onClick }) {
1331
1355
  style: {
1332
1356
  width: 32,
1333
1357
  height: 32,
1334
- borderRadius: "8px",
1358
+ borderRadius: "50%",
1335
1359
  background: tokens.accent + "30",
1336
1360
  display: "flex",
1337
1361
  alignItems: "center",
@@ -1437,10 +1461,11 @@ function AccountDropdown({
1437
1461
  display: "flex",
1438
1462
  alignItems: "center",
1439
1463
  gap: "6px",
1440
- background: "transparent",
1441
- border: "none",
1464
+ background: tokens.bgCard,
1465
+ border: `1px solid ${tokens.border}`,
1442
1466
  cursor: "pointer",
1443
- padding: "4px 0",
1467
+ padding: "7px 10px",
1468
+ borderRadius: "999px",
1444
1469
  color: tokens.textSecondary,
1445
1470
  fontFamily: "inherit",
1446
1471
  fontSize: "0.85rem",
@@ -1497,7 +1522,7 @@ function AccountDropdown({
1497
1522
  marginTop: "4px",
1498
1523
  background: tokens.bgCard,
1499
1524
  border: `1px solid ${tokens.border}`,
1500
- borderRadius: tokens.radius,
1525
+ borderRadius: tokens.radiusLg,
1501
1526
  boxShadow: tokens.shadowLg,
1502
1527
  zIndex: 50,
1503
1528
  overflow: "hidden",
@@ -1556,8 +1581,8 @@ function AccountDropdown({
1556
1581
  fontWeight: 600,
1557
1582
  color: tokens.success,
1558
1583
  background: tokens.successBg,
1559
- padding: "1px 5px",
1560
- borderRadius: "3px",
1584
+ padding: "2px 7px",
1585
+ borderRadius: "999px",
1561
1586
  textTransform: "uppercase",
1562
1587
  letterSpacing: "0.03em"
1563
1588
  },
@@ -1772,7 +1797,7 @@ function AdvancedSettings({
1772
1797
  marginTop: "10px",
1773
1798
  padding: "14px",
1774
1799
  background: tokens.bgInput,
1775
- borderRadius: tokens.radius,
1800
+ borderRadius: tokens.radiusLg,
1776
1801
  border: `1px solid ${tokens.border}`
1777
1802
  },
1778
1803
  children: [
@@ -1802,13 +1827,13 @@ function AdvancedSettings({
1802
1827
  asset: isSelected ? null : asset
1803
1828
  }),
1804
1829
  style: {
1805
- padding: "6px 14px",
1830
+ padding: "7px 14px",
1806
1831
  fontSize: "0.8rem",
1807
1832
  fontWeight: 600,
1808
1833
  fontFamily: "inherit",
1809
- borderRadius: "6px",
1834
+ borderRadius: "999px",
1810
1835
  border: `1.5px solid ${isSelected ? tokens.accent : tokens.border}`,
1811
- background: isSelected ? tokens.accent + "18" : "transparent",
1836
+ background: isSelected ? tokens.accent + "18" : tokens.bgCard,
1812
1837
  color: isSelected ? tokens.accent : tokens.text,
1813
1838
  cursor: "pointer",
1814
1839
  outline: "none",
@@ -1846,13 +1871,13 @@ function AdvancedSettings({
1846
1871
  chain: isSelected ? null : chain.name
1847
1872
  }),
1848
1873
  style: {
1849
- padding: "6px 14px",
1874
+ padding: "7px 14px",
1850
1875
  fontSize: "0.8rem",
1851
1876
  fontWeight: 600,
1852
1877
  fontFamily: "inherit",
1853
- borderRadius: "6px",
1878
+ borderRadius: "999px",
1854
1879
  border: `1.5px solid ${isSelected ? tokens.accent : tokens.border}`,
1855
- background: isSelected ? tokens.accent + "18" : "transparent",
1880
+ background: isSelected ? tokens.accent + "18" : tokens.bgCard,
1856
1881
  color: isSelected ? tokens.accent : tokens.text,
1857
1882
  cursor: "pointer",
1858
1883
  outline: "none",
@@ -1873,9 +1898,9 @@ function AdvancedSettings({
1873
1898
  display: "flex",
1874
1899
  alignItems: "center",
1875
1900
  gap: "6px",
1876
- background: "transparent",
1901
+ background: tokens.bgCard,
1877
1902
  border: `1px dashed ${tokens.border}`,
1878
- borderRadius: tokens.radius,
1903
+ borderRadius: "999px",
1879
1904
  padding: "10px 14px",
1880
1905
  width: "100%",
1881
1906
  cursor: connectingNewAccount ? "not-allowed" : "pointer",
@@ -2141,12 +2166,27 @@ function SwypePayment({
2141
2166
  if (!token || cancelled) return;
2142
2167
  const { config } = await fetchUserConfig(apiBaseUrl, token);
2143
2168
  if (cancelled) return;
2144
- if (!config.passkey || !activeCredentialId) {
2145
- setStep("register-passkey");
2146
- } else if (depositAmount != null && depositAmount > 0) {
2147
- setStep("ready");
2169
+ if (config.passkey?.credentialId) {
2170
+ const hasKey = activeCredentialId ? activeCredentialId === config.passkey.credentialId : await deviceHasPasskey(config.passkey.credentialId);
2171
+ if (cancelled) return;
2172
+ if (hasKey) {
2173
+ if (!activeCredentialId) {
2174
+ setActiveCredentialId(config.passkey.credentialId);
2175
+ window.localStorage.setItem(
2176
+ ACTIVE_CREDENTIAL_STORAGE_KEY,
2177
+ config.passkey.credentialId
2178
+ );
2179
+ }
2180
+ if (depositAmount != null && depositAmount > 0) {
2181
+ setStep("ready");
2182
+ } else {
2183
+ setStep("enter-amount");
2184
+ }
2185
+ } else {
2186
+ setStep("register-passkey");
2187
+ }
2148
2188
  } else {
2149
- setStep("enter-amount");
2189
+ setStep("register-passkey");
2150
2190
  }
2151
2191
  } catch {
2152
2192
  if (!cancelled) {
@@ -2482,7 +2522,7 @@ function SwypePayment({
2482
2522
  background: tokens.bgCard,
2483
2523
  borderRadius: tokens.radiusLg,
2484
2524
  border: `1px solid ${tokens.border}`,
2485
- padding: "28px 24px",
2525
+ padding: "30px 24px 24px",
2486
2526
  maxWidth: 420,
2487
2527
  width: "100%",
2488
2528
  boxShadow: tokens.shadowLg,
@@ -2490,24 +2530,26 @@ function SwypePayment({
2490
2530
  color: tokens.text
2491
2531
  };
2492
2532
  const headingStyle = {
2493
- fontSize: "1.2rem",
2494
- fontWeight: 600,
2495
- margin: "0 0 20px 0",
2533
+ fontSize: "2rem",
2534
+ fontWeight: 700,
2535
+ margin: "0 0 18px 0",
2536
+ letterSpacing: "-0.02em",
2496
2537
  color: tokens.text,
2497
2538
  textAlign: "center"
2498
2539
  };
2499
2540
  const btnPrimary = {
2500
2541
  width: "100%",
2501
- padding: "14px",
2502
- background: tokens.accent,
2542
+ padding: "15px 18px",
2543
+ background: `linear-gradient(180deg, ${tokens.accent}, ${tokens.accentHover})`,
2503
2544
  color: tokens.accentText,
2504
2545
  border: "none",
2505
- borderRadius: tokens.radius,
2506
- fontSize: "1rem",
2507
- fontWeight: 600,
2546
+ borderRadius: "999px",
2547
+ fontSize: "1.03rem",
2548
+ fontWeight: 700,
2508
2549
  cursor: "pointer",
2509
- transition: "background 0.15s ease",
2510
- fontFamily: "inherit"
2550
+ transition: "filter 0.15s ease, transform 0.15s ease",
2551
+ fontFamily: "inherit",
2552
+ boxShadow: "0 8px 18px rgba(46, 182, 194, 0.28)"
2511
2553
  };
2512
2554
  const btnDisabled = {
2513
2555
  ...btnPrimary,
@@ -2516,15 +2558,16 @@ function SwypePayment({
2516
2558
  };
2517
2559
  ({
2518
2560
  ...btnPrimary,
2561
+ background: tokens.bgCard,
2519
2562
  color: tokens.textSecondary,
2520
2563
  border: `1px solid ${tokens.border}`});
2521
2564
  const errorStyle = {
2522
2565
  background: tokens.errorBg,
2523
- border: `1px solid ${tokens.error}`,
2524
- borderRadius: tokens.radius,
2525
- padding: "10px 14px",
2566
+ border: `1px solid ${tokens.error}66`,
2567
+ borderRadius: tokens.radiusLg,
2568
+ padding: "11px 14px",
2526
2569
  color: tokens.error,
2527
- fontSize: "0.825rem",
2570
+ fontSize: "0.86rem",
2528
2571
  marginBottom: "14px",
2529
2572
  lineHeight: 1.5
2530
2573
  };
@@ -2534,7 +2577,8 @@ function SwypePayment({
2534
2577
  style: {
2535
2578
  display: "flex",
2536
2579
  alignItems: "center",
2537
- gap: "8px",
2580
+ justifyContent: "center",
2581
+ gap: "10px",
2538
2582
  marginBottom: "20px"
2539
2583
  },
2540
2584
  children: [
@@ -2542,10 +2586,22 @@ function SwypePayment({
2542
2586
  "div",
2543
2587
  {
2544
2588
  style: {
2545
- width: 6,
2546
- height: 6,
2547
- borderRadius: "50%",
2548
- background: tokens.accent
2589
+ width: 28,
2590
+ height: 7,
2591
+ borderRadius: 999,
2592
+ background: tokens.accent,
2593
+ opacity: 0.95
2594
+ }
2595
+ }
2596
+ ),
2597
+ /* @__PURE__ */ jsxRuntime.jsx(
2598
+ "div",
2599
+ {
2600
+ style: {
2601
+ width: 8,
2602
+ height: 8,
2603
+ borderRadius: 999,
2604
+ background: tokens.border
2549
2605
  }
2550
2606
  }
2551
2607
  ),
@@ -2735,8 +2791,8 @@ function SwypePayment({
2735
2791
  gap: "8px",
2736
2792
  background: tokens.bgInput,
2737
2793
  border: `1px solid ${tokens.border}`,
2738
- borderRadius: tokens.radius,
2739
- padding: "4px 14px 4px 4px",
2794
+ borderRadius: tokens.radiusLg,
2795
+ padding: "6px 14px 6px 8px",
2740
2796
  marginBottom: "8px"
2741
2797
  },
2742
2798
  children: [
@@ -2783,9 +2839,10 @@ function SwypePayment({
2783
2839
  fontSize: "0.825rem",
2784
2840
  fontWeight: 600,
2785
2841
  color: tokens.textMuted,
2786
- background: tokens.bgHover,
2787
- padding: "4px 10px",
2788
- borderRadius: "6px"
2842
+ background: tokens.bgCard,
2843
+ padding: "6px 12px",
2844
+ border: `1px solid ${tokens.border}`,
2845
+ borderRadius: "999px"
2789
2846
  },
2790
2847
  children: "USD"
2791
2848
  }
@@ -2911,7 +2968,8 @@ function SwypePayment({
2911
2968
  marginBottom: "16px",
2912
2969
  padding: "12px 14px",
2913
2970
  background: tokens.bgInput,
2914
- borderRadius: tokens.radius,
2971
+ borderRadius: tokens.radiusLg,
2972
+ border: `1px solid ${tokens.border}`,
2915
2973
  lineHeight: 1.7
2916
2974
  },
2917
2975
  children: [
@@ -3110,9 +3168,9 @@ function SwypePayment({
3110
3168
  width: "100%",
3111
3169
  marginBottom: "12px",
3112
3170
  padding: "10px 12px",
3113
- borderRadius: tokens.radius,
3171
+ borderRadius: tokens.radiusLg,
3114
3172
  border: `1px solid ${tokens.border}`,
3115
- background: tokens.bgCard,
3173
+ background: tokens.bgInput,
3116
3174
  color: tokens.text,
3117
3175
  fontFamily: "inherit",
3118
3176
  fontSize: "0.875rem",
@@ -3151,9 +3209,9 @@ function SwypePayment({
3151
3209
  style: {
3152
3210
  width: "100%",
3153
3211
  padding: "10px 12px",
3154
- borderRadius: tokens.radius,
3212
+ borderRadius: tokens.radiusLg,
3155
3213
  border: `1px solid ${tokens.border}`,
3156
- background: tokens.bgCard,
3214
+ background: tokens.bgInput,
3157
3215
  color: tokens.text,
3158
3216
  fontFamily: "inherit",
3159
3217
  fontSize: "0.875rem",
@@ -3196,7 +3254,7 @@ function SwypePayment({
3196
3254
  ] }),
3197
3255
  /* @__PURE__ */ jsxRuntime.jsx("h2", { style: { ...headingStyle, marginBottom: "8px" }, children: "Authorize Transfer" }),
3198
3256
  /* @__PURE__ */ jsxRuntime.jsx("p", { style: { fontSize: "0.85rem", color: tokens.textSecondary, margin: "0 0 16px 0", lineHeight: 1.5 }, children: "Use your passkey to confirm this payment." }),
3199
- /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { fontSize: "0.825rem", color: tokens.textSecondary, padding: "12px 14px", background: tokens.bgInput, borderRadius: tokens.radius, textAlign: "left", lineHeight: 1.7, marginBottom: "16px" }, children: [
3257
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { fontSize: "0.825rem", color: tokens.textSecondary, padding: "12px 14px", background: tokens.bgInput, borderRadius: tokens.radiusLg, border: `1px solid ${tokens.border}`, textAlign: "left", lineHeight: 1.7, marginBottom: "16px" }, children: [
3200
3258
  payload.amount && payload.tokenSymbol && /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", justifyContent: "space-between" }, children: [
3201
3259
  /* @__PURE__ */ jsxRuntime.jsx("span", { children: "Amount" }),
3202
3260
  /* @__PURE__ */ jsxRuntime.jsxs("span", { style: { fontWeight: 600, color: tokens.text }, children: [
@@ -3387,7 +3445,8 @@ function SwypePayment({
3387
3445
  margin: "0 0 24px 0",
3388
3446
  padding: "14px",
3389
3447
  background: tokens.bgInput,
3390
- borderRadius: tokens.radius,
3448
+ borderRadius: tokens.radiusLg,
3449
+ border: `1px solid ${tokens.border}`,
3391
3450
  textAlign: "left",
3392
3451
  lineHeight: 1.8
3393
3452
  },
@@ -3462,6 +3521,7 @@ exports.SwypePayment = SwypePayment;
3462
3521
  exports.SwypeProvider = SwypeProvider;
3463
3522
  exports.createPasskeyCredential = createPasskeyCredential;
3464
3523
  exports.darkTheme = darkTheme;
3524
+ exports.deviceHasPasskey = deviceHasPasskey;
3465
3525
  exports.getTheme = getTheme;
3466
3526
  exports.lightTheme = lightTheme;
3467
3527
  exports.swypeApi = api_exports;