@getpara/react-sdk-lite 2.10.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 (40) 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.js +70 -25
  10. package/dist/modal/components/AddFunds/AddFundsReceive.js +1 -1
  11. package/dist/modal/components/AddFunds/AddFundsSettings.js +134 -29
  12. package/dist/modal/components/Body/Body.js +4 -0
  13. package/dist/modal/components/ErrorBoundary.d.ts +20 -0
  14. package/dist/modal/components/ErrorBoundary.js +27 -0
  15. package/dist/modal/components/OnRampComponents/OnRampProviderButton.js +3 -8
  16. package/dist/modal/components/common.d.ts +5 -1
  17. package/dist/modal/components/common.js +27 -1
  18. package/dist/modal/hooks/index.d.ts +1 -0
  19. package/dist/modal/hooks/index.js +1 -0
  20. package/dist/modal/hooks/useSendMutations.d.ts +51 -0
  21. package/dist/modal/hooks/useSendMutations.js +170 -0
  22. package/dist/modal/hooks/useTransactionMonitoring.d.ts +1 -0
  23. package/dist/modal/hooks/useTransactionMonitoring.js +175 -0
  24. package/dist/modal/index.d.ts +1 -1
  25. package/dist/modal/index.js +1 -1
  26. package/dist/modal/stores/index.d.ts +1 -0
  27. package/dist/modal/stores/index.js +1 -0
  28. package/dist/modal/stores/modal/actions.js +0 -1
  29. package/dist/modal/stores/modal/useModalSessionStore.d.ts +28 -0
  30. package/dist/modal/stores/modal/useModalSessionStore.js +26 -0
  31. package/dist/modal/stores/modal/useModalStore.d.ts +1 -3
  32. package/dist/modal/stores/modal/useModalStore.js +0 -1
  33. package/dist/modal/utils/onramps.d.ts +61 -0
  34. package/dist/modal/utils/onramps.js +112 -0
  35. package/dist/modal/utils/steps.d.ts +4 -2
  36. package/dist/modal/utils/steps.js +6 -2
  37. package/dist/provider/hooks/utils/useEventListeners.js +2 -2
  38. package/package.json +9 -8
  39. package/dist/modal/utils/validateOnRampConfig.d.ts +0 -5
  40. package/dist/modal/utils/validateOnRampConfig.js +0 -32
