@getpara/react-sdk-lite 2.9.0 → 2.11.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 (50) hide show
  1. package/dist/modal/ParaModal.js +3 -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 +36 -109
  9. package/dist/modal/components/AddFunds/AddFundsContext.d.ts +2 -0
  10. package/dist/modal/components/AddFunds/AddFundsContext.js +88 -31
  11. package/dist/modal/components/AddFunds/AddFundsProvider.js +2 -2
  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/Body/Body.js +4 -0
  15. package/dist/modal/components/ErrorBoundary.d.ts +20 -0
  16. package/dist/modal/components/ErrorBoundary.js +27 -0
  17. package/dist/modal/components/OnRampComponents/OnRampProviderButton.js +3 -8
  18. package/dist/modal/components/common.d.ts +5 -1
  19. package/dist/modal/components/common.js +27 -1
  20. package/dist/modal/hooks/index.d.ts +1 -0
  21. package/dist/modal/hooks/index.js +1 -0
  22. package/dist/modal/hooks/useSendMutations.d.ts +51 -0
  23. package/dist/modal/hooks/useSendMutations.js +170 -0
  24. package/dist/modal/hooks/useTransactionMonitoring.d.ts +1 -0
  25. package/dist/modal/hooks/useTransactionMonitoring.js +175 -0
  26. package/dist/modal/index.d.ts +1 -1
  27. package/dist/modal/index.js +1 -1
  28. package/dist/modal/stores/index.d.ts +1 -0
  29. package/dist/modal/stores/index.js +1 -0
  30. package/dist/modal/stores/modal/actions.js +0 -1
  31. package/dist/modal/stores/modal/useModalSessionStore.d.ts +28 -0
  32. package/dist/modal/stores/modal/useModalSessionStore.js +26 -0
  33. package/dist/modal/stores/modal/useModalStore.d.ts +1 -3
  34. package/dist/modal/stores/modal/useModalStore.js +0 -1
  35. package/dist/modal/types/modalProps.d.ts +3 -1
  36. package/dist/modal/utils/onramps.d.ts +61 -0
  37. package/dist/modal/utils/onramps.js +112 -0
  38. package/dist/modal/utils/steps.d.ts +4 -2
  39. package/dist/modal/utils/steps.js +6 -2
  40. package/dist/provider/hooks/queries/useProfileBalance.js +33 -6
  41. package/dist/provider/hooks/utils/index.d.ts +1 -0
  42. package/dist/provider/hooks/utils/index.js +2 -0
  43. package/dist/provider/hooks/utils/useEventListeners.js +2 -2
  44. package/dist/provider/hooks/utils/useSetBalanceOverrides.d.ts +34 -0
  45. package/dist/provider/hooks/utils/useSetBalanceOverrides.js +12 -0
  46. package/dist/provider/stores/slices/modal.js +11 -1
  47. package/dist/provider/stores/types.d.ts +8 -0
  48. package/package.json +9 -8
  49. package/dist/modal/utils/validateOnRampConfig.d.ts +0 -5
  50. package/dist/modal/utils/validateOnRampConfig.js +0 -32
@@ -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,7 @@ 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
64
  const { data: balances } = useProfileBalance({ isComprehensive: true });
71
- const { signTransactionAsync } = useSignTransaction();
72
- const { signMessageAsync } = useSignMessage();
73
65
  const { selectedWallet, setSelectedWallet } = useWalletState();
74
66
  const [estimate, setEstimate] = useState(null);
75
67
  const [broadcast, setBroadcast] = useState(null);
