@getpara/react-sdk-lite 2.0.0-alpha.71 → 2.0.0-alpha.73

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 (49) hide show
  1. package/dist/cli/cli.mjs +26 -1
  2. package/dist/modal/components/Account/Account.js +39 -2
  3. package/dist/modal/components/Account/AccountSend/AccountSendAsset.d.ts +1 -0
  4. package/dist/modal/components/Account/AccountSend/AccountSendAsset.js +94 -0
  5. package/dist/modal/components/Account/AccountSend/AccountSendForm.d.ts +1 -0
  6. package/dist/modal/components/Account/AccountSend/AccountSendForm.js +343 -0
  7. package/dist/modal/components/Account/AccountSend/AccountSendNetwork.d.ts +1 -0
  8. package/dist/modal/components/Account/AccountSend/AccountSendNetwork.js +53 -0
  9. package/dist/modal/components/Account/AccountSend/AccountSendNoAssets.d.ts +1 -0
  10. package/dist/modal/components/Account/AccountSend/AccountSendNoAssets.js +56 -0
  11. package/dist/modal/components/Account/AccountSend/AssetNetwork.d.ts +5 -0
  12. package/dist/modal/components/Account/AccountSend/AssetNetwork.js +36 -0
  13. package/dist/modal/components/Account/AccountSend/context.d.ts +38 -0
  14. package/dist/modal/components/Account/AccountSend/context.js +418 -0
  15. package/dist/modal/components/Account/AccountSend/index.d.ts +4 -0
  16. package/dist/modal/components/Account/AccountSend/index.js +67 -0
  17. package/dist/modal/components/AddFunds/AddFundsAsset.js +1 -2
  18. package/dist/modal/components/AddFunds/AddFundsProvider.js +1 -2
  19. package/dist/modal/components/AddFunds/AddFundsSettings.js +12 -52
  20. package/dist/modal/components/AddFunds/common.d.ts +0 -14
  21. package/dist/modal/components/AddFunds/common.js +1 -8
  22. package/dist/modal/components/Body/Body.js +13 -13
  23. package/dist/modal/components/Header/hooks/useStepTitle.js +4 -1
  24. package/dist/modal/components/IFrameStep/IFrameStep.js +1 -1
  25. package/dist/modal/components/QuantityInput.d.ts +9 -0
  26. package/dist/modal/components/QuantityInput.js +91 -0
  27. package/dist/modal/components/SearchableButtonList.d.ts +34 -0
  28. package/dist/modal/components/SearchableButtonList.js +223 -0
  29. package/dist/modal/components/WalletSelectOld/WalletSelectOld.d.ts +7 -1
  30. package/dist/modal/components/WalletSelectOld/WalletSelectOld.js +16 -7
  31. package/dist/modal/components/common.d.ts +4 -1
  32. package/dist/modal/components/common.js +14 -1
  33. package/dist/modal/hooks/index.d.ts +4 -0
  34. package/dist/modal/hooks/index.js +5 -0
  35. package/dist/modal/hooks/useDebounce.d.ts +4 -0
  36. package/dist/modal/hooks/useDebounce.js +16 -0
  37. package/dist/modal/stores/modal/actions.js +2 -1
  38. package/dist/modal/stores/modal/useModalStore.d.ts +3 -1
  39. package/dist/modal/stores/modal/useModalStore.js +2 -1
  40. package/dist/modal/utils/countryCodes.js +11 -1
  41. package/dist/modal/utils/steps.d.ts +8 -2
  42. package/dist/modal/utils/steps.js +13 -1
  43. package/dist/provider/hooks/queries/useAccount.js +53 -20
  44. package/dist/provider/hooks/queries/useProfileBalance.d.ts +4 -0
  45. package/dist/provider/hooks/queries/useProfileBalance.js +10 -5
  46. package/dist/provider/hooks/utils/useEventListeners.js +4 -1
  47. package/dist/provider/hooks/utils/useWalletState.d.ts +1 -0
  48. package/dist/provider/hooks/utils/useWalletState.js +2 -1
  49. package/package.json +8 -8
