@getpara/react-sdk-lite 2.10.0 → 2.12.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 (55) hide show
  1. package/dist/modal/ParaModal.js +14 -1
  2. package/dist/modal/components/Account/Account.js +114 -22
  3. package/dist/modal/components/Account/AccountMonitorTx.d.ts +1 -0
  4. package/dist/modal/components/Account/AccountMonitorTx.js +256 -0
  5. package/dist/modal/components/Account/AccountSend/AccountSendAsset.js +2 -2
  6. package/dist/modal/components/Account/AccountSend/AccountSendForm.js +68 -10
  7. package/dist/modal/components/Account/AccountSend/context.d.ts +2 -0
  8. package/dist/modal/components/Account/AccountSend/context.js +50 -110
  9. package/dist/modal/components/Account/AccountWallet.js +1 -6
  10. package/dist/modal/components/Account/AccountWalletSelect.js +5 -12
  11. package/dist/modal/components/AddFunds/AddFundsContext.js +70 -25
  12. package/dist/modal/components/AddFunds/AddFundsReceive.js +1 -1
  13. package/dist/modal/components/AddFunds/AddFundsSettings.js +134 -29
  14. package/dist/modal/components/AuthInput/hooks/useDropdownPosition.d.ts +1 -1
  15. package/dist/modal/components/AuthInput/hooks/useDropdownPosition.js +25 -17
  16. package/dist/modal/components/AuthOptions/AuthOptions.js +1 -1
  17. package/dist/modal/components/Body/Body.js +4 -0
  18. package/dist/modal/components/Controls/ChainSelect.js +2 -3
  19. package/dist/modal/components/ErrorBoundary.d.ts +20 -0
  20. package/dist/modal/components/ErrorBoundary.js +27 -0
  21. package/dist/modal/components/ExternalWalletStep/ExternalWalletStep.js +1 -1
  22. package/dist/modal/components/OnRampComponents/OnRampProviderButton.js +3 -8
  23. package/dist/modal/components/WalletSelectOld/WalletSelectOld.js +6 -13
  24. package/dist/modal/components/common.d.ts +10 -1
  25. package/dist/modal/components/common.js +44 -11
  26. package/dist/modal/hooks/index.d.ts +1 -0
  27. package/dist/modal/hooks/index.js +1 -0
  28. package/dist/modal/hooks/useFarcasterLogin.js +1 -1
  29. package/dist/modal/hooks/useSendMutations.d.ts +51 -0
  30. package/dist/modal/hooks/useSendMutations.js +170 -0
  31. package/dist/modal/hooks/useTelegramLogin.js +1 -1
  32. package/dist/modal/hooks/useTransactionMonitoring.d.ts +1 -0
  33. package/dist/modal/hooks/useTransactionMonitoring.js +175 -0
  34. package/dist/modal/index.d.ts +1 -1
  35. package/dist/modal/index.js +1 -1
  36. package/dist/modal/stores/index.d.ts +1 -0
  37. package/dist/modal/stores/index.js +1 -0
  38. package/dist/modal/stores/modal/actions.js +0 -1
  39. package/dist/modal/stores/modal/useModalSessionStore.d.ts +28 -0
  40. package/dist/modal/stores/modal/useModalSessionStore.js +26 -0
  41. package/dist/modal/stores/modal/useModalStore.d.ts +2 -3
  42. package/dist/modal/stores/modal/useModalStore.js +2 -2
  43. package/dist/modal/utils/onramps.d.ts +61 -0
  44. package/dist/modal/utils/onramps.js +112 -0
  45. package/dist/modal/utils/steps.d.ts +4 -2
  46. package/dist/modal/utils/steps.js +6 -2
  47. package/dist/provider/hooks/mutations/utils.js +1 -1
  48. package/dist/provider/hooks/utils/useAutoSessionKeepAlive.js +1 -1
  49. package/dist/provider/hooks/utils/useEventListeners.js +2 -2
  50. package/dist/provider/hooks/utils/useModal.d.ts +2 -1
  51. package/dist/provider/hooks/utils/useModal.js +10 -3
  52. package/dist/provider/providers/ExternalWalletProvider.js +2 -2
  53. package/package.json +9 -8
  54. package/dist/modal/utils/validateOnRampConfig.d.ts +0 -5
  55. package/dist/modal/utils/validateOnRampConfig.js +0 -32
