@multiversx/sdk-dapp-liquidity 1.1.0-alpha.31 → 1.1.0-alpha.32
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/package.json +1 -1
- package/reactjs/components/BridgeForm/BridgeForm.js +2 -5
- package/reactjs/components/BridgeForm/BridgeForm.mjs +2 -5
- package/reactjs/hooks/useAccount.d.ts +4 -4
- package/reactjs/hooks/useBridgeFormik.d.ts +0 -1
- package/reactjs/hooks/useBridgeFormik.js +6 -32
- package/reactjs/hooks/useBridgeFormik.mjs +7 -33
package/package.json
CHANGED
|
@@ -271,11 +271,9 @@ const BridgeForm = ({
|
|
|
271
271
|
);
|
|
272
272
|
const handleOnChangeFirstAmount = React.useCallback((amount) => {
|
|
273
273
|
setFirstAmount(() => amount);
|
|
274
|
-
setLastChangedField(reactjs_hooks_useBridgeFormik.BridgeFormikValuesEnum.firstAmount);
|
|
275
274
|
}, []);
|
|
276
275
|
const handleOnChangeSecondAmount = React.useCallback((amount) => {
|
|
277
276
|
setSecondAmount(() => amount);
|
|
278
|
-
setLastChangedField(reactjs_hooks_useBridgeFormik.BridgeFormikValuesEnum.secondAmount);
|
|
279
277
|
}, []);
|
|
280
278
|
const handleHistoryClose = React.useCallback(() => {
|
|
281
279
|
onHistoryClose == null ? void 0 : onHistoryClose();
|
|
@@ -557,8 +555,7 @@ const BridgeForm = ({
|
|
|
557
555
|
handleBlur,
|
|
558
556
|
handleChange,
|
|
559
557
|
handleSubmit,
|
|
560
|
-
resetSwapForm
|
|
561
|
-
setLastChangedField
|
|
558
|
+
resetSwapForm
|
|
562
559
|
} = reactjs_hooks_useBridgeFormik.useBridgeFormik({
|
|
563
560
|
rate,
|
|
564
561
|
nativeAuthToken,
|
|
@@ -691,7 +688,7 @@ const BridgeForm = ({
|
|
|
691
688
|
inputName: "firstAmount",
|
|
692
689
|
inputValue: formik.values.firstAmount ?? "",
|
|
693
690
|
amountError: firstAmount !== "" ? rateValidationError ?? firstAmountError : void 0,
|
|
694
|
-
disabled:
|
|
691
|
+
disabled: true,
|
|
695
692
|
onInputDebounceChange: handleOnChangeFirstAmount,
|
|
696
693
|
onInputChange: handleChange,
|
|
697
694
|
onBlur: handleBlur
|
|
@@ -268,11 +268,9 @@ const BridgeForm = ({
|
|
|
268
268
|
);
|
|
269
269
|
const handleOnChangeFirstAmount = useCallback((amount) => {
|
|
270
270
|
setFirstAmount(() => amount);
|
|
271
|
-
setLastChangedField(BridgeFormikValuesEnum.firstAmount);
|
|
272
271
|
}, []);
|
|
273
272
|
const handleOnChangeSecondAmount = useCallback((amount) => {
|
|
274
273
|
setSecondAmount(() => amount);
|
|
275
|
-
setLastChangedField(BridgeFormikValuesEnum.secondAmount);
|
|
276
274
|
}, []);
|
|
277
275
|
const handleHistoryClose = useCallback(() => {
|
|
278
276
|
onHistoryClose == null ? void 0 : onHistoryClose();
|
|
@@ -554,8 +552,7 @@ const BridgeForm = ({
|
|
|
554
552
|
handleBlur,
|
|
555
553
|
handleChange,
|
|
556
554
|
handleSubmit,
|
|
557
|
-
resetSwapForm
|
|
558
|
-
setLastChangedField
|
|
555
|
+
resetSwapForm
|
|
559
556
|
} = useBridgeFormik({
|
|
560
557
|
rate,
|
|
561
558
|
nativeAuthToken,
|
|
@@ -688,7 +685,7 @@ const BridgeForm = ({
|
|
|
688
685
|
inputName: "firstAmount",
|
|
689
686
|
inputValue: formik.values.firstAmount ?? "",
|
|
690
687
|
amountError: firstAmount !== "" ? rateValidationError ?? firstAmountError : void 0,
|
|
691
|
-
disabled:
|
|
688
|
+
disabled: true,
|
|
692
689
|
onInputDebounceChange: handleOnChangeFirstAmount,
|
|
693
690
|
onInputChange: handleChange,
|
|
694
691
|
onBlur: handleBlur
|
|
@@ -6,7 +6,7 @@ export declare const useAccount: () => {
|
|
|
6
6
|
embeddedWalletInfo?: {
|
|
7
7
|
user: import('@reown/appkit/react').AccountControllerState["user"];
|
|
8
8
|
authProvider: import('@reown/appkit/react').AccountControllerState["socialProvider"] | "email";
|
|
9
|
-
accountType: import(
|
|
9
|
+
accountType: import('@reown/appkit/react').PreferredAccountTypes[import('@reown/appkit-common').ChainNamespace] | undefined;
|
|
10
10
|
isSmartAccountDeployed: boolean;
|
|
11
11
|
};
|
|
12
12
|
status: import('@reown/appkit/react').AccountControllerState["status"];
|
|
@@ -25,7 +25,7 @@ export declare const useAccount: () => {
|
|
|
25
25
|
embeddedWalletInfo?: {
|
|
26
26
|
user: import('@reown/appkit/react').AccountControllerState["user"];
|
|
27
27
|
authProvider: import('@reown/appkit/react').AccountControllerState["socialProvider"] | "email";
|
|
28
|
-
accountType: import(
|
|
28
|
+
accountType: import('@reown/appkit/react').PreferredAccountTypes[import('@reown/appkit-common').ChainNamespace] | undefined;
|
|
29
29
|
isSmartAccountDeployed: boolean;
|
|
30
30
|
};
|
|
31
31
|
status: import('@reown/appkit/react').AccountControllerState["status"];
|
|
@@ -44,7 +44,7 @@ export declare const useAccount: () => {
|
|
|
44
44
|
embeddedWalletInfo?: {
|
|
45
45
|
user: import('@reown/appkit/react').AccountControllerState["user"];
|
|
46
46
|
authProvider: import('@reown/appkit/react').AccountControllerState["socialProvider"] | "email";
|
|
47
|
-
accountType: import(
|
|
47
|
+
accountType: import('@reown/appkit/react').PreferredAccountTypes[import('@reown/appkit-common').ChainNamespace] | undefined;
|
|
48
48
|
isSmartAccountDeployed: boolean;
|
|
49
49
|
};
|
|
50
50
|
status: import('@reown/appkit/react').AccountControllerState["status"];
|
|
@@ -63,7 +63,7 @@ export declare const useAccount: () => {
|
|
|
63
63
|
embeddedWalletInfo?: {
|
|
64
64
|
user: import('@reown/appkit/react').AccountControllerState["user"];
|
|
65
65
|
authProvider: import('@reown/appkit/react').AccountControllerState["socialProvider"] | "email";
|
|
66
|
-
accountType: import(
|
|
66
|
+
accountType: import('@reown/appkit/react').PreferredAccountTypes[import('@reown/appkit-common').ChainNamespace] | undefined;
|
|
67
67
|
isSmartAccountDeployed: boolean;
|
|
68
68
|
};
|
|
69
69
|
status: import('@reown/appkit/react').AccountControllerState["status"];
|
|
@@ -99,5 +99,4 @@ export declare const useBridgeFormik: ({ nativeAuthToken, mvxAccountAddress, fir
|
|
|
99
99
|
setFieldValue: (field: string, value: any, shouldValidate?: boolean) => Promise<void> | Promise<import('formik').FormikErrors<TradeFormikValuesType>>;
|
|
100
100
|
resetSwapForm: () => void;
|
|
101
101
|
setFieldTouched: (field: string, touched?: boolean, shouldValidate?: boolean) => Promise<void> | Promise<import('formik').FormikErrors<TradeFormikValuesType>>;
|
|
102
|
-
setLastChangedField: import('react').Dispatch<import('react').SetStateAction<BridgeFormikValuesEnum.firstAmount | BridgeFormikValuesEnum.secondAmount | null>>;
|
|
103
102
|
};
|
|
@@ -31,7 +31,6 @@ const useBridgeFormik = ({
|
|
|
31
31
|
rate,
|
|
32
32
|
onSubmit
|
|
33
33
|
}) => {
|
|
34
|
-
const [lastChangedField, setLastChangedField] = React.useState(null);
|
|
35
34
|
const pendingSigningRef = React.useRef();
|
|
36
35
|
const account = reactjs_hooks_useAccount.useAccount();
|
|
37
36
|
const initialValues = {
|
|
@@ -46,7 +45,7 @@ const useBridgeFormik = ({
|
|
|
46
45
|
setFieldValue("firstAmount", "");
|
|
47
46
|
setFieldValue("secondAmount", "");
|
|
48
47
|
};
|
|
49
|
-
const onSubmitFormik = async (
|
|
48
|
+
const onSubmitFormik = async (values) => {
|
|
50
49
|
var _a, _b;
|
|
51
50
|
if (pendingSigningRef.current) {
|
|
52
51
|
return;
|
|
@@ -56,11 +55,11 @@ const useBridgeFormik = ({
|
|
|
56
55
|
url: helpers_getApiURL.getApiURL(),
|
|
57
56
|
nativeAuthToken: nativeAuthToken ?? "",
|
|
58
57
|
body: {
|
|
59
|
-
tokenIn: ((_a =
|
|
58
|
+
tokenIn: ((_a = values.firstToken) == null ? void 0 : _a.address) ?? "",
|
|
60
59
|
amountIn: (firstAmount == null ? void 0 : firstAmount.toString()) ?? "",
|
|
61
|
-
fromChainId:
|
|
62
|
-
tokenOut: ((_b =
|
|
63
|
-
toChainId:
|
|
60
|
+
fromChainId: values.fromChainId ?? "",
|
|
61
|
+
tokenOut: ((_b = values.secondToken) == null ? void 0 : _b.address) ?? "",
|
|
62
|
+
toChainId: values.toChainId ?? "",
|
|
64
63
|
amountOut: (secondAmount == null ? void 0 : secondAmount.toString()) ?? "",
|
|
65
64
|
sender: account.address ?? "",
|
|
66
65
|
receiver: mvxAccountAddress ?? "",
|
|
@@ -112,7 +111,6 @@ const useBridgeFormik = ({
|
|
|
112
111
|
onSubmit: onSubmitFormik
|
|
113
112
|
});
|
|
114
113
|
const {
|
|
115
|
-
values,
|
|
116
114
|
errors,
|
|
117
115
|
touched,
|
|
118
116
|
handleBlur,
|
|
@@ -121,29 +119,6 @@ const useBridgeFormik = ({
|
|
|
121
119
|
setFieldValue,
|
|
122
120
|
setFieldTouched
|
|
123
121
|
} = formik$1;
|
|
124
|
-
React.useEffect(() => {
|
|
125
|
-
if (!values.firstAmount && touched.firstAmount) {
|
|
126
|
-
setFieldValue("secondAmount", 0, true);
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
if (lastChangedField === "firstAmount" && values.firstAmount && values.firstAmount !== "" && (rate == null ? void 0 : rate.fee) && rate.fee !== "0") {
|
|
130
|
-
const calculatedSecondAmount = parseFloat(values.firstAmount) - Number(rate.fee);
|
|
131
|
-
setFieldValue(
|
|
132
|
-
"secondAmount",
|
|
133
|
-
calculatedSecondAmount > 0 ? calculatedSecondAmount : "0"
|
|
134
|
-
);
|
|
135
|
-
}
|
|
136
|
-
}, [values.firstAmount, rate == null ? void 0 : rate.fee, lastChangedField, touched.firstAmount]);
|
|
137
|
-
React.useEffect(() => {
|
|
138
|
-
if (!values.secondAmount && touched.secondAmount) {
|
|
139
|
-
setFieldValue("firstAmount", 0, true);
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
if (lastChangedField === "secondAmount" && values.secondAmount && values.secondAmount !== "" && (rate == null ? void 0 : rate.fee) && rate.fee !== "0") {
|
|
143
|
-
const calculatedFirstAmount = parseFloat(values.secondAmount) + Number(rate.fee);
|
|
144
|
-
setFieldValue("firstAmount", calculatedFirstAmount);
|
|
145
|
-
}
|
|
146
|
-
}, [values.secondAmount, rate == null ? void 0 : rate.fee, lastChangedField, touched.secondAmount]);
|
|
147
122
|
React.useEffect(() => {
|
|
148
123
|
setFieldValue("firstToken", firstToken, true);
|
|
149
124
|
}, [firstToken]);
|
|
@@ -173,8 +148,7 @@ const useBridgeFormik = ({
|
|
|
173
148
|
handleSubmit,
|
|
174
149
|
setFieldValue,
|
|
175
150
|
resetSwapForm,
|
|
176
|
-
setFieldTouched
|
|
177
|
-
setLastChangedField
|
|
151
|
+
setFieldTouched
|
|
178
152
|
};
|
|
179
153
|
};
|
|
180
154
|
exports.BridgeFormikValuesEnum = BridgeFormikValuesEnum;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useFormik } from "formik";
|
|
2
|
-
import {
|
|
2
|
+
import { useRef, useEffect } from "react";
|
|
3
3
|
import { object, string } from "yup";
|
|
4
4
|
import { useAccount } from "./useAccount.mjs";
|
|
5
5
|
import { useAmountSchema } from "./validation/useAmountSchema.mjs";
|
|
@@ -28,7 +28,6 @@ const useBridgeFormik = ({
|
|
|
28
28
|
rate,
|
|
29
29
|
onSubmit
|
|
30
30
|
}) => {
|
|
31
|
-
const [lastChangedField, setLastChangedField] = useState(null);
|
|
32
31
|
const pendingSigningRef = useRef();
|
|
33
32
|
const account = useAccount();
|
|
34
33
|
const initialValues = {
|
|
@@ -43,7 +42,7 @@ const useBridgeFormik = ({
|
|
|
43
42
|
setFieldValue("firstAmount", "");
|
|
44
43
|
setFieldValue("secondAmount", "");
|
|
45
44
|
};
|
|
46
|
-
const onSubmitFormik = async (
|
|
45
|
+
const onSubmitFormik = async (values) => {
|
|
47
46
|
var _a, _b;
|
|
48
47
|
if (pendingSigningRef.current) {
|
|
49
48
|
return;
|
|
@@ -53,11 +52,11 @@ const useBridgeFormik = ({
|
|
|
53
52
|
url: getApiURL(),
|
|
54
53
|
nativeAuthToken: nativeAuthToken ?? "",
|
|
55
54
|
body: {
|
|
56
|
-
tokenIn: ((_a =
|
|
55
|
+
tokenIn: ((_a = values.firstToken) == null ? void 0 : _a.address) ?? "",
|
|
57
56
|
amountIn: (firstAmount == null ? void 0 : firstAmount.toString()) ?? "",
|
|
58
|
-
fromChainId:
|
|
59
|
-
tokenOut: ((_b =
|
|
60
|
-
toChainId:
|
|
57
|
+
fromChainId: values.fromChainId ?? "",
|
|
58
|
+
tokenOut: ((_b = values.secondToken) == null ? void 0 : _b.address) ?? "",
|
|
59
|
+
toChainId: values.toChainId ?? "",
|
|
61
60
|
amountOut: (secondAmount == null ? void 0 : secondAmount.toString()) ?? "",
|
|
62
61
|
sender: account.address ?? "",
|
|
63
62
|
receiver: mvxAccountAddress ?? "",
|
|
@@ -109,7 +108,6 @@ const useBridgeFormik = ({
|
|
|
109
108
|
onSubmit: onSubmitFormik
|
|
110
109
|
});
|
|
111
110
|
const {
|
|
112
|
-
values,
|
|
113
111
|
errors,
|
|
114
112
|
touched,
|
|
115
113
|
handleBlur,
|
|
@@ -118,29 +116,6 @@ const useBridgeFormik = ({
|
|
|
118
116
|
setFieldValue,
|
|
119
117
|
setFieldTouched
|
|
120
118
|
} = formik;
|
|
121
|
-
useEffect(() => {
|
|
122
|
-
if (!values.firstAmount && touched.firstAmount) {
|
|
123
|
-
setFieldValue("secondAmount", 0, true);
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
if (lastChangedField === "firstAmount" && values.firstAmount && values.firstAmount !== "" && (rate == null ? void 0 : rate.fee) && rate.fee !== "0") {
|
|
127
|
-
const calculatedSecondAmount = parseFloat(values.firstAmount) - Number(rate.fee);
|
|
128
|
-
setFieldValue(
|
|
129
|
-
"secondAmount",
|
|
130
|
-
calculatedSecondAmount > 0 ? calculatedSecondAmount : "0"
|
|
131
|
-
);
|
|
132
|
-
}
|
|
133
|
-
}, [values.firstAmount, rate == null ? void 0 : rate.fee, lastChangedField, touched.firstAmount]);
|
|
134
|
-
useEffect(() => {
|
|
135
|
-
if (!values.secondAmount && touched.secondAmount) {
|
|
136
|
-
setFieldValue("firstAmount", 0, true);
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
if (lastChangedField === "secondAmount" && values.secondAmount && values.secondAmount !== "" && (rate == null ? void 0 : rate.fee) && rate.fee !== "0") {
|
|
140
|
-
const calculatedFirstAmount = parseFloat(values.secondAmount) + Number(rate.fee);
|
|
141
|
-
setFieldValue("firstAmount", calculatedFirstAmount);
|
|
142
|
-
}
|
|
143
|
-
}, [values.secondAmount, rate == null ? void 0 : rate.fee, lastChangedField, touched.secondAmount]);
|
|
144
119
|
useEffect(() => {
|
|
145
120
|
setFieldValue("firstToken", firstToken, true);
|
|
146
121
|
}, [firstToken]);
|
|
@@ -170,8 +145,7 @@ const useBridgeFormik = ({
|
|
|
170
145
|
handleSubmit,
|
|
171
146
|
setFieldValue,
|
|
172
147
|
resetSwapForm,
|
|
173
|
-
setFieldTouched
|
|
174
|
-
setLastChangedField
|
|
148
|
+
setFieldTouched
|
|
175
149
|
};
|
|
176
150
|
};
|
|
177
151
|
export {
|