@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
@@ -0,0 +1,175 @@
1
+ "use client";
2
+ import {
3
+ __objRest,
4
+ __spreadProps,
5
+ __spreadValues
6
+ } from "../../chunk-MMUBH76A.js";
7
+ import { useEffect, useMemo, useRef, useState } from "react";
8
+ import { useInternalClient } from "../../provider/hooks/utils/useInternalClient.js";
9
+ import { useModalStore, useModalSessionStore } from "../stores/index.js";
10
+ import { getBaseUrl } from "@getpara/web-sdk";
11
+ import { useAccount } from "../../provider/index.js";
12
+ import { ModalStep } from "../utils/steps.js";
13
+ import { SESSION_COOKIE_HEADER_NAME } from "@getpara/user-management-client";
14
+ const TRANSACTION_CLEANUP_DELAY_MS = 3e4;
15
+ function useTransactionMonitoring() {
16
+ var _a, _b, _c, _d, _e, _f;
17
+ const sendTx = useModalSessionStore((state) => state.sendTx);
18
+ const setSendTx = useModalSessionStore((state) => state.setSendTx);
19
+ const currentStep = useModalStore((state) => state.step);
20
+ const para = useInternalClient();
21
+ const socketRef = useRef(null);
22
+ const subscribedDataRef = useRef(null);
23
+ const socketIoModuleRef = useRef(null);
24
+ const [isLoadingSocketIo, setIsLoadingSocketIo] = useState(false);
25
+ const {
26
+ embedded: { userId },
27
+ isConnected
28
+ } = useAccount();
29
+ const socketUrl = useMemo(() => {
30
+ var _a2;
31
+ if (!((_a2 = para.ctx) == null ? void 0 : _a2.env)) return null;
32
+ return getBaseUrl(para.ctx.env, "ws");
33
+ }, [(_a = para.ctx) == null ? void 0 : _a.env]);
34
+ useEffect(() => {
35
+ var _a2, _b2, _c2, _d2;
36
+ if (typeof window === "undefined") {
37
+ return;
38
+ }
39
+ const shouldMonitor = isConnected && userId && userId === (sendTx == null ? void 0 : sendTx.userId) && ((_a2 = sendTx == null ? void 0 : sendTx.result) == null ? void 0 : _a2.status) && ((_b2 = sendTx == null ? void 0 : sendTx.result) == null ? void 0 : _b2.txHash) && ((_c2 = sendTx == null ? void 0 : sendTx.result) == null ? void 0 : _c2.network) && socketUrl;
40
+ if (!shouldMonitor) {
41
+ if (socketRef.current) {
42
+ if (subscribedDataRef.current) {
43
+ socketRef.current.emit("tx:unsubscribe", subscribedDataRef.current);
44
+ subscribedDataRef.current = null;
45
+ }
46
+ socketRef.current.disconnect();
47
+ socketRef.current = null;
48
+ }
49
+ if (sendTx && (!isConnected || !userId || userId !== sendTx.userId)) {
50
+ setSendTx(null);
51
+ }
52
+ return;
53
+ }
54
+ const subscribeData = __spreadValues({
55
+ txHash: sendTx.result.txHash
56
+ }, sendTx.result.network);
57
+ if (!socketRef.current && !isLoadingSocketIo) {
58
+ setIsLoadingSocketIo(true);
59
+ import("socket.io-client").then((socketIoModule) => {
60
+ var _a3, _b3;
61
+ socketIoModuleRef.current = socketIoModule;
62
+ const { io } = socketIoModule;
63
+ const sessionCookie = (_a3 = para == null ? void 0 : para.retrieveSessionCookie) == null ? void 0 : _a3.call(para);
64
+ if (!sessionCookie) {
65
+ setIsLoadingSocketIo(false);
66
+ return;
67
+ }
68
+ socketRef.current = io(socketUrl, {
69
+ transports: ["polling", "websocket"],
70
+ reconnection: true,
71
+ reconnectionAttempts: 5,
72
+ reconnectionDelay: 1e3,
73
+ upgrade: true,
74
+ extraHeaders: {
75
+ [SESSION_COOKIE_HEADER_NAME]: sessionCookie
76
+ }
77
+ });
78
+ socketRef.current.on("connect_error", () => {
79
+ var _a4;
80
+ const sendTx2 = useModalSessionStore.getState().sendTx;
81
+ if ((_a4 = sendTx2 == null ? void 0 : sendTx2.result) == null ? void 0 : _a4.explorerUrl) {
82
+ const _b4 = sendTx2.result, { status: _status } = _b4, rest = __objRest(_b4, ["status"]);
83
+ setSendTx(__spreadProps(__spreadValues({}, sendTx2), {
84
+ result: __spreadValues({}, rest)
85
+ }));
86
+ }
87
+ return;
88
+ });
89
+ socketRef.current.on("tx:error", (error) => {
90
+ console.error("Transaction monitoring error:", error);
91
+ });
92
+ if (((_b3 = subscribedDataRef.current) == null ? void 0 : _b3.txHash) !== subscribeData.txHash) {
93
+ socketRef.current.emit("tx:subscribe", subscribeData);
94
+ subscribedDataRef.current = subscribeData;
95
+ }
96
+ socketRef.current.on("tx:status", (status) => {
97
+ if (!status || typeof status !== "object") {
98
+ return;
99
+ }
100
+ if (!status.status || !["PENDING", "CONFIRMED", "FAILED"].includes(status.status)) {
101
+ return;
102
+ }
103
+ if (status.confirmations !== void 0 && (typeof status.confirmations !== "number" || status.confirmations < 0)) {
104
+ return;
105
+ }
106
+ if (status.blockNumber !== void 0 && (typeof status.blockNumber !== "number" || status.blockNumber < 0)) {
107
+ return;
108
+ }
109
+ const currentSendTx = useModalSessionStore.getState().sendTx;
110
+ if (currentSendTx && currentSendTx.userId === para.userId) {
111
+ const updatedSendTx = __spreadProps(__spreadValues({}, currentSendTx), {
112
+ result: __spreadProps(__spreadValues({}, currentSendTx.result), {
113
+ status: __spreadValues({}, status)
114
+ })
115
+ });
116
+ setSendTx(updatedSendTx);
117
+ }
118
+ });
119
+ setIsLoadingSocketIo(false);
120
+ }).catch((err) => {
121
+ console.error("[useTransactionMonitoring] Failed to load socket.io-client:", err);
122
+ setIsLoadingSocketIo(false);
123
+ });
124
+ }
125
+ if (((_d2 = subscribedDataRef.current) == null ? void 0 : _d2.txHash) !== subscribeData.txHash && socketRef.current) {
126
+ socketRef.current.emit("tx:subscribe", subscribeData);
127
+ subscribedDataRef.current = subscribeData;
128
+ }
129
+ return () => {
130
+ var _a3, _b3;
131
+ if (socketRef.current && ((_a3 = subscribedDataRef.current) == null ? void 0 : _a3.txHash) === subscribeData.txHash) {
132
+ socketRef.current.emit("tx:unsubscribe", subscribedDataRef.current);
133
+ subscribedDataRef.current = null;
134
+ if (!((_b3 = sendTx == null ? void 0 : sendTx.result) == null ? void 0 : _b3.status) || !isConnected) {
135
+ socketRef.current.disconnect();
136
+ socketRef.current = null;
137
+ }
138
+ }
139
+ };
140
+ }, [(_b = sendTx == null ? void 0 : sendTx.result) == null ? void 0 : _b.txHash, (_c = sendTx == null ? void 0 : sendTx.result) == null ? void 0 : _c.network, socketUrl, setSendTx, isConnected, userId, isLoadingSocketIo, para]);
141
+ useEffect(() => {
142
+ return () => {
143
+ if (socketRef.current) {
144
+ socketRef.current.disconnect();
145
+ socketRef.current = null;
146
+ }
147
+ };
148
+ }, []);
149
+ useEffect(() => {
150
+ var _a2, _b2, _c2;
151
+ if (typeof window === "undefined") return;
152
+ const status = (_b2 = (_a2 = sendTx == null ? void 0 : sendTx.result) == null ? void 0 : _a2.status) == null ? void 0 : _b2.status;
153
+ const isCompleted = status === "CONFIRMED" || status === "FAILED";
154
+ const isOnAccountOrMonitor = currentStep === ModalStep.ACCOUNT_MAIN || currentStep === ModalStep.ACCOUNT_MONITOR_TX;
155
+ if (isCompleted && sendTx && !isOnAccountOrMonitor) {
156
+ setSendTx(null);
157
+ return;
158
+ }
159
+ if (isCompleted && currentStep === ModalStep.ACCOUNT_MAIN && ((_c2 = sendTx == null ? void 0 : sendTx.result) == null ? void 0 : _c2.txHash)) {
160
+ const txHash = sendTx.result.txHash;
161
+ const timeoutId = setTimeout(() => {
162
+ var _a3, _b3;
163
+ const sessionState = useModalSessionStore.getState();
164
+ const modalState = useModalStore.getState();
165
+ if (((_b3 = (_a3 = sessionState.sendTx) == null ? void 0 : _a3.result) == null ? void 0 : _b3.txHash) === txHash && modalState.step === ModalStep.ACCOUNT_MAIN) {
166
+ setSendTx(null);
167
+ }
168
+ }, TRANSACTION_CLEANUP_DELAY_MS);
169
+ return () => clearTimeout(timeoutId);
170
+ }
171
+ }, [(_e = (_d = sendTx == null ? void 0 : sendTx.result) == null ? void 0 : _d.status) == null ? void 0 : _e.status, (_f = sendTx == null ? void 0 : sendTx.result) == null ? void 0 : _f.txHash, currentStep, setSendTx]);
172
+ }
173
+ export {
174
+ useTransactionMonitoring
175
+ };
@@ -5,4 +5,4 @@ export { AuthLayout } from './types/modalProps.js';
5
5
  export * from './utils/openPopup.js';
