@swype-org/react-sdk 0.1.189 → 0.1.190

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
@@ -3856,6 +3856,22 @@ function DepositScreen({
3856
3856
  }) {
3857
3857
  const { tokens } = useSwypeConfig();
3858
3858
  const amount = initialAmount;
3859
+ const [accountPickerOpen, setAccountPickerOpen] = useState(false);
3860
+ const pickerRef = useRef(null);
3861
+ useEffect(() => {
3862
+ if (!accountPickerOpen) return;
3863
+ const handleClick = (e) => {
3864
+ if (pickerRef.current && !pickerRef.current.contains(e.target)) {
3865
+ setAccountPickerOpen(false);
3866
+ }
3867
+ };
3868
+ document.addEventListener("mousedown", handleClick);
3869
+ return () => document.removeEventListener("mousedown", handleClick);
3870
+ }, [accountPickerOpen]);
3871
+ const selectedAccount = accounts?.find((a) => a.id === selectedAccountId);
3872
+ const selectedProviderName = selectedAccount?.name ?? "Wallet";
3873
+ const selectedProviderLogo = KNOWN_LOGOS[selectedProviderName.toLowerCase()];
3874
+ const hasMultipleAccounts = accounts != null && accounts.length > 1;
3859
3875
  const isLowBalance = availableBalance < MIN_DEPOSIT;
3860
3876
  const exceedsLimit = remainingLimit != null && amount > remainingLimit && !isLowBalance;
3861
3877
  const canDeposit = amount >= MIN_DEPOSIT && !exceedsLimit && !isLowBalance && !processing;
@@ -3921,94 +3937,116 @@ function DepositScreen({
3921
3937
  ] }),