@@ -0,0 +1,27 @@
1
+ "use client";
2
+ import "../../chunk-MMUBH76A.js";
3
+ import { Component } from "react";
4
+ class ErrorBoundary extends Component {
5
+ constructor(props) {
6
+ super(props);
7
+ this.state = { hasError: false };
8
+ }
9
+ static getDerivedStateFromError() {
10
+ return { hasError: true };
11
+ }
12
+ componentDidCatch(error, errorInfo) {
13
+ var _a, _b;
14
+ console.error("[ErrorBoundary] Caught error:", error, errorInfo);
15
+ (_b = (_a = this.props).onError) == null ? void 0 : _b.call(_a, error, errorInfo);
16
+ }
17
+ render() {
18
+ var _a;
19
+ if (this.state.hasError) {
20
+ return (_a = this.props.fallback) != null ? _a : null;
21
+ }
22
+ return this.props.children;
23
+ }
24
+ }
25
+ export {
26
+ ErrorBoundary
27
+ };
@@ -16,10 +16,10 @@ const OnRampProviderButton = ({ config, index, onClick: _onClick }) => {
16
16
  return /* @__PURE__ */ jsx(StyledButton, { variant: "tertiary", fullWidth: true, onClick, children: /* @__PURE__ */ jsxs(Container, { children: [
17
17
  /* @__PURE__ */ jsx(IconContainer, { children: /* @__PURE__ */ jsx(CpslIcon, { icon, color: backgroundColors[0] }) }),
18
18
  /* @__PURE__ */ jsxs(ProviderInfoContainer, { children: [
19
- /* @__PURE__ */ jsx(Text, { variant: "bodyL", weight: "medium", children: name }),
19
+ /* @__PURE__ */ jsx(CpslText, { variant: "bodyL", weight: "medium", children: name }),
20
20
  /* @__PURE__ */ jsxs(ProviderInfoInnerContainer, { children: [
21
- /* @__PURE__ */ jsx(Text, { variant: "bodyXS", weight: "medium", children: methods.join(", ") }),
22
- /* @__PURE__ */ jsx(Text, { variant: "bodyXS", weight: "medium", children: feeString })
21
+ /* @__PURE__ */ jsx(CpslText, { variant: "bodyXS", weight: "medium", children: methods.join(", ") }),
22
+ /* @__PURE__ */ jsx(CpslText, { variant: "bodyXS", weight: "medium", children: feeString })
23
23
  ] })
24
24
  ] })
25
25
  ] }) });
@@ -57,11 +57,6 @@ const IconContainer = safeStyled.span`
57
57
  width: 48px;
58
58
  flex-shrink: 0;
59
59
  `;
60
- const Text = safeStyled(CpslText)`
61
- &::part(text-element) {
62
- color: #fff;
63
- }
64
- `;
65
60
  export {
66
61
  OnRampProviderButton
67
62
  };
@@ -1,6 +1,6 @@
1
1
  import { CpslInput, CpslText, CpslTileButton } from '@getpara/react-components';
2
2
  import { TLinkedAccountType, TNetwork, TOnRampAsset } from '@getpara/web-sdk';
3
- import { ComponentProps, PropsWithChildren } from 'react';
3
+ import { ComponentProps, PropsWithChildren, ReactNode } from 'react';
4
4
  export declare const SpinnerContainer: import("styled-components/dist/types.js").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
5
5
  export declare const QRContainer: import("styled-components/dist/types.js").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
6
6
  export declare const InfoBoxContent: import("styled-components/dist/types.js").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
@@ -59,6 +59,10 @@ export declare function GradientScroll({ height, gap, children }: PropsWithChild
59
59
  export declare const HeroGenericIcon: ({ accountType }: {
60
60
  accountType: "EMAIL" | "PHONE";
61
61
  }) => import("react/jsx-runtime").JSX.Element;
62
+ export declare const ExplorerLink: ({ href, text }: {
63
+ href: string;
64
+ text: ReactNode;
65
+ }) => import("react/jsx-runtime").JSX.Element;
62
66
  export * from './SearchableButtonList.js';
63
67
  export * from './QuantityInput.js';
64
68
  export { AnimatedHeightWrapper } from './Body/AnimatedHeightWrapper.js';
@@ -4,7 +4,7 @@ import {
4
4
  __spreadProps,
5
5
  __spreadValues
6
6
  } from "../../chunk-MMUBH76A.js";
7
- import { jsx } from "react/jsx-runtime";
7
+ import { jsx, jsxs } from "react/jsx-runtime";
8
8
  import { CpslIcon, CpslInput, CpslSelect, CpslSelectItem, CpslText, CpslTileButton } from "@getpara/react-components";
9
9
  import { ACCOUNT_TYPES, safeStyled, MOBILE_SIZE, NETWORKS, ON_RAMP_ASSETS } from "@getpara/react-common";
10
10
  import { useStore } from "../../provider/stores/useStore.js";
@@ -276,6 +276,31 @@ const Avatar = safeStyled.div`
276
276
  justify-content: center;
277
277
  background-color: var(--cpsl-color-background-8);
278
278
  `;
279
+ const ExplorerLinkBase = safeStyled.a`
280
+ font-family: var(--cpsl-font-family);
281
+ font-size: 14px;
282
+ position: relative;
283
+ display: flex;
284
+ align-items: center;
285
+ justify-content: center;
286
+ width: 100%;
287
+ background: transparent;
288
+ border: none;
289
+ cursor: pointer;
290
+ color: var(--cpsl-color-text-primary);
291
+ --icon-color: var(--cpsl-color-text-primary);
292
+
293
+ &:hover {
294
+ color: var(--cpsl-color-text-contrast);
295
+ --icon-color: var(--cpsl-color-text-contrast);
296
+ }
297
+ `;
298
+ const ExplorerLink = ({ href, text }) => {
299
+ return /* @__PURE__ */ jsxs(ExplorerLinkBase, { target: "_blank", href, rel: "noopener noreferrer", children: [
300
+ /* @__PURE__ */ jsx("span", { children: text }),
301
+ /* @__PURE__ */ jsx(CpslIcon, { icon: "externalLink", size: "16px", style: { marginLeft: "6px" } })
302
+ ] });
303
+ };
279
304
  export * from "./SearchableButtonList.js";
280
305
  export * from "./QuantityInput.js";
281
306
  import { AnimatedHeightWrapper } from "./Body/AnimatedHeightWrapper.js";
@@ -286,6 +311,7 @@ export {
286
311
  CenteredText,
287
312
  ErrorContainer,
288
313
  ErrorIcon,
314
+ ExplorerLink,
289
315
  FilledDisabledInput,
290
316
  FullWidthFilledDisabledInput,
291
317
  GradientScroll,
@@ -1,4 +1,5 @@
1
1
  export * from './useDebounce.js';
2
2
  export * from './useFarcasterLogin.js';
3
3
  export * from './useGoBack.js';
4
+ export * from './useSendMutations.js';
4
5
  export * from './useTelegramLogin.js';
@@ -2,4 +2,5 @@
2
2
  export * from "./useDebounce.js";
3
3
  export * from "./useFarcasterLogin.js";
4
4
  export * from "./useGoBack.js";
5
+ export * from "./useSendMutations.js";
5
6
  export * from "./useTelegramLogin.js";
@@ -0,0 +1,51 @@
1
+ import { BroadcastTransactionResult, EstimateTransactionResult } from '@getpara/web-sdk';
2
+ import { EstimateTransactionOpts, NetworkDefinition, RpcMetadata, TransactionType } from '@getpara/shared';
3
+ type BroadcastOpts = Omit<NetworkDefinition, 'type'> & {
4
+ userId: string;
5
+ walletId: string;
6
+ walletAddress: string;
7
+ walletType: TransactionType;
8
+ txSerialized: string;
9
+ message?: string;
10
+ txUrlFormat?: string;
11
+ rpc?: RpcMetadata;
12
+ simulateFailure?: boolean;
13
+ };
14
+ export declare function useSendMutations({ estimateOnSuccess, estimateOnError, broadcastOnSuccess, broadcastOnError, }: {
15
+ estimateOnSuccess: (data: EstimateTransactionResult) => void;
16
+ estimateOnError: (error: Error) => void;
17
+ broadcastOnSuccess?: (data: BroadcastTransactionResult) => void;
18
+ broadcastOnError: (error: Error) => void;
19
+ }): {
20
+ estimateMutate: import("@tanstack/react-query").UseMutateFunction<Partial<{
21
+ result: Pick<import("@getpara/shared").CreateTransactionSuccess, "txSerialized" | "message">;
22
+ error: import("@getpara/shared").TransactionError;
23
+ feeAmount: string;
24
+ feeValue: string;
25
+ transferAmount: string;
26
+ transferValue: string;
27
+ }> | null, Error, {
28
+ userId: string;
29
+ walletId: string;
30
+ opts: EstimateTransactionOpts;
31
+ }, unknown>;
32
+ estimateMutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<Partial<{
33
+ result: Pick<import("@getpara/shared").CreateTransactionSuccess, "txSerialized" | "message">;
34
+ error: import("@getpara/shared").TransactionError;
35
+ feeAmount: string;
36
+ feeValue: string;
37
+ transferAmount: string;
38
+ transferValue: string;
39
+ }> | null, Error, {
40
+ userId: string;
41
+ walletId: string;
42
+ opts: EstimateTransactionOpts;
43
+ }, unknown>;
44
+ broadcastMutate: import("@tanstack/react-query").UseMutateFunction<BroadcastTransactionResult | null, Error, BroadcastOpts, unknown>;
45
+ broadcastMutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<BroadcastTransactionResult | null, Error, BroadcastOpts, unknown>;
46
+ estimateIsPending: boolean;
47
+ estimateIsError: boolean;
48
+ broadcastIsPending: boolean;
49
+ broadcastIsError: boolean;
50
+ };
51
+ export {};
@@ -0,0 +1,170 @@
1
+ "use client";
2
+ import {
3
+ __async,
4
+ __spreadProps,
5
+ __spreadValues
6
+ } from "../../chunk-MMUBH76A.js";
7
+ import { useMutation, useQueryClient } from "@tanstack/react-query";
8
+ import { useInternalClient } from "../../provider/hooks/utils/useInternalClient.js";
9
+ import { useModalStore, useModalSessionStore } from "../stores/index.js";
10
+ import { useSignMessage, useSignTransaction, useWalletState } from "../../provider/index.js";
11
+ import {
12
+ hexStringToBase64
13
+ } from "@getpara/web-sdk";
14
+ import { useMemo, useCallback } from "react";
15
+ import { ModalStep } from "../utils/steps.js";
16
+ import { useStore } from "../../provider/stores/useStore.js";
17
+ function useSendMutations({
18
+ estimateOnSuccess,
19
+ estimateOnError,
20
+ broadcastOnSuccess,
21
+ broadcastOnError
22
+ }) {
23
+ const para = useInternalClient();
24
+ const setStep = useModalStore((state) => state.setStep);
25
+ const setSendTx = useModalSessionStore((state) => state.setSendTx);
26
+ const { signTransactionAsync } = useSignTransaction();
27
+ const { signMessageAsync } = useSignMessage();
28
+ const { selectedWallet } = useWalletState();
29
+ const queryClient = useQueryClient();
30
+ const refs = useStore((state) => state.refs);
31
+ const defaultBroadcastOnSuccess = useCallback(
32
+ (data) => {
33
+ if (!!(data == null ? void 0 : data.error)) {
34
+ return;
35
+ } else if (!!data) {
36
+ const currentSendTx = useModalSessionStore.getState().sendTx;
37
+ if (currentSendTx) {
38
+ setSendTx(__spreadProps(__spreadValues({}, currentSendTx), { result: data }));
39
+ }
40
+ setStep(ModalStep.ACCOUNT_MAIN);
41
+ refs.balancesInvalidationTime.current = Date.now();
42
+ queryClient.invalidateQueries({
43
+ queryKey: ["useProfileBalance"],
44
+ refetchType: "active"
45
+ });
46
+ }
47
+ },
48
+ [setSendTx, setStep, queryClient, refs]
49
+ );
50
+ const handleBroadcastSuccess = useCallback(
51
+ (data) => {
52
+ defaultBroadcastOnSuccess(data);
53
+ broadcastOnSuccess == null ? void 0 : broadcastOnSuccess(data);
54
+ },
55
+ [defaultBroadcastOnSuccess, broadcastOnSuccess]
56
+ );
57
+ const {
58
+ mutate: estimateMutate,
59
+ mutateAsync: estimateMutateAsync,
60
+ isPending: estimateIsPending,
61
+ isError: estimateIsError
62
+ } = useMutation({
63
+ mutationKey: ["estimate-tx"],
64
+ mutationFn: (_0) => __async(this, [_0], function* ({ userId, walletId, opts }) {
65
+ if (!para.userId || !selectedWallet.id) {
66
+ return null;
67
+ }
68
+ const result = yield para.ctx.client.estimateSendTransaction({
69
+ userId,
70
+ walletId,
71
+ opts
72
+ });
73
+ return result;
74
+ }),
75
+ onSuccess: (data, variables) => {
76
+ setSendTx(__spreadValues({}, variables));
77
+ estimateOnSuccess(data);
78
+ },
79
+ onError: estimateOnError
80
+ });
81
+ const {
82
+ mutate: broadcastMutate,
83
+ mutateAsync: broadcastMutateAsync,
84
+ isPending: broadcastIsPending,
85
+ isError: broadcastIsError
86
+ } = useMutation({
87
+ mutationKey: ["broadcast-tx"],
88
+ mutationFn: (_0) => __async(this, [_0], function* ({
89
+ userId,
90
+ walletId,
91
+ walletAddress,
92
+ walletType,
93
+ txSerialized,
94
+ message,
95
+ evmChainId,
96
+ isDevnet,
97
+ txUrlFormat,
98
+ rpc,
99
+ simulateFailure
100
+ }) {
101
+ var _a, _b;
102
+ if (!para.userId || !selectedWallet.id) {
103
+ return null;
104
+ }
105
+ let signature;
106
+ switch (walletType) {
107
+ case "SOLANA":
108
+ signature = (_a = yield signMessageAsync({
109
+ walletId,
110
+ messageBase64: message
111
+ })) == null ? void 0 : _a.signature;
112
+ break;
113
+ case "EVM":
114
+ default:
115
+ signature = (_b = yield signTransactionAsync({
116
+ walletId,
117
+ rlpEncodedTxBase64: hexStringToBase64(txSerialized),
118
+ chainId: evmChainId
119
+ })) == null ? void 0 : _b.signature;
120
+ if (!!signature) {
121
+ signature = `0x${signature}`;
122
+ }
123
+ break;
124
+ }
125
+ const result = yield para.ctx.client.broadcastSendTransaction({
126
+ userId,
127
+ walletId,
128
+ opts: {
129
+ type: walletType,
130
+ evmChainId,
131
+ isDevnet,
132
+ tx: txSerialized,
133
+ signature,
134
+ sourceAddress: walletAddress,
135
+ txUrlFormat,
136
+ rpc,
137
+ simulateFailure
138
+ }
139
+ });
140
+ return result;
141
+ }),
142
+ onSuccess: handleBroadcastSuccess,
143
+ onError: broadcastOnError
144
+ });
145
+ return useMemo(
146
+ () => ({
147
+ estimateMutate,
148
+ estimateMutateAsync,
149
+ broadcastMutate,
150
+ broadcastMutateAsync,
151
+ estimateIsPending,
152
+ estimateIsError,
153
+ broadcastIsPending,
154
+ broadcastIsError
155
+ }),
156
+ [
157
+ estimateMutate,
158
+ estimateMutateAsync,
159
+ broadcastMutate,
160
+ broadcastMutateAsync,
161
+ estimateIsPending,
162
+ estimateIsError,
163
+ broadcastIsPending,
164
+ broadcastIsError
165
+ ]
166
+ );
167
+ }
168
+ export {
169
+ useSendMutations
170
+ };
@@ -0,0 +1 @@
1
+ export declare function useTransactionMonitoring(): void;
@@ -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()(