@getpara/react-sdk-lite 2.8.0 → 2.10.0

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.
Files changed (48) hide show
  1. package/dist/modal/ParaModal.js +1 -1
  2. package/dist/modal/components/Account/Account.js +17 -7
  3. package/dist/modal/components/Account/AccountProfile.js +30 -9
  4. package/dist/modal/components/Account/AccountSend/AccountSendForm.js +7 -1
  5. package/dist/modal/components/Account/AccountWallet.js +2 -0
  6. package/dist/modal/components/AddFunds/AddFunds.js +1 -4
  7. package/dist/modal/components/AddFunds/AddFundsAsset.js +25 -88
  8. package/dist/modal/components/AddFunds/AddFundsContext.d.ts +8 -2
  9. package/dist/modal/components/AddFunds/AddFundsContext.js +116 -22
  10. package/dist/modal/components/AddFunds/AddFundsNetwork.d.ts +1 -0
  11. package/dist/modal/components/AddFunds/AddFundsNetwork.js +31 -0
  12. package/dist/modal/components/AddFunds/AddFundsProvider.js +50 -65
  13. package/dist/modal/components/AddFunds/AddFundsReceive.js +4 -1
  14. package/dist/modal/components/AddFunds/AddFundsSettings.js +126 -143
  15. package/dist/modal/components/AuthInput/AuthInput.js +12 -1
  16. package/dist/modal/components/AuthMainStep/AuthMainStepContent.js +32 -11
  17. package/dist/modal/components/BiometricCreationStep/BiometricCreationStep.js +17 -8
  18. package/dist/modal/components/BiometricLoginStep/BiometricLoginStep.js +25 -9
  19. package/dist/modal/components/Body/Body.js +3 -51
  20. package/dist/modal/components/ExternalWalletStep/ExternalWalletStep.js +25 -8
  21. package/dist/modal/components/ExternalWallets/ExternalWallets.js +33 -13
  22. package/dist/modal/components/IFrameStep/IFrameStep.js +1 -1
  23. package/dist/modal/components/OAuth/OAuth.js +5 -3
  24. package/dist/modal/components/OnRampComponents/OnRampProviderButton.js +15 -24
  25. package/dist/modal/components/QuantityInput.js +62 -9
  26. package/dist/modal/components/RecoverySecretStep/RecoverySecretStep.js +4 -4
  27. package/dist/modal/components/SearchableButtonList.d.ts +2 -1
  28. package/dist/modal/components/SearchableButtonList.js +3 -1
  29. package/dist/modal/components/Setup2FAStep/Setup2FAStep.js +6 -5
  30. package/dist/modal/components/VerificationCodeStep/VerificationCodeStep.js +4 -2
  31. package/dist/modal/components/WalletCreationDoneStep/WalletCreationDoneStep.js +2 -2
  32. package/dist/modal/components/common.d.ts +1 -1
  33. package/dist/modal/stores/modal/actions.js +2 -1
  34. package/dist/modal/stores/modal/useModalStore.d.ts +2 -0
  35. package/dist/modal/stores/modal/useModalStore.js +2 -1
  36. package/dist/modal/types/modalProps.d.ts +3 -1
  37. package/dist/modal/utils/validatePortalOrigin.js +6 -0
  38. package/dist/provider/ParaProviderMin.js +3 -0
  39. package/dist/provider/hooks/queries/useProfileBalance.js +33 -6
  40. package/dist/provider/hooks/utils/index.d.ts +1 -0
  41. package/dist/provider/hooks/utils/index.js +2 -0
  42. package/dist/provider/hooks/utils/useSetBalanceOverrides.d.ts +34 -0
  43. package/dist/provider/hooks/utils/useSetBalanceOverrides.js +12 -0
  44. package/dist/provider/stores/slices/modal.js +11 -1
  45. package/dist/provider/stores/types.d.ts +8 -0
  46. package/package.json +8 -8
  47. package/dist/modal/components/AddFunds/common.d.ts +0 -5
  48. package/dist/modal/components/AddFunds/common.js +0 -17
@@ -110,7 +110,7 @@ const ParaModal = forwardRef((props, ref) => {
110
110
  onClose,
111
111
  defaultAuthIdentifier
112
112
  }), rest),
113
- reactSdkVersion: "2.8.0"
113
+ reactSdkVersion: "2.10.0"
114
114
  });
115
115
  } catch (e) {
116
116
  }
