@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.
- package/dist/modal/ParaModal.js +3 -1
- package/dist/modal/components/Account/Account.js +114 -22
- package/dist/modal/components/Account/AccountMonitorTx.d.ts +1 -0
- package/dist/modal/components/Account/AccountMonitorTx.js +256 -0
- package/dist/modal/components/Account/AccountSend/AccountSendAsset.js +2 -2
- package/dist/modal/components/Account/AccountSend/AccountSendForm.js +68 -10
- package/dist/modal/components/Account/AccountSend/context.d.ts +2 -0
- package/dist/modal/components/Account/AccountSend/context.js +36 -109
- package/dist/modal/components/AddFunds/AddFundsContext.d.ts +2 -0
- package/dist/modal/components/AddFunds/AddFundsContext.js +88 -31
- package/dist/modal/components/AddFunds/AddFundsProvider.js +2 -2
- package/dist/modal/components/AddFunds/AddFundsReceive.js +1 -1
- package/dist/modal/components/AddFunds/AddFundsSettings.js +134 -29
- package/dist/modal/components/Body/Body.js +4 -0
- package/dist/modal/components/ErrorBoundary.d.ts +20 -0
- package/dist/modal/components/ErrorBoundary.js +27 -0
- package/dist/modal/components/OnRampComponents/OnRampProviderButton.js +3 -8
- package/dist/modal/components/common.d.ts +5 -1
- package/dist/modal/components/common.js +27 -1
- package/dist/modal/hooks/index.d.ts +1 -0
- package/dist/modal/hooks/index.js +1 -0
- package/dist/modal/hooks/useSendMutations.d.ts +51 -0
- package/dist/modal/hooks/useSendMutations.js +170 -0
- package/dist/modal/hooks/useTransactionMonitoring.d.ts +1 -0
- package/dist/modal/hooks/useTransactionMonitoring.js +175 -0
- package/dist/modal/index.d.ts +1 -1
- package/dist/modal/index.js +1 -1
- package/dist/modal/stores/index.d.ts +1 -0
- package/dist/modal/stores/index.js +1 -0
- package/dist/modal/stores/modal/actions.js +0 -1
- package/dist/modal/stores/modal/useModalSessionStore.d.ts +28 -0
- package/dist/modal/stores/modal/useModalSessionStore.js +26 -0
- package/dist/modal/stores/modal/useModalStore.d.ts +1 -3
- package/dist/modal/stores/modal/useModalStore.js +0 -1
- package/dist/modal/types/modalProps.d.ts +3 -1
- package/dist/modal/utils/onramps.d.ts +61 -0
- package/dist/modal/utils/onramps.js +112 -0
- package/dist/modal/utils/steps.d.ts +4 -2
- package/dist/modal/utils/steps.js +6 -2
- package/dist/provider/hooks/queries/useProfileBalance.js +33 -6
- package/dist/provider/hooks/utils/index.d.ts +1 -0
- package/dist/provider/hooks/utils/index.js +2 -0
- package/dist/provider/hooks/utils/useEventListeners.js +2 -2
- package/dist/provider/hooks/utils/useSetBalanceOverrides.d.ts +34 -0
- package/dist/provider/hooks/utils/useSetBalanceOverrides.js +12 -0
- package/dist/provider/stores/slices/modal.js +11 -1
- package/dist/provider/stores/types.d.ts +8 -0
- package/package.json +9 -8
- package/dist/modal/utils/validateOnRampConfig.d.ts +0 -5
- package/dist/modal/utils/validateOnRampConfig.js +0 -32
|
@@ -6,17 +6,17 @@ import {
|
|
|
6
6
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
7
7
|
import { useMemo, useState } from "react";
|
|
8
8
|
import { useAddFunds } from "./AddFundsContext.js";
|
|
9
|
+
import { isAmountWithinProviderLimits, PROVIDER_LIMITS } from "../../utils/onramps.js";
|
|
9
10
|
import { CpslButton, CpslIcon, CpslRow, CpslText } from "@getpara/react-components";
|
|
10
11
|
import { AssetIcon, contentMotionProps } from "../common.js";
|
|
11
12
|
import { QuantityInput } from "../QuantityInput.js";
|
|
12
|
-
import { formatAssetQuantity } from "@getpara/web-sdk";
|
|
13
|
+
import { formatAssetQuantity, OnRampPurchaseType, EnabledFlow } from "@getpara/web-sdk";
|
|
13
14
|
import { OnRampStep, useModalStore } from "../../stores/index.js";
|
|
14
15
|
import { safeStyled, getAssetCode, getNetworkName } from "@getpara/react-common";
|
|
15
16
|
import { AnimatePresence, motion, useIsPresent } from "framer-motion";
|
|
16
17
|
import { AddFundsAsset } from "./AddFundsAsset.js";
|
|
17
18
|
import { WalletSelectOld } from "../WalletSelectOld/WalletSelectOld.js";
|
|
18
19
|
import { useAccount } from "../../../provider/index.js";
|
|
19
|
-
import { useDebounce } from "../../hooks/useDebounce.js";
|
|
20
20
|
import { useAssetInfo } from "../../../provider/hooks/utils/useAssetInfo.js";
|
|
21
21
|
import { AddFundsNetwork } from "./AddFundsNetwork.js";
|
|
22
22
|
import { useStore } from "../../../provider/stores/useStore.js";
|
|
@@ -31,6 +31,7 @@ function AddFundsSettings() {
|
|
|
31
31
|
const { embedded } = useAccount();
|
|
32
32
|
const {
|
|
33
33
|
assets,
|
|
34
|
+
networks,
|
|
34
35
|
narrowedNetworks,
|
|
35
36
|
asset,
|
|
36
37
|
setAsset,
|
|
@@ -40,25 +41,90 @@ function AddFundsSettings() {
|
|
|
40
41
|
setFiatQuantity,
|
|
41
42
|
isProviderAllowed,
|
|
42
43
|
settingsStep,
|
|
43
|
-
TestModeAlert
|
|
44
|
+
TestModeAlert,
|
|
45
|
+
onRampConfig,
|
|
46
|
+
activeWallet,
|
|
47
|
+
tab
|
|
44
48
|
} = useAddFunds();
|
|
45
|
-
const [value, setValue] = useState(parseFloat(fiatQuantity || "25.00").toFixed(2));
|
|
46
|
-
const dbValue = useDebounce(value, 200);
|
|
49
|
+
const [value, setValue] = useState(parseFloat(String(fiatQuantity || "25.00")).toFixed(2));
|
|
47
50
|
const assetQuantity = useMemo(() => {
|
|
48
51
|
var _a, _b, _c;
|
|
49
52
|
if (!asset) {
|
|
50
53
|
return -1;
|
|
51
54
|
}
|
|
52
55
|
const assetValue = (_c = (_b = (_a = assetInfo.data) == null ? void 0 : _a[asset]) == null ? void 0 : _b.price) == null ? void 0 : _c.value;
|
|
53
|
-
const
|
|
54
|
-
if (!assetValue || !asset || !
|
|
56
|
+
const valueFloat = !value || isNaN(parseFloat(value)) ? null : parseFloat(value);
|
|
57
|
+
if (!assetValue || !asset || !valueFloat) {
|
|
55
58
|
return -1;
|
|
56
59
|
}
|
|
57
60
|
if (["TETHER", "USDC", "CUSD"].includes(asset)) {
|
|
58
|
-
return
|
|
61
|
+
return valueFloat;
|
|
62
|
+
}
|
|
63
|
+
return valueFloat / assetValue;
|
|
64
|
+
}, [asset, assetInfo, value]);
|
|
65
|
+
const providerAvailability = useMemo(() => {
|
|
66
|
+
if (!value || value.trim() === "") {
|
|
67
|
+
return { hasProviders: false, reason: null, minAmount: null, maxAmount: null };
|
|
68
|
+
}
|
|
69
|
+
const hasBasicSupport = Object.values(isProviderAllowed).some((allowed) => allowed === true);
|
|
70
|
+
if (!hasBasicSupport) {
|
|
71
|
+
return { hasProviders: false, reason: "NO_SUPPORT", minAmount: null, maxAmount: null };
|
|
72
|
+
}
|
|
73
|
+
if (!onRampConfig || !(activeWallet == null ? void 0 : activeWallet.type) || !asset || !network) {
|
|
74
|
+
return { hasProviders: hasBasicSupport, reason: null, minAmount: null, maxAmount: null };
|
|
75
|
+
}
|
|
76
|
+
const amount = parseFloat(value);
|
|
77
|
+
if (isNaN(amount)) {
|
|
78
|
+
return { hasProviders: false, reason: "INVALID_AMOUNT", minAmount: null, maxAmount: null };
|
|
79
|
+
}
|
|
80
|
+
const purchaseType = tab === EnabledFlow.BUY ? OnRampPurchaseType.BUY : OnRampPurchaseType.SELL;
|
|
81
|
+
let hasAtLeastOne = false;
|
|
82
|
+
let allBelowMin = true;
|
|
83
|
+
let allAboveMax = true;
|
|
84
|
+
const mins = [];
|
|
85
|
+
const maxes = [];
|
|
86
|
+
onRampConfig.providers.forEach((id) => {
|
|
87
|
+
if (!isProviderAllowed[id]) return;
|
|
88
|
+
const withinLimits = isAmountWithinProviderLimits(amount, id, purchaseType);
|
|
89
|
+
if (withinLimits) {
|
|
90
|
+
hasAtLeastOne = true;
|
|
91
|
+
allBelowMin = false;
|
|
92
|
+
allAboveMax = false;
|
|
93
|
+
} else {
|
|
94
|
+
const limits = PROVIDER_LIMITS[id][purchaseType];
|
|
95
|
+
if (limits.min !== null) mins.push(limits.min);
|
|
96
|
+
if (limits.max !== null) maxes.push(limits.max);
|
|
97
|
+
if (limits.min !== null && amount >= limits.min) allBelowMin = false;
|
|
98
|
+
if (limits.max !== null && amount <= limits.max) allAboveMax = false;
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
if (hasAtLeastOne) {
|
|
102
|
+
return { hasProviders: true, reason: null, minAmount: null, maxAmount: null };
|
|
103
|
+
}
|
|
104
|
+
if (allBelowMin && mins.length > 0) {
|
|
105
|
+
return {
|
|
106
|
+
hasProviders: false,
|
|
107
|
+
reason: "BELOW_MIN",
|
|
108
|
+
minAmount: Math.min(...mins),
|
|
109
|
+
maxAmount: null
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
if (allAboveMax && maxes.length > 0) {
|
|
113
|
+
return {
|
|
114
|
+
hasProviders: false,
|
|
115
|
+
reason: "ABOVE_MAX",
|
|
116
|
+
minAmount: null,
|
|
117
|
+
maxAmount: Math.max(...maxes)
|
|
118
|
+
};
|
|
59
119
|
}
|
|
60
|
-
return
|
|
61
|
-
|
|
120
|
+
return {
|
|
121
|
+
hasProviders: false,
|
|
122
|
+
reason: "NO_PROVIDERS",
|
|
123
|
+
minAmount: null,
|
|
124
|
+
maxAmount: null
|
|
125
|
+
};
|
|
126
|
+
}, [isProviderAllowed, value, onRampConfig, activeWallet == null ? void 0 : activeWallet.type, asset, network, tab]);
|
|
127
|
+
const hasAvailableProviders = providerAvailability.hasProviders;
|
|
62
128
|
const { key, Content } = useMemo(() => {
|
|
63
129
|
switch (settingsStep) {
|
|
64
130
|
case "NO_PROVIDERS":
|
|
@@ -70,6 +136,7 @@ function AddFundsSettings() {
|
|
|
70
136
|
] })
|
|
71
137
|
};
|
|
72
138
|
case "FORM": {
|
|
139
|
+
const isClickable = !!network && (assets.length > 1 || networks.length > 1);
|
|
73
140
|
return {
|
|
74
141
|
key: "form",
|
|
75
142
|
Content: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
@@ -79,7 +146,9 @@ function AddFundsSettings() {
|
|
|
79
146
|
AssetButton,
|
|
80
147
|
{
|
|
81
148
|
variant: "tertiary",
|
|
82
|
-
|
|
149
|
+
$isClickable: isClickable,
|
|
150
|
+
cursor: isClickable ? "pointer" : "auto",
|
|
151
|
+
onClick: isClickable ? () => {
|
|
83
152
|
switch (true) {
|
|
84
153
|
case assets.length === 1:
|
|
85
154
|
setNetwork(null);
|
|
@@ -92,7 +161,7 @@ function AddFundsSettings() {
|
|
|
92
161
|
children: [
|
|
93
162
|
/* @__PURE__ */ jsx(AssetIcon, { asset, size: "24px" }),
|
|
94
163
|
/* @__PURE__ */ jsx(CpslText, { variant: "bodyS", color: "contrast", children: assetQuantity > 0 ? formatAssetQuantity({ quantity: assetQuantity, symbol: getAssetCode(asset) }) : getAssetCode(asset) }),
|
|
95
|
-
/* @__PURE__ */ jsx(CpslIcon, { icon: "chevronRight", size: "24px", color: "var(--cpsl-color-text-contrast)" })
|
|
164
|
+
isClickable && /* @__PURE__ */ jsx(CpslIcon, { icon: "chevronRight", size: "24px", color: "var(--cpsl-color-text-contrast)" })
|
|
96
165
|
]
|
|
97
166
|
}
|
|
98
167
|
),
|
|
@@ -101,21 +170,37 @@ function AddFundsSettings() {
|
|
|
101
170
|
getNetworkName(network)
|
|
102
171
|
] })
|
|
103
172
|
] }),
|
|
104
|
-
/* @__PURE__ */ jsxs(
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
173
|
+
/* @__PURE__ */ jsxs(CpslRow, { col: true, gap: "8px", children: [
|
|
174
|
+
/* @__PURE__ */ jsxs(
|
|
175
|
+
CpslButton,
|
|
176
|
+
{
|
|
177
|
+
fullWidth: true,
|
|
178
|
+
disabled: !hasAvailableProviders,
|
|
179
|
+
onClick: () => {
|
|
180
|
+
setFiatQuantity(value != null ? value : void 0);
|
|
181
|
+
setOnRampStep(OnRampStep.PROVIDER);
|
|
182
|
+
},
|
|
183
|
+
children: [
|
|
184
|
+
"Continue",
|
|
185
|
+
/* @__PURE__ */ jsx(CpslIcon, { icon: "arrow" })
|
|
186
|
+
]
|
|
187
|
+
}
|
|
188
|
+
),
|
|
189
|
+
!hasAvailableProviders && value !== "" && asset && network && (() => {
|
|
190
|
+
const { reason, minAmount, maxAmount } = providerAvailability;
|
|
191
|
+
let message = "No providers available for this transaction";
|
|
192
|
+
if (reason === "INVALID_AMOUNT") {
|
|
193
|
+
message = "Please enter a valid amount";
|
|
194
|
+
} else if (reason === "BELOW_MIN" && minAmount !== null) {
|
|
195
|
+
message = `Amount too low, must be $${minAmount.toFixed(2)} or greater`;
|
|
196
|
+
} else if (reason === "ABOVE_MAX" && maxAmount !== null) {
|
|
197
|
+
message = `Amount too high, must be $${maxAmount.toFixed(2)} or less`;
|
|
198
|
+
} else if (reason) {
|
|
199
|
+
message = "No providers available for this transaction";
|
|
200
|
+
}
|
|
201
|
+
return /* @__PURE__ */ jsx(CpslText, { variant: "bodyXS", color: "error", align: "center", children: message });
|
|
202
|
+
})()
|
|
203
|
+
] })
|
|
119
204
|
] })
|
|
120
205
|
};
|
|
121
206
|
}
|
|
@@ -136,7 +221,18 @@ function AddFundsSettings() {
|
|
|
136
221
|
};
|
|
137
222
|
}
|
|
138
223
|
}
|
|
139
|
-
}, [
|
|
224
|
+
}, [
|
|
225
|
+
asset,
|
|
226
|
+
network,
|
|
227
|
+
assets,
|
|
228
|
+
narrowedNetworks,
|
|
229
|
+
isProviderAllowed,
|
|
230
|
+
assetQuantity,
|
|
231
|
+
isPresent,
|
|
232
|
+
value,
|
|
233
|
+
hideWallets,
|
|
234
|
+
providerAvailability
|
|
235
|
+
]);
|
|
140
236
|
const isWalletSelectVisible = useMemo(() => {
|
|
141
237
|
return settingsStep && ["FORM", "NO_PROVIDERS"].includes(settingsStep) && (embedded == null ? void 0 : embedded.wallets) && embedded.wallets.length > 1;
|
|
142
238
|
}, [embedded, settingsStep]);
|
|
@@ -171,8 +267,17 @@ const AssetButton = safeStyled(CpslButton)`
|
|
|
171
267
|
--button-padding-top: 8px;
|
|
172
268
|
--button-padding-bottom: 8px;
|
|
173
269
|
--button-padding-start: 8px;
|
|
174
|
-
--button-padding-end: 8px;
|
|
270
|
+
--button-padding-end: ${({ $isClickable }) => $isClickable ? "8px" : "16px"};
|
|
175
271
|
--button-gap: 4px;
|
|
272
|
+
|
|
273
|
+
${({ $isClickable }) => !$isClickable && `
|
|
274
|
+
&:hover {
|
|
275
|
+
--button-tertiary-hover-background-color: var(--button-tertiary-background-color);
|
|
276
|
+
--button-tertiary-hover-border-color: var(--button-tertiary-border-color);
|
|
277
|
+
--button-tertiary-active-background-color: var(--button-tertiary-background-color);
|
|
278
|
+
--button-tertiary-active-border-color: var(--button-tertiary-border-color);
|
|
279
|
+
}
|
|
280
|
+
`}
|
|
176
281
|
`;
|
|
177
282
|
export {
|
|
178
283
|
AddFundsSettings
|
|
@@ -46,6 +46,7 @@ import { Footer } from "../Footer/Footer.js";
|
|
|
46
46
|
import { renderTextWithLinks } from "../../utils/renderTextWithLinks.js";
|
|
47
47
|
import { AccountWallet } from "../Account/AccountWallet.js";
|
|
48
48
|
import { AccountSend } from "../Account/AccountSend/index.js";
|
|
49
|
+
import { AccountMonitorTx } from "../Account/AccountMonitorTx.js";
|
|
49
50
|
const MIN_HEIGHT = {
|
|
50
51
|
[ModalStep.ADD_FUNDS_AWAITING]: "680px"
|
|
51
52
|
};
|
|
@@ -219,6 +220,9 @@ const Body = ({
|
|
|
219
220
|
case ModalStep.ACCOUNT_SEND_NETWORK: {
|
|
220
221
|
return /* @__PURE__ */ jsx(AccountSend, { step: "SEND_NETWORK" });
|
|
221
222
|
}
|
|
223
|
+
case ModalStep.ACCOUNT_MONITOR_TX: {
|
|
224
|
+
return /* @__PURE__ */ jsx(AccountMonitorTx, {});
|
|
225
|
+
}
|
|
222
226
|
default: {
|
|
223
227
|
if (IFrameSteps.includes(currentStep)) {
|
|
224
228
|
return null;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Component, ErrorInfo, ReactNode } from 'react';
|
|
2
|
+
interface Props {
|
|
3
|
+
children: ReactNode;
|
|
4
|
+
fallback?: ReactNode;
|
|
5
|
+
onError?: (error: Error, errorInfo: ErrorInfo) => void;
|
|
6
|
+
}
|
|
7
|
+
interface State {
|
|
8
|
+
hasError: boolean;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Error boundary component that catches JavaScript errors in child components
|
|
12
|
+
* and displays a fallback UI instead of crashing the entire component tree.
|
|
13
|
+
*/
|
|
14
|
+
export declare class ErrorBoundary extends Component<Props, State> {
|
|
15
|
+
constructor(props: Props);
|
|
16
|
+
static getDerivedStateFromError(): State;
|
|
17
|
+
componentDidCatch(error: Error, errorInfo: ErrorInfo): void;
|
|
18
|
+
render(): ReactNode;
|
|
19
|
+
}
|
|
20
|
+
export {};
|
|
@@ -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(
|
|
19
|
+
/* @__PURE__ */ jsx(CpslText, { variant: "bodyL", weight: "medium", children: name }),
|
|
20
20
|
/* @__PURE__ */ jsxs(ProviderInfoInnerContainer, { children: [
|
|
21
|
-
/* @__PURE__ */ jsx(
|
|
22
|
-
/* @__PURE__ */ jsx(
|
|
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,
|
|
@@ -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;
|