@swype-org/react-sdk 0.1.100 → 0.1.103

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.js CHANGED
@@ -158,6 +158,7 @@ var api_exports = {};
158
158
  __export(api_exports, {
159
159
  createAccount: () => createAccount,
160
160
  createTransfer: () => createTransfer,
161
+ fetchAccount: () => fetchAccount,
161
162
  fetchAccounts: () => fetchAccounts,
162
163
  fetchAuthorizationSession: () => fetchAuthorizationSession,
163
164
  fetchChains: () => fetchChains,
@@ -204,14 +205,28 @@ async function fetchAccounts(apiBaseUrl, token, credentialId) {
204
205
  const data = await res.json();
205
206
  return data.items;
206
207
  }
208
+ async function fetchAccount(apiBaseUrl, token, accountId, credentialId) {
209
+ const params = new URLSearchParams({ credentialId });
210
+ const res = await fetch(`${apiBaseUrl}/v1/accounts/${accountId}?${params.toString()}`, {
211
+ headers: { Authorization: `Bearer ${token}` }
212
+ });
213
+ if (!res.ok) await throwApiError(res);
214
+ return await res.json();
215
+ }
207
216
  async function createAccount(apiBaseUrl, token, params) {
217
+ const body = {
218
+ id: params.id ?? crypto.randomUUID(),
219
+ name: params.name,
220
+ credentialId: params.credentialId,
221
+ providerId: params.providerId
222
+ };
208
223
  const res = await fetch(`${apiBaseUrl}/v1/accounts`, {
209
224
  method: "POST",
210
225
  headers: {
211
226
  "Content-Type": "application/json",
212
227
  Authorization: `Bearer ${token}`
213
228
  },
214
- body: JSON.stringify(params)
229
+ body: JSON.stringify(body)
215
230
  });
216
231
  if (!res.ok) await throwApiError(res);
217
232
  return await res.json();
@@ -1861,6 +1876,7 @@ function createInitialState(config) {
1861
1876
  accounts: [],
1862
1877
  chains: [],
1863
1878
  loadingData: false,
1879
+ selectedProviderId: null,
1864
1880
  selectedAccountId: null,
1865
1881
  selectedWalletId: null,
1866
1882
  amount: config.depositAmount != null ? config.depositAmount.toString() : "",
@@ -1955,7 +1971,9 @@ function paymentReducer(state, action) {
1955
1971
  case "SELECT_PROVIDER":
1956
1972
  return {
1957
1973
  ...state,
1958
- selectedAccountId: null
1974
+ selectedProviderId: action.providerId,
1975
+ selectedAccountId: null,
1976
+ selectedWalletId: null
1959
1977
  };
1960
1978
  case "SELECT_ACCOUNT":
1961
1979
  return {
@@ -2024,7 +2042,7 @@ function paymentReducer(state, action) {
2024
2042
  case "MOBILE_SETUP_COMPLETE":
2025
2043
  return {
2026
2044
  ...state,
2027
- transfer: action.transfer,
2045
+ transfer: action.transfer ?? state.transfer,
2028
2046
  error: null,
2029
2047
  mobileFlow: false,
2030
2048
  deeplinkUri: null,
@@ -2046,6 +2064,7 @@ function paymentReducer(state, action) {
2046
2064
  ...state,
2047
2065
  mobileFlow: true,
2048
2066
  deeplinkUri: action.deeplinkUri,
2067
+ selectedProviderId: action.providerId ?? state.selectedProviderId,
2049
2068
  error: action.error ?? null,
2050
2069
  step: "open-wallet"
2051
2070
  };
@@ -2101,6 +2120,7 @@ function paymentReducer(state, action) {
2101
2120
  amount: action.depositAmount != null ? action.depositAmount.toString() : "",
2102
2121
  mobileFlow: false,
2103
2122
  deeplinkUri: null,
2123
+ selectedProviderId: null,
2104
2124
  selectedWalletId: null,
2105
2125
  selectedAccountId: action.firstAccountId
2106
2126
  };
@@ -2532,36 +2552,160 @@ var KNOWN_LOGOS = {
2532
2552
  base: BASE_LOGO,
2533
2553
  "trust wallet": TRUST_WALLET_LOGO
2534
2554
  };
2535
- function SourceCard({ name, address, verified, onChangeSource }) {
2555
+ function hasActiveWallet2(account) {
2556
+ return account.wallets.some((w) => w.status === "ACTIVE");
2557
+ }
2558
+ function SourceCard({
2559
+ name,
2560
+ address,
2561
+ verified,
2562
+ accounts,
2563
+ selectedAccountId,
2564
+ onSelectAccount,
2565
+ onAuthorizeAccount,
2566
+ onAddProvider
2567
+ }) {
2536
2568
  const { tokens } = useSwypeConfig();
2537
- return /* @__PURE__ */ jsxs("div", { style: containerStyle6(tokens), children: [
2538
- /* @__PURE__ */ jsxs("div", { style: leftStyle, children: [
2539
- KNOWN_LOGOS[name.toLowerCase()] ? /* @__PURE__ */ jsx(
2540
- "img",
2541
- {
2542
- src: KNOWN_LOGOS[name.toLowerCase()],
2543
- alt: name,
2544
- style: logoImgStyle
2545
- }
2546
- ) : /* @__PURE__ */ jsx("div", { style: iconStyle3(tokens.textMuted), children: /* @__PURE__ */ jsx("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", children: /* @__PURE__ */ jsx(
2547
- "path",
2569
+ const [open, setOpen] = useState(false);
2570
+ const containerRef = useRef(null);
2571
+ const hasDropdown = accounts != null && accounts.length > 0;
2572
+ useEffect(() => {
2573
+ if (!open) return;
2574
+ const handleClick = (e) => {
2575
+ if (containerRef.current && !containerRef.current.contains(e.target)) {
2576
+ setOpen(false);
2577
+ }
2578
+ };
2579
+ document.addEventListener("mousedown", handleClick);
2580
+ return () => document.removeEventListener("mousedown", handleClick);
2581
+ }, [open]);
2582
+ return /* @__PURE__ */ jsxs("div", { ref: containerRef, style: { position: "relative" }, children: [
2583
+ /* @__PURE__ */ jsxs("div", { style: cardContainerStyle(tokens), children: [
2584
+ /* @__PURE__ */ jsxs("div", { style: leftStyle, children: [
2585
+ KNOWN_LOGOS[name.toLowerCase()] ? /* @__PURE__ */ jsx(
2586
+ "img",
2587
+ {
2588
+ src: KNOWN_LOGOS[name.toLowerCase()],
2589
+ alt: name,
2590
+ style: logoImgStyle
2591
+ }
2592
+ ) : /* @__PURE__ */ jsx("div", { style: iconStyle3(tokens.textMuted), children: /* @__PURE__ */ jsx("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", children: /* @__PURE__ */ jsx(
2593
+ "path",
2594
+ {
2595
+ d: "M21 7H3c-1.1 0-2 .9-2 2v6c0 1.1.9 2 2 2h18c1.1 0 2-.9 2-2V9c0-1.1-.9-2-2-2zm0 8H3V9h18v6z",
2596
+ fill: "currentColor"
2597
+ }
2598
+ ) }) }),
2599
+ /* @__PURE__ */ jsxs("div", { children: [
2600
+ /* @__PURE__ */ jsxs("div", { style: nameRowStyle, children: [
2601
+ /* @__PURE__ */ jsx("span", { style: nameStyle(tokens.text), children: name }),
2602
+ verified && /* @__PURE__ */ jsx("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", children: /* @__PURE__ */ jsx("path", { d: "M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41L9 16.17z", fill: tokens.accent }) })
2603
+ ] }),
2604
+ address && /* @__PURE__ */ jsx("span", { style: addressStyle(tokens.textMuted), children: address })
2605
+ ] })
2606
+ ] }),
2607
+ hasDropdown && /* @__PURE__ */ jsxs(
2608
+ "button",
2548
2609
  {
2549
- d: "M21 7H3c-1.1 0-2 .9-2 2v6c0 1.1.9 2 2 2h18c1.1 0 2-.9 2-2V9c0-1.1-.9-2-2-2zm0 8H3V9h18v6z",
2550
- fill: "currentColor"
2610
+ type: "button",
2611
+ onClick: () => setOpen(!open),
2612
+ style: changeStyle(tokens.accent),
2613
+ children: [
2614
+ "Change source",
2615
+ /* @__PURE__ */ jsx(
2616
+ "svg",
2617
+ {
2618
+ width: "10",
2619
+ height: "10",
2620
+ viewBox: "0 0 24 24",
2621
+ fill: "none",
2622
+ style: {
2623
+ marginLeft: 4,
2624
+ transform: open ? "rotate(180deg)" : "rotate(0deg)",
2625
+ transition: "transform 0.15s ease"
2626
+ },
2627
+ children: /* @__PURE__ */ jsx(
2628
+ "path",
2629
+ {
2630
+ d: "M7 10l5 5 5-5",
2631
+ stroke: tokens.accent,
2632
+ strokeWidth: "2.5",
2633
+ strokeLinecap: "round",
2634
+ strokeLinejoin: "round"
2635
+ }
2636
+ )
2637
+ }
2638
+ )
2639
+ ]
2551
2640
  }
2552
- ) }) }),
2553
- /* @__PURE__ */ jsxs("div", { children: [
2554
- /* @__PURE__ */ jsxs("div", { style: nameRowStyle, children: [
2555
- /* @__PURE__ */ jsx("span", { style: nameStyle(tokens.text), children: name }),
2556
- verified && /* @__PURE__ */ jsx("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", children: /* @__PURE__ */ jsx("path", { d: "M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41L9 16.17z", fill: tokens.accent }) })
2557
- ] }),
2558
- address && /* @__PURE__ */ jsx("span", { style: addressStyle(tokens.textMuted), children: address })
2559
- ] })
2641
+ )
2560
2642
  ] }),
2561
- onChangeSource && /* @__PURE__ */ jsx("button", { type: "button", onClick: onChangeSource, style: changeStyle(tokens.accent), children: "Change source" })
2643
+ open && hasDropdown && /* @__PURE__ */ jsxs("div", { style: dropdownStyle(tokens), children: [
2644
+ accounts.map((account) => {
2645
+ const active = hasActiveWallet2(account);
2646
+ const isSelected = account.id === selectedAccountId;
2647
+ return /* @__PURE__ */ jsxs(
2648
+ "button",
2649
+ {
2650
+ type: "button",
2651
+ onClick: () => {
2652
+ if (active) {
2653
+ onSelectAccount?.(account.id);
2654
+ } else {
2655
+ onAuthorizeAccount?.(account.id);
2656
+ }
2657
+ setOpen(false);
2658
+ },
2659
+ style: dropdownRowStyle(tokens, active, isSelected),
2660
+ children: [
2661
+ /* @__PURE__ */ jsxs("div", { style: dropdownRowLeftStyle, children: [
2662
+ KNOWN_LOGOS[account.name.toLowerCase()] ? /* @__PURE__ */ jsx(
2663
+ "img",
2664
+ {
2665
+ src: KNOWN_LOGOS[account.name.toLowerCase()],
2666
+ alt: account.name,
2667
+ style: dropdownLogoStyle
2668
+ }
2669
+ ) : /* @__PURE__ */ jsx("div", { style: dropdownFallbackIconStyle(active ? tokens.textMuted : tokens.border), children: account.name.charAt(0) }),
2670
+ /* @__PURE__ */ jsx("span", { style: dropdownNameStyle(active ? tokens.text : tokens.textMuted), children: account.name })
2671
+ ] }),
2672
+ /* @__PURE__ */ jsxs("div", { style: dropdownRowRightStyle, children: [
2673
+ active ? /* @__PURE__ */ jsx("span", { style: activeBadgeStyle(tokens), children: "Active" }) : /* @__PURE__ */ jsx("span", { style: inactiveBadgeStyle(tokens), children: "Setup incomplete" }),
2674
+ isSelected && /* @__PURE__ */ jsx("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", children: /* @__PURE__ */ jsx(
2675
+ "path",
2676
+ {
2677
+ d: "M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41L9 16.17z",
2678
+ fill: tokens.accent
2679
+ }
2680
+ ) })
2681
+ ] })
2682
+ ]
2683
+ },
2684
+ account.id
2685
+ );
2686
+ }),
2687
+ onAddProvider && /* @__PURE__ */ jsxs(Fragment, { children: [
2688
+ /* @__PURE__ */ jsx("div", { style: dropdownDividerStyle(tokens.border) }),
2689
+ /* @__PURE__ */ jsxs(
2690
+ "button",
2691
+ {
2692
+ type: "button",
2693
+ onClick: () => {
2694
+ onAddProvider();
2695
+ setOpen(false);
2696
+ },
2697
+ style: addProviderStyle(tokens),
2698
+ children: [
2699
+ /* @__PURE__ */ jsx("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", children: /* @__PURE__ */ jsx("path", { d: "M12 5v14M5 12h14", stroke: "currentColor", strokeWidth: "2.5", strokeLinecap: "round" }) }),
2700
+ "Add Provider"
2701
+ ]
2702
+ }
2703
+ )
2704
+ ] })
2705
+ ] })
2562
2706
  ] });
2563
2707
  }
2564
- var containerStyle6 = (tokens) => ({
2708
+ var cardContainerStyle = (tokens) => ({
2565
2709
  display: "flex",
2566
2710
  alignItems: "center",
2567
2711
  justifyContent: "space-between",
@@ -2602,6 +2746,8 @@ var addressStyle = (color) => ({
2602
2746
  fontFamily: '"SF Mono", "Fira Code", monospace'
2603
2747
  });
2604
2748
  var changeStyle = (color) => ({
2749
+ display: "flex",
2750
+ alignItems: "center",
2605
2751
  background: "transparent",
2606
2752
  border: "none",
2607
2753
  color,
@@ -2611,6 +2757,117 @@ var changeStyle = (color) => ({
2611
2757
  fontFamily: "inherit",
2612
2758
  padding: 0
2613
2759
  });
2760
+ var dropdownStyle = (tokens) => ({
2761
+ position: "absolute",
2762
+ top: "100%",
2763
+ left: 0,
2764
+ right: 0,
2765
+ marginTop: 4,
2766
+ background: tokens.bgCard,
2767
+ border: `1px solid ${tokens.border}`,
2768
+ borderRadius: tokens.radiusLg,
2769
+ boxShadow: tokens.shadowLg,
2770
+ zIndex: 50,
2771
+ overflow: "hidden"
2772
+ });
2773
+ var dropdownRowStyle = (tokens, active, isSelected) => ({
2774
+ display: "flex",
2775
+ alignItems: "center",
2776
+ justifyContent: "space-between",
2777
+ width: "100%",
2778
+ padding: "10px 14px",
2779
+ background: isSelected ? tokens.accent + "12" : "transparent",
2780
+ border: "none",
2781
+ borderBottom: `1px solid ${tokens.border}`,
2782
+ cursor: "pointer",
2783
+ fontFamily: "inherit",
2784
+ fontSize: "0.85rem",
2785
+ textAlign: "left",
2786
+ outline: "none",
2787
+ opacity: active ? 1 : 0.55,
2788
+ transition: "background 0.1s ease"
2789
+ });
2790
+ var dropdownRowLeftStyle = {
2791
+ display: "flex",
2792
+ alignItems: "center",
2793
+ gap: 10,
2794
+ minWidth: 0,
2795
+ flex: 1
2796
+ };
2797
+ var dropdownRowRightStyle = {
2798
+ display: "flex",
2799
+ alignItems: "center",
2800
+ gap: 8,
2801
+ flexShrink: 0
2802
+ };
2803
+ var dropdownLogoStyle = {
2804
+ width: 20,
2805
+ height: 20,
2806
+ borderRadius: "50%",
2807
+ objectFit: "contain",
2808
+ flexShrink: 0
2809
+ };
2810
+ var dropdownFallbackIconStyle = (color) => ({
2811
+ width: 20,
2812
+ height: 20,
2813
+ borderRadius: "50%",
2814
+ display: "flex",
2815
+ alignItems: "center",
2816
+ justifyContent: "center",
2817
+ fontSize: "0.72rem",
2818
+ fontWeight: 700,
2819
+ color,
2820
+ flexShrink: 0
2821
+ });
2822
+ var dropdownNameStyle = (color) => ({
2823
+ fontWeight: 500,
2824
+ color,
2825
+ whiteSpace: "nowrap",
2826
+ overflow: "hidden",
2827
+ textOverflow: "ellipsis"
2828
+ });
2829
+ var activeBadgeStyle = (tokens) => ({
2830
+ fontSize: "0.6rem",
2831
+ fontWeight: 600,
2832
+ color: tokens.success,
2833
+ background: tokens.successBg,
2834
+ padding: "2px 7px",
2835
+ borderRadius: 999,
2836
+ textTransform: "uppercase",
2837
+ letterSpacing: "0.03em",
2838
+ whiteSpace: "nowrap"
2839
+ });
2840
+ var inactiveBadgeStyle = (tokens) => ({
2841
+ fontSize: "0.6rem",
2842
+ fontWeight: 600,
2843
+ color: tokens.warning,
2844
+ background: tokens.warningBg ?? `${tokens.warning}1a`,
2845
+ padding: "2px 7px",
2846
+ borderRadius: 999,
2847
+ textTransform: "uppercase",
2848
+ letterSpacing: "0.03em",
2849
+ whiteSpace: "nowrap"
2850
+ });
2851
+ var dropdownDividerStyle = (borderColor) => ({
2852
+ height: 0,
2853
+ borderTop: `1px solid ${borderColor}`
2854
+ });
2855
+ var addProviderStyle = (tokens) => ({
2856
+ display: "flex",
2857
+ alignItems: "center",
2858
+ gap: 8,
2859
+ width: "100%",
2860
+ padding: "10px 14px",
2861
+ background: "transparent",
2862
+ border: "none",
2863
+ color: tokens.accent,
2864
+ fontWeight: 600,
2865
+ fontSize: "0.85rem",
2866
+ cursor: "pointer",
2867
+ fontFamily: "inherit",
2868
+ textAlign: "left",
2869
+ outline: "none"
2870
+ });
2614
2871
  function StepList({ steps }) {
2615
2872
  const { tokens } = useSwypeConfig();
2616
2873
  return /* @__PURE__ */ jsx("div", { style: listStyle, children: steps.map((step, i) => {
@@ -2688,13 +2945,13 @@ function SettingsMenu({ onLogout }) {
2688
2945
  document.addEventListener("mousedown", handleClickOutside);
2689
2946
  return () => document.removeEventListener("mousedown", handleClickOutside);
2690
2947
  }, [open]);
2691
- return /* @__PURE__ */ jsxs("div", { ref: menuRef, style: containerStyle7, children: [
2948
+ return /* @__PURE__ */ jsxs("div", { ref: menuRef, style: containerStyle6, children: [
2692
2949
  /* @__PURE__ */ jsx("button", { type: "button", onClick: toggle, style: triggerStyle(tokens.text), "aria-label": "Settings", children: /* @__PURE__ */ jsxs("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", children: [
2693
2950
  /* @__PURE__ */ jsx("circle", { cx: "12", cy: "5", r: "2", fill: "currentColor" }),
2694
2951
  /* @__PURE__ */ jsx("circle", { cx: "12", cy: "12", r: "2", fill: "currentColor" }),
2695
2952
  /* @__PURE__ */ jsx("circle", { cx: "12", cy: "19", r: "2", fill: "currentColor" })
2696
2953
  ] }) }),
2697
- open && /* @__PURE__ */ jsx("div", { style: dropdownStyle(tokens), children: /* @__PURE__ */ jsxs(
2954
+ open && /* @__PURE__ */ jsx("div", { style: dropdownStyle2(tokens), children: /* @__PURE__ */ jsxs(
2698
2955
  "button",
2699
2956
  {
2700
2957
  type: "button",
@@ -2715,7 +2972,7 @@ function SettingsMenu({ onLogout }) {
2715
2972
  ) })
2716
2973
  ] });
2717
2974
  }
2718
- var containerStyle7 = {
2975
+ var containerStyle6 = {
2719
2976
  position: "relative"
2720
2977
  };
2721
2978
  var triggerStyle = (color) => ({
@@ -2728,7 +2985,7 @@ var triggerStyle = (color) => ({
2728
2985
  alignItems: "center",
2729
2986
  justifyContent: "center"
2730
2987
  });
2731
- var dropdownStyle = (tokens) => ({
2988
+ var dropdownStyle2 = (tokens) => ({
2732
2989
  position: "absolute",
2733
2990
  right: 0,
2734
2991
  top: "100%",
@@ -3690,12 +3947,16 @@ function DepositScreen({
3690
3947
  processing,
3691
3948
  error,
3692
3949
  onDeposit,
3693
- onChangeSource,
3694
3950
  onSwitchWallet,
3695
3951
  onBack,
3696
3952
  onLogout,
3697
3953
  onIncreaseLimit,
3698
- increasingLimit
3954
+ increasingLimit,
3955
+ accounts,
3956
+ selectedAccountId,
3957
+ onSelectAccount,
3958
+ onAuthorizeAccount,
3959
+ onAddProvider
3699
3960
  }) {
3700
3961
  const { tokens } = useSwypeConfig();
3701
3962
  const amount = initialAmount;
@@ -3721,7 +3982,11 @@ function DepositScreen({
3721
3982
  name: sourceName,
3722
3983
  address: sourceAddress,
3723
3984
  verified: sourceVerified,
3724
- onChangeSource
3985
+ accounts,
3986
+ selectedAccountId,
3987
+ onSelectAccount,
3988
+ onAuthorizeAccount,
3989
+ onAddProvider
3725
3990
  }
3726
3991
  ),
3727
3992
  /* @__PURE__ */ jsx("div", { style: amountDisplayStyle, children: /* @__PURE__ */ jsxs("span", { style: amountStyle({ ...tokens, dimmed: true }), children: [
@@ -3791,7 +4056,11 @@ function DepositScreen({
3791
4056
  name: sourceName,
3792
4057
  address: sourceAddress,
3793
4058
  verified: sourceVerified,
3794
- onChangeSource
4059
+ accounts,
4060
+ selectedAccountId,
4061
+ onSelectAccount,
4062
+ onAuthorizeAccount,
4063
+ onAddProvider
3795
4064
  }
3796
4065
  ),
3797
4066
  /* @__PURE__ */ jsx("div", { style: amountDisplayStyle, children: /* @__PURE__ */ jsxs("span", { style: amountStyle(tokens), children: [
@@ -4924,12 +5193,16 @@ function StepRenderer({
4924
5193
  processing: state.creatingTransfer,
4925
5194
  error: state.error,
4926
5195
  onDeposit: handlers.onPay,
4927
- onChangeSource: () => handlers.onNavigate("wallet-picker"),
4928
5196
  onSwitchWallet: () => handlers.onNavigate("wallet-picker"),
4929
5197
  onBack: onBack ?? (() => handlers.onLogout()),
4930
5198
  onLogout: handlers.onLogout,
4931
5199
  onIncreaseLimit: handlers.onIncreaseLimit,
4932
- increasingLimit: state.increasingLimit
5200
+ increasingLimit: state.increasingLimit,
5201
+ accounts: state.accounts,
5202
+ selectedAccountId: state.selectedAccountId,
5203
+ onSelectAccount: handlers.onSelectAccount,
5204
+ onAuthorizeAccount: handlers.onContinueConnection,
5205
+ onAddProvider: () => handlers.onNavigate("wallet-picker")
4933
5206
  }
4934
5207
  );
4935
5208
  }
@@ -4998,10 +5271,14 @@ function StepRenderer({
4998
5271
  processing: false,
4999
5272
  error: state.error,
5000
5273
  onDeposit: handlers.onPay,
5001
- onChangeSource: () => handlers.onNavigate("wallet-picker"),
5002
5274
  onSwitchWallet: () => handlers.onNavigate("wallet-picker"),
5003
5275
  onBack: onBack ?? (() => handlers.onLogout()),
5004
- onLogout: handlers.onLogout
5276
+ onLogout: handlers.onLogout,
5277
+ accounts: state.accounts,
5278
+ selectedAccountId: state.selectedAccountId,
5279
+ onSelectAccount: handlers.onSelectAccount,
5280
+ onAuthorizeAccount: handlers.onContinueConnection,
5281
+ onAddProvider: () => handlers.onNavigate("wallet-picker")
5005
5282
  }
5006
5283
  );
5007
5284
  }
@@ -5026,7 +5303,7 @@ var PaymentErrorBoundary = class extends Component {
5026
5303
  if (!this.state.hasError) {
5027
5304
  return this.props.children;
5028
5305
  }
5029
- return /* @__PURE__ */ jsxs("div", { style: containerStyle8, children: [
5306
+ return /* @__PURE__ */ jsxs("div", { style: containerStyle7, children: [
5030
5307
  /* @__PURE__ */ jsx("div", { style: iconStyle4, children: /* @__PURE__ */ jsxs("svg", { width: "48", height: "48", viewBox: "0 0 24 24", fill: "none", children: [
5031
5308
  /* @__PURE__ */ jsx("circle", { cx: "12", cy: "12", r: "10", stroke: "#ef4444", strokeWidth: "1.5" }),
5032
5309
  /* @__PURE__ */ jsx("path", { d: "M12 8v5", stroke: "#ef4444", strokeWidth: "1.5", strokeLinecap: "round" }),
@@ -5038,7 +5315,7 @@ var PaymentErrorBoundary = class extends Component {
5038
5315
  ] });
5039
5316
  }
5040
5317
  };
5041
- var containerStyle8 = {
5318
+ var containerStyle7 = {
5042
5319
  display: "flex",
5043
5320
  flexDirection: "column",
5044
5321
  alignItems: "center",
@@ -5118,6 +5395,7 @@ function SwypePaymentInner({
5118
5395
  );
5119
5396
  const loadingDataRef = useRef(false);
5120
5397
  const pollingTransferIdRef = useRef(null);
5398
+ const setupAccountIdRef = useRef(null);
5121
5399
  const mobileSetupFlowRef = useRef(false);
5122
5400
  const handlingMobileReturnRef = useRef(false);
5123
5401
  const processingStartedAtRef = useRef(null);
@@ -5438,6 +5716,15 @@ function SwypePaymentInner({
5438
5716
  amount: payAmount
5439
5717
  });
5440
5718
  dispatch({ type: "TRANSFER_CREATED", transfer: t });
5719
+ if (t.status === "COMPLETED") {
5720
+ dispatch({ type: "TRANSFER_COMPLETED", transfer: t });
5721
+ onComplete?.(t);
5722
+ return;
5723
+ }
5724
+ if (t.status === "FAILED") {
5725
+ dispatch({ type: "TRANSFER_FAILED", transfer: t, error: "Transfer failed." });
5726
+ return;
5727
+ }
5441
5728
  const signedTransfer = await transferSigning.signTransfer(t.id);
5442
5729
  dispatch({ type: "TRANSFER_SIGNED", transfer: signedTransfer });
5443
5730
  polling.startPolling(t.id);
@@ -5465,6 +5752,7 @@ function SwypePaymentInner({
5465
5752
  transferSigning,
5466
5753
  polling,
5467
5754
  onError,
5755
+ onComplete,
5468
5756
  idempotencyKey,
5469
5757
  merchantAuthorization
5470
5758
  ]);
@@ -5495,7 +5783,6 @@ function SwypePaymentInner({
5495
5783
  }
5496
5784
  }
5497
5785
  const t = await createTransfer(apiBaseUrl, token, {
5498
- id: idempotencyKey,
5499
5786
  credentialId: state.activeCredentialId,
5500
5787
  merchantAuthorization,
5501
5788
  sourceType: effectiveSourceType,
@@ -5522,7 +5809,6 @@ function SwypePaymentInner({
5522
5809
  getAccessToken,
5523
5810
  polling,
5524
5811
  onError,
5525
- idempotencyKey,
5526
5812
  merchantAuthorization,
5527
5813
  destination
5528
5814
  ]);
@@ -5567,7 +5853,9 @@ function SwypePaymentInner({
5567
5853
  try {
5568
5854
  const token = await getAccessToken();
5569
5855
  if (!token) throw new Error("Not authenticated");
5856
+ const accountId = crypto.randomUUID();
5570
5857
  const account = await createAccount(apiBaseUrl, token, {
5858
+ id: accountId,
5571
5859
  name: providerName,
5572
5860
  credentialId: state.activeCredentialId,
5573
5861
  providerId
@@ -5581,6 +5869,7 @@ function SwypePaymentInner({
5581
5869
  if (isMobile) {
5582
5870
  handlingMobileReturnRef.current = false;
5583
5871
  mobileSetupFlowRef.current = true;
5872
+ setupAccountIdRef.current = account.id;
5584
5873
  persistMobileFlowState({
5585
5874
  accountId: account.id,
5586
5875
  sessionId: session.id,
@@ -5616,10 +5905,23 @@ function SwypePaymentInner({
5616
5905
  const handleContinueConnection = useCallback(
5617
5906
  (accountId) => {
5618
5907
  const acct = state.accounts.find((a) => a.id === accountId);
5908
+ if (!acct) return;
5909
+ const matchedProvider = state.providers.find((p) => p.name === acct.name);
5910
+ if (matchedProvider) {
5911
+ handleSelectProvider(matchedProvider.id);
5912
+ }
5913
+ },
5914
+ [state.accounts, state.providers, handleSelectProvider]
5915
+ );
5916
+ const handleSelectAccount = useCallback(
5917
+ (accountId) => {
5918
+ const acct = state.accounts.find((a) => a.id === accountId);
5919
+ if (!acct) return;
5920
+ const activeWallet = acct.wallets.find((w) => w.status === "ACTIVE") ?? null;
5619
5921
  dispatch({
5620
5922
  type: "SELECT_ACCOUNT",
5621
5923
  accountId,
5622
- walletId: acct?.wallets[0]?.id ?? null
5924
+ walletId: activeWallet?.id ?? null
5623
5925
  });
5624
5926
  },
5625
5927
  [state.accounts]
@@ -5992,6 +6294,46 @@ function SwypePaymentInner({
5992
6294
  if (!polledTransfer || polledTransfer.status !== "AUTHORIZED") return;
5993
6295
  void handleAuthorizedMobileReturn(polledTransfer, mobileSetupFlowRef.current);
5994
6296
  }, [state.mobileFlow, polling.transfer, handleAuthorizedMobileReturn]);
6297
+ useEffect(() => {
6298
+ if (!state.mobileFlow || !mobileSetupFlowRef.current) return;
6299
+ if (state.step !== "open-wallet") return;
6300
+ if (!state.activeCredentialId || !setupAccountIdRef.current) return;
6301
+ const accountId = setupAccountIdRef.current;
6302
+ const credentialId = state.activeCredentialId;
6303
+ let cancelled = false;
6304
+ const POLL_INTERVAL_MS = 3e3;
6305
+ const poll = async () => {
6306
+ try {
6307
+ const token = await getAccessTokenRef.current();
6308
+ if (!token || cancelled) return;
6309
+ const acct = await fetchAccount(apiBaseUrl, token, accountId, credentialId);
6310
+ if (cancelled) return;
6311
+ const hasActive = acct.wallets.some((w) => w.status === "ACTIVE");
6312
+ if (hasActive) {
6313
+ cancelled = true;
6314
+ mobileSetupFlowRef.current = false;
6315
+ setupAccountIdRef.current = null;
6316
+ clearMobileFlowState();
6317
+ await reloadAccounts();
6318
+ dispatch({ type: "MOBILE_SETUP_COMPLETE" });
6319
+ }
6320
+ } catch {
6321
+ }
6322
+ };
6323
+ poll();
6324
+ const intervalId = window.setInterval(poll, POLL_INTERVAL_MS);
6325
+ const handleVisibility = () => {
6326
+ if (document.visibilityState === "visible" && !cancelled) {
6327
+ poll();
6328
+ }
6329
+ };
6330
+ document.addEventListener("visibilitychange", handleVisibility);
6331
+ return () => {
6332
+ cancelled = true;
6333
+ window.clearInterval(intervalId);
6334
+ document.removeEventListener("visibilitychange", handleVisibility);
6335
+ };
6336
+ }, [state.mobileFlow, state.step, state.activeCredentialId, apiBaseUrl, reloadAccounts]);
5995
6337
  useEffect(() => {
5996
6338
  if (!state.mobileFlow) return;
5997
6339
  if (handlingMobileReturnRef.current) return;
@@ -6051,6 +6393,7 @@ function SwypePaymentInner({
6051
6393
  onVerifyPasskeyViaPopup: handleVerifyPasskeyViaPopup,
6052
6394
  onSelectProvider: handleSelectProvider,
6053
6395
  onContinueConnection: handleContinueConnection,
6396
+ onSelectAccount: handleSelectAccount,
6054
6397
  onPay: handlePay,
6055
6398
  onIncreaseLimit: handleIncreaseLimit,
6056
6399
  onConfirmSign: handleConfirmSign,
@@ -6075,6 +6418,7 @@ function SwypePaymentInner({
6075
6418
  handleVerifyPasskeyViaPopup,
6076
6419
  handleSelectProvider,
6077
6420
  handleContinueConnection,
6421
+ handleSelectAccount,
6078
6422
  handlePay,
6079
6423
  handleIncreaseLimit,
6080
6424
  handleConfirmSign,