@@ -66,11 +66,11 @@ const Account = () => {
66
66
  useEffect(() => {
67
67
  setGuestAddFundsTab();
68
68
  }, []);
69
- return /* @__PURE__ */ jsx(StepContainer, { $wide: true, children: /* @__PURE__ */ jsxs($InnerStepContainer, { children: [
69
+ return /* @__PURE__ */ jsx(StepContainer, { $wide: true, "data-testid": "para-account-main", children: /* @__PURE__ */ jsxs($InnerStepContainer, { children: [
70
70
  /* @__PURE__ */ jsx(AccountHeader, { withBalance: true }),
71
71
  /* @__PURE__ */ jsxs(LowerContainer, { children: [
72
72
  isGuestMode && /* @__PURE__ */ jsxs(Fragment, { children: [
73
- profileBalance && profileBalance.value && profileBalance.value.value > 0 && /* @__PURE__ */ jsxs(Alert, { children: [
73
+ profileBalance && profileBalance.value && profileBalance.value.value > 0 && /* @__PURE__ */ jsxs(Alert, { "data-testid": "para-guest-warning", children: [
74
74
  /* @__PURE__ */ jsx(CpslIcon, { icon: "alertTriangle", size: "24px", style: { color: "var(--cpsl-color-utility-yellow)" } }),
75
75
  "You've funded this account - complete account setup to maintain access."
76
76
  ] }),
@@ -82,6 +82,7 @@ const Account = () => {
82
82
  onClick: () => {
83
83
  setStep(ModalStep.AUTH_GUEST_SIGNUP);
84
84
  },
85
+ "data-testid": "para-complete-setup",
85
86
  children: [
86
87
  /* @__PURE__ */ jsx(CpslIcon, { icon: "stars02" }),
87
88
  "Complete Account Setup"
@@ -89,15 +90,24 @@ const Account = () => {
89
90
  }
90
91
  )
91
92
  ] }),
92
- !!(sendTx == null ? void 0 : sendTx.explorerUrl) && /* @__PURE__ */ jsxs(MonitorLink, { target: "_blank", href: sendTx.explorerUrl, rel: "noopener noreferrer", children: [
93
+ !!(sendTx == null ? void 0 : sendTx.explorerUrl) && /* @__PURE__ */ jsxs(MonitorLink, { target: "_blank", href: sendTx.explorerUrl, rel: "noopener noreferrer", "data-testid": "para-monitor-tx", children: [
93
94
  /* @__PURE__ */ jsx("span", { children: "Monitor Transaction" }),
94
95
  /* @__PURE__ */ jsx(CpslIcon, { icon: "externalLink", size: "16px", style: { marginLeft: "6px" } })
95
96
  ] }),
96
97
  /* @__PURE__ */ jsx(ButtonContainer, { children: isOnRampLoaded ? /* @__PURE__ */ jsxs(Fragment, { children: [
97
- (onRampConfig.isBuyEnabled || onRampConfig.isReceiveEnabled) && !cantBuyAndWithdraw && /* @__PURE__ */ jsx(OptionButton, { icon: "plusCircle", onClick: handleBuyClick, children: /* @__PURE__ */ jsx(CpslText, { variant: "bodyXS", color: "secondary", weight: "medium", children: "Add Funds" }) }),
98
- embedded.authType !== "externalWallet" && /* @__PURE__ */ jsx(OptionButton, { icon: "send", onClick: handleSendClick, disabled: !profileBalance, children: /* @__PURE__ */ jsx(CpslText, { variant: "bodyXS", color: "secondary", weight: "medium", children: "Send" }) }),
99
- onRampConfig.isWithdrawEnabled && !cantBuyAndWithdraw && /* @__PURE__ */ jsx(OptionButton, { icon: "arrowCircleDown", onClick: handleSellClick, children: /* @__PURE__ */ jsx(CpslText, { variant: "bodyXS", color: "secondary", weight: "medium", children: "Withdraw" }) }),
100
- /* @__PURE__ */ jsx(OptionButton, { icon: "user01", onClick: handleProfileClick, children: /* @__PURE__ */ jsx(CpslText, { variant: "bodyXS", color: "secondary", weight: "medium", children: isEnabled ? "Profile" : "Settings" }) })
98
+ (onRampConfig.isBuyEnabled || onRampConfig.isReceiveEnabled) && !cantBuyAndWithdraw && /* @__PURE__ */ jsx(OptionButton, { icon: "plusCircle", onClick: handleBuyClick, "data-testid": "para-add-funds-tile", children: /* @__PURE__ */ jsx(CpslText, { variant: "bodyXS", color: "secondary", weight: "medium", children: "Add Funds" }) }),
99
+ embedded.authType !== "externalWallet" && /* @__PURE__ */ jsx(
100
+ OptionButton,
101
+ {
102
+ icon: "send",
103
+ onClick: handleSendClick,
104
+ disabled: !profileBalance,
105
+ "data-testid": "para-send-tile",
106
+ children: /* @__PURE__ */ jsx(CpslText, { variant: "bodyXS", color: "secondary", weight: "medium", children: "Send" })
107
+ }
108
+ ),
109
+ onRampConfig.isWithdrawEnabled && !cantBuyAndWithdraw && /* @__PURE__ */ jsx(OptionButton, { icon: "arrowCircleDown", onClick: handleSellClick, "data-testid": "para-withdraw-tile", children: /* @__PURE__ */ jsx(CpslText, { variant: "bodyXS", color: "secondary", weight: "medium", children: "Withdraw" }) }),
110
+ /* @__PURE__ */ jsx(OptionButton, { icon: "user01", onClick: handleProfileClick, "data-testid": "para-profile-tile", children: /* @__PURE__ */ jsx(CpslText, { variant: "bodyXS", color: "secondary", weight: "medium", children: isEnabled ? "Profile" : "Settings" }) })
101
111
  ] }) : /* @__PURE__ */ jsx(CpslSpinner, {}) })
102
112
  ] })
103
113
  ] }) });
@@ -66,10 +66,20 @@ const AccountProfile = ({
66
66
  /* @__PURE__ */ jsx(Content, { children: wallets.map((wallet) => /* @__PURE__ */ jsx(WalletEntry, { wallet, isSelectable: true }, `${wallet.address}-${wallet.type}`)) })
67
67
  ] }, partner.id);
68
68
  }),
69
- !embedded.isGuestMode && /* @__PURE__ */ jsx(CpslButton, { fullWidth: true, variant: "tertiary", onClick: switchWallets, disabled: isSwitchWalletsPending, children: isSwitchWalletsPending ? "Please Wait..." : /* @__PURE__ */ jsxs(Fragment, { children: [
70
- /* @__PURE__ */ jsx(CpslIcon, { icon: "shuffle", slot: "start", size: "16px" }),
71
- para.isMultiWallet ? "Switch Wallets" : "Switch Wallet"
72
- ] }) })
69
+ !embedded.isGuestMode && /* @__PURE__ */ jsx(
70
+ CpslButton,
71
+ {
72
+ fullWidth: true,
73
+ variant: "tertiary",
74
+ onClick: switchWallets,
75
+ disabled: isSwitchWalletsPending,
76
+ "data-testid": "para-switch-wallets",
77
+ children: isSwitchWalletsPending ? "Please Wait..." : /* @__PURE__ */ jsxs(Fragment, { children: [
78
+ /* @__PURE__ */ jsx(CpslIcon, { icon: "shuffle", slot: "start", size: "16px" }),
79
+ para.isMultiWallet ? "Switch Wallets" : "Switch Wallet"
80
+ ] })
81
+ }
82
+ )
73
83
  ] }),
74
84
  !embedded.isGuestMode && /* @__PURE__ */ jsxs(Section, { children: [
75
85
  /* @__PURE__ */ jsx(Title, { variant: "bodyS", color: "secondary", children: "Connected Wallets" }),
@@ -85,6 +95,7 @@ const AccountProfile = ({
85
95
  onClick: () => {
86
96
  setStep(ModalStep.ADD_EX_WALLET_MORE);
87
97
  },
98
+ "data-testid": "para-add-wallet",
88
99
  children: [
89
100
  /* @__PURE__ */ jsx(CpslIcon, { icon: "plus", slot: "start" }),
90
101
  "Add Wallet"
@@ -108,16 +119,26 @@ const AccountProfile = ({
108
119
  linkedAccount.id
109
120
  );
110
121
  }) }),
111
- /* @__PURE__ */ jsxs(CpslButton, { fullWidth: true, variant: "tertiary", onClick: () => linkAccount(void 0), children: [
122
+ /* @__PURE__ */ jsxs(CpslButton, { fullWidth: true, variant: "tertiary", onClick: () => linkAccount(void 0), "data-testid": "para-link-account", children: [
112
123
  /* @__PURE__ */ jsx(CpslIcon, { icon: "userPlus", slot: "start", size: "16px" }),
113
124
  "Link an account"
114
125
  ] })
115
126
  ] })
116
127
  ] }),
117
- /* @__PURE__ */ jsxs(DisconnectButton, { variant: "destructive", fullWidth: true, onClick: onDisconnect, disabled: isDisconnecting, children: [
118
- hideWallets ? "Logout" : "Disconnect Wallet",
119
- /* @__PURE__ */ jsx(CpslIcon, { icon: "logOut", slot: "end" })
120
- ] })
128
+ /* @__PURE__ */ jsxs(
129
+ DisconnectButton,
130
+ {
131
+ variant: "destructive",
132
+ fullWidth: true,
133
+ onClick: onDisconnect,
134
+ disabled: isDisconnecting,
135
+ "data-testid": "para-disconnect",
136
+ children: [
137
+ hideWallets ? "Logout" : "Disconnect Wallet",
138
+ /* @__PURE__ */ jsx(CpslIcon, { icon: "logOut", slot: "end" })
139
+ ]
140
+ }
141
+ )
121
142
  ] });
122
143
  };
123
144
  const Section = safeStyled.div`
@@ -175,7 +175,8 @@ function AccountSendForm() {
175
175
  }
176
176
  },
177
177
  symbol: inputMode === "VALUE" ? "$" : void 0,
178
- size: "56px"
178
+ size: "56px",
179
+ "data-testid": "para-send-amount"
179
180
  }
180
181
  ),
181
182
  !!assetPrice && assetPrice.value > 0 && !isTestnet && /* @__PURE__ */ jsxs(
@@ -190,6 +191,7 @@ function AccountSendForm() {
190
191
  cursor: "pointer"
191
192
  },
192
193
  onClick: () => setInputMode((prev) => prev === "VALUE" ? "AMOUNT" : "VALUE"),
194
+ "data-testid": "para-send-toggle-mode",
193
195
  children: [
194
196
  /* @__PURE__ */ jsx(CpslText, { variant: "bodyM", color: "secondary", children: inputMode === "VALUE" ? formatAssetQuantity({
195
197
  quantity: isMax && assetAmountOnNetwork ? assetAmountOnNetwork : transferAmount,
@@ -218,6 +220,7 @@ function AccountSendForm() {
218
220
  alignItems: "center",
219
221
  justifyContent: "space-between"
220
222
  },
223
+ "data-testid": "para-send-asset-select",
221
224
  children: [
222
225
  /* @__PURE__ */ jsxs(
223
226
  "div",
@@ -303,6 +306,7 @@ function AccountSendForm() {
303
306
  e.stopPropagation();
304
307
  setIsMax(true);
305
308
  },
309
+ "data-testid": "para-send-max",
306
310
  children: /* @__PURE__ */ jsx(CpslText, { variant: "bodyXS", color: "primary", children: "Max" })
307
311
  }
308
312
  ),
@@ -320,6 +324,7 @@ function AccountSendForm() {
320
324
  value: inputDestinationAddress,
321
325
  onCpslInput: (e) => setInputDestinationAddress(e.detail.value),
322
326
  style: { width: "100%" },
327
+ "data-testid": "para-send-recipient",
323
328
  children: /* @__PURE__ */ jsx(WalletTypeIcon, { walletType: selectedWallet.type, size: "24px", slot: "start" })
324
329
  }
325
330
  ),
@@ -336,6 +341,7 @@ function AccountSendForm() {
336
341
  pending: estimateIsPending || broadcastIsPending,
337
342
  disabled: estimateIsPending || broadcastIsPending || !((_l = estimate == null ? void 0 : estimate.result) == null ? void 0 : _l.txSerialized) || !!(estimate == null ? void 0 : estimate.error),
338
343
  onClick: onSubmit,
344
+ "data-testid": "para-send-confirm",
339
345
  children: "Confirm Send"
340
346
  }
341
347
  )
@@ -71,6 +71,7 @@ const AccountWallet = () => {
71
71
  onClick: () => {
72
72
  window.open(url(profileWallet.address), "_blank");
73
73
  },
74
+ "data-testid": "para-view-explorer",
74
75
  children: [
75
76
  "View wallet on ",
76
77
  name,
@@ -103,6 +104,7 @@ const AccountWallet = () => {
103
104
  setProfileWallet(void 0);
104
105
  setStep(ModalStep.ACCOUNT_PROFILE);
105
106
  }),
107
+ "data-testid": "para-disconnect-wallet",
106
108
  children: [
107
109
  /* @__PURE__ */ jsx(CpslIcon, { icon: "key", slot: "start" }),
108
110
  "Disconnect"
@@ -7,7 +7,7 @@ import { CpslIcon, CpslSpinner, CpslTab, CpslTabs } from "@getpara/react-compone
7
7
  import { OnRampStep } from "../../stores/index.js";
8
8
  import { useModalStore } from "../../stores/modal/useModalStore.js";
9
9
  import { useEffect, useMemo } from "react";
10
- import { getAddFundsStep, ModalStep } from "../../utils/steps.js";
10
+ import { getAddFundsStep } from "../../utils/steps.js";
11
11
  import { safeStyled } from "@getpara/react-common";
12
12
  import { useAccount, useWallet } from "../../../provider/index.js";
13
13
  import { AddFundsProvider } from "./AddFundsProvider.js";
@@ -15,10 +15,8 @@ import { AddFundsReceive } from "./AddFundsReceive.js";
15
15
  import { AddFundsContextProvider, TABS } from "./AddFundsContext.js";
16
16
  import { AnimatePresence } from "framer-motion";
17
17
  import { AddFundsSettings } from "./AddFundsSettings.js";
18
- import { WalletSelectOld } from "../WalletSelectOld/WalletSelectOld.js";
19
18
  const AddFunds = () => {
20
19
  var _a;
21
- const step = useModalStore((state) => state.step);
22
20
  const onRampConfig = useModalStore((state) => state.onRampConfig);
23
21
  const onRampStep = useModalStore((state) => state.onRampStep);
24
22
  const storedTab = useModalStore((state) => state.accountAddFundTab);
@@ -61,7 +59,6 @@ const AddFunds = () => {
61
59
  /* @__PURE__ */ jsx(CpslIcon, { slot: "start", icon }),
62
60
  title
63
61
  ] }, tab2)) }) }),
64
- (step === ModalStep.ADD_FUNDS_RECEIVE || (embedded == null ? void 0 : embedded.wallets) && embedded.wallets.length > 1) && /* @__PURE__ */ jsx(WalletSelectOld, {}),
65
62
  /* @__PURE__ */ jsx(AnimatePresence, { mode: "wait", children: /* @__PURE__ */ jsx(AddFundsContextProvider, { "data-testid": "add-funds", tab, children: Content }) })
66
63
  ] });
67
64
  };
@@ -1,99 +1,36 @@
1
1
  "use client";
2
- import {
3
- __async,
4
- __spreadProps,
5
- __spreadValues
6
- } from "../../../chunk-MMUBH76A.js";
7
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
+ import "../../../chunk-MMUBH76A.js";
3
+ import { jsx } from "react/jsx-runtime";
8
4
  import * as comp from "@getpara/react-components";
9
- import { formatCurrency, getOnRampNetworks } from "@getpara/web-sdk";
10
- import { safeStyled, getAssetCode, getAssetName, ON_RAMP_ASSETS } from "@getpara/react-common";
11
- import { useModalStore } from "../../stores/index.js";
12
- import { useState } from "react";
5
+ import { formatCurrency } from "@getpara/web-sdk";
6
+ import { getAssetCode, getAssetName, ON_RAMP_ASSETS } from "@getpara/react-common";
13
7
  import { useAddFunds } from "./AddFundsContext.js";
14
- import { useWallet } from "../../../provider/hooks/queries/useWallet.js";
15
- import { AssetIcon, contentMotionProps, GradientScroll } from "../common.js";
16
- import { AnimatePresence, motion } from "framer-motion";
8
+ import { AssetIcon, SearchableButtonList } from "../common.js";
17
9
  import { useAssets } from "../../../provider/providers/AssetsProvider.js";
18
10
  function AddFundsAsset() {
19
- const onRampConfig = useModalStore((state) => state.onRampConfig);
20
- const { assets, setAsset, network, setNetwork } = useAddFunds();
21
- const { data: activeWallet } = useWallet();
11
+ const { assets, setAsset } = useAddFunds();
22
12
  const { assetMetadata } = useAssets();
23
- const [searchStr, setSearchStr] = useState("");
24
- const onSelect = (_asset) => __async(this, null, function* () {
25
- yield setAsset(_asset);
26
- if (!network && !!onRampConfig && !!activeWallet) {
27
- yield setNetwork(
28
- getOnRampNetworks(onRampConfig.assetInfo, {
29
- walletType: activeWallet.type,
30
- assets: [_asset]
31
- })[0]
32
- );
33
- }
34
- });
35
- return /* @__PURE__ */ jsxs(Fragment, { children: [
36
- /* @__PURE__ */ jsx(AnimatePresence, { mode: "sync", children: assets.length >= 4 && /* @__PURE__ */ jsx(motion.div, __spreadProps(__spreadValues({}, contentMotionProps), { children: /* @__PURE__ */ jsx(
37
- SearchInput,
38
- {
39
- placeholder: "Search for an asset",
40
- value: searchStr,
41
- onCpslInput: (e) => {
42
- setSearchStr(e.detail.value);
43
- },
44
- children: /* @__PURE__ */ jsx(comp.CpslIcon, { icon: "search", slot: "start" })
45
- }
46
- ) })) }),
47
- /* @__PURE__ */ jsx(GradientScroll, { height: "calc(100% - 56px)", gap: "8px", children: /* @__PURE__ */ jsx(AssetList, { children: /* @__PURE__ */ jsx(AnimatePresence, { mode: "sync", children: assets.filter((asset) => {
48
- return searchStr === "" || getAssetCode(asset).toLowerCase().startsWith(searchStr.toLowerCase()) || getAssetName(asset).toLowerCase().startsWith(searchStr.toLowerCase());
49
- }).map((asset) => /* @__PURE__ */ jsx(
50
- motion.li,
51
- {
52
- style: { width: "100%" },
53
- initial: { opacity: 0 },
54
- animate: { opacity: 1 },
55
- exit: { opacity: 0 },
56
- transition: { duration: 0.2 },
57
- children: /* @__PURE__ */ jsxs(AssetButton, { fullWidth: true, variant: "secondary", onClick: () => onSelect(asset), children: [
58
- /* @__PURE__ */ jsx(AssetIcon, { asset, size: "48px" }),
59
- /* @__PURE__ */ jsxs(Info, { children: [
60
- /* @__PURE__ */ jsx(Code, { color: "contrast", variant: "bodyL", children: ON_RAMP_ASSETS[asset].code }),
61
- /* @__PURE__ */ jsx(Name, { color: "contrast", variant: "bodyS", children: ON_RAMP_ASSETS[asset].name })
62
- ] }),
63
- (assetMetadata == null ? void 0 : assetMetadata[asset]) && /* @__PURE__ */ jsx(comp.CpslText, { variant: "bodyM", children: formatCurrency(assetMetadata[asset].price) })
64
- ] }, asset)
13
+ return /* @__PURE__ */ jsx(
14
+ SearchableButtonList,
15
+ {
16
+ height: 300,
17
+ items: assets,
18
+ transformItem: (asset) => {
19
+ return {
20
+ key: asset,
21
+ icon: /* @__PURE__ */ jsx(AssetIcon, { asset, size: "48px" }),
22
+ text: ON_RAMP_ASSETS[asset].code,
23
+ endText: (assetMetadata == null ? void 0 : assetMetadata[asset]) ? /* @__PURE__ */ jsx(comp.CpslText, { variant: "bodyM", children: formatCurrency(assetMetadata[asset].price) }) : null
24
+ };
25
+ },
26
+ searchPlaceholder: "Search for an asset",
27
+ searchFilter: ({ item, searchStr }) => {
28
+ return searchStr === "" || getAssetCode(item).toLowerCase().startsWith(searchStr.toLowerCase()) || getAssetName(item).toLowerCase().startsWith(searchStr.toLowerCase());
65
29
  },
66
- asset
67
- )) }) }) })
68
- ] });
30
+ onSelect: (asset) => setAsset(asset)
31
+ }
32
+ );
69
33
  }
70
- const AssetList = safeStyled.ul`
71
- display: flex;
72
- flex-direction: column;
73
- width: 100%;
74
- gap: 8px;
75
- list-style: none;
76
- padding-inline-start: 0;
77
- margin: 0;
78
- padding: 0px;
79
- `;
80
- const AssetButton = safeStyled(comp.CpslButton)`
81
- display: flex;
82
- justify-content: center;
83
- align-items: center;
84
- gap: 8px;
85
- --button-secondary-background-color: var(--cpsl-color-background-8);
86
- --button-secondary-border-color: var(--cpsl-color-background-8);
87
- --button-secondary-hover-background-color: var(--cpsl-color-background-16);
88
- --button-secondary-hover-border-color: var(--cpsl-color-background-16);
89
- `;
90
- const Info = safeStyled(comp.CpslCol)`
91
- text-align: left;
92
- `, Code = comp.CpslText, Name = comp.CpslText;
93
- const SearchInput = safeStyled(comp.CpslInput)`
94
- --container-background-color: var(--cpsl-color-background-8);
95
- --input-background-color: transparent;
96
- `;
97
34
  export {
98
35
  AddFundsAsset
99
36
  };
@@ -9,19 +9,25 @@ export declare const TABS: [
9
9
  IconType,
10
10
  ReactNode
11
11
  ][];
12
+ type SettingsStep = 'FORM' | 'ASSETS' | 'NETWORKS' | 'NO_PROVIDERS';
12
13
  type Value = {
13
- network: TNetwork | undefined;
14
+ network: TNetwork | null;
14
15
  setNetwork: Dispatch<SetStateAction<Value['network']>>;
15
- asset: TOnRampAsset | undefined;
16
+ asset: TOnRampAsset | null;
16
17
  setAsset: Dispatch<SetStateAction<Value['asset']>>;
17
18
  fiatQuantity: string | undefined;
18
19
  setFiatQuantity: Dispatch<SetStateAction<Value['fiatQuantity']>>;
19
20
  networks: TNetwork[];
21
+ narrowedNetworks: TNetwork[];
20
22
  assets: TOnRampAsset[];
21
23
  isProviderAllowed: Partial<Record<OnRampProvider, boolean>>;
22
24
  tab: Tab;
23
25
  activeWallet: ReturnType<typeof useWallet>['data'];
24
26
  onRampConfig: OnRampConfig;
27
+ /** On-ramp test mode: only respects config in PROD; non-PROD always behaves as test mode. */
28
+ isTestMode: boolean;
29
+ settingsStep: SettingsStep | null;
30
+ TestModeAlert: ReactNode;
25
31
  };
26
32
  export declare const AddFundsContext: import("react").Context<Value>;
27
33
  export declare function AddFundsContextProvider({ tab, children }: PropsWithChildren<{
@@ -3,7 +3,7 @@ import {
3
3
  __spreadProps,
4
4
  __spreadValues
5
5
  } from "../../../chunk-MMUBH76A.js";
6
- import { jsx } from "react/jsx-runtime";
6
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
7
7
  import {
8
8
  createContext,
9
9
  useContext,
@@ -18,9 +18,12 @@ import {
18
18
  EnabledFlow,
19
19
  getOnRampAssets,
20
20
  getOnRampNetworks,
21
- OnRampPurchaseType
21
+ OnRampPurchaseType,
22
+ Environment
22
23
  } from "@getpara/web-sdk";
23
- import { getNetworkFromChainId, getNetworkOrMainNetEquivalent } from "@getpara/react-common";
24
+ import { getNetworkFromChainId, getNetworkOrMainNetEquivalent, safeStyled } from "@getpara/react-common";
25
+ import { CpslAlert, CpslIcon } from "@getpara/react-components";
26
+ import { useStore } from "../../../provider/stores/useStore.js";
24
27
  const TABS = [
25
28
  [EnabledFlow.BUY, "isBuyEnabled", "creditCard", "Buy"],
26
29
  [EnabledFlow.RECEIVE, "isReceiveEnabled", "qrCode", "Receive"],
@@ -28,20 +31,24 @@ const TABS = [
28
31
  ];
29
32
  const DEFAULT = {
30
33
  networks: [],
34
+ narrowedNetworks: [],
31
35
  assets: [],
32
36
  isProviderAllowed: {},
33
37
  tab: TABS[0][0],
34
- network: void 0,
38
+ network: null,
35
39
  setNetwork: () => {
36
40
  },
37
- asset: void 0,
41
+ asset: null,
38
42
  setAsset: () => {
39
43
  },
40
44
  fiatQuantity: "25.00",
41
45
  setFiatQuantity: () => {
42
46
  },
43
47
  onRampConfig: {},
44
- activeWallet: {}
48
+ activeWallet: {},
49
+ isTestMode: true,
50
+ settingsStep: "FORM",
51
+ TestModeAlert: null
45
52
  };
46
53
  function isValid(onRampConfig, walletType, network, asset) {
47
54
  var _a, _b;
@@ -49,26 +56,31 @@ function isValid(onRampConfig, walletType, network, asset) {
49
56
  }
50
57
  const AddFundsContext = createContext(DEFAULT);
51
58
  function AddFundsContextProvider({ tab, children }) {
52
- var _a, _b;
59
+ var _a, _b, _c, _d, _e;
60
+ const appName = useStore((state) => state.appName);
61
+ const client = useStore((state) => state.client);
53
62
  const onRampConfig = useModalStore((state) => state.onRampConfig);
54
63
  const onRampStep = useModalStore((state) => state.onRampStep);
55
64
  const setOnRampStep = useModalStore((state) => state.setOnRampStep);
65
+ const isTestModeAlertDismissed = useModalStore((state) => state.isTestModeAlertDismissed);
66
+ const setIsTestModeAlertDismissed = useModalStore((state) => state.setIsTestModeAlertDismissed);
56
67
  const { chainId } = useExternalWallets();
68
+ const isTestMode = ((_a = client == null ? void 0 : client.ctx) == null ? void 0 : _a.env) === Environment.PROD ? (_b = onRampConfig == null ? void 0 : onRampConfig.testMode) != null ? _b : false : true;
57
69
  const { data: activeWallet } = useWallet();
58
- const [fiatQuantity, setFiatQuantity] = useState((_b = (_a = onRampConfig == null ? void 0 : onRampConfig.defaultBuyAmount) == null ? void 0 : _a[0]) != null ? _b : "25.00");
70
+ const [fiatQuantity, setFiatQuantity] = useState((_d = (_c = onRampConfig == null ? void 0 : onRampConfig.defaultBuyAmount) == null ? void 0 : _c[0]) != null ? _d : "25.00");
59
71
  const networks = useMemo(() => {
60
72
  if (!onRampConfig) {
61
73
  return [];
62
74
  }
63
75
  const detectedNetwork = getNetworkFromChainId(chainId);
64
76
  const isExternal = (activeWallet == null ? void 0 : activeWallet.isExternal) && !!detectedNetwork;
65
- return isExternal ? [getNetworkOrMainNetEquivalent(detectedNetwork, onRampConfig.testMode)] : getOnRampNetworks(onRampConfig.assetInfo, {
77
+ return isExternal ? [getNetworkOrMainNetEquivalent(detectedNetwork, isTestMode)] : getOnRampNetworks(onRampConfig.assetInfo, {
66
78
  walletType: activeWallet == null ? void 0 : activeWallet.type,
67
79
  allowed: onRampConfig.allowedAssets ? Object.keys(onRampConfig.allowedAssets) : void 0,
68
80
  providers: onRampConfig.providers,
69
81
  action: OnRampPurchaseType[tab === EnabledFlow.BUY ? "BUY" : "SELL"]
70
82
  });
71
- }, [chainId, activeWallet, onRampConfig, tab]);
83
+ }, [chainId, activeWallet, onRampConfig, tab, isTestMode]);
72
84
  const assets = useMemo(() => {
73
85
  if (!onRampConfig) {
74
86
  return [];
@@ -94,24 +106,66 @@ function AddFundsContextProvider({ tab, children }) {
94
106
  )
95
107
  ];
96
108
  }, [networks, onRampConfig, activeWallet, tab]);
97
- const [network, setNetwork] = useState(
98
- !!(activeWallet == null ? void 0 : activeWallet.type) && !!(onRampConfig == null ? void 0 : onRampConfig.defaultOnRampNetwork) && !!onRampConfig.assetInfo[activeWallet.type][onRampConfig.defaultOnRampNetwork] ? onRampConfig.defaultOnRampNetwork : void 0
99
- );
100
- const [asset, setAsset] = useState(
101
- !!network && !!(onRampConfig == null ? void 0 : onRampConfig.defaultOnRampAsset) && assets.includes(onRampConfig.defaultOnRampAsset) ? onRampConfig.defaultOnRampAsset : void 0
102
- );
109
+ const [network, setNetwork] = useState(null);
110
+ const [asset, setAsset] = useState(null);
111
+ const narrowedNetworks = useMemo(() => {
112
+ return !asset || !onRampConfig ? networks : getOnRampNetworks(onRampConfig.assetInfo, {
113
+ walletType: activeWallet == null ? void 0 : activeWallet.type,
114
+ allowed: onRampConfig.allowedAssets ? Object.entries(onRampConfig.allowedAssets).filter(([_, value2]) => value2 === true || value2.includes(asset)).map(([key]) => key) : void 0,
115
+ assets: [asset],
116
+ providers: onRampConfig.providers,
117
+ action: tab === EnabledFlow.BUY ? OnRampPurchaseType.BUY : OnRampPurchaseType.SELL
118
+ });
119
+ }, [networks, asset, activeWallet == null ? void 0 : activeWallet.type, onRampConfig, tab]);
103
120
  const isProviderAllowed = useMemo(
104
121
  () => onRampConfig && !!(activeWallet == null ? void 0 : activeWallet.type) ? onRampConfig.providers.reduce(
105
122
  (acc, id) => {
106
- var _a2, _b2, _c, _d, _e;
123
+ var _a2, _b2, _c2, _d2, _e2;
107
124
  return __spreadProps(__spreadValues({}, acc), {
108
- [id]: !!network && !!asset && !!((_e = (_d = (_c = (_b2 = (_a2 = onRampConfig.assetInfo[activeWallet.type]) == null ? void 0 : _a2[network]) == null ? void 0 : _b2[asset]) == null ? void 0 : _c[id]) == null ? void 0 : _d[1]) == null ? void 0 : _e[tab === EnabledFlow.BUY ? "BUY" : "SELL"])
125
+ [id]: !!network && !!asset && !!((_e2 = (_d2 = (_c2 = (_b2 = (_a2 = onRampConfig.assetInfo[activeWallet.type]) == null ? void 0 : _a2[network]) == null ? void 0 : _b2[asset]) == null ? void 0 : _c2[id]) == null ? void 0 : _d2[1]) == null ? void 0 : _e2[tab === EnabledFlow.BUY ? "BUY" : "SELL"])
109
126
  });
110
127
  },
111
128
  {}
112
129
  ) : {},
113
130
  [onRampConfig, network, asset, activeWallet, tab]
114
131
  );
132
+ const settingsStep = useMemo(() => {
133
+ switch (true) {
134
+ case (assets.length === 0 && networks.length === 0):
135
+ return "NO_PROVIDERS";
136
+ case (!!asset && !!network):
137
+ return "FORM";
138
+ case !asset:
139
+ return "ASSETS";
140
+ case !network:
141
+ return "NETWORKS";
142
+ default:
143
+ return null;
144
+ }
145
+ }, [asset, network, assets.length, networks.length]);
146
+ const TestModeAlert = useMemo(() => {
147
+ var _a2;
148
+ const isProd = ((_a2 = client == null ? void 0 : client.ctx) == null ? void 0 : _a2.env) === Environment.PROD;
149
+ return isTestMode && !isTestModeAlertDismissed ? /* @__PURE__ */ jsx(CpslAlert, { variant: "error", filled: true, children: /* @__PURE__ */ jsxs(Fragment, { children: [
150
+ /* @__PURE__ */ jsx("span", { children: isProd ? /* @__PURE__ */ jsxs(Fragment, { children: [
151
+ "This Para Modal is configured to run on-ramp services in ",
152
+ /* @__PURE__ */ jsx("b", { children: "test mode" }),
153
+ " only, for development purposes. If you are a user of ",
154
+ appName,
155
+ ", please contact support."
156
+ ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
157
+ "On-ramp services are configured to run in ",
158
+ /* @__PURE__ */ jsx("b", { children: "test mode" }),
159
+ " only outside of the PROD environment."
160
+ ] }) }),
161
+ /* @__PURE__ */ jsx(CloseButton, { onClick: () => setIsTestModeAlertDismissed(true), children: /* @__PURE__ */ jsx(CloseX, { icon: "x" }) })
162
+ ] }) }) : null;
163
+ }, [isTestModeAlertDismissed, appName, isTestMode, setIsTestModeAlertDismissed, (_e = client == null ? void 0 : client.ctx) == null ? void 0 : _e.env]);
164
+ useEffect(() => {
165
+ if (!!asset && !network && narrowedNetworks.length === 1) {
166
+ setNetwork(narrowedNetworks[0]);
167
+ }
168
+ }, [asset, network, narrowedNetworks]);
115
169
  const value = useMemo(() => {
116
170
  if (!onRampConfig || !activeWallet) {
117
171
  return DEFAULT;
@@ -119,6 +173,7 @@ function AddFundsContextProvider({ tab, children }) {
119
173
  return {
120
174
  tab,
121
175
  networks,
176
+ narrowedNetworks,
122
177
  assets,
123
178
  isProviderAllowed,
124
179
  asset,
@@ -128,22 +183,41 @@ function AddFundsContextProvider({ tab, children }) {
128
183
  fiatQuantity,
129
184
  setFiatQuantity,
130
185
  activeWallet,
131
- onRampConfig
186
+ onRampConfig,
187
+ isTestMode,
188
+ settingsStep,
189
+ TestModeAlert
132
190
  };
133
191
  }, [
134
192
  tab,
135
193
  networks,
194
+ narrowedNetworks,
136
195
  assets,
137
196
  isProviderAllowed,
138
197
  asset,
139
- setAsset,
140
198
  network,
141
- setNetwork,
142
199
  fiatQuantity,
143
200
  setFiatQuantity,
144
201
  activeWallet,
145
- onRampConfig
202
+ onRampConfig,
203
+ isTestMode,
204
+ settingsStep,
205
+ TestModeAlert
146
206
  ]);
207
+ useEffect(() => {
208
+ const newNetwork = !!(activeWallet == null ? void 0 : activeWallet.type) && !!(onRampConfig == null ? void 0 : onRampConfig.defaultOnRampNetwork) && !!onRampConfig.assetInfo[activeWallet.type][onRampConfig.defaultOnRampNetwork] ? onRampConfig.defaultOnRampNetwork : networks.find(
209
+ (network2) => (activeWallet == null ? void 0 : activeWallet.type) === "COSMOS" ? network2 === "COSMOS" : (activeWallet == null ? void 0 : activeWallet.type) === "SOLANA" ? network2 === "SOLANA" : network2 === "ETHEREUM"
210
+ ) || networks[0] || null;
211
+ const newAsset = !!network && !!(onRampConfig == null ? void 0 : onRampConfig.defaultOnRampAsset) && assets.includes(onRampConfig.defaultOnRampAsset) ? onRampConfig.defaultOnRampAsset : assets.find(
212
+ (asset2) => (activeWallet == null ? void 0 : activeWallet.type) === "COSMOS" ? asset2 === "ATOM" : (activeWallet == null ? void 0 : activeWallet.type) === "SOLANA" ? asset2 === "SOLANA" : asset2 === "ETHEREUM"
213
+ ) || assets[0] || null;
214
+ if (newAsset !== asset) {
215
+ setAsset(newAsset);
216
+ }
217
+ if (newNetwork !== network) {
218
+ setNetwork(newNetwork);
219
+ }
220
+ }, [activeWallet == null ? void 0 : activeWallet.type, assets, networks]);
147
221
  useEffect(() => {
148
222
  if (!!activeWallet && onRampStep === OnRampStep.PROVIDER && !isValid(onRampConfig, activeWallet.type, network, asset)) {
149
223
  setOnRampStep(OnRampStep.SETTINGS);
@@ -152,6 +226,26 @@ function AddFundsContextProvider({ tab, children }) {
152
226
  return /* @__PURE__ */ jsx(AddFundsContext.Provider, { value, children });
153
227
  }
154
228
  const useAddFunds = () => useContext(AddFundsContext);
229
+ const CloseButton = safeStyled.button`
230
+ background-color: transparent;
231
+ border: none;
232
+ padding: 0;
233
+ cursor: pointer;
234
+ flex-shrink: 0;
235
+ display: flex;
236
+ align-items: center;
237
+ justify-content: center;
238
+ width: 20px;
239
+ height: 20px;
240
+ position: absolute;
241
+ top: 8px;
242
+ right: 8px;
243
+ `;
244
+ const CloseX = safeStyled(CpslIcon)`
245
+ --icon-color: var(--cpsl-color-utility-yellow-dark, #92400e);
246
+ --height: 18px;
247
+ --width: 18px;
248
+ `;
155
249
  export {
156
250
  AddFundsContext,
157
251
  AddFundsContextProvider,
@@ -0,0 +1 @@
1
+ export declare function AddFundsNetwork(): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,31 @@
1
+ "use client";
2
+ import "../../../chunk-MMUBH76A.js";
3
+ import { jsx, jsxs } from "react/jsx-runtime";
4
+ import { getNetworkName } from "@getpara/react-common";
5
+ import { useAddFunds } from "./AddFundsContext.js";
6
+ import { Heading, NetworkIcon, SearchableButtonList } from "../common.js";
7
+ import { CpslRow } from "@getpara/react-components";
8
+ function AddFundsNetwork() {
9
+ const { narrowedNetworks, setNetwork } = useAddFunds();
10
+ return /* @__PURE__ */ jsxs(CpslRow, { col: true, gap: "8px", style: { width: "100%" }, children: [
11
+ /* @__PURE__ */ jsx(Heading, { children: "Choose Network" }),
12
+ /* @__PURE__ */ jsx(
13
+ SearchableButtonList,
14
+ {
15
+ height: 300,
16
+ items: narrowedNetworks,
17
+ transformItem: (network) => {
18
+ return {
19
+ key: network,
20
+ icon: /* @__PURE__ */ jsx(NetworkIcon, { network, size: "48px" }),
21
+ text: getNetworkName(network)
22
+ };
23
+ },
24
+ onSelect: (network) => setNetwork(network)
25
+ }
26
+ )
27
+ ] });
28
+ }
29
+ export {
30
+ AddFundsNetwork
31
+ };