3922
3938
  children: [
3923
3939
  /* @__PURE__ */ jsx(ScreenHeader, { onBack }),
3924
- /* @__PURE__ */ jsxs("div", { style: depositCardStyle(tokens), children: [
3925
- /* @__PURE__ */ jsx("div", { style: depositLabelStyle(tokens.textMuted), children: "Depositing" }),
3926
- /* @__PURE__ */ jsxs("div", { style: amountRowStyle2, children: [
3927
- /* @__PURE__ */ jsxs("div", { style: amountValueStyle(tokens.text), children: [
3928
- "$",
3929
- amount.toLocaleString("en-US", { minimumFractionDigits: 0, maximumFractionDigits: 2 })
3940
+ /* @__PURE__ */ jsxs("div", { ref: pickerRef, style: depositCardWrapStyle, children: [
3941
+ /* @__PURE__ */ jsxs("div", { style: depositCardStyle(tokens), children: [
3942
+ /* @__PURE__ */ jsx("div", { style: depositLabelStyle(tokens.textMuted), children: "Depositing" }),
3943
+ /* @__PURE__ */ jsxs("div", { style: amountRowStyle2, children: [
3944
+ /* @__PURE__ */ jsxs("div", { style: amountValueStyle(tokens.text), children: [
3945
+ "$",
3946
+ amount.toLocaleString("en-US", { minimumFractionDigits: 0, maximumFractionDigits: 2 })
3947
+ ] }),
3948
+ /* @__PURE__ */ jsxs(
3949
+ "button",
3950
+ {
3951
+ type: "button",
3952
+ onClick: onSelectToken,
3953
+ style: tokenIconButtonStyle2(!!onSelectToken),
3954
+ children: [
3955
+ /* @__PURE__ */ jsxs("div", { style: tokenIconWrapStyle2, children: [
3956
+ /* @__PURE__ */ jsxs("svg", { width: "36", height: "36", viewBox: "0 0 36 36", fill: "none", children: [
3957
+ /* @__PURE__ */ jsx("circle", { cx: "18", cy: "18", r: "18", fill: "#2DB84B" }),
3958
+ /* @__PURE__ */ jsx("text", { x: "18", y: "23", textAnchor: "middle", fontSize: "18", fill: "#fff", fontWeight: "700", children: "$" })
3959
+ ] }),
3960
+ /* @__PURE__ */ jsxs("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", style: checkBadgeStyle2, children: [
3961
+ /* @__PURE__ */ jsx("circle", { cx: "8", cy: "8", r: "8", fill: "#2775CA" }),
3962
+ /* @__PURE__ */ jsx("path", { d: "M5 8l2 2 4-4", stroke: "#fff", strokeWidth: "1.6", strokeLinecap: "round", strokeLinejoin: "round" })
3963
+ ] })
3964
+ ] }),
3965
+ /* @__PURE__ */ jsx("svg", { width: "12", height: "12", viewBox: "0 0 24 24", fill: "none", style: { opacity: 0.5 }, children: /* @__PURE__ */ jsx("path", { d: "M6 9l6 6 6-6", stroke: tokens.textMuted, strokeWidth: "2.5", strokeLinecap: "round", strokeLinejoin: "round" }) })
3966
+ ]
3967
+ }
3968
+ )
3930
3969
  ] }),
3931
3970
  /* @__PURE__ */ jsxs(
3932
3971
  "button",
3933
3972
  {
3934
3973
  type: "button",
3935
- onClick: onSelectToken,
3936
- style: tokenIconButtonStyle2(!!onSelectToken),
3974
+ onClick: hasMultipleAccounts ? () => setAccountPickerOpen(!accountPickerOpen) : void 0,
3975
+ style: walletBalanceRowStyle(hasMultipleAccounts),
3937
3976
  children: [
3938
- /* @__PURE__ */ jsxs("div", { style: tokenIconWrapStyle2, children: [
3939
- /* @__PURE__ */ jsxs("svg", { width: "36", height: "36", viewBox: "0 0 36 36", fill: "none", children: [
3940
- /* @__PURE__ */ jsx("circle", { cx: "18", cy: "18", r: "18", fill: "#2DB84B" }),
3941
- /* @__PURE__ */ jsx("text", { x: "18", y: "23", textAnchor: "middle", fontSize: "18", fill: "#fff", fontWeight: "700", children: "$" })
3942
- ] }),
3943
- /* @__PURE__ */ jsxs("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", style: checkBadgeStyle2, children: [
3944
- /* @__PURE__ */ jsx("circle", { cx: "8", cy: "8", r: "8", fill: "#2775CA" }),
3945
- /* @__PURE__ */ jsx("path", { d: "M5 8l2 2 4-4", stroke: "#fff", strokeWidth: "1.6", strokeLinecap: "round", strokeLinejoin: "round" })
3946
- ] })
3977
+ selectedProviderLogo ? /* @__PURE__ */ jsx("img", { src: selectedProviderLogo, alt: selectedProviderName, style: providerLogoStyle }) : /* @__PURE__ */ jsx("div", { style: providerFallbackStyle(tokens.textMuted), children: selectedProviderName.charAt(0) }),
3978
+ /* @__PURE__ */ jsxs("span", { style: walletBalanceStyle(tokens.text), children: [
3979
+ "$",
3980
+ availableBalance.toLocaleString("en-US", { minimumFractionDigits: 2, maximumFractionDigits: 2 })
3947
3981
  ] }),
3948
- /* @__PURE__ */ jsx("svg", { width: "12", height: "12", viewBox: "0 0 24 24", fill: "none", style: { opacity: 0.5 }, children: /* @__PURE__ */ jsx("path", { d: "M6 9l6 6 6-6", stroke: tokens.textMuted, strokeWidth: "2.5", strokeLinecap: "round", strokeLinejoin: "round" }) })
3982
+ hasMultipleAccounts && /* @__PURE__ */ jsx("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", style: { opacity: 0.4 }, children: /* @__PURE__ */ jsx("path", { d: "M7 10l5-5 5 5M7 14l5 5 5-5", stroke: tokens.textMuted, strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }) })
3949
3983
  ]
3950
3984
  }
3951
3985
  )
3952
- ] })
3953
- ] }),
3954
- accounts && accounts.length > 0 && /* @__PURE__ */ jsxs("div", { style: accountSectionStyle, children: [
3955
- /* @__PURE__ */ jsx("div", { style: accountSectionLabelStyle(tokens.textMuted), children: "Choose account" }),
3956
- /* @__PURE__ */ jsxs("div", { style: accountListStyle(tokens), children: [
3957
- accounts.map((account) => {
3958
- const preferredWallet = getPreferredDepositWallet(account, amount);
3959
- const active = hasActiveDepositWallet(account);
3960
- const isSelected = account.id === selectedAccountId;
3961
- const walletAddress = preferredWallet ? getWalletAddress(preferredWallet) : null;
3962
- const truncatedAddress = walletAddress ? `${walletAddress.slice(0, 6)}...${walletAddress.slice(-4)}` : null;
3963
- const accountBalance = account.wallets.reduce(
3964
- (sum, w) => sum + w.balance.available.amount,
3965
- 0
3966
- );
3967
- const providerLogo = KNOWN_LOGOS[account.name.toLowerCase()];
3968
- return /* @__PURE__ */ jsxs(
3986
+ ] }),
3987
+ accountPickerOpen && accounts && accounts.length > 0 && /* @__PURE__ */ jsxs("div", { style: accountDropdownOuterStyle(tokens), children: [
3988
+ /* @__PURE__ */ jsx("div", { style: accountDropdownLabelStyle(tokens.textMuted), children: "Choose account" }),
3989
+ /* @__PURE__ */ jsxs("div", { style: accountDropdownInnerStyle(tokens), children: [
3990
+ accounts.map((account) => {
3991
+ const preferredWallet = getPreferredDepositWallet(account, amount);
3992
+ const active = hasActiveDepositWallet(account);
3993
+ const isSelected = account.id === selectedAccountId;
3994
+ const walletAddress = preferredWallet ? getWalletAddress(preferredWallet) : null;
3995
+ const truncatedAddress = walletAddress ? `${walletAddress.slice(0, 6)}...${walletAddress.slice(-4)}` : null;
3996
+ const accountBalance = account.wallets.reduce(
3997
+ (sum, w) => sum + w.balance.available.amount,
3998
+ 0
3999
+ );
4000
+ const providerLogo = KNOWN_LOGOS[account.name.toLowerCase()];
4001
+ return /* @__PURE__ */ jsxs(
4002
+ "button",
4003
+ {
4004
+ type: "button",
4005
+ onClick: () => {
4006
+ if (active) {
4007
+ onSelectAccount?.(account.id);
4008
+ } else {
4009
+ onAuthorizeAccount?.(account.id);
4010
+ }
4011
+ setAccountPickerOpen(false);
4012
+ },
4013
+ style: accountRowStyle(tokens, isSelected),
4014
+ children: [
4015
+ /* @__PURE__ */ jsxs("div", { style: accountRowLeftStyle, children: [
4016
+ providerLogo ? /* @__PURE__ */ jsx("img", { src: providerLogo, alt: account.name, style: accountLogoStyle }) : /* @__PURE__ */ jsx("div", { style: accountFallbackIconStyle(tokens.textMuted), children: account.name.charAt(0) }),
4017
+ /* @__PURE__ */ jsxs("div", { style: accountInfoStyle, children: [
4018
+ /* @__PURE__ */ jsx("span", { style: accountAddressStyle(tokens.text), children: truncatedAddress ?? account.nickname ?? account.name }),
4019
+ /* @__PURE__ */ jsxs("span", { style: accountBalanceTextStyle(tokens.textMuted), children: [
4020
+ "$",
4021
+ accountBalance.toLocaleString("en-US", { minimumFractionDigits: 2, maximumFractionDigits: 2 })
4022
+ ] })
4023
+ ] })
4024
+ ] }),
4025
+ isSelected ? /* @__PURE__ */ jsxs("svg", { width: "22", height: "22", viewBox: "0 0 22 22", fill: "none", children: [
4026
+ /* @__PURE__ */ jsx("circle", { cx: "11", cy: "11", r: "11", fill: tokens.success }),
4027
+ /* @__PURE__ */ jsx("path", { d: "M7 11l3 3 5-5", stroke: "#fff", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" })
4028
+ ] }) : /* @__PURE__ */ jsx("div", { style: radioEmptyStyle(tokens.border) })
4029
+ ]
4030
+ },
4031
+ account.id
4032
+ );
4033
+ }),
4034
+ onAddProvider && /* @__PURE__ */ jsxs(
3969
4035
  "button",
3970
4036
  {
3971
4037
  type: "button",
3972
4038
  onClick: () => {
3973
- if (active) {
3974
- onSelectAccount?.(account.id);
3975
- } else {
3976
- onAuthorizeAccount?.(account.id);
3977
- }
4039
+ onAddProvider();
4040
+ setAccountPickerOpen(false);
3978
4041
  },
3979
- style: accountRowStyle(tokens),
4042
+ style: addAccountBtnStyle(tokens),
3980
4043
  children: [
3981
- /* @__PURE__ */ jsxs("div", { style: accountRowLeftStyle, children: [
3982
- providerLogo ? /* @__PURE__ */ jsx("img", { src: providerLogo, alt: account.name, style: accountLogoStyle }) : /* @__PURE__ */ jsx("div", { style: accountFallbackIconStyle(tokens.textMuted), children: account.name.charAt(0) }),
3983
- /* @__PURE__ */ jsxs("div", { style: accountInfoStyle, children: [
3984
- /* @__PURE__ */ jsx("span", { style: accountAddressStyle(tokens.text), children: truncatedAddress ?? account.nickname ?? account.name }),
3985
- /* @__PURE__ */ jsxs("span", { style: accountBalanceTextStyle(tokens.textMuted), children: [
3986
- "$",
3987
- accountBalance.toLocaleString("en-US", { minimumFractionDigits: 2, maximumFractionDigits: 2 })
3988
- ] })
3989
- ] })
3990
- ] }),
3991
- isSelected ? /* @__PURE__ */ jsxs("svg", { width: "22", height: "22", viewBox: "0 0 22 22", fill: "none", children: [
3992
- /* @__PURE__ */ jsx("circle", { cx: "11", cy: "11", r: "11", fill: tokens.success }),
3993
- /* @__PURE__ */ jsx("path", { d: "M7 11l3 3 5-5", stroke: "#fff", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" })
3994
- ] }) : /* @__PURE__ */ jsx("div", { style: radioEmptyStyle(tokens.border) })
4044
+ /* @__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" }) }),
4045
+ "Add Account"
3995
4046
  ]
3996
- },
3997
- account.id
3998
- );
3999
- }),
4000
- onAddProvider && /* @__PURE__ */ jsxs(
4001
- "button",
4002
- {
4003
- type: "button",
4004
- onClick: onAddProvider,
4005
- style: addAccountBtnStyle(tokens),
4006
- children: [
4007
- /* @__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" }) }),
4008
- "Add Account"
4009
- ]
4010
- }
4011
- )
4047
+ }
4048
+ )
4049
+ ] })
4012
4050
  ] })
4013
4051
  ] }),
4014
4052
  remainingLimit != null && /* @__PURE__ */ jsxs("div", { style: spendingLimitStyle(tokens.textMuted), children: [
@@ -4024,12 +4062,15 @@ function DepositScreen({
4024
4062
  }
4025
4063
  );
4026
4064
  }
4065
+ var depositCardWrapStyle = {
4066
+ position: "relative",
4067
+ marginBottom: 20
4068
+ };
4027
4069
  var depositCardStyle = (tokens) => ({
4028
4070
  background: tokens.bgInput,
4029
4071
  border: `1px solid ${tokens.border}`,
4030
4072
  borderRadius: tokens.radiusLg,
4031
- padding: "16px 20px",
4032
- marginBottom: 20
4073
+ padding: "16px 20px"
4033
4074
  });
4034
4075
  var depositLabelStyle = (color) => ({
4035
4076
  fontSize: "0.75rem",
@@ -4069,16 +4110,60 @@ var checkBadgeStyle2 = {
4069
4110
  bottom: -1,
4070
4111
  right: -3
4071
4112
  };
4072
- var accountSectionStyle = {
4073
- marginBottom: 20
4113
+ var walletBalanceRowStyle = (clickable) => ({
4114
+ display: "flex",
4115
+ alignItems: "center",
4116
+ gap: 8,
4117
+ background: "transparent",
4118
+ border: "none",
4119
+ padding: 0,
4120
+ cursor: clickable ? "pointer" : "default",
4121
+ fontFamily: "inherit",
4122
+ outline: "none"
4123
+ });
4124
+ var providerLogoStyle = {
4125
+ width: 18,
4126
+ height: 18,
4127
+ borderRadius: "50%",
4128
+ objectFit: "contain"
4074
4129
  };
4075
- var accountSectionLabelStyle = (color) => ({
4130
+ var providerFallbackStyle = (color) => ({
4131
+ width: 18,
4132
+ height: 18,
4133
+ borderRadius: "50%",
4134
+ display: "flex",
4135
+ alignItems: "center",
4136
+ justifyContent: "center",
4137
+ fontSize: "0.65rem",
4138
+ fontWeight: 700,
4139
+ color,
4140
+ flexShrink: 0
4141
+ });
4142
+ var walletBalanceStyle = (color) => ({
4143
+ fontSize: "0.9rem",
4144
+ fontWeight: 600,
4145
+ color
4146
+ });
4147
+ var accountDropdownOuterStyle = (tokens) => ({
4148
+ position: "absolute",
4149
+ top: "100%",
4150
+ left: 0,
4151
+ right: 0,
4152
+ marginTop: 4,
4153
+ background: tokens.bgCard,
4154
+ border: `1px solid ${tokens.border}`,
4155
+ borderRadius: tokens.radiusLg,
4156
+ boxShadow: tokens.shadowLg,
4157
+ zIndex: 50,
4158
+ padding: "12px 14px 14px"
4159
+ });
4160
+ var accountDropdownLabelStyle = (color) => ({
4076
4161
  fontSize: "0.78rem",
4077
4162
  fontWeight: 500,
4078
4163
  color,
4079
4164
  marginBottom: 8
4080
4165
  });
4081
- var accountListStyle = (tokens) => ({
4166
+ var accountDropdownInnerStyle = (tokens) => ({
4082
4167
  background: tokens.bgInput,
4083
4168
  border: `1px solid ${tokens.border}`,
4084
4169
  borderRadius: tokens.radiusLg,
@@ -4090,7 +4175,7 @@ var accountRowStyle = (tokens, isSelected) => ({
4090
4175
  justifyContent: "space-between",
4091
4176
  width: "100%",
4092
4177
  padding: "14px 16px",
4093
- background: "transparent",
4178
+ background: isSelected ? `${tokens.accent}10` : "transparent",
4094
4179
  border: "none",
4095
4180
  borderBottom: `1px solid ${tokens.border}`,
4096
4181
  cursor: "pointer",