@swype-org/react-sdk 0.1.102 → 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
@@ -2552,36 +2552,160 @@ var KNOWN_LOGOS = {
2552
2552
  base: BASE_LOGO,
2553
2553
  "trust wallet": TRUST_WALLET_LOGO
2554
2554
  };
2555
- 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
+ }) {
2556
2568
  const { tokens } = useSwypeConfig();
2557
- return /* @__PURE__ */ jsxs("div", { style: containerStyle6(tokens), children: [
2558
- /* @__PURE__ */ jsxs("div", { style: leftStyle, children: [
2559
- KNOWN_LOGOS[name.toLowerCase()] ? /* @__PURE__ */ jsx(
2560
- "img",
2561
- {
2562
- src: KNOWN_LOGOS[name.toLowerCase()],
2563
- alt: name,
2564
- style: logoImgStyle
2565
- }
2566
- ) : /* @__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(
2567
- "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",
2568
2609
  {
2569
- 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",
2570
- 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
+ ]
2571
2640
  }
2572
- ) }) }),
2573
- /* @__PURE__ */ jsxs("div", { children: [
2574
- /* @__PURE__ */ jsxs("div", { style: nameRowStyle, children: [
2575
- /* @__PURE__ */ jsx("span", { style: nameStyle(tokens.text), children: name }),
2576
- 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 }) })
2577
- ] }),
2578
- address && /* @__PURE__ */ jsx("span", { style: addressStyle(tokens.textMuted), children: address })
2579
- ] })
2641
+ )
2580
2642
  ] }),
2581
- 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
+ ] })
2582
2706
  ] });
2583
2707
  }