6
6
  export { ON_RAMP_PROVIDERS, ON_RAMP_ASSETS, NETWORKS, getAssetIcon, getAssetCode, getNetworkIcon, getNetworkName, } from '@getpara/react-common';
7
7
  export { SaveRecoverySecret } from './components/RecoverySecretStep/RecoverySecretStep.js';
8
- export * from './utils/validateOnRampConfig.js';
8
+ export * from './utils/onramps.js';
@@ -14,7 +14,7 @@ import {
14
14
  getNetworkName
15
15
  } from "@getpara/react-common";
16
16
  import { SaveRecoverySecret } from "./components/RecoverySecretStep/RecoverySecretStep.js";
17
- export * from "./utils/validateOnRampConfig.js";
17
+ export * from "./utils/onramps.js";
18
18
  export {
19
19
  AuthLayout,
20
20
  ModalStep,
@@ -1 +1,2 @@
1
1
  export * from './modal/useModalStore.js';
2
+ export * from './modal/useModalSessionStore.js';
@@ -1,2 +1,3 @@
1
1
  "use client";
2
2
  export * from "./modal/useModalStore.js";
3
+ export * from "./modal/useModalSessionStore.js";
@@ -139,7 +139,6 @@ const getActions = (set, get) => ({
139
139
  setIsPasskeySupported: (isPasskeySupported) => set({ isPasskeySupported }),
140
140
  setAccountLinkOptions: (accountLinkOptions) => set({ accountLinkOptions }),
141
141
  setProfileWallet: (profileWallet) => set({ profileWallet }),
142
- setSendTx: (sendTx) => set({ sendTx }),
143
142
  setIsTestModeAlertDismissed: (isTestModeAlertDismissed) => set({ isTestModeAlertDismissed })
144
143
  });
145
144
  export {
@@ -0,0 +1,28 @@
1
+ import { BroadcastTransactionResult } from '@getpara/web-sdk';
2
+ import { CreateTransactionOpts } from '@getpara/shared';
3
+ export type SendTx = {
4
+ userId: string;
5
+ walletId: string;
6
+ opts: CreateTransactionOpts;
7
+ transferAmount?: string;
8
+ result?: BroadcastTransactionResult;
9
+ };
10
+ interface ModalSessionState {
11
+ sendTx: SendTx | null;
12
+ }
13
+ interface ModalSessionActions {
14
+ setSendTx: (_: SendTx | null) => void;
15
+ }
16
+ export type ModalSessionStore = ModalSessionState & ModalSessionActions;
17
+ export declare const useModalSessionStore: import("zustand").UseBoundStore<Omit<import("zustand").StoreApi<ModalSessionStore>, "persist"> & {
18
+ persist: {
19
+ setOptions: (options: Partial<import("zustand/middleware").PersistOptions<ModalSessionStore, unknown>>) => void;
20
+ clearStorage: () => void;
21
+ rehydrate: () => Promise<void> | void;
22
+ hasHydrated: () => boolean;
23
+ onHydrate: (fn: (state: ModalSessionStore) => void) => () => void;
24
+ onFinishHydration: (fn: (state: ModalSessionStore) => void) => () => void;
25
+ getOptions: () => Partial<import("zustand/middleware").PersistOptions<ModalSessionStore, unknown>>;
26
+ };
27
+ }>;
28
+ export {};
@@ -0,0 +1,26 @@
1
+ "use client";
2
+ import {
3
+ __spreadProps,
4
+ __spreadValues
5
+ } from "../../../chunk-MMUBH76A.js";
6
+ import { create } from "zustand";
7
+ import { persist, createJSONStorage } from "zustand/middleware";
8
+ import { PARA_STORAGE_PREFIX } from "@getpara/core-sdk";
9
+ const DEFAULT_SESSION_STATE = {
10
+ sendTx: null
11
+ };
12
+ const useModalSessionStore = create()(
13
+ persist(
14
+ (set) => __spreadProps(__spreadValues({}, DEFAULT_SESSION_STATE), {
15
+ setSendTx: (sendTx) => set({ sendTx })
16
+ }),
17
+ {
18
+ version: 1,
19
+ name: `${PARA_STORAGE_PREFIX}modalSessionState`,
20
+ storage: createJSONStorage(() => sessionStorage)
21
+ }
22
+ )
23
+ );
24
+ export {
25
+ useModalSessionStore
26
+ };
@@ -1,6 +1,6 @@
1
1
  import { AvailableWallet } from '@getpara/core-sdk';
2
2
  import { ModalStep } from '../../utils/steps.js';
3
- import { AuthStateLogin, AuthStateSignup, AuthState, AuthStateVerify, OnRampConfig as OnRampConfigBase, OnRampPurchase, TWalletType, Setup2faResponse, SupportedAccountLinks, BroadcastTransactionResult } from '@getpara/web-sdk';
3
+ import { AuthStateLogin, AuthStateSignup, AuthState, AuthStateVerify, OnRampConfig as OnRampConfigBase, OnRampPurchase, TWalletType, Setup2faResponse, SupportedAccountLinks } from '@getpara/web-sdk';
4
4
  import { Tab as AddFundsTabType } from '../../components/AddFunds/AddFundsContext.js';
5
5
  import { TAuthLayout } from '../../types/modalProps.js';
6
6
  import { MutableRefObject } from 'react';
@@ -61,7 +61,6 @@ interface ModalState {
61
61
  isPasskeySupported: boolean;
62
62
  accountLinkOptions: SupportedAccountLinks;
63
63
  profileWallet?: AvailableWallet;
64
- sendTx: BroadcastTransactionResult | null;
65
64
  isTestModeAlertDismissed: boolean;
66
65
  }
67
66
  export interface ModalActions {
@@ -102,7 +101,6 @@ export interface ModalActions {
102
101
  setIsPasskeySupported: (_: boolean) => void;
103
102
  setAccountLinkOptions: (_: SupportedAccountLinks) => void;
104
103
  setProfileWallet: (_?: AvailableWallet) => void;
105
- setSendTx: (_: BroadcastTransactionResult | null) => void;
106
104
  setIsTestModeAlertDismissed: (_: boolean) => void;
107
105
  }
108
106
  export type ModalStore = ModalState & ModalActions;
@@ -50,7 +50,6 @@ const DEFAULT_MODAL_STATE = {
50
50
  isPasskeySupported: true,
51
51
  accountLinkOptions: [...LINKED_ACCOUNT_TYPES],
52
52
  profileWallet: void 0,
53
- sendTx: null,
54
53
  isTestModeAlertDismissed: false
55
54
  };
56
55
  const useModalStore = create()(
@@ -74,7 +74,9 @@ export interface ParaModalProps {
74
74
  */
75
75
  logo?: string;
76
76
  /**
77
- * Whether or not to run configured on-ramp providers in test mode.
77
+ * Whether to run configured on-ramp providers in test mode in the PROD environment.
78
+ *
79
+ * On-ramp and off-ramp widgets will always run in test mode outside of PROD.
78
80
  */
79
81
  onRampTestMode?: boolean;
80
82
  /**
@@ -0,0 +1,61 @@
1
+ import { OnRampConfig, OnRampProvider, OnRampPurchaseType, TNetwork, TOnRampAsset, TWalletType } from '@getpara/web-sdk';
2
+ export declare class OnRampConfigError extends Error {
3
+ constructor(message: string);
4
+ }
5
+ /**
6
+ * Provider-specific transaction amount limits (in USD).
7
+ * These limits are enforced client-side to prevent users from selecting
8
+ * providers that don't support their desired transaction amount.
9
+ *
10
+ * Last verified: February 2025
11
+ * Sources:
12
+ * - MoonPay: https://support.moonpay.com/customers/docs/moonpay-transaction-limits
13
+ * - Stripe: https://docs.stripe.com/crypto/using-the-dashboard#onramp-minimums-and-maximums
14
+ * - Ramp: https://support.ramp.network/en/articles/471-transaction-limits
15
+ */
16
+ export declare const PROVIDER_LIMITS: Record<OnRampProvider, Record<OnRampPurchaseType, {
17
+ min: number | null;
18
+ max: number | null;
19
+ }>>;
20
+ export declare function validateOnRampConfig(obj?: OnRampConfig): obj is OnRampConfig;
21
+ /**
22
+ * Gets a default asset and network combination that are guaranteed to work together.
23
+ *
24
+ * When preferredAsset is provided:
25
+ * - Locks in that asset and finds the best compatible network
26
+ * - Returns { asset: preferredAsset, network: <compatible network> }
27
+ *
28
+ * When preferredAsset is not provided:
29
+ * - Finds the best asset+network combination
30
+ * - Priority order:
31
+ * 1. Partner's defaults (if both are valid together)
32
+ * 2. Wallet-type-specific combo (COSMOS→ATOM on COSMOS, SOLANA→SOL on SOLANA, etc.)
33
+ * 3. First valid asset+network combination from available lists
34
+ *
35
+ * @param params - Configuration object
36
+ * @param params.walletType - The wallet type (EVM, SOLANA, COSMOS)
37
+ * @param params.onRampConfig - OnRamp configuration
38
+ * @param params.networks - Available networks (from getOnRampNetworks)
39
+ * @param params.assets - Available assets (from assets calculation)
40
+ * @param params.preferredAsset - Optional asset to lock in (will only find compatible network)
41
+ * @returns Object with asset and network, both null if no valid combination exists
42
+ */
43
+ export declare function getDefaultAssetAndNetwork({ walletType, onRampConfig, networks, assets, preferredAsset, }: {
44
+ walletType: TWalletType | undefined;
45
+ onRampConfig: OnRampConfig | undefined;
46
+ networks: TNetwork[];
47
+ assets: TOnRampAsset[];
48
+ preferredAsset?: TOnRampAsset | null;
49
+ }): {
50
+ asset: TOnRampAsset | null;
51
+ network: TNetwork | null;
52
+ };
53
+ /**
54
+ * Checks if an amount falls within the provider's limits for a given operation type.
55
+ * @param amount - The amount to check (can be undefined for invalid inputs)
56
+ * @param provider - The provider to check limits for
57
+ * @param type - The transaction type (BUY or SELL)
58
+ * @param limits - Optional provider limits object (defaults to PROVIDER_LIMITS)
59
+ * @returns true if the amount is within limits, false otherwise
60
+ */
61
+ export declare function isAmountWithinProviderLimits(amount: number | undefined, provider: OnRampProvider, type: OnRampPurchaseType, limits?: typeof PROVIDER_LIMITS): boolean;
@@ -0,0 +1,112 @@
1
+ "use client";
2
+ import "../../chunk-MMUBH76A.js";
3
+ import { OnRampProvider, OnRampPurchaseType } from "@getpara/web-sdk";
4
+ class OnRampConfigError extends Error {
5
+ constructor(message) {
6
+ super(`On-ramp configuration error: ${message}.`);
7
+ this.name = "OnRampConfigError";
8
+ }
9
+ }
10
+ const PROVIDER_LIMITS = {
11
+ [OnRampProvider.MOONPAY]: {
12
+ [OnRampPurchaseType.BUY]: { min: 20, max: 3e4 },
13
+ [OnRampPurchaseType.SELL]: { min: 20, max: 1e4 }
14
+ },
15
+ [OnRampProvider.STRIPE]: {
16
+ [OnRampPurchaseType.BUY]: { min: 0.5, max: null },
17
+ [OnRampPurchaseType.SELL]: { min: 0.5, max: null }
18
+ },
19
+ [OnRampProvider.RAMP]: {
20
+ [OnRampPurchaseType.BUY]: { min: null, max: null },
21
+ [OnRampPurchaseType.SELL]: { min: null, max: null }
22
+ }
23
+ };
24
+ function checkHasProviders({ providers }) {
25
+ if (!providers || providers.length < 1) {
26
+ throw new OnRampConfigError("No providers are configured");
27
+ }
28
+ }
29
+ function checkDuplicateProviders({ providers }) {
30
+ if (!providers) return;
31
+ providers.forEach((id, index) => {
32
+ if (providers.findIndex((p) => p === id) !== index) {
33
+ throw new OnRampConfigError(`Provider ${id} is configured more than once`);
34
+ }
35
+ });
36
+ }
37
+ function validateOnRampConfig(obj) {
38
+ if (!obj) {
39
+ return false;
40
+ }
41
+ checkHasProviders(obj);
42
+ checkDuplicateProviders(obj);
43
+ return true;
44
+ }
45
+ function getDefaultAssetAndNetwork({
46
+ walletType,
47
+ onRampConfig,
48
+ networks,
49
+ assets,
50
+ preferredAsset
51
+ }) {
52
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
53
+ if (!walletType || !onRampConfig || networks.length === 0 || assets.length === 0) {
54
+ return { asset: null, network: null };
55
+ }
56
+ if (preferredAsset && assets.includes(preferredAsset)) {
57
+ if (onRampConfig.defaultOnRampNetwork && networks.includes(onRampConfig.defaultOnRampNetwork) && ((_c = (_b = (_a = onRampConfig.assetInfo) == null ? void 0 : _a[walletType]) == null ? void 0 : _b[onRampConfig.defaultOnRampNetwork]) == null ? void 0 : _c[preferredAsset])) {
58
+ return { asset: preferredAsset, network: onRampConfig.defaultOnRampNetwork };
59
+ }
60
+ const preferredNetwork = walletType === "COSMOS" ? "COSMOS" : walletType === "SOLANA" ? "SOLANA" : "ETHEREUM";
61
+ if (networks.includes(preferredNetwork) && ((_f = (_e = (_d = onRampConfig.assetInfo) == null ? void 0 : _d[walletType]) == null ? void 0 : _e[preferredNetwork]) == null ? void 0 : _f[preferredAsset])) {
62
+ return { asset: preferredAsset, network: preferredNetwork };
63
+ }
64
+ const supportedNetwork = networks.find((network) => {
65
+ var _a2, _b2, _c2;
66
+ return !!((_c2 = (_b2 = (_a2 = onRampConfig.assetInfo) == null ? void 0 : _a2[walletType]) == null ? void 0 : _b2[network]) == null ? void 0 : _c2[preferredAsset]);
67
+ });
68
+ if (supportedNetwork) {
69
+ return { asset: preferredAsset, network: supportedNetwork };
70
+ }
71
+ return { asset: preferredAsset, network: null };
72
+ }
73
+ const partnerAsset = onRampConfig.defaultOnRampAsset;
74
+ const partnerNetwork = onRampConfig.defaultOnRampNetwork;
75
+ if (partnerAsset && partnerNetwork && assets.includes(partnerAsset) && networks.includes(partnerNetwork) && ((_i = (_h = (_g = onRampConfig.assetInfo) == null ? void 0 : _g[walletType]) == null ? void 0 : _h[partnerNetwork]) == null ? void 0 : _i[partnerAsset])) {
76
+ return { asset: partnerAsset, network: partnerNetwork };
77
+ }
78
+ const walletTypeAsset = walletType === "COSMOS" ? "ATOM" : walletType === "SOLANA" ? "SOLANA" : "ETHEREUM";
79
+ const walletTypeNetwork = walletType === "COSMOS" ? "COSMOS" : walletType === "SOLANA" ? "SOLANA" : "ETHEREUM";
80
+ if (assets.includes(walletTypeAsset) && networks.includes(walletTypeNetwork) && ((_l = (_k = (_j = onRampConfig.assetInfo) == null ? void 0 : _j[walletType]) == null ? void 0 : _k[walletTypeNetwork]) == null ? void 0 : _l[walletTypeAsset])) {
81
+ return { asset: walletTypeAsset, network: walletTypeNetwork };
82
+ }
83
+ for (const testAsset of assets) {
84
+ if (networks.includes(walletTypeNetwork) && ((_o = (_n = (_m = onRampConfig.assetInfo) == null ? void 0 : _m[walletType]) == null ? void 0 : _n[walletTypeNetwork]) == null ? void 0 : _o[testAsset])) {
85
+ return { asset: testAsset, network: walletTypeNetwork };
86
+ }
87
+ const validNetwork = networks.find((network) => {
88
+ var _a2, _b2, _c2;
89
+ return !!((_c2 = (_b2 = (_a2 = onRampConfig.assetInfo) == null ? void 0 : _a2[walletType]) == null ? void 0 : _b2[network]) == null ? void 0 : _c2[testAsset]);
90
+ });
91
+ if (validNetwork) {
92
+ return { asset: testAsset, network: validNetwork };
93
+ }
94
+ }
95
+ return { asset: null, network: null };
96
+ }
97
+ function isAmountWithinProviderLimits(amount, provider, type, limits = PROVIDER_LIMITS) {
98
+ if (typeof amount !== "number" || isNaN(amount)) {
99
+ return false;
100
+ }
101
+ const { min, max } = limits[provider][type];
102
+ if (min !== null && amount < min) return false;
103
+ if (max !== null && amount > max) return false;
104
+ return true;
105
+ }
106
+ export {
107
+ OnRampConfigError,
108
+ PROVIDER_LIMITS,
109
+ getDefaultAssetAndNetwork,
110
+ isAmountWithinProviderLimits,
111
+ validateOnRampConfig
112
+ };
@@ -50,7 +50,8 @@ export declare enum ModalStep {
50
50
  LINK_EX_WALLET_NETWORK_SELECT = "LINK_EX_WALLET_NETWORK_SELECT",
51
51
  ACCOUNT_SEND = "ACCOUNT_SEND",
52
52
  ACCOUNT_SEND_ASSET = "ACCOUNT_SEND_ASSET",
53
- ACCOUNT_SEND_NETWORK = "ACCOUNT_SEND_NETWORK"
53
+ ACCOUNT_SEND_NETWORK = "ACCOUNT_SEND_NETWORK",
54
+ ACCOUNT_MONITOR_TX = "ACCOUNT_MONITOR_TX"
54
55
  }
55
56
  export type ModalStepPropU = keyof typeof ModalStep | ModalStep;
56
57
  export type ModalStepPropL = Lowercase<ModalStepPropU>;
@@ -79,7 +80,8 @@ declare enum AccountStep {
79
80
  LINK_EX_WALLET_NETWORK_SELECT = "LINK_EX_WALLET_NETWORK_SELECT",
80
81
  ACCOUNT_SEND = "ACCOUNT_SEND",
81
82
  ACCOUNT_SEND_ASSET = "ACCOUNT_SEND_ASSET",
82
- ACCOUNT_SEND_NETWORK = "ACCOUNT_SEND_NETWORK"
83
+ ACCOUNT_SEND_NETWORK = "ACCOUNT_SEND_NETWORK",
84
+ ACCOUNT_MONITOR_TX = "ACCOUNT_MONITOR_TX"
83
85
  }
84
86
  export declare const RESET_TO_AUTH_STEPS: ModalStep[];
85
87
  export declare const RESET_TO_ACCOUNT_STEPS: ModalStep[];
@@ -52,6 +52,7 @@ var ModalStep = /* @__PURE__ */ ((ModalStep2) => {
52
52
  ModalStep2["ACCOUNT_SEND"] = "ACCOUNT_SEND";
53
53
  ModalStep2["ACCOUNT_SEND_ASSET"] = "ACCOUNT_SEND_ASSET";
54
54
  ModalStep2["ACCOUNT_SEND_NETWORK"] = "ACCOUNT_SEND_NETWORK";
55
+ ModalStep2["ACCOUNT_MONITOR_TX"] = "ACCOUNT_MONITOR_TX";
55
56
  return ModalStep2;
56
57
  })(ModalStep || {});
57
58
  var AccountStep = /* @__PURE__ */ ((AccountStep2) => {
@@ -79,6 +80,7 @@ var AccountStep = /* @__PURE__ */ ((AccountStep2) => {
79
80
  AccountStep2["ACCOUNT_SEND"] = "ACCOUNT_SEND";
80
81
  AccountStep2["ACCOUNT_SEND_ASSET"] = "ACCOUNT_SEND_ASSET";
81
82
  AccountStep2["ACCOUNT_SEND_NETWORK"] = "ACCOUNT_SEND_NETWORK";
83
+ AccountStep2["ACCOUNT_MONITOR_TX"] = "ACCOUNT_MONITOR_TX";
82
84
  return AccountStep2;
83
85
  })(AccountStep || {});
84
86
  const RESET_TO_AUTH_STEPS = [
@@ -129,7 +131,8 @@ const RESET_TO_ACCOUNT_STEPS = [
129
131
  "ADD_EX_WALLET_SELECTED" /* ADD_EX_WALLET_SELECTED */,
130
132
  "ADD_EX_WALLET_NETWORK_SELECT" /* ADD_EX_WALLET_NETWORK_SELECT */,
131
133
  "LINK_EX_WALLET_NETWORK_SELECT" /* LINK_EX_WALLET_NETWORK_SELECT */,
132
- "EXTERNAL_WALLET_VERIFICATION" /* EXTERNAL_WALLET_VERIFICATION */
134
+ "EXTERNAL_WALLET_VERIFICATION" /* EXTERNAL_WALLET_VERIFICATION */,
135
+ "ACCOUNT_MONITOR_TX" /* ACCOUNT_MONITOR_TX */
133
136
  ];
134
137
  const AccountPreviousStep = {
135
138
  ["ACCOUNT_MAIN" /* ACCOUNT_MAIN */]: void 0,
@@ -155,7 +158,8 @@ const AccountPreviousStep = {
155
158
  ["LINK_EX_WALLET_NETWORK_SELECT" /* LINK_EX_WALLET_NETWORK_SELECT */]: "ACCOUNT_PROFILE_LIST" /* ACCOUNT_PROFILE_LIST */,
156
159
  ["ACCOUNT_SEND" /* ACCOUNT_SEND */]: "ACCOUNT_MAIN" /* ACCOUNT_MAIN */,
157
160
  ["ACCOUNT_SEND_ASSET" /* ACCOUNT_SEND_ASSET */]: "ACCOUNT_SEND" /* ACCOUNT_SEND */,
158
- ["ACCOUNT_SEND_NETWORK" /* ACCOUNT_SEND_NETWORK */]: "ACCOUNT_SEND_ASSET" /* ACCOUNT_SEND_ASSET */
161
+ ["ACCOUNT_SEND_NETWORK" /* ACCOUNT_SEND_NETWORK */]: "ACCOUNT_SEND_ASSET" /* ACCOUNT_SEND_ASSET */,
162
+ ["ACCOUNT_MONITOR_TX" /* ACCOUNT_MONITOR_TX */]: "ACCOUNT_MAIN" /* ACCOUNT_MAIN */
159
163
  };
160
164
  var SignUpModalStep = /* @__PURE__ */ ((SignUpModalStep2) => {
161
165
  SignUpModalStep2["AUTH_MAIN"] = "AUTH_MAIN";
@@ -1,13 +1,15 @@
1
1
  "use client";
2
2
  import {
3
- __async
3
+ __async,
4
+ __spreadProps,
5
+ __spreadValues
4
6
  } from "../../../chunk-MMUBH76A.js";
5
7
  import { useQuery } from "@tanstack/react-query";
6
- import { useRef, useEffect } from "react";
8
+ import { useRef, useEffect, useMemo } from "react";
7
9
  import { useStore } from "../../stores/useStore.js";
8
10
  import { useInternalClient } from "../utils/useInternalClient.js";
9
11
  import { useIsFullyLoggedIn } from "./useIsFullyLoggedIn.js";
10
- import { filterProfileBalance } from "@getpara/shared";
12
+ import { filterProfileBalance, formatCurrency } from "@getpara/shared";
11
13
  const useProfileBalance = (options) => {
12
14
  var _a, _b, _c;
13
15
  const client = useInternalClient();
@@ -17,6 +19,7 @@ const useProfileBalance = (options) => {
17
19
  return (_a2 = state.modalConfig) == null ? void 0 : _a2.balances;
18
20
  });
19
21
  const refs = useStore((state) => state.refs);
22
+ const balanceOverrides = useStore((state) => state.balanceOverrides);
20
23
  const isComprehensive = (_a = options == null ? void 0 : options.isComprehensive) != null ? _a : false;
21
24
  const previousTriggerRef = useRef(options == null ? void 0 : options.refetchTrigger);
22
25
  const shouldRefetchRef = useRef(false);
@@ -28,8 +31,10 @@ const useProfileBalance = (options) => {
28
31
  previousTriggerRef.current = options == null ? void 0 : options.refetchTrigger;
29
32
  }
30
33
  }, [options == null ? void 0 : options.refetchTrigger]);
31
- return useQuery({
32
- enabled: isSuccess && !!client,
34
+ const requiresOverrides = (config == null ? void 0 : config.useBalanceOverrides) && (config == null ? void 0 : config.displayType) === "AGGREGATED";
35
+ const shouldUseOverrides = requiresOverrides && !!balanceOverrides;
36
+ const query = useQuery({
37
+ enabled: isSuccess && !!client && (!requiresOverrides || !!balanceOverrides),
33
38
  queryKey: [
34
39
  "useProfileBalance",
35
40
  isFullyLoggedIn != null ? isFullyLoggedIn : null,
@@ -56,9 +61,31 @@ const useProfileBalance = (options) => {
56
61
  isInitialLoadRef.current = false;
57
62
  return isComprehensive ? profileBalance : filterProfileBalance(profileBalance, config || { displayType: "AGGREGATED" });
58
63
  }),
59
- // We handle refetch manually
60
64
  refetchOnWindowFocus: false
61
65
  });
66
+ const data = useMemo(() => {
67
+ var _a2;
68
+ const raw = query.data;
69
+ if (!raw || !shouldUseOverrides) return raw;
70
+ const overrides = balanceOverrides.value;
71
+ const result = structuredClone(raw);
72
+ for (const [walletAddress, override] of Object.entries(overrides)) {
73
+ const wallet = result.wallets.find((w) => w.address === walletAddress);
74
+ if (((_a2 = wallet == null ? void 0 : wallet.value) == null ? void 0 : _a2.value) === void 0) continue;
75
+ if (typeof override !== "number" || !Number.isFinite(override)) continue;
76
+ wallet.value.value = override;
77
+ wallet.formattedValue = formatCurrency(wallet.value);
78
+ }
79
+ if (result.value) {
80
+ result.value.value = result.wallets.reduce((sum, wallet) => {
81
+ var _a3, _b2;
82
+ return sum + ((_b2 = (_a3 = wallet.value) == null ? void 0 : _a3.value) != null ? _b2 : 0);
83
+ }, 0);
84
+ result.formattedValue = formatCurrency(result.value);
85
+ }
86
+ return result;
87
+ }, [query.data, shouldUseOverrides, balanceOverrides == null ? void 0 : balanceOverrides.version]);
88
+ return __spreadProps(__spreadValues({}, query), { data: data != null ? data : void 0 });
62
89
  };
63
90
  export {
64
91
  useProfileBalance
@@ -1,3 +1,4 @@
1
1
  export { useClient } from './useClient.js';
2
2
  export { useModal } from './useModal.js';
3
3
  export { useWalletState } from './useWalletState.js';
4
+ export { useSetBalanceOverrides } from './useSetBalanceOverrides.js';
@@ -3,8 +3,10 @@ import "../../../chunk-MMUBH76A.js";
3
3
  import { useClient } from "./useClient.js";
4
4
  import { useModal } from "./useModal.js";
5
5
  import { useWalletState } from "./useWalletState.js";
6
+ import { useSetBalanceOverrides } from "./useSetBalanceOverrides.js";
6
7
  export {
7
8
  useClient,
8
9
  useModal,
10
+ useSetBalanceOverrides,
9
11
  useWalletState
10
12
  };
@@ -11,7 +11,7 @@ import { ACCOUNT_BASE_KEY } from "../queries/useAccount.js";
11
11
  import { WALLET_BASE_KEY } from "../queries/useWallet.js";
12
12
  import { WALLET_BALANCE_BASE_KEY } from "../queries/useWalletBalance.js";
13
13
  import { IS_FULLY_LOGGED_IN_BASE_KEY } from "../queries/useIsFullyLoggedIn.js";
14
- import { useModalStore } from "../../../modal/stores/index.js";
14
+ import { useModalSessionStore } from "../../../modal/stores/index.js";
15
15
  const useEventListeners = ({
16
16
  onLogin,
17
17
  onLogout,
@@ -29,7 +29,7 @@ const useEventListeners = ({
29
29
  const refs = useStore((state) => state.refs);
30
30
  const clearSelectedWallet = useStore((state) => state.clearSelectedWallet);
31
31
  const { updateSelectedWallet } = useWalletState();
32
- const setSendTx = useModalStore((state) => state.setSendTx);
32
+ const setSendTx = useModalSessionStore((state) => state.setSendTx);
33
33
  const loginOrSetupListener = useCallback(() => {
34
34
  queryClient.refetchQueries({ queryKey: [IS_FULLY_LOGGED_IN_BASE_KEY] });
35
35
  queryClient.refetchQueries({ queryKey: [ACCOUNT_BASE_KEY] });