@@ -78,6 +70,7 @@ function AccountSendProvider({ children, step }) {
78
70
  const [transferValue, setTransferValue] = useState(0);
79
71
  const [transferAmount, setTransferAmount] = useState(getTransferAmount(sendMetadata, transferValue));
80
72
  const [isMax, setIsMax] = useState(false);
73
+ const [simulateFailure, setSimulateFailure] = useState(false);
81
74
  const optionsType = useMemo(() => {
82
75
  const walletBalance = balances == null ? void 0 : balances.wallets.find(({ address }) => address === (selectedWallet == null ? void 0 : selectedWallet.address));
83
76
  if (!walletBalance || walletBalance.assets.length === 0) {
@@ -88,106 +81,26 @@ function AccountSendProvider({ children, step }) {
88
81
  }
89
82
  return "MULTIPLE";
90
83
  }, [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);
84
+ const estimateOnSuccess = useCallback((estimateResult) => {
85
+ setEstimate(estimateResult);
86
+ }, []);
87
+ const broadcastOnSuccess = useCallback((data) => {
88
+ if (!!(data == null ? void 0 : data.error)) {
89
+ setBroadcast(data);
113
90
  }
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
- }
91
+ }, []);
92
+ const { estimateMutate, broadcastMutate, estimateIsPending, estimateIsError, broadcastIsPending, broadcastIsError } = useSendMutations({
93
+ estimateOnSuccess,
94
+ estimateOnError: (e) => {
95
+ console.error(e);
184
96
  },
185
- onError: (error) => {
186
- console.error(error);
97
+ broadcastOnSuccess,
98
+ broadcastOnError: (e) => {
99
+ console.error(e);
187
100
  }
188
101
  });
189
102
  const onSubmit = useCallback(() => {
190
- var _a2, _b2, _c2, _d2, _e2, _f2;
103
+ var _a2, _b2, _c2, _d2, _e2, _f2, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
191
104
  broadcastMutate({
192
105
  userId: para.userId,
193
106
  walletId: selectedWallet.id,
@@ -196,7 +109,15 @@ function AccountSendProvider({ children, step }) {
196
109
  txSerialized: (_a2 = estimate == null ? void 0 : estimate.result) == null ? void 0 : _a2.txSerialized,
197
110
  message: (_b2 = estimate == null ? void 0 : estimate.result) == null ? void 0 : _b2.message,
198
111
  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"
112
+ isDevnet: ((_f2 = (_e2 = sendMetadata == null ? void 0 : sendMetadata.network) == null ? void 0 : _e2.metadata) == null ? void 0 : _f2.internalId) === "SOLANA_DEVNET",
113
+ 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,
114
+ rpc: ((_k = (_j = sendMetadata == null ? void 0 : sendMetadata.network) == null ? void 0 : _j.metadata) == null ? void 0 : _k.rpcUrl) ? {
115
+ httpUrls: [(_m = (_l = sendMetadata == null ? void 0 : sendMetadata.network) == null ? void 0 : _l.metadata) == null ? void 0 : _m.rpcUrl],
116
+ wsUrls: [
117
+ (_o = (_n = sendMetadata == null ? void 0 : sendMetadata.network) == null ? void 0 : _n.metadata) == null ? void 0 : _o.rpcUrl.replace(/^https:\/\//, "wss://").replace(/^http:\/\//, "ws://")
118
+ ]
119
+ } : (_q = (_p = sendMetadata == null ? void 0 : sendMetadata.network) == null ? void 0 : _p.metadata) == null ? void 0 : _q.rpc,
120
+ simulateFailure
200
121
  });
201
122
  }, [
202
123
  para.userId,
@@ -206,7 +127,9 @@ function AccountSendProvider({ children, step }) {
206
127
  (_a = estimate == null ? void 0 : estimate.result) == null ? void 0 : _a.txSerialized,
207
128
  (_b = estimate == null ? void 0 : estimate.result) == null ? void 0 : _b.message,
208
129
  (_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
130
+ (_f = (_e = sendMetadata == null ? void 0 : sendMetadata.network) == null ? void 0 : _e.metadata) == null ? void 0 : _f.internalId,
131
+ simulateFailure,
132
+ broadcastMutate
210
133
  ]);
211
134
  const availableWallets = useMemo(() => {
212
135
  return para.availableWallets.filter(({ type }) => type !== "COSMOS");
@@ -391,7 +314,9 @@ function AccountSendProvider({ children, step }) {
391
314
  broadcast,
392
315
  broadcastIsPending,
393
316
  broadcastIsError,
394
- optionsType
317
+ optionsType,
318
+ simulateFailure,
319
+ setSimulateFailure
395
320
  };
396
321
  }, [
397
322
  step,
@@ -415,7 +340,9 @@ function AccountSendProvider({ children, step }) {
415
340
  broadcast,
416
341
  broadcastIsPending,
417
342
  broadcastIsError,
418
- optionsType
343
+ optionsType,
344
+ simulateFailure,
345
+ setSimulateFailure
419
346
  ]);
420
347
  return /* @__PURE__ */ jsx(AccountSendContext.Provider, { value, children });
421
348
  }
@@ -24,6 +24,8 @@ type Value = {
24
24
  tab: Tab;
25
25
  activeWallet: ReturnType<typeof useWallet>['data'];
26
26
  onRampConfig: OnRampConfig;
27
+ /** On-ramp test mode: only respects config in PROD; non-PROD always behaves as test mode. */
28
+ isTestMode: boolean;
27
29
  settingsStep: SettingsStep | null;
28
30
  TestModeAlert: ReactNode;
29
31
  };
@@ -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";
@@ -18,11 +19,13 @@ import {
18
19
  EnabledFlow,
19
20
  getOnRampAssets,
20
21
  getOnRampNetworks,
21
- OnRampPurchaseType
22
+ OnRampPurchaseType,
23
+ Environment
22
24
  } from "@getpara/web-sdk";
23
25
  import { getNetworkFromChainId, getNetworkOrMainNetEquivalent, safeStyled } from "@getpara/react-common";
24
26
  import { CpslAlert, CpslIcon } from "@getpara/react-components";
25
27
  import { useStore } from "../../../provider/stores/useStore.js";
28
+ import { getDefaultAssetAndNetwork, isAmountWithinProviderLimits } from "../../utils/onramps.js";
26
29
  const TABS = [
27
30
  [EnabledFlow.BUY, "isBuyEnabled", "creditCard", "Buy"],
28
31
  [EnabledFlow.RECEIVE, "isReceiveEnabled", "qrCode", "Receive"],
@@ -45,6 +48,7 @@ const DEFAULT = {
45
48
  },
46
49
  onRampConfig: {},
47
50
  activeWallet: {},
51
+ isTestMode: true,
48
52
  settingsStep: "FORM",
49
53
  TestModeAlert: null
50
54
  };
@@ -54,29 +58,33 @@ function isValid(onRampConfig, walletType, network, asset) {
54
58
  }
55
59
  const AddFundsContext = createContext(DEFAULT);
56
60
  function AddFundsContextProvider({ tab, children }) {
57
- var _a, _b;
61
+ var _a, _b, _c, _d, _e, _f;
58
62
  const appName = useStore((state) => state.appName);
63
+ const client = useStore((state) => state.client);
59
64
  const onRampConfig = useModalStore((state) => state.onRampConfig);
60
65
  const onRampStep = useModalStore((state) => state.onRampStep);
61
66
  const setOnRampStep = useModalStore((state) => state.setOnRampStep);
62
67
  const isTestModeAlertDismissed = useModalStore((state) => state.isTestModeAlertDismissed);
63
68
  const setIsTestModeAlertDismissed = useModalStore((state) => state.setIsTestModeAlertDismissed);
64
69
  const { chainId } = useExternalWallets();
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;
65
71
  const { data: activeWallet } = useWallet();
66
- const [fiatQuantity, setFiatQuantity] = useState((_b = (_a = onRampConfig == null ? void 0 : onRampConfig.defaultBuyAmount) == null ? void 0 : _a[0]) != null ? _b : "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
+ );
67
75
  const networks = useMemo(() => {
68
76
  if (!onRampConfig) {
69
77
  return [];
70
78
  }
71
79
  const detectedNetwork = getNetworkFromChainId(chainId);
72
80
  const isExternal = (activeWallet == null ? void 0 : activeWallet.isExternal) && !!detectedNetwork;
73
- return isExternal ? [getNetworkOrMainNetEquivalent(detectedNetwork, onRampConfig.testMode)] : getOnRampNetworks(onRampConfig.assetInfo, {
81
+ return isExternal ? [getNetworkOrMainNetEquivalent(detectedNetwork, isTestMode)] : getOnRampNetworks(onRampConfig.assetInfo, {
74
82
  walletType: activeWallet == null ? void 0 : activeWallet.type,
75
83
  allowed: onRampConfig.allowedAssets ? Object.keys(onRampConfig.allowedAssets) : void 0,
76
84
  providers: onRampConfig.providers,
77
85
  action: OnRampPurchaseType[tab === EnabledFlow.BUY ? "BUY" : "SELL"]
78
86
  });
79
- }, [chainId, activeWallet, onRampConfig, tab]);
87
+ }, [chainId, activeWallet, onRampConfig, tab, isTestMode]);
80
88
  const assets = useMemo(() => {
81
89
  if (!onRampConfig) {
82
90
  return [];
@@ -114,16 +122,22 @@ function AddFundsContextProvider({ tab, children }) {
114
122
  });
115
123
  }, [networks, asset, activeWallet == null ? void 0 : activeWallet.type, onRampConfig, tab]);
116
124
  const isProviderAllowed = useMemo(
117
- () => onRampConfig && !!(activeWallet == null ? void 0 : activeWallet.type) ? onRampConfig.providers.reduce(
118
- (acc, id) => {
119
- var _a2, _b2, _c, _d, _e;
120
- return __spreadProps(__spreadValues({}, acc), {
121
- [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"])
122
- });
123
- },
124
- {}
125
- ) : {},
126
- [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]
127
141
  );
128
142
  const settingsStep = useMemo(() => {
129
143
  switch (true) {
@@ -140,17 +154,23 @@ function AddFundsContextProvider({ tab, children }) {
140
154
  }
141
155
  }, [asset, network, assets.length, networks.length]);
142
156
  const TestModeAlert = useMemo(() => {
143
- return (onRampConfig == null ? void 0 : onRampConfig.testMode) && !isTestModeAlertDismissed ? /* @__PURE__ */ jsx(CpslAlert, { variant: "error", filled: true, children: /* @__PURE__ */ jsxs(Fragment, { children: [
144
- /* @__PURE__ */ jsxs("span", { children: [
157
+ var _a2;
158
+ const isProd = ((_a2 = client == null ? void 0 : client.ctx) == null ? void 0 : _a2.env) === Environment.PROD;
159
+ return isTestMode && !isTestModeAlertDismissed ? /* @__PURE__ */ jsx(CpslAlert, { variant: "error", filled: true, children: /* @__PURE__ */ jsxs(Fragment, { children: [
160
+ /* @__PURE__ */ jsx("span", { children: isProd ? /* @__PURE__ */ jsxs(Fragment, { children: [
145
161
  "This Para Modal is configured to run on-ramp services in ",
146
162
  /* @__PURE__ */ jsx("b", { children: "test mode" }),
147
163
  " only, for development purposes. If you are a user of ",
148
164
  appName,
149
165
  ", please contact support."
150
- ] }),
166
+ ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
167
+ "On-ramp services are configured to run in ",
168
+ /* @__PURE__ */ jsx("b", { children: "test mode" }),
169
+ " only outside of the PROD environment."
170
+ ] }) }),
151
171
  /* @__PURE__ */ jsx(CloseButton, { onClick: () => setIsTestModeAlertDismissed(true), children: /* @__PURE__ */ jsx(CloseX, { icon: "x" }) })
152
172
  ] }) }) : null;
153
- }, [isTestModeAlertDismissed, appName, onRampConfig == null ? void 0 : onRampConfig.testMode, setIsTestModeAlertDismissed]);
173
+ }, [isTestModeAlertDismissed, appName, isTestMode, setIsTestModeAlertDismissed, (_f = client == null ? void 0 : client.ctx) == null ? void 0 : _f.env]);
154
174
  useEffect(() => {
155
175
  if (!!asset && !network && narrowedNetworks.length === 1) {
156
176
  setNetwork(narrowedNetworks[0]);
@@ -174,6 +194,7 @@ function AddFundsContextProvider({ tab, children }) {
174
194
  setFiatQuantity,
175
195
  activeWallet,
176
196
  onRampConfig,
197
+ isTestMode,
177
198
  settingsStep,
178
199
  TestModeAlert
179
200
  };
@@ -186,26 +207,62 @@ function AddFundsContextProvider({ tab, children }) {
186
207
  asset,
187
208
  network,
188
209
  fiatQuantity,
189
- setFiatQuantity,
190
210
  activeWallet,
191
211
  onRampConfig,
212
+ isTestMode,
192
213
  settingsStep,
193
214
  TestModeAlert
194
215
  ]);
216
+ const prevWalletTypeRef = useRef(activeWallet == null ? void 0 : activeWallet.type);
195
217
  useEffect(() => {
196
- const newNetwork = !!(activeWallet == null ? void 0 : activeWallet.type) && !!(onRampConfig == null ? void 0 : onRampConfig.defaultOnRampNetwork) && !!onRampConfig.assetInfo[activeWallet.type][onRampConfig.defaultOnRampNetwork] ? onRampConfig.defaultOnRampNetwork : networks.find(
197
- (network2) => (activeWallet == null ? void 0 : activeWallet.type) === "COSMOS" ? network2 === "COSMOS" : (activeWallet == null ? void 0 : activeWallet.type) === "SOLANA" ? network2 === "SOLANA" : network2 === "ETHEREUM"
198
- ) || networks[0] || null;
199
- const newAsset = !!network && !!(onRampConfig == null ? void 0 : onRampConfig.defaultOnRampAsset) && assets.includes(onRampConfig.defaultOnRampAsset) ? onRampConfig.defaultOnRampAsset : assets.find(
200
- (asset2) => (activeWallet == null ? void 0 : activeWallet.type) === "COSMOS" ? asset2 === "ATOM" : (activeWallet == null ? void 0 : activeWallet.type) === "SOLANA" ? asset2 === "SOLANA" : asset2 === "ETHEREUM"
201
- ) || assets[0] || null;
202
- if (newAsset !== asset) {
203
- 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;
204
250
  }
205
- if (newNetwork !== network) {
206
- 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
+ }
207
264
  }
208
- }, [activeWallet == null ? void 0 : activeWallet.type, assets, networks]);
265
+ }, [activeWallet == null ? void 0 : activeWallet.type, assets, networks, onRampConfig]);
209
266
  useEffect(() => {
210
267
  if (!!activeWallet && onRampStep === OnRampStep.PROVIDER && !isValid(onRampConfig, activeWallet.type, network, asset)) {
211
268
  setOnRampStep(OnRampStep.SETTINGS);
@@ -20,7 +20,7 @@ function AddFundsProvider() {
20
20
  const setOnRampStep = useModalStore((state) => state.setOnRampStep);
21
21
  const onRampConfig = useModalStore((state) => state.onRampConfig);
22
22
  const setOnRampPurchase = useModalStore((state) => state.setOnRampPurchase);
23
- const { asset, network, fiatQuantity, isProviderAllowed, tab, TestModeAlert } = useAddFunds();
23
+ const { asset, network, fiatQuantity, isProviderAllowed, tab, TestModeAlert, isTestMode } = useAddFunds();
24
24
  const { data: activeWallet } = useWallet();
25
25
  useEffect(() => {
26
26
  if (Object.values(isProviderAllowed).every((v) => !v)) {
@@ -57,7 +57,7 @@ function AddFundsProvider() {
57
57
  network,
58
58
  asset: asset || void 0,
59
59
  fiatQuantity,
60
- testMode: onRampConfig == null ? void 0 : onRampConfig.testMode
60
+ testMode: isTestMode
61
61
  }
62
62
  });
63
63
  setOnRampPurchase(__spreadProps(__spreadValues({}, newOnRampPurchase), { fiat: "USD" }));
@@ -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",