@multiversx/sdk-dapp-liquidity 1.1.0-alpha.44 → 1.1.0-alpha.46

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 CHANGED
@@ -28,7 +28,7 @@
28
28
  },
29
29
  "homepage": "https://github.com/multiversx/mx-sdk-dapp-liquidity#readme",
30
30
  "license": "MIT",
31
- "version": "1.1.0-alpha.44",
31
+ "version": "1.1.0-alpha.46",
32
32
  "main": "index.js",
33
33
  "module": "index.mjs",
34
34
  "types": "index.d.ts",
@@ -141,6 +141,7 @@ const BridgeForm = ({
141
141
  const initializedInitialTokensRef = React.useRef(false);
142
142
  const [isTokenSelectorVisible, setIsTokenSelectorVisible] = React.useState(false);
143
143
  const [pendingSigning, setPendingSigning] = React.useState(false);
144
+ const [forceRefetchRate, setForceRefetchRate] = React.useState(1);
144
145
  const [siginingTransactionsCount, setSigningTransactionsCount] = React.useState(0);
145
146
  const account = reactjs_hooks_useAccount.useAccount();
146
147
  const { switchNetwork } = react.useAppKitNetwork();
@@ -569,6 +570,7 @@ const BridgeForm = ({
569
570
  toChainId: mvxChainId,
570
571
  secondToken,
571
572
  secondAmount,
573
+ setForceRefetchRate,
572
574
  onSubmit
573
575
  });
574
576
  const hasError = Boolean(
@@ -584,9 +586,9 @@ const BridgeForm = ({
584
586
  }
585
587
  fetchRateInterval = setInterval(() => {
586
588
  fetchRateDebounced(firstAmount);
587
- }, 60 * 1e3);
589
+ }, 50 * 1e3);
588
590
  return () => clearInterval(fetchRateInterval);
589
- }, [firstAmount, fetchRateDebounced]);
591
+ }, [firstAmount, forceRefetchRate, fetchRateDebounced]);
590
592
  React.useEffect(() => {
591
593
  if (!(rate == null ? void 0 : rate.amountOut)) {
592
594
  return;
@@ -138,6 +138,7 @@ const BridgeForm = ({
138
138
  const initializedInitialTokensRef = useRef(false);
139
139
  const [isTokenSelectorVisible, setIsTokenSelectorVisible] = useState(false);
140
140
  const [pendingSigning, setPendingSigning] = useState(false);
141
+ const [forceRefetchRate, setForceRefetchRate] = useState(1);
141
142
  const [siginingTransactionsCount, setSigningTransactionsCount] = useState(0);
142
143
  const account = useAccount();
143
144
  const { switchNetwork } = useAppKitNetwork();
@@ -566,6 +567,7 @@ const BridgeForm = ({
566
567
  toChainId: mvxChainId,
567
568
  secondToken,
568
569
  secondAmount,
570
+ setForceRefetchRate,
569
571
  onSubmit
570
572
  });
571
573
  const hasError = Boolean(
@@ -581,9 +583,9 @@ const BridgeForm = ({
581
583
  }
582
584
  fetchRateInterval = setInterval(() => {
583
585
  fetchRateDebounced(firstAmount);
584
- }, 60 * 1e3);
586
+ }, 50 * 1e3);
585
587
  return () => clearInterval(fetchRateInterval);
586
- }, [firstAmount, fetchRateDebounced]);
588
+ }, [firstAmount, forceRefetchRate, fetchRateDebounced]);
587
589
  useEffect(() => {
588
590
  if (!(rate == null ? void 0 : rate.amountOut)) {
589
591
  return;
@@ -19,7 +19,7 @@ export interface TradeFormikValuesType {
19
19
  fromChainId?: string;
20
20
  toChainId?: string;
21
21
  }
22
- export declare const useBridgeFormik: ({ mvxAccountAddress, firstToken, firstAmount, secondToken, secondAmount, fromChainId, toChainId, rate, onSubmit }: {
22
+ export declare const useBridgeFormik: ({ mvxAccountAddress, firstToken, firstAmount, secondToken, secondAmount, fromChainId, toChainId, setForceRefetchRate, rate, onSubmit }: {
23
23
  mvxAccountAddress?: string;
24
24
  firstAmount?: string;
25
25
  secondAmount?: string;
@@ -27,6 +27,7 @@ export declare const useBridgeFormik: ({ mvxAccountAddress, firstToken, firstAmo
27
27
  toChainId?: string;
28
28
  firstToken?: TokenType;
29
29
  secondToken?: TokenType;
30
+ setForceRefetchRate?: (value: (previous: number) => number) => void;
30
31
  rate?: RateRequestResponse;
31
32
  onSubmit: ({ transactions, provider }: {
32
33
  transactions: ServerTransaction[];
@@ -28,6 +28,7 @@ const useBridgeFormik = ({
28
28
  secondAmount,
29
29
  fromChainId,
30
30
  toChainId,
31
+ setForceRefetchRate,
31
32
  rate,
32
33
  onSubmit
33
34
  }) => {
@@ -52,34 +53,40 @@ const useBridgeFormik = ({
52
53
  return;
53
54
  }
54
55
  pendingSigningRef.current = true;
55
- const { data } = await api_confirmRate.confirmRate({
56
- url: helpers_getApiURL.getApiURL(),
57
- nativeAuthToken: nativeAuthToken ?? "",
58
- body: {
59
- tokenIn: ((_a = values.firstToken) == null ? void 0 : _a.address) ?? "",
60
- amountIn: (firstAmount == null ? void 0 : firstAmount.toString()) ?? "",
61
- fromChainId: values.fromChainId ?? "",
62
- tokenOut: ((_b = values.secondToken) == null ? void 0 : _b.address) ?? "",
63
- toChainId: values.toChainId ?? "",
64
- amountOut: (secondAmount == null ? void 0 : secondAmount.toString()) ?? "",
65
- sender: account.address ?? "",
66
- receiver: mvxAccountAddress ?? "",
67
- fee: (rate == null ? void 0 : rate.fee) ?? "0",
68
- provider: (rate == null ? void 0 : rate.provider) ?? types_providerType.ProviderType.None,
69
- orderId: (rate == null ? void 0 : rate.orderId) ?? ""
56
+ try {
57
+ const { data } = await api_confirmRate.confirmRate({
58
+ url: helpers_getApiURL.getApiURL(),
59
+ nativeAuthToken: nativeAuthToken ?? "",
60
+ body: {
61
+ tokenIn: ((_a = values.firstToken) == null ? void 0 : _a.address) ?? "",
62
+ amountIn: (firstAmount == null ? void 0 : firstAmount.toString()) ?? "",
63
+ fromChainId: values.fromChainId ?? "",
64
+ tokenOut: ((_b = values.secondToken) == null ? void 0 : _b.address) ?? "",
65
+ toChainId: values.toChainId ?? "",
66
+ amountOut: (secondAmount == null ? void 0 : secondAmount.toString()) ?? "",
67
+ sender: account.address ?? "",
68
+ receiver: mvxAccountAddress ?? "",
69
+ fee: (rate == null ? void 0 : rate.fee) ?? "0",
70
+ provider: (rate == null ? void 0 : rate.provider) ?? types_providerType.ProviderType.None,
71
+ orderId: (rate == null ? void 0 : rate.orderId) ?? ""
72
+ }
73
+ });
74
+ const transactions = data;
75
+ if (!transactions || transactions.length === 0) {
76
+ pendingSigningRef.current = false;
77
+ return;
70
78
  }
71
- });
72
- const transactions = data;
73
- if (!transactions || transactions.length === 0) {
79
+ resetSwapForm();
80
+ onSubmit({
81
+ transactions,
82
+ provider: (rate == null ? void 0 : rate.provider) ?? types_providerType.ProviderType.None
83
+ });
84
+ } catch (error) {
85
+ console.error("Error confirming rate:", error);
86
+ setForceRefetchRate == null ? void 0 : setForceRefetchRate((prevState) => prevState + 1);
87
+ } finally {
74
88
  pendingSigningRef.current = false;
75
- return;
76
89
  }
77
- resetSwapForm();
78
- onSubmit({
79
- transactions,
80
- provider: (rate == null ? void 0 : rate.provider) ?? types_providerType.ProviderType.None
81
- });
82
- pendingSigningRef.current = false;
83
90
  };
84
91
  const formik$1 = formik.useFormik({
85
92
  initialValues,
@@ -25,6 +25,7 @@ const useBridgeFormik = ({
25
25
  secondAmount,
26
26
  fromChainId,
27
27
  toChainId,
28
+ setForceRefetchRate,
28
29
  rate,
29
30
  onSubmit
30
31
  }) => {
@@ -49,34 +50,40 @@ const useBridgeFormik = ({
49
50
  return;
50
51
  }
51
52
  pendingSigningRef.current = true;
52
- const { data } = await confirmRate({
53
- url: getApiURL(),
54
- nativeAuthToken: nativeAuthToken ?? "",
55
- body: {
56
- tokenIn: ((_a = values.firstToken) == null ? void 0 : _a.address) ?? "",
57
- amountIn: (firstAmount == null ? void 0 : firstAmount.toString()) ?? "",
58
- fromChainId: values.fromChainId ?? "",
59
- tokenOut: ((_b = values.secondToken) == null ? void 0 : _b.address) ?? "",
60
- toChainId: values.toChainId ?? "",
61
- amountOut: (secondAmount == null ? void 0 : secondAmount.toString()) ?? "",
62
- sender: account.address ?? "",
63
- receiver: mvxAccountAddress ?? "",
64
- fee: (rate == null ? void 0 : rate.fee) ?? "0",
65
- provider: (rate == null ? void 0 : rate.provider) ?? ProviderType.None,
66
- orderId: (rate == null ? void 0 : rate.orderId) ?? ""
53
+ try {
54
+ const { data } = await confirmRate({
55
+ url: getApiURL(),
56
+ nativeAuthToken: nativeAuthToken ?? "",
57
+ body: {
58
+ tokenIn: ((_a = values.firstToken) == null ? void 0 : _a.address) ?? "",
59
+ amountIn: (firstAmount == null ? void 0 : firstAmount.toString()) ?? "",
60
+ fromChainId: values.fromChainId ?? "",
61
+ tokenOut: ((_b = values.secondToken) == null ? void 0 : _b.address) ?? "",
62
+ toChainId: values.toChainId ?? "",
63
+ amountOut: (secondAmount == null ? void 0 : secondAmount.toString()) ?? "",
64
+ sender: account.address ?? "",
65
+ receiver: mvxAccountAddress ?? "",
66
+ fee: (rate == null ? void 0 : rate.fee) ?? "0",
67
+ provider: (rate == null ? void 0 : rate.provider) ?? ProviderType.None,
68
+ orderId: (rate == null ? void 0 : rate.orderId) ?? ""
69
+ }
70
+ });
71
+ const transactions = data;
72
+ if (!transactions || transactions.length === 0) {
73
+ pendingSigningRef.current = false;
74
+ return;
67
75
  }
68
- });
69
- const transactions = data;
70
- if (!transactions || transactions.length === 0) {
76
+ resetSwapForm();
77
+ onSubmit({
78
+ transactions,
79
+ provider: (rate == null ? void 0 : rate.provider) ?? ProviderType.None
80
+ });
81
+ } catch (error) {
82
+ console.error("Error confirming rate:", error);
83
+ setForceRefetchRate == null ? void 0 : setForceRefetchRate((prevState) => prevState + 1);
84
+ } finally {
71
85
  pendingSigningRef.current = false;
72
- return;
73
86
  }
74
- resetSwapForm();
75
- onSubmit({
76
- transactions,
77
- provider: (rate == null ? void 0 : rate.provider) ?? ProviderType.None
78
- });
79
- pendingSigningRef.current = false;
80
87
  };
81
88
  const formik = useFormik({
82
89
  initialValues,