@@ -29,6 +29,8 @@ type Value = {
29
29
  broadcastIsPending: boolean;
30
30
  broadcastIsError: boolean;
31
31
  optionsType: OptionsType;
32
+ simulateFailure: boolean;
33
+ setSimulateFailure: Dispatch<SetStateAction<boolean>>;
32
34
  };
33
35
  export declare const AccountSendContext: import("react").Context<Value>;
34
36
  export declare function AccountSendProvider({ children, step }: PropsWithChildren<{
@@ -1,6 +1,5 @@
1
1
  "use client";
2
2
  import {
3
- __async,
4
3
  __spreadProps,
5
4
  __spreadValues
6
5
  } from "../../../../chunk-MMUBH76A.js";
@@ -14,12 +13,9 @@ import {
14
13
  useRef,
15
14
  useState
16
15
  } from "react";
17
- import { useMutation, useQueryClient } from "@tanstack/react-query";
18
16
  import { useInternalClient } from "../../../../provider/hooks/utils/useInternalClient.js";
19
- import { useProfileBalance, useSignMessage, useSignTransaction, useWalletState } from "../../../../provider/index.js";
20
- import { hexStringToBase64 } from "@getpara/web-sdk";
21
- import { useModalStore } from "../../../stores/index.js";
22
- import { ModalStep } from "../../../utils/steps.js";
17
+ import { useProfileBalance, useWalletState } from "../../../../provider/index.js";
18
+ import { useSendMutations } from "../../../hooks/index.js";
23
19
  import { useStore } from "../../../../provider/stores/useStore.js";
24
20
  const getDefaultSendMetadata = (balances, wallet) => {
25
21
  if (!balances || !(wallet == null ? void 0 : wallet.type) || !(wallet == null ? void 0 : wallet.address) || (wallet == null ? void 0 : wallet.type) === "COSMOS") {
@@ -65,11 +61,8 @@ function AccountSendProvider({ children, step }) {
65
61
  var _a2;
66
62
  return (_a2 = state.modalConfig) == null ? void 0 : _a2.balances;
67
63
  });
68
- const setStep = useModalStore((state) => state.setStep);
69
- const setSendTx = useModalStore((state) => state.setSendTx);
70
- const { data: balances } = useProfileBalance({ isComprehensive: true });
71
- const { signTransactionAsync } = useSignTransaction();
72
- const { signMessageAsync } = useSignMessage();
64
+ const [refetchTrigger, setRefetchTrigger] = useState(0);
65
+ const { data: balances } = useProfileBalance({ isComprehensive: true, refetchTrigger });
73
66
  const { selectedWallet, setSelectedWallet } = useWalletState();
74
67
  const [estimate, setEstimate] = useState(null);
75
68
  const [broadcast, setBroadcast] = useState(null);
@@ -78,6 +71,7 @@ function AccountSendProvider({ children, step }) {
78
71
  const [transferValue, setTransferValue] = useState(0);
79
72
  const [transferAmount, setTransferAmount] = useState(getTransferAmount(sendMetadata, transferValue));
80
73
  const [isMax, setIsMax] = useState(false);
74
+ const [simulateFailure, setSimulateFailure] = useState(false);
81
75
  const optionsType = useMemo(() => {
82
76
  const walletBalance = balances == null ? void 0 : balances.wallets.find(({ address }) => address === (selectedWallet == null ? void 0 : selectedWallet.address));
83
77
  if (!walletBalance || walletBalance.assets.length === 0) {
@@ -88,106 +82,26 @@ function AccountSendProvider({ children, step }) {
88
82
  }
89
83
  return "MULTIPLE";
90
84
  }, [balances, selectedWallet == null ? void 0 : selectedWallet.address]);
91
- const {
92
- mutate: estimateMutate,
93
- isPending: estimateIsPending,
94
- isError: estimateIsError
95
- } = useMutation({
96
- mutationKey: ["estimate-tx"],
97
- mutationFn: (_0) => __async(this, [_0], function* ({ userId, walletId, opts }) {
98
- if (!para.userId || !selectedWallet.id) {
99
- return null;
100
- }
101
- const result = yield para.ctx.client.estimateSendTransaction({
102
- userId,
103
- walletId,
104
- opts
105
- });
106
- return result;
107
- }),
108
- onSuccess: (data) => {
109
- setEstimate(data);
110
- },
111
- onError: (error) => {
112
- console.error(error);
85
+ const estimateOnSuccess = useCallback((estimateResult) => {
86
+ setEstimate(estimateResult);
87
+ }, []);
88
+ const broadcastOnSuccess = useCallback((data) => {
89
+ if (!!(data == null ? void 0 : data.error)) {
90
+ setBroadcast(data);
113
91
  }
114
- });
115
- const queryClient = useQueryClient();
116
- const refs = useStore((state) => state.refs);
117
- const {
118
- mutate: broadcastMutate,
119
- isPending: broadcastIsPending,
120
- isError: broadcastIsError
121
- } = useMutation({
122
- mutationKey: ["broadcast-tx"],
123
- mutationFn: (_0) => __async(this, [_0], function* ({
124
- userId,
125
- walletId,
126
- walletAddress,
127
- walletType,
128
- txSerialized,
129
- message,
130
- evmChainId,
131
- isDevnet
132
- }) {
133
- var _a2, _b2, _c2, _d2, _e2;
134
- if (!para.userId || !selectedWallet.id) {
135
- return null;
136
- }
137
- let signature;
138
- switch (walletType) {
139
- case "SOLANA":
140
- signature = (_a2 = yield signMessageAsync({
141
- walletId,
142
- messageBase64: message
143
- })) == null ? void 0 : _a2.signature;
144
- break;
145
- case "EVM":
146
- default:
147
- signature = (_b2 = yield signTransactionAsync({
148
- walletId,
149
- rlpEncodedTxBase64: hexStringToBase64(txSerialized),
150
- chainId: evmChainId
151
- })) == null ? void 0 : _b2.signature;
152
- if (!!signature) {
153
- signature = `0x${signature}`;
154
- }
155
- break;
156
- }
157
- const result = yield para.ctx.client.broadcastSendTransaction({
158
- userId,
159
- walletId,
160
- opts: {
161
- type: walletType,
162
- evmChainId,
163
- isDevnet,
164
- tx: txSerialized,
165
- signature,
166
- sourceAddress: walletAddress,
167
- txUrlFormat: (_e2 = (_d2 = (_c2 = sendMetadata == null ? void 0 : sendMetadata.network) == null ? void 0 : _c2.metadata) == null ? void 0 : _d2.explorer) == null ? void 0 : _e2.txUrlFormat
168
- }
169
- });
170
- return result;
171
- }),
172
- onSuccess: (data) => {
173
- if (!!(data == null ? void 0 : data.error)) {
174
- setBroadcast(data);
175
- } else if (!!data) {
176
- setSendTx(data);
177
- setStep(ModalStep.ACCOUNT_MAIN);
178
- refs.balancesInvalidationTime.current = Date.now();
179
- queryClient.invalidateQueries({
180
- queryKey: ["useProfileBalance"],
181
- refetchType: "active"
182
- });
183
- }
92
+ }, []);
93
+ const { estimateMutate, broadcastMutate, estimateIsPending, estimateIsError, broadcastIsPending, broadcastIsError } = useSendMutations({
94
+ estimateOnSuccess,
95
+ estimateOnError: (e) => {
96
+ console.error(e);
184
97
  },
185
- onError: (error) => {
186
- console.error(error);
98
+ broadcastOnSuccess,
99
+ broadcastOnError: (e) => {
100
+ console.error(e);
187
101
  }
188
102
  });
189
103
  const onSubmit = useCallback(() => {
190
- var _a2, _b2, _c2, _d2, _e2, _f2;
104
+ var _a2, _b2, _c2, _d2, _e2, _f2, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
191
105
  broadcastMutate({
192
106
  userId: para.userId,
193
107
  walletId: selectedWallet.id,
@@ -196,7 +110,15 @@ function AccountSendProvider({ children, step }) {
196
110
  txSerialized: (_a2 = estimate == null ? void 0 : estimate.result) == null ? void 0 : _a2.txSerialized,
197
111
  message: (_b2 = estimate == null ? void 0 : estimate.result) == null ? void 0 : _b2.message,
198
112
  evmChainId: (_d2 = (_c2 = sendMetadata == null ? void 0 : sendMetadata.network) == null ? void 0 : _c2.metadata) == null ? void 0 : _d2.evmChainId,
199
- isDevnet: ((_f2 = (_e2 = sendMetadata == null ? void 0 : sendMetadata.network) == null ? void 0 : _e2.metadata) == null ? void 0 : _f2.internalId) === "SOLANA_DEVNET"
113
+ isDevnet: ((_f2 = (_e2 = sendMetadata == null ? void 0 : sendMetadata.network) == null ? void 0 : _e2.metadata) == null ? void 0 : _f2.internalId) === "SOLANA_DEVNET",
114
+ txUrlFormat: (_i = (_h = (_g = sendMetadata == null ? void 0 : sendMetadata.network) == null ? void 0 : _g.metadata) == null ? void 0 : _h.explorer) == null ? void 0 : _i.txUrlFormat,
115
+ rpc: ((_k = (_j = sendMetadata == null ? void 0 : sendMetadata.network) == null ? void 0 : _j.metadata) == null ? void 0 : _k.rpcUrl) ? {
116
+ httpUrls: [(_m = (_l = sendMetadata == null ? void 0 : sendMetadata.network) == null ? void 0 : _l.metadata) == null ? void 0 : _m.rpcUrl],
117
+ wsUrls: [
118
+ (_o = (_n = sendMetadata == null ? void 0 : sendMetadata.network) == null ? void 0 : _n.metadata) == null ? void 0 : _o.rpcUrl.replace(/^https:\/\//, "wss://").replace(/^http:\/\//, "ws://")
119
+ ]
120
+ } : (_q = (_p = sendMetadata == null ? void 0 : sendMetadata.network) == null ? void 0 : _p.metadata) == null ? void 0 : _q.rpc,
121
+ simulateFailure
200
122
  });
201
123
  }, [
202
124
  para.userId,
@@ -206,7 +128,9 @@ function AccountSendProvider({ children, step }) {
206
128
  (_a = estimate == null ? void 0 : estimate.result) == null ? void 0 : _a.txSerialized,
207
129
  (_b = estimate == null ? void 0 : estimate.result) == null ? void 0 : _b.message,
208
130
  (_d = (_c = sendMetadata == null ? void 0 : sendMetadata.network) == null ? void 0 : _c.metadata) == null ? void 0 : _d.evmChainId,
209
- (_f = (_e = sendMetadata == null ? void 0 : sendMetadata.network) == null ? void 0 : _e.metadata) == null ? void 0 : _f.internalId
131
+ (_f = (_e = sendMetadata == null ? void 0 : sendMetadata.network) == null ? void 0 : _e.metadata) == null ? void 0 : _f.internalId,
132
+ simulateFailure,
133
+ broadcastMutate
210
134
  ]);
211
135
  const availableWallets = useMemo(() => {
212
136
  return para.availableWallets.filter(({ type }) => type !== "COSMOS");
@@ -238,6 +162,7 @@ function AccountSendProvider({ children, step }) {
238
162
  const prevWalletAddressRef = useRef(selectedWallet == null ? void 0 : selectedWallet.address);
239
163
  const isSettingMaxRef = useRef(false);
240
164
  const isResettingRef = useRef(false);
165
+ const recentTxCompletedRef = useRef(false);
241
166
  const resetState = useCallback(() => {
242
167
  if (isResettingRef.current) {
243
168
  return;
@@ -368,6 +293,17 @@ function AccountSendProvider({ children, step }) {
368
293
  assetAmountOnNetwork,
369
294
  isMax
370
295
  ]);
296
+ useEffect(() => {
297
+ if (broadcast && !broadcast.error) {
298
+ recentTxCompletedRef.current = true;
299
+ }
300
+ }, [broadcast]);
301
+ useEffect(() => {
302
+ if (step === "SEND_FORM" && recentTxCompletedRef.current) {
303
+ setRefetchTrigger((prev) => prev + 1);
304
+ recentTxCompletedRef.current = false;
305
+ }
306
+ }, [step]);
371
307
  const value = useMemo(() => {
372
308
  return {
373
309
  step,
@@ -391,7 +327,9 @@ function AccountSendProvider({ children, step }) {
391
327
  broadcast,
392
328
  broadcastIsPending,
393
329
  broadcastIsError,
394
- optionsType
330
+ optionsType,
331
+ simulateFailure,
332
+ setSimulateFailure
395
333
  };
396
334
  }, [
397
335
  step,
@@ -415,7 +353,9 @@ function AccountSendProvider({ children, step }) {
415
353
  broadcast,
416
354
  broadcastIsPending,
417
355
  broadcastIsError,
418
- optionsType
356
+ optionsType,
357
+ simulateFailure,
358
+ setSimulateFailure
419
359
  ]);
420
360
  return /* @__PURE__ */ jsx(AccountSendContext.Provider, { value, children });
421
361
  }
@@ -7,7 +7,7 @@ import { safeStyled, SpinnerContainer } from "@getpara/react-common";
7
7
  import { CpslButton, CpslIcon, CpslSpinner } from "@getpara/react-components";
8
8
  import { useModalStore } from "../../stores/modal/useModalStore.js";
9
9
  import { WalletEntry } from "./AccountProfileEntry.js";
10
- import { useEffect, useMemo } from "react";
10
+ import { useMemo } from "react";
11
11
  import { useAccount, useExportPrivateKey } from "../../../provider/index.js";
12
12
  import { useExternalWallets } from "../../../provider/providers/ExternalWalletProvider.js";
13
13
  import { ModalStep } from "../../utils/steps.js";
@@ -113,11 +113,6 @@ const AccountWallet = () => {
113
113
  )
114
114
  ] });
115
115
  }, [profileWallet, connectionType, disconnectStatus]);
116
- useEffect(() => {
117
- return () => {
118
- setProfileWallet(void 0);
119
- };
120
- }, []);
121
116
  return /* @__PURE__ */ jsx(Container, { children: Content });
122
117
  };
123
118
  const Container = safeStyled.div`
@@ -4,10 +4,11 @@ import { jsx, jsxs } from "react/jsx-runtime";
4
4
  import { useEffect, useMemo, useRef } from "react";
5
5
  import { useInternalClient } from "../../../provider/hooks/utils/useInternalClient.js";
6
6
  import { useDropdownPosition } from "../AuthInput/hooks/useDropdownPosition.js";
7
- import { getExternalWalletIcon, MOBILE_SIZE, safeStyled, useCopyToClipboard } from "@getpara/react-common";
7
+ import { getExternalWalletIcon, safeStyled, useCopyToClipboard } from "@getpara/react-common";
8
8
  import { useAccount, useWallet, useWalletState } from "../../../provider/index.js";
9
9
  import { CpslButton, CpslIcon, CpslSelect, CpslSelectItem, CpslText } from "@getpara/react-components";
10
10
  import { truncateAddress } from "@getpara/web-sdk";
11
+ import { getMobilePopoverPositionCSS } from "../common.js";
11
12
  const getValue = (id, type) => {
12
13
  return id && type ? `${id}~${type}` : void 0;
13
14
  };
@@ -79,7 +80,7 @@ const AccountWalletSelect = () => {
79
80
  resize();
80
81
  }
81
82
  }, [activeWallet, availableWallets, dropdownMaxHeight]);
82
- return /* @__PURE__ */ jsx(Container, { children: /* @__PURE__ */ jsx(SelectContainer, { ref: containerRef, id: "addressInputContainer", children: /* @__PURE__ */ jsxs(
83
+ return /* @__PURE__ */ jsx(Container, { children: /* @__PURE__ */ jsx(SelectContainer, { ref: containerRef, children: /* @__PURE__ */ jsxs(
83
84
  Select,
84
85
  {
85
86
  selectedValue: getValue(activeWallet == null ? void 0 : activeWallet.id, activeWallet == null ? void 0 : activeWallet.type),
@@ -89,10 +90,9 @@ const AccountWalletSelect = () => {
89
90
  },
90
91
  showFormattedSelectedItem: true,
91
92
  placeholder: "Choose wallet...",
92
- anchorElId: "addressInputContainer",
93
93
  dropdownMaxHeight,
94
94
  $width: dropdownWidth != null ? dropdownWidth : 0,
95
- $top: (mobileAnchor != null ? mobileAnchor : 0) + 184 + 1,
95
+ $top: mobileAnchor != null ? mobileAnchor : void 0,
96
96
  selectedItemVariant: "bodyXS",
97
97
  icon: isMultiWallet ? "chevronUp" : null,
98
98
  disabled: !isMultiWallet,
@@ -148,14 +148,7 @@ const Select = safeStyled(CpslSelect)`
148
148
 
149
149
  &::part(popover) {
150
150
  /* Have to adjust the top of the popover here since we're using a transform on the modal which causes fixed position items to not be relative to the viewport */
151
- @media (max-width: ${MOBILE_SIZE}px) {
152
- top: ${({ $top }) => $top ? `${$top}px` : "0px"};
153
- bottom: 16px;
154
- }
155
- cpsl-auth-modal.force-mobile-media & {
156
- top: ${({ $top }) => $top ? `${$top}px` : "0px"};
157
- bottom: 16px;
158
- }
151
+ ${({ $top }) => getMobilePopoverPositionCSS($top)}
159
152
  }
160
153
 
161
154
  &::part(icon) {
@@ -9,6 +9,7 @@ import {
9
9
  useContext,
10
10
  useEffect,
11
11
  useMemo,
12
+ useRef,
12
13
  useState
13
14
  } from "react";
14
15
  import { OnRampStep, useModalStore } from "../../stores/index.js";
@@ -24,6 +25,7 @@ import {
24
25
  import { getNetworkFromChainId, getNetworkOrMainNetEquivalent, safeStyled } from "@getpara/react-common";
25
26
  import { CpslAlert, CpslIcon } from "@getpara/react-components";
26
27
  import { useStore } from "../../../provider/stores/useStore.js";
28
+ import { getDefaultAssetAndNetwork, isAmountWithinProviderLimits } from "../../utils/onramps.js";
27
29
  const TABS = [
28
30
  [EnabledFlow.BUY, "isBuyEnabled", "creditCard", "Buy"],
29
31
  [EnabledFlow.RECEIVE, "isReceiveEnabled", "qrCode", "Receive"],
@@ -56,7 +58,7 @@ function isValid(onRampConfig, walletType, network, asset) {
56
58
  }
57
59
  const AddFundsContext = createContext(DEFAULT);
58
60
  function AddFundsContextProvider({ tab, children }) {
59
- var _a, _b, _c, _d, _e;
61
+ var _a, _b, _c, _d, _e, _f;
60
62
  const appName = useStore((state) => state.appName);
61
63
  const client = useStore((state) => state.client);
62
64
  const onRampConfig = useModalStore((state) => state.onRampConfig);
@@ -67,7 +69,9 @@ function AddFundsContextProvider({ tab, children }) {
67
69
  const { chainId } = useExternalWallets();
68
70
  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;
69
71
  const { data: activeWallet } = useWallet();
70
- const [fiatQuantity, setFiatQuantity] = useState((_d = (_c = onRampConfig == null ? void 0 : onRampConfig.defaultBuyAmount) == null ? void 0 : _c[0]) != null ? _d : "25.00");
72
+ const [fiatQuantity, setFiatQuantity] = useState(
73
+ (_e = (_d = (_c = onRampConfig == null ? void 0 : onRampConfig.defaultBuyAmount) == null ? void 0 : _c[0]) == null ? void 0 : _d.toString()) != null ? _e : "25.00"
74
+ );
71
75
  const networks = useMemo(() => {
72
76
  if (!onRampConfig) {
73
77
  return [];
@@ -118,16 +122,22 @@ function AddFundsContextProvider({ tab, children }) {
118
122
  });
119
123
  }, [networks, asset, activeWallet == null ? void 0 : activeWallet.type, onRampConfig, tab]);
120
124
  const isProviderAllowed = useMemo(
121
- () => onRampConfig && !!(activeWallet == null ? void 0 : activeWallet.type) ? onRampConfig.providers.reduce(
122
- (acc, id) => {
123
- var _a2, _b2, _c2, _d2, _e2;
124
- return __spreadProps(__spreadValues({}, acc), {
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"])
126
- });
127
- },
128
- {}
129
- ) : {},
130
- [onRampConfig, network, asset, activeWallet, tab]
125
+ () => onRampConfig && !!(activeWallet == null ? void 0 : activeWallet.type) ? onRampConfig.providers.reduce((acc, id) => {
126
+ var _a2, _b2, _c2, _d2, _e2;
127
+ const purchaseType = tab === EnabledFlow.BUY ? OnRampPurchaseType.BUY : OnRampPurchaseType.SELL;
128
+ let isAllowed = !!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[purchaseType]);
129
+ if (isAllowed && fiatQuantity) {
130
+ const fiatQtyString = String(fiatQuantity);
131
+ if (fiatQtyString.trim() !== "") {
132
+ const amount = parseFloat(fiatQtyString);
133
+ if (!isNaN(amount) && !isAmountWithinProviderLimits(amount, id, purchaseType)) {
134
+ isAllowed = false;
135
+ }
136
+ }
137
+ }
138
+ return __spreadProps(__spreadValues({}, acc), { [id]: isAllowed });
139
+ }, {}) : {},
140
+ [onRampConfig, network, asset, activeWallet, tab, fiatQuantity]
131
141
  );
132
142
  const settingsStep = useMemo(() => {
133
143
  switch (true) {
@@ -160,7 +170,7 @@ function AddFundsContextProvider({ tab, children }) {
160
170
  ] }) }),
161
171
  /* @__PURE__ */ jsx(CloseButton, { onClick: () => setIsTestModeAlertDismissed(true), children: /* @__PURE__ */ jsx(CloseX, { icon: "x" }) })
162
172
  ] }) }) : null;
163
- }, [isTestModeAlertDismissed, appName, isTestMode, setIsTestModeAlertDismissed, (_e = client == null ? void 0 : client.ctx) == null ? void 0 : _e.env]);
173
+ }, [isTestModeAlertDismissed, appName, isTestMode, setIsTestModeAlertDismissed, (_f = client == null ? void 0 : client.ctx) == null ? void 0 : _f.env]);
164
174
  useEffect(() => {
165
175
  if (!!asset && !network && narrowedNetworks.length === 1) {
166
176
  setNetwork(narrowedNetworks[0]);
@@ -197,27 +207,62 @@ function AddFundsContextProvider({ tab, children }) {
197
207
  asset,
198
208
  network,
199
209
  fiatQuantity,
200
- setFiatQuantity,
201
210
  activeWallet,
202
211
  onRampConfig,
203
212
  isTestMode,
204
213
  settingsStep,
205
214
  TestModeAlert
206
215
  ]);
216
+ const prevWalletTypeRef = useRef(activeWallet == null ? void 0 : activeWallet.type);
207
217
  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);
218
+ const walletTypeChanged = prevWalletTypeRef.current !== (activeWallet == null ? void 0 : activeWallet.type);
219
+ prevWalletTypeRef.current = activeWallet == null ? void 0 : activeWallet.type;
220
+ if (assets.length === 0 || networks.length === 0) {
221
+ return;
222
+ }
223
+ if (walletTypeChanged) {
224
+ const { asset: newAsset, network: newNetwork } = getDefaultAssetAndNetwork({
225
+ walletType: activeWallet == null ? void 0 : activeWallet.type,
226
+ onRampConfig,
227
+ networks,
228
+ assets
229
+ });
230
+ if (newAsset !== asset) {
231
+ setAsset(newAsset);
232
+ }
233
+ if (newNetwork !== network) {
234
+ setNetwork(newNetwork);
235
+ }
236
+ return;
237
+ }
238
+ if (asset && !network) {
239
+ const { network: newNetwork } = getDefaultAssetAndNetwork({
240
+ walletType: activeWallet == null ? void 0 : activeWallet.type,
241
+ onRampConfig,
242
+ networks,
243
+ assets,
244
+ preferredAsset: asset
245
+ });
246
+ if (newNetwork !== network) {
247
+ setNetwork(newNetwork);
248
+ }
249
+ return;
216
250
  }
217
- if (newNetwork !== network) {
218
- setNetwork(newNetwork);
251
+ if (!network && !asset) {
252
+ const { asset: newAsset, network: newNetwork } = getDefaultAssetAndNetwork({
253
+ walletType: activeWallet == null ? void 0 : activeWallet.type,
254
+ onRampConfig,
255
+ networks,
256
+ assets
257
+ });
258
+ if (newAsset !== asset) {
259
+ setAsset(newAsset);
260
+ }
261
+ if (newNetwork !== network) {
262
+ setNetwork(newNetwork);
263
+ }
219
264
  }
220
- }, [activeWallet == null ? void 0 : activeWallet.type, assets, networks]);
265
+ }, [activeWallet == null ? void 0 : activeWallet.type, assets, networks, onRampConfig]);
221
266
  useEffect(() => {
222
267
  if (!!activeWallet && onRampStep === OnRampStep.PROVIDER && !isValid(onRampConfig, activeWallet.type, network, asset)) {
223
268
  setOnRampStep(OnRampStep.SETTINGS);
@@ -27,7 +27,7 @@ function AddFundsReceive() {
27
27
  [para, activeWallet == null ? void 0 : activeWallet.id, activeWallet == null ? void 0 : activeWallet.type]
28
28
  );
29
29
  return /* @__PURE__ */ jsxs(Fragment, { children: [
30
- (embedded == null ? void 0 : embedded.wallets) && embedded.wallets.length > 1 && /* @__PURE__ */ jsx(WalletSelectOld, { noTitle: true, style: { width: "100%" } }),
30
+ (embedded == null ? void 0 : embedded.wallets) && /* @__PURE__ */ jsx(WalletSelectOld, { noTitle: true, style: { width: "100%" } }),
31
31
  !isMobile() && /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(InnerStepContainer, { children: /* @__PURE__ */ jsx(QRContainer, { children: !address ? /* @__PURE__ */ jsx(CpslSpinner, { size: 100 }) : /* @__PURE__ */ jsx(CpslQrCode, { url: address }, address) }) }) }),
32
32
  (activeWallet == null ? void 0 : activeWallet.type) && /* @__PURE__ */ jsx(InnerStepContainer, { children: /* @__PURE__ */ jsxs(CenteredText, { variant: "bodyS", weight: "semiBold", children: [
33
33
  "Only send funds on",