2584
- var containerStyle6 = (tokens) => ({
2708
+ var cardContainerStyle = (tokens) => ({
2585
2709
  display: "flex",
2586
2710
  alignItems: "center",
2587
2711
  justifyContent: "space-between",
@@ -2622,6 +2746,8 @@ var addressStyle = (color) => ({
2622
2746
  fontFamily: '"SF Mono", "Fira Code", monospace'
2623
2747
  });
2624
2748
  var changeStyle = (color) => ({
2749
+ display: "flex",
2750
+ alignItems: "center",
2625
2751
  background: "transparent",
2626
2752
  border: "none",
2627
2753
  color,
@@ -2631,6 +2757,117 @@ var changeStyle = (color) => ({
2631
2757
  fontFamily: "inherit",
2632
2758
  padding: 0
2633
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
+ });
2634
2871
  function StepList({ steps }) {
2635
2872
  const { tokens } = useSwypeConfig();
2636
2873
  return /* @__PURE__ */ jsx("div", { style: listStyle, children: steps.map((step, i) => {
@@ -2708,13 +2945,13 @@ function SettingsMenu({ onLogout }) {
2708
2945
  document.addEventListener("mousedown", handleClickOutside);
2709
2946
  return () => document.removeEventListener("mousedown", handleClickOutside);
2710
2947
  }, [open]);
2711
- return /* @__PURE__ */ jsxs("div", { ref: menuRef, style: containerStyle7, children: [
2948
+ return /* @__PURE__ */ jsxs("div", { ref: menuRef, style: containerStyle6, children: [
2712
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: [
2713
2950
  /* @__PURE__ */ jsx("circle", { cx: "12", cy: "5", r: "2", fill: "currentColor" }),
2714
2951
  /* @__PURE__ */ jsx("circle", { cx: "12", cy: "12", r: "2", fill: "currentColor" }),
2715
2952
  /* @__PURE__ */ jsx("circle", { cx: "12", cy: "19", r: "2", fill: "currentColor" })
2716
2953
  ] }) }),
2717
- open && /* @__PURE__ */ jsx("div", { style: dropdownStyle(tokens), children: /* @__PURE__ */ jsxs(
2954
+ open && /* @__PURE__ */ jsx("div", { style: dropdownStyle2(tokens), children: /* @__PURE__ */ jsxs(
2718
2955
  "button",
2719
2956
  {
2720
2957
  type: "button",
@@ -2735,7 +2972,7 @@ function SettingsMenu({ onLogout }) {
2735
2972
  ) })
2736
2973
  ] });
2737
2974
  }
2738
- var containerStyle7 = {
2975
+ var containerStyle6 = {
2739
2976
  position: "relative"
2740
2977
  };
2741
2978
  var triggerStyle = (color) => ({
@@ -2748,7 +2985,7 @@ var triggerStyle = (color) => ({
2748
2985
  alignItems: "center",
2749
2986
  justifyContent: "center"
2750
2987
  });
2751
- var dropdownStyle = (tokens) => ({
2988
+ var dropdownStyle2 = (tokens) => ({
2752
2989
  position: "absolute",
2753
2990
  right: 0,
2754
2991
  top: "100%",
@@ -3710,12 +3947,16 @@ function DepositScreen({
3710
3947
  processing,
3711
3948
  error,
3712
3949
  onDeposit,
3713
- onChangeSource,
3714
3950
  onSwitchWallet,
3715
3951
  onBack,
3716
3952
  onLogout,
3717
3953
  onIncreaseLimit,
3718
- increasingLimit
3954
+ increasingLimit,
3955
+ accounts,
3956
+ selectedAccountId,
3957
+ onSelectAccount,
3958
+ onAuthorizeAccount,
3959
+ onAddProvider
3719
3960
  }) {
3720
3961
  const { tokens } = useSwypeConfig();
3721
3962
  const amount = initialAmount;
@@ -3741,7 +3982,11 @@ function DepositScreen({
3741
3982
  name: sourceName,
3742
3983
  address: sourceAddress,
3743
3984
  verified: sourceVerified,
3744
- onChangeSource
3985
+ accounts,
3986
+ selectedAccountId,
3987
+ onSelectAccount,
3988
+ onAuthorizeAccount,
3989
+ onAddProvider
3745
3990
  }
3746
3991
  ),
3747
3992
  /* @__PURE__ */ jsx("div", { style: amountDisplayStyle, children: /* @__PURE__ */ jsxs("span", { style: amountStyle({ ...tokens, dimmed: true }), children: [
@@ -3811,7 +4056,11 @@ function DepositScreen({
3811
4056
  name: sourceName,
3812
4057
  address: sourceAddress,
3813
4058
  verified: sourceVerified,
3814
- onChangeSource
4059
+ accounts,
4060
+ selectedAccountId,
4061
+ onSelectAccount,
4062
+ onAuthorizeAccount,
4063
+ onAddProvider
3815
4064
  }
3816
4065
  ),
3817
4066
  /* @__PURE__ */ jsx("div", { style: amountDisplayStyle, children: /* @__PURE__ */ jsxs("span", { style: amountStyle(tokens), children: [
@@ -4944,12 +5193,16 @@ function StepRenderer({
4944
5193
  processing: state.creatingTransfer,
4945
5194
  error: state.error,
4946
5195
  onDeposit: handlers.onPay,
4947
- onChangeSource: () => handlers.onNavigate("wallet-picker"),
4948
5196
  onSwitchWallet: () => handlers.onNavigate("wallet-picker"),
4949
5197
  onBack: onBack ?? (() => handlers.onLogout()),
4950
5198
  onLogout: handlers.onLogout,
4951
5199
  onIncreaseLimit: handlers.onIncreaseLimit,
4952
- 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")
4953
5206
  }
4954
5207
  );
4955
5208
  }
@@ -5018,10 +5271,14 @@ function StepRenderer({
5018
5271
  processing: false,
5019
5272
  error: state.error,
5020
5273
  onDeposit: handlers.onPay,
5021
- onChangeSource: () => handlers.onNavigate("wallet-picker"),
5022
5274
  onSwitchWallet: () => handlers.onNavigate("wallet-picker"),
5023
5275
  onBack: onBack ?? (() => handlers.onLogout()),
5024
- 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")
5025
5282
  }
5026
5283
  );
5027
5284
  }
@@ -5046,7 +5303,7 @@ var PaymentErrorBoundary = class extends Component {
5046
5303
  if (!this.state.hasError) {
5047
5304
  return this.props.children;
5048
5305
  }
5049
- return /* @__PURE__ */ jsxs("div", { style: containerStyle8, children: [
5306
+ return /* @__PURE__ */ jsxs("div", { style: containerStyle7, children: [
5050
5307
  /* @__PURE__ */ jsx("div", { style: iconStyle4, children: /* @__PURE__ */ jsxs("svg", { width: "48", height: "48", viewBox: "0 0 24 24", fill: "none", children: [
5051
5308
  /* @__PURE__ */ jsx("circle", { cx: "12", cy: "12", r: "10", stroke: "#ef4444", strokeWidth: "1.5" }),
5052
5309
  /* @__PURE__ */ jsx("path", { d: "M12 8v5", stroke: "#ef4444", strokeWidth: "1.5", strokeLinecap: "round" }),
@@ -5058,7 +5315,7 @@ var PaymentErrorBoundary = class extends Component {
5058
5315
  ] });
5059
5316
  }
5060
5317
  };
5061
- var containerStyle8 = {
5318
+ var containerStyle7 = {
5062
5319
  display: "flex",
5063
5320
  flexDirection: "column",
5064
5321
  alignItems: "center",
@@ -5656,6 +5913,19 @@ function SwypePaymentInner({
5656
5913
  },
5657
5914
  [state.accounts, state.providers, handleSelectProvider]
5658
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;
5921
+ dispatch({
5922
+ type: "SELECT_ACCOUNT",
5923
+ accountId,
5924
+ walletId: activeWallet?.id ?? null
5925
+ });
5926
+ },
5927
+ [state.accounts]
5928
+ );
5659
5929
  const handleNewPayment = useCallback(() => {
5660
5930
  clearMobileFlowState();
5661
5931
  processingStartedAtRef.current = null;
@@ -6123,6 +6393,7 @@ function SwypePaymentInner({
6123
6393
  onVerifyPasskeyViaPopup: handleVerifyPasskeyViaPopup,
6124
6394
  onSelectProvider: handleSelectProvider,
6125
6395
  onContinueConnection: handleContinueConnection,
6396
+ onSelectAccount: handleSelectAccount,
6126
6397
  onPay: handlePay,
6127
6398
  onIncreaseLimit: handleIncreaseLimit,
6128
6399
  onConfirmSign: handleConfirmSign,
@@ -6147,6 +6418,7 @@ function SwypePaymentInner({
6147
6418
  handleVerifyPasskeyViaPopup,
6148
6419
  handleSelectProvider,
6149
6420
  handleContinueConnection,
6421
+ handleSelectAccount,
6150
6422
  handlePay,
6151
6423
  handleIncreaseLimit,
6152
6424
  handleConfirmSign,