@@ -0,0 +1,5 @@
1
+ export declare function AssetNetwork({ size, assetSrc, networkSrc, }: {
2
+ size?: number;
3
+ assetSrc?: string;
4
+ networkSrc?: string;
5
+ }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,36 @@
1
+ "use client";
2
+ import "../../../../chunk-MMUBH76A.js";
3
+ import { jsx, jsxs } from "react/jsx-runtime";
4
+ import { CpslIcon } from "@getpara/react-components";
5
+ function AssetNetwork({
6
+ size = 40,
7
+ assetSrc,
8
+ networkSrc
9
+ }) {
10
+ return /* @__PURE__ */ jsxs("div", { style: { position: "relative", width: `${size}px`, height: `${size}px` }, children: [
11
+ assetSrc ? /* @__PURE__ */ jsx(CpslIcon, { radius: "full", src: assetSrc, size: `${size}px` }) : /* @__PURE__ */ jsx(
12
+ CpslIcon,
13
+ {
14
+ icon: "coins",
15
+ radius: "full",
16
+ size: `${size}px`,
17
+ inset: `${size / 8}px`,
18
+ color: "var(--cpsl-color-text-contrast)",
19
+ background: "var(--cpsl-color-accent-64)"
20
+ }
21
+ ),
22
+ networkSrc && /* @__PURE__ */ jsx(
23
+ CpslIcon,
24
+ {
25
+ radius: "full",
26
+ src: networkSrc,
27
+ size: `${2 + size * 3 / 8}px`,
28
+ border: "1px solid var(--cpsl-color-background-4)",
29
+ style: { position: "absolute", bottom: 0, right: 0 }
30
+ }
31
+ )
32
+ ] });
33
+ }
34
+ export {
35
+ AssetNetwork
36
+ };
@@ -0,0 +1,38 @@
1
+ import { Dispatch, PropsWithChildren, SetStateAction } from 'react';
2
+ import { AssetValue, BroadcastTransactionResult, EstimateTransactionResult, WalletBalance } from '@getpara/shared';
3
+ export type SendStep = 'SEND_FORM' | 'SEND_ASSET' | 'SEND_NETWORK';
4
+ type SendMetadata = {
5
+ asset: WalletBalance['assets'][number] | null;
6
+ network: WalletBalance['assets'][number]['networks'][number] | null;
7
+ };
8
+ type OptionsType = 'MULTIPLE' | 'SINGLE_ASSET' | 'SINGLE_NETWORK' | 'NONE';
9
+ type Value = {
10
+ step: SendStep;
11
+ sendMetadata: SendMetadata;
12
+ setSendMetadata: Dispatch<SetStateAction<SendMetadata>>;
13
+ assetPrice: AssetValue | null;
14
+ assetValueOnNetwork: AssetValue | null;
15
+ assetAmountOnNetwork: number;
16
+ destinationAddress: string;
17
+ setDestinationAddress: Dispatch<SetStateAction<string>>;
18
+ transferValue: number;
19
+ setTransferValue: Dispatch<SetStateAction<number>>;
20
+ transferAmount: number;
21
+ setTransferAmount: Dispatch<SetStateAction<number>>;
22
+ estimate: EstimateTransactionResult | null;
23
+ isMax: boolean;
24
+ setIsMax: Dispatch<SetStateAction<boolean>>;
25
+ estimateIsPending: boolean;
26
+ estimateIsError: boolean;
27
+ onSubmit: () => void;
28
+ broadcast: BroadcastTransactionResult | null;
29
+ broadcastIsPending: boolean;
30
+ broadcastIsError: boolean;
31
+ optionsType: OptionsType;
32
+ };
33
+ export declare const AccountSendContext: import("react").Context<Value>;
34
+ export declare function AccountSendProvider({ children, step }: PropsWithChildren<{
35
+ step: SendStep;
36
+ }>): import("react/jsx-runtime").JSX.Element;
37
+ export declare const useSend: () => Value;
38
+ export {};
@@ -0,0 +1,418 @@
1
+ "use client";
2
+ import {
3
+ __async,
4
+ __spreadProps,
5
+ __spreadValues
6
+ } from "../../../../chunk-MMUBH76A.js";
7
+ import { jsx } from "react/jsx-runtime";
8
+ import {
9
+ createContext,
10
+ useCallback,
11
+ useContext,
12
+ useEffect,
13
+ useMemo,
14
+ useRef,
15
+ useState
16
+ } from "react";
17
+ import { useMutation, useQueryClient } from "@tanstack/react-query";
18
+ 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";
23
+ import { useStore } from "../../../../provider/stores/useStore.js";
24
+ const getDefaultSendMetadata = (balances, wallet) => {
25
+ if (!balances || !(wallet == null ? void 0 : wallet.type) || !(wallet == null ? void 0 : wallet.address) || (wallet == null ? void 0 : wallet.type) === "COSMOS") {
26
+ return { asset: null, network: null };
27
+ }
28
+ const walletBalance = balances.wallets.find(({ address }) => address === (wallet == null ? void 0 : wallet.address));
29
+ if (!walletBalance) {
30
+ return { asset: null, network: null };
31
+ }
32
+ const defaultAsset = walletBalance.assets.find(
33
+ ({ metadata }) => (metadata == null ? void 0 : metadata.symbol) === ((wallet == null ? void 0 : wallet.type) === "EVM" ? "ETH" : "SOL")
34
+ );
35
+ if (!defaultAsset) {
36
+ return { asset: null, network: null };
37
+ }
38
+ const defaultNetwork = defaultAsset.networks[0] || null;
39
+ return { asset: defaultAsset, network: defaultNetwork };
40
+ };
41
+ const getTransferAmount = (sendMetadata, transferValue) => {
42
+ var _a, _b, _c, _d, _e;
43
+ const isPriced = ((_b = (_a = sendMetadata == null ? void 0 : sendMetadata.asset) == null ? void 0 : _a.metadata) == null ? void 0 : _b.price) !== void 0 && ((_e = (_d = (_c = sendMetadata == null ? void 0 : sendMetadata.asset) == null ? void 0 : _c.metadata) == null ? void 0 : _d.price) == null ? void 0 : _e.value) > 0;
44
+ if (isPriced) {
45
+ return transferValue / sendMetadata.asset.metadata.price.value;
46
+ }
47
+ return 0;
48
+ };
49
+ const getTransferValue = (sendMetadata, transferAmount) => {
50
+ var _a, _b, _c, _d, _e;
51
+ const isPriced = ((_b = (_a = sendMetadata == null ? void 0 : sendMetadata.asset) == null ? void 0 : _a.metadata) == null ? void 0 : _b.price) !== void 0 && ((_e = (_d = (_c = sendMetadata == null ? void 0 : sendMetadata.asset) == null ? void 0 : _c.metadata) == null ? void 0 : _d.price) == null ? void 0 : _e.value) > 0;
52
+ if (isPriced) {
53
+ return transferAmount * sendMetadata.asset.metadata.price.value;
54
+ }
55
+ return 0;
56
+ };
57
+ const AccountSendContext = createContext({});
58
+ function AccountSendProvider({ children, step }) {
59
+ var _a, _b, _c, _d, _e, _f;
60
+ const para = useInternalClient();
61
+ const setStep = useModalStore((state) => state.setStep);
62
+ const setSendTx = useModalStore((state) => state.setSendTx);
63
+ const { data: balances } = useProfileBalance({ isComprehensive: true });
64
+ const { signTransactionAsync } = useSignTransaction();
65
+ const { signMessageAsync } = useSignMessage();
66
+ const { selectedWallet, setSelectedWallet } = useWalletState();
67
+ const [estimate, setEstimate] = useState(null);
68
+ const [broadcast, setBroadcast] = useState(null);
69
+ const [sendMetadata, setSendMetadata] = useState(() => getDefaultSendMetadata(balances, selectedWallet));
70
+ const [destinationAddress, setDestinationAddress] = useState("");
71
+ const [transferValue, setTransferValue] = useState(0);
72
+ const [transferAmount, setTransferAmount] = useState(getTransferAmount(sendMetadata, transferValue));
73
+ const [isMax, setIsMax] = useState(false);
74
+ const optionsType = useMemo(() => {
75
+ const walletBalance = balances == null ? void 0 : balances.wallets.find(({ address }) => address === (selectedWallet == null ? void 0 : selectedWallet.address));
76
+ if (!walletBalance || walletBalance.assets.length === 0) {
77
+ return "NONE";
78
+ }
79
+ if ((walletBalance == null ? void 0 : walletBalance.assets.length) === 1) {
80
+ return walletBalance.assets[0].networks.length === 1 ? "SINGLE_NETWORK" : "SINGLE_ASSET";
81
+ }
82
+ return "MULTIPLE";
83
+ }, [balances, selectedWallet == null ? void 0 : selectedWallet.address]);
84
+ const {
85
+ mutate: estimateMutate,
86
+ isPending: estimateIsPending,
87
+ isError: estimateIsError
88
+ } = useMutation({
89
+ mutationKey: ["estimate-tx"],
90
+ mutationFn: (_0) => __async(this, [_0], function* ({ userId, walletId, opts }) {
91
+ if (!para.userId || !selectedWallet.id) {
92
+ return null;
93
+ }
94
+ const result = yield para.ctx.client.estimateSendTransaction({
95
+ userId,
96
+ walletId,
97
+ opts
98
+ });
99
+ return result;
100
+ }),
101
+ onSuccess: (data) => {
102
+ setEstimate(data);
103
+ },
104
+ onError: (error) => {
105
+ console.error(error);
106
+ }
107
+ });
108
+ const queryClient = useQueryClient();
109
+ const refs = useStore((state) => state.refs);
110
+ const {
111
+ mutate: broadcastMutate,
112
+ isPending: broadcastIsPending,
113
+ isError: broadcastIsError
114
+ } = useMutation({
115
+ mutationKey: ["broadcast-tx"],
116
+ mutationFn: (_0) => __async(this, [_0], function* ({
117
+ userId,
118
+ walletId,
119
+ walletAddress,
120
+ walletType,
121
+ txSerialized,
122
+ message,
123
+ evmChainId,
124
+ isDevnet
125
+ }) {
126
+ var _a2, _b2, _c2, _d2, _e2;
127
+ if (!para.userId || !selectedWallet.id) {
128
+ return null;
129
+ }
130
+ let signature;
131
+ switch (walletType) {
132
+ case "SOLANA":
133
+ signature = (_a2 = yield signMessageAsync({
134
+ walletId,
135
+ messageBase64: message
136
+ })) == null ? void 0 : _a2.signature;
137
+ break;
138
+ case "EVM":
139
+ default:
140
+ signature = (_b2 = yield signTransactionAsync({
141
+ walletId,
142
+ rlpEncodedTxBase64: hexStringToBase64(txSerialized),
143
+ chainId: evmChainId
144
+ })) == null ? void 0 : _b2.signature;
145
+ if (!!signature) {
146
+ signature = `0x${signature}`;
147
+ }
148
+ break;
149
+ }
150
+ const result = yield para.ctx.client.broadcastSendTransaction({
151
+ userId,
152
+ walletId,
153
+ opts: {
154
+ type: walletType,
155
+ evmChainId,
156
+ isDevnet,
157
+ tx: txSerialized,
158
+ signature,
159
+ sourceAddress: walletAddress,
160
+ 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
161
+ }
162
+ });
163
+ return result;
164
+ }),
165
+ onSuccess: (data) => {
166
+ if (!!(data == null ? void 0 : data.error)) {
167
+ setBroadcast(data);
168
+ } else if (!!data) {
169
+ setSendTx(data);
170
+ setStep(ModalStep.ACCOUNT_MAIN);
171
+ refs.balancesInvalidationTime.current = Date.now();
172
+ queryClient.invalidateQueries({
173
+ queryKey: ["useProfileBalance"],
174
+ refetchType: "active"
175
+ });
176
+ }
177
+ },
178
+ onError: (error) => {
179
+ console.error(error);
180
+ }
181
+ });
182
+ const onSubmit = useCallback(() => {
183
+ var _a2, _b2, _c2, _d2, _e2, _f2;
184
+ broadcastMutate({
185
+ userId: para.userId,
186
+ walletId: selectedWallet.id,
187
+ walletAddress: selectedWallet.address,
188
+ walletType: selectedWallet.type,
189
+ txSerialized: (_a2 = estimate == null ? void 0 : estimate.result) == null ? void 0 : _a2.txSerialized,
190
+ message: (_b2 = estimate == null ? void 0 : estimate.result) == null ? void 0 : _b2.message,
191
+ evmChainId: (_d2 = (_c2 = sendMetadata == null ? void 0 : sendMetadata.network) == null ? void 0 : _c2.metadata) == null ? void 0 : _d2.evmChainId,
192
+ isDevnet: ((_f2 = (_e2 = sendMetadata == null ? void 0 : sendMetadata.network) == null ? void 0 : _e2.metadata) == null ? void 0 : _f2.internalId) === "SOLANA_DEVNET"
193
+ });
194
+ }, [
195
+ para.userId,
196
+ selectedWallet.id,
197
+ selectedWallet.address,
198
+ selectedWallet.type,
199
+ (_a = estimate == null ? void 0 : estimate.result) == null ? void 0 : _a.txSerialized,
200
+ (_b = estimate == null ? void 0 : estimate.result) == null ? void 0 : _b.message,
201
+ (_d = (_c = sendMetadata == null ? void 0 : sendMetadata.network) == null ? void 0 : _c.metadata) == null ? void 0 : _d.evmChainId,
202
+ (_f = (_e = sendMetadata == null ? void 0 : sendMetadata.network) == null ? void 0 : _e.metadata) == null ? void 0 : _f.internalId
203
+ ]);
204
+ const availableWallets = useMemo(() => {
205
+ return para.availableWallets.filter(({ type }) => type !== "COSMOS");
206
+ }, [para.availableWallets]);
207
+ const { assetPrice, assetValueOnNetwork, assetAmountOnNetwork } = useMemo(() => {
208
+ var _a2, _b2, _c2, _d2, _e2, _f2, _g;
209
+ const assetAmountOnNetwork2 = ((_a2 = sendMetadata.network) == null ? void 0 : _a2.quantity) || 0;
210
+ if (((_c2 = (_b2 = sendMetadata.asset) == null ? void 0 : _b2.metadata) == null ? void 0 : _c2.price) && ((_f2 = (_e2 = (_d2 = sendMetadata.asset) == null ? void 0 : _d2.metadata) == null ? void 0 : _e2.price) == null ? void 0 : _f2.value) > 0) {
211
+ return {
212
+ assetPrice: sendMetadata.asset.metadata.price,
213
+ assetValueOnNetwork: ((_g = sendMetadata.network) == null ? void 0 : _g.value) || null,
214
+ assetAmountOnNetwork: assetAmountOnNetwork2
215
+ };
216
+ }
217
+ return {
218
+ assetPrice: null,
219
+ assetValueOnNetwork: null,
220
+ assetAmountOnNetwork: assetAmountOnNetwork2
221
+ };
222
+ }, [sendMetadata.asset, sendMetadata.network]);
223
+ useEffect(() => {
224
+ if (availableWallets.length > 0 && selectedWallet.type === "COSMOS") {
225
+ const defaultWallet = availableWallets.find((wallet) => wallet.type !== "EVM");
226
+ (defaultWallet == null ? void 0 : defaultWallet.id) && (defaultWallet == null ? void 0 : defaultWallet.type) && setSelectedWallet(defaultWallet);
227
+ }
228
+ }, [availableWallets, selectedWallet.type, setSelectedWallet]);
229
+ const updateSourceRef = useRef(null);
230
+ const prevSendMetadataRef = useRef(sendMetadata);
231
+ const prevWalletAddressRef = useRef(selectedWallet == null ? void 0 : selectedWallet.address);
232
+ const isSettingMaxRef = useRef(false);
233
+ const isResettingRef = useRef(false);
234
+ const resetState = useCallback(() => {
235
+ if (isResettingRef.current) {
236
+ return;
237
+ }
238
+ isResettingRef.current = true;
239
+ updateSourceRef.current = "value";
240
+ setDestinationAddress("");
241
+ setTransferValue(0);
242
+ setTransferAmount(0);
243
+ setIsMax(false);
244
+ setEstimate(null);
245
+ setTimeout(() => {
246
+ isResettingRef.current = false;
247
+ updateSourceRef.current = null;
248
+ }, 0);
249
+ }, []);
250
+ useEffect(() => {
251
+ const walletAddressChanged = prevWalletAddressRef.current !== (selectedWallet == null ? void 0 : selectedWallet.address);
252
+ if (walletAddressChanged) {
253
+ prevWalletAddressRef.current = selectedWallet == null ? void 0 : selectedWallet.address;
254
+ const newSendMetadata = getDefaultSendMetadata(
255
+ balances || null,
256
+ selectedWallet ? { type: selectedWallet.type, address: selectedWallet.address } : null
257
+ );
258
+ setSendMetadata(newSendMetadata);
259
+ resetState();
260
+ }
261
+ }, [selectedWallet == null ? void 0 : selectedWallet.address, balances, resetState]);
262
+ useEffect(() => {
263
+ var _a2, _b2;
264
+ const sendMetadataChanged = ((_a2 = prevSendMetadataRef.current) == null ? void 0 : _a2.asset) !== (sendMetadata == null ? void 0 : sendMetadata.asset) || ((_b2 = prevSendMetadataRef.current) == null ? void 0 : _b2.network) !== (sendMetadata == null ? void 0 : sendMetadata.network);
265
+ const walletAddressChanged = prevWalletAddressRef.current !== (selectedWallet == null ? void 0 : selectedWallet.address);
266
+ if (sendMetadataChanged && !walletAddressChanged && !isResettingRef.current) {
267
+ prevSendMetadataRef.current = sendMetadata;
268
+ resetState();
269
+ } else if (sendMetadataChanged) {
270
+ prevSendMetadataRef.current = sendMetadata;
271
+ }
272
+ }, [sendMetadata, selectedWallet == null ? void 0 : selectedWallet.address, resetState]);
273
+ useEffect(() => {
274
+ if (step !== "SEND_FORM" || sendMetadata.network) {
275
+ return;
276
+ }
277
+ if (sendMetadata.asset && sendMetadata.asset.networks.length > 0) {
278
+ setSendMetadata((prev) => __spreadProps(__spreadValues({}, prev), {
279
+ network: prev.asset.networks[0]
280
+ }));
281
+ return;
282
+ }
283
+ const defaultMetadata = getDefaultSendMetadata(balances, selectedWallet);
284
+ if (defaultMetadata.asset !== sendMetadata.asset || defaultMetadata.network !== sendMetadata.network) {
285
+ setSendMetadata(defaultMetadata);
286
+ }
287
+ }, [step, sendMetadata.asset, sendMetadata.network, balances, selectedWallet]);
288
+ useEffect(() => {
289
+ if (isResettingRef.current || isSettingMaxRef.current) {
290
+ return;
291
+ }
292
+ if (updateSourceRef.current !== "amount") {
293
+ updateSourceRef.current = "value";
294
+ setTransferAmount(getTransferAmount(sendMetadata, transferValue));
295
+ setTimeout(() => {
296
+ updateSourceRef.current = null;
297
+ }, 0);
298
+ }
299
+ }, [transferValue, sendMetadata]);
300
+ useEffect(() => {
301
+ if (isResettingRef.current || isSettingMaxRef.current) {
302
+ return;
303
+ }
304
+ if (updateSourceRef.current !== "value") {
305
+ updateSourceRef.current = "amount";
306
+ const newValue = getTransferValue(sendMetadata, transferAmount);
307
+ setTransferValue((prevValue) => {
308
+ if (newValue !== prevValue) {
309
+ return newValue;
310
+ }
311
+ return prevValue;
312
+ });
313
+ setTimeout(() => {
314
+ updateSourceRef.current = null;
315
+ }, 0);
316
+ }
317
+ }, [transferAmount, sendMetadata]);
318
+ useEffect(() => {
319
+ if (isResettingRef.current) {
320
+ return;
321
+ }
322
+ if (!isSettingMaxRef.current && transferAmount !== assetAmountOnNetwork) {
323
+ setIsMax(false);
324
+ }
325
+ }, [transferAmount, assetAmountOnNetwork]);
326
+ useEffect(() => {
327
+ var _a2, _b2, _c2, _d2, _e2, _f2, _g;
328
+ if (isResettingRef.current) {
329
+ return;
330
+ }
331
+ const isSendMax = isMax && assetAmountOnNetwork > 0;
332
+ if (!destinationAddress || destinationAddress.length === 0 || !isSendMax && transferAmount <= 0) {
333
+ setEstimate(null);
334
+ return;
335
+ }
336
+ estimateMutate({
337
+ walletId: selectedWallet.id,
338
+ userId: para.userId,
339
+ opts: {
340
+ type: selectedWallet.type === "COSMOS" ? "EVM" : selectedWallet.type,
341
+ sourceAddress: selectedWallet.address,
342
+ destinationAddress,
343
+ contractAddress: (_a2 = sendMetadata == null ? void 0 : sendMetadata.network) == null ? void 0 : _a2.contractAddress,
344
+ transferAmount: isMax && assetAmountOnNetwork ? assetAmountOnNetwork : transferAmount,
345
+ evmChainId: (_c2 = (_b2 = sendMetadata == null ? void 0 : sendMetadata.network) == null ? void 0 : _b2.metadata) == null ? void 0 : _c2.evmChainId,
346
+ isDevnet: selectedWallet.type === "SOLANA" && ((_e2 = (_d2 = sendMetadata == null ? void 0 : sendMetadata.network) == null ? void 0 : _d2.metadata) == null ? void 0 : _e2.internalId) === "SOLANA_DEVNET",
347
+ tokenSymbol: (_g = (_f2 = sendMetadata == null ? void 0 : sendMetadata.asset) == null ? void 0 : _f2.metadata) == null ? void 0 : _g.symbol
348
+ }
349
+ });
350
+ }, [
351
+ transferAmount,
352
+ destinationAddress,
353
+ selectedWallet.address,
354
+ selectedWallet.type,
355
+ selectedWallet.id,
356
+ sendMetadata == null ? void 0 : sendMetadata.asset,
357
+ sendMetadata == null ? void 0 : sendMetadata.network,
358
+ para.userId,
359
+ assetAmountOnNetwork,
360
+ isMax
361
+ ]);
362
+ const value = useMemo(() => {
363
+ return {
364
+ step,
365
+ sendMetadata,
366
+ setSendMetadata,
367
+ destinationAddress,
368
+ setDestinationAddress,
369
+ transferValue,
370
+ setTransferValue,
371
+ transferAmount,
372
+ setTransferAmount,
373
+ assetPrice,
374
+ assetValueOnNetwork,
375
+ assetAmountOnNetwork,
376
+ estimate,
377
+ isMax,
378
+ setIsMax,
379
+ onSubmit,
380
+ estimateIsPending,
381
+ estimateIsError,
382
+ broadcast,
383
+ broadcastIsPending,
384
+ broadcastIsError,
385
+ optionsType
386
+ };
387
+ }, [
388
+ step,
389
+ sendMetadata,
390
+ setSendMetadata,
391
+ destinationAddress,
392
+ setDestinationAddress,
393
+ transferValue,
394
+ setTransferValue,
395
+ transferAmount,
396
+ setTransferAmount,
397
+ assetPrice,
398
+ assetValueOnNetwork,
399
+ assetAmountOnNetwork,
400
+ estimate,
401
+ isMax,
402
+ setIsMax,
403
+ onSubmit,
404
+ estimateIsPending,
405
+ estimateIsError,
406
+ broadcast,
407
+ broadcastIsPending,
408
+ broadcastIsError,
409
+ optionsType
410
+ ]);
411
+ return /* @__PURE__ */ jsx(AccountSendContext.Provider, { value, children });
412
+ }
413
+ const useSend = () => useContext(AccountSendContext);
414
+ export {
415
+ AccountSendContext,
416
+ AccountSendProvider,
417
+ useSend
418
+ };
@@ -0,0 +1,4 @@
1
+ import { SendStep } from './context.js';
2
+ export declare function AccountSend({ step }: {
3
+ step: SendStep;
4
+ }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,67 @@
1
+ "use client";
2
+ import "../../../../chunk-MMUBH76A.js";
3
+ import { jsx, jsxs } from "react/jsx-runtime";
4
+ import { StepContainer } from "../../common.js";
5
+ import { useMemo, useRef, useEffect, useState } from "react";
6
+ import { AccountSendForm } from "./AccountSendForm.js";
7
+ import { AccountSendProvider, useSend } from "./context.js";
8
+ import { AccountSendAsset } from "./AccountSendAsset.js";
9
+ import { AccountSendNetwork } from "./AccountSendNetwork.js";
10
+ import { AnimatePresence, motion } from "framer-motion";
11
+ import { BODY_MOTION_VARIANTS, BODY_TRANSITION, safeStyled } from "@getpara/react-common";
12
+ import { WalletSelectOld } from "../../WalletSelectOld/WalletSelectOld.js";
13
+ import { AccountSendNoAssets } from "./AccountSendNoAssets.js";
14
+ const STEP_ORDER = ["SEND_FORM", "SEND_ASSET", "SEND_NETWORK"];
15
+ function AccountSendIndex() {
16
+ const { step, optionsType } = useSend();
17
+ const prevStepRef = useRef(step);
18
+ const [direction, setDirection] = useState(1);
19
+ useEffect(() => {
20
+ const prevIndex = STEP_ORDER.indexOf(prevStepRef.current);
21
+ const currentIndex = STEP_ORDER.indexOf(step);
22
+ setDirection(currentIndex > prevIndex ? 1 : -1);
23
+ prevStepRef.current = step;
24
+ }, [step]);
25
+ const Content = useMemo(() => {
26
+ if (optionsType === "NONE") {
27
+ return /* @__PURE__ */ jsx(AccountSendNoAssets, {});
28
+ }
29
+ switch (step) {
30
+ case "SEND_FORM":
31
+ return /* @__PURE__ */ jsx(AccountSendForm, {});
32
+ case "SEND_ASSET":
33
+ return /* @__PURE__ */ jsx(AccountSendAsset, {});
34
+ case "SEND_NETWORK":
35
+ return /* @__PURE__ */ jsx(AccountSendNetwork, {});
36
+ }
37
+ }, [step, optionsType]);
38
+ return /* @__PURE__ */ jsxs(StepContainer, { style: { gap: "16px" }, children: [
39
+ step === "SEND_FORM" && /* @__PURE__ */ jsx(WalletSelectOld, { noTitle: true, types: ["EVM", "SOLANA"], isEmbeddedOnly: true, style: { width: "100%" } }),
40
+ /* @__PURE__ */ jsx(AnimatePresence, { mode: "popLayout", initial: false, custom: direction, children: /* @__PURE__ */ jsx(
41
+ AnimatedContainer,
42
+ {
43
+ custom: direction,
44
+ variants: BODY_MOTION_VARIANTS,
45
+ initial: "enter",
46
+ animate: "center",
47
+ exit: "exit",
48
+ transition: BODY_TRANSITION,
49
+ children: Content
50
+ },
51
+ step
52
+ ) })
53
+ ] });
54
+ }
55
+ const AnimatedContainer = safeStyled(motion.div)`
56
+ position: relative;
57
+ display: flex;
58
+ flex-direction: column;
59
+ gap: 12px;
60
+ width: 100%;
61
+ `;
62
+ function AccountSend({ step }) {
63
+ return /* @__PURE__ */ jsx(AccountSendProvider, { step, children: /* @__PURE__ */ jsx(AccountSendIndex, {}) });
64
+ }
65
+ export {
66
+ AccountSend
67
+ };
@@ -12,9 +12,8 @@ import { useModalStore } from "../../stores/index.js";
12
12
  import { useState } from "react";
13
13
  import { useAddFunds } from "./AddFundsContext.js";
14
14
  import { useWallet } from "../../../provider/hooks/queries/useWallet.js";
15
- import { AssetIcon, GradientScroll } from "../common.js";
15
+ import { AssetIcon, contentMotionProps, GradientScroll } from "../common.js";
16
16
  import { AnimatePresence, motion } from "framer-motion";
17
- import { contentMotionProps } from "./common.js";
18
17
  import { useAssets } from "../../../provider/providers/AssetsProvider.js";
19
18
  function AddFundsAsset() {
20
19
  const onRampConfig = useModalStore((state) => state.onRampConfig);
@@ -6,7 +6,7 @@ import {
6
6
  } from "../../../chunk-MMUBH76A.js";
7
7
  import { jsx, jsxs } from "react/jsx-runtime";
8
8
  import { safeStyled } from "@getpara/react-common";
9
- import { Heading, InnerStepContainer } from "../common.js";
9
+ import { contentMotionProps, Heading, InnerStepContainer } from "../common.js";
10
10
  import { CpslText } from "@getpara/react-components";
11
11
  import { useAddFunds } from "./AddFundsContext.js";
12
12
  import { useModalStore } from "../../stores/index.js";
@@ -15,7 +15,6 @@ import { motion, AnimatePresence } from "framer-motion";
15
15
  import { OnRampProviderButton } from "../OnRampComponents/OnRampProviderButton.js";
16
16
  import { useWallet } from "../../../provider/index.js";
17
17
  import { EnabledFlow, OnRampPurchaseType } from "@getpara/web-sdk";
18
- import { contentMotionProps } from "./common.js";
19
18
  import { useInternalClient } from "../../../provider/hooks/utils/useInternalClient.js";
20
19
  function AddFundsProvider() {
21
20
  const para = useInternalClient();