@multiversx/sdk-dapp-liquidity 1.0.3 → 1.0.5

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.
@@ -1,5 +1,5 @@
1
1
  import { ServerTransaction } from '../types/transaction';
2
- import { ConfirmRateDto } from '../dto/ConfirmRate.dto.ts';
2
+ import { ConfirmRateDto } from '../dto/ConfirmRate.dto';
3
3
  import { AxiosResponse } from 'axios';
4
4
 
5
5
  type ConfirmRateProps = {
@@ -1,11 +1,13 @@
1
1
  import { ServerTransaction } from '../types/transaction';
2
+ import { ProviderType } from '../types/providerType';
2
3
  import { BatchTransactions } from '../types/batchTransactions';
3
4
  import { AxiosRequestConfig, AxiosResponse } from 'axios';
4
5
 
5
6
  export type SendTransactionsType = {
6
7
  transactions: ServerTransaction[];
8
+ provider: ProviderType;
7
9
  url: string;
8
10
  token: string;
9
11
  axiosConfig?: AxiosRequestConfig;
10
12
  };
11
- export declare const sendTransactions: ({ transactions, url, token, axiosConfig }: SendTransactionsType) => Promise<AxiosResponse<BatchTransactions>>;
13
+ export declare const sendTransactions: ({ transactions, provider, url, token, axiosConfig }: SendTransactionsType) => Promise<AxiosResponse<BatchTransactions>>;
@@ -5,6 +5,7 @@ const axios = require("axios");
5
5
  const helpers_serializeTransaction = require("../helpers/serializeTransaction.js");
6
6
  const sendTransactions = async ({
7
7
  transactions,
8
+ provider,
8
9
  url,
9
10
  token,
10
11
  axiosConfig
@@ -20,9 +21,12 @@ const sendTransactions = async ({
20
21
  };
21
22
  return axios.post(
22
23
  `/transactions`,
23
- transactions.map(
24
- (transaction) => JSON.parse(helpers_serializeTransaction.serializeTransaction(transaction))
25
- ),
24
+ {
25
+ transactions: transactions.map(
26
+ (transaction) => JSON.parse(helpers_serializeTransaction.serializeTransaction(transaction))
27
+ ),
28
+ provider
29
+ },
26
30
  config
27
31
  );
28
32
  };
@@ -2,6 +2,7 @@ import axios from "axios";
2
2
  import { serializeTransaction } from "../helpers/serializeTransaction.mjs";
3
3
  const sendTransactions = async ({
4
4
  transactions,
5
+ provider,
5
6
  url,
6
7
  token,
7
8
  axiosConfig
@@ -17,9 +18,12 @@ const sendTransactions = async ({
17
18
  };
18
19
  return axios.post(
19
20
  `/transactions`,
20
- transactions.map(
21
- (transaction) => JSON.parse(serializeTransaction(transaction))
22
- ),
21
+ {
22
+ transactions: transactions.map(
23
+ (transaction) => JSON.parse(serializeTransaction(transaction))
24
+ ),
25
+ provider
26
+ },
23
27
  config
24
28
  );
25
29
  };
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
3
  const axios = require("axios");
4
+ const types_providerType = require("../../types/providerType.js");
4
5
  const api_confirmRate = require("../confirmRate.js");
5
6
  jest.mock("axios");
6
7
  const mockedAxios = axios;
@@ -16,7 +17,9 @@ describe("confirmRate", () => {
16
17
  fromChainId: "97",
17
18
  toChainId: "44",
18
19
  sender: "0x123",
19
- receiver: "0x456"
20
+ receiver: "0x456",
21
+ provider: types_providerType.ProviderType.None,
22
+ orderId: "123"
20
23
  };
21
24
  const nativeAuthToken = "ZXJkMXdoOWMwc2pyMnhuOGh6ZjAybHd3Y3I0amsyczg0dGF0OXVkMmthcTZ6cjd4enB2bDlsNXE4YXdtZXg.YUhSMGNITTZMeTlrWlhadVpYUXVkR1Z0Y0d4aGRHVXRaR0Z3Y0M1dGRXeDBhWFpsY25ONExtTnZiUS5lZjc2YjRjNzZlZjZlMTNhNjM5MDc2N2ZjNzhhODhjYTRiYmI1OTE4YTJiOWRkYzQ0OTQyOTI3NjkzNjUwNjUxLjg2NDAwLmV5SjBhVzFsYzNSaGJYQWlPakUzTXpNME9EazBNREI5.04a986df7f0142837f9b1ca1ae4829f7b471e4c3470602ca6a16f2a4d7c6616c4e7628a93b4ce87d9534e95ab9215f893faeb9e0904e1d834007c16e43b12d01";
22
25
  const config = {
@@ -61,7 +64,9 @@ describe("confirmRate", () => {
61
64
  fromChainId: "97",
62
65
  toChainId: "44",
63
66
  sender: "0x123",
64
- receiver: "0x456"
67
+ receiver: "0x456",
68
+ provider: types_providerType.ProviderType.None,
69
+ orderId: "123"
65
70
  };
66
71
  const nativeAuthToken = "";
67
72
  const config = {
@@ -104,7 +109,9 @@ describe("confirmRate", () => {
104
109
  fromChainId: "97",
105
110
  toChainId: "44",
106
111
  sender: "0x123",
107
- receiver: "0x456"
112
+ receiver: "0x456",
113
+ provider: types_providerType.ProviderType.None,
114
+ orderId: "123"
108
115
  };
109
116
  const nativeAuthToken = "";
110
117
  const config = {
@@ -1,4 +1,5 @@
1
1
  import axios from "axios";
2
+ import { ProviderType } from "../../types/providerType.mjs";
2
3
  import { confirmRate } from "../confirmRate.mjs";
3
4
  jest.mock("axios");
4
5
  const mockedAxios = axios;
@@ -14,7 +15,9 @@ describe("confirmRate", () => {
14
15
  fromChainId: "97",
15
16
  toChainId: "44",
16
17
  sender: "0x123",
17
- receiver: "0x456"
18
+ receiver: "0x456",
19
+ provider: ProviderType.None,
20
+ orderId: "123"
18
21
  };
19
22
  const nativeAuthToken = "ZXJkMXdoOWMwc2pyMnhuOGh6ZjAybHd3Y3I0amsyczg0dGF0OXVkMmthcTZ6cjd4enB2bDlsNXE4YXdtZXg.YUhSMGNITTZMeTlrWlhadVpYUXVkR1Z0Y0d4aGRHVXRaR0Z3Y0M1dGRXeDBhWFpsY25ONExtTnZiUS5lZjc2YjRjNzZlZjZlMTNhNjM5MDc2N2ZjNzhhODhjYTRiYmI1OTE4YTJiOWRkYzQ0OTQyOTI3NjkzNjUwNjUxLjg2NDAwLmV5SjBhVzFsYzNSaGJYQWlPakUzTXpNME9EazBNREI5.04a986df7f0142837f9b1ca1ae4829f7b471e4c3470602ca6a16f2a4d7c6616c4e7628a93b4ce87d9534e95ab9215f893faeb9e0904e1d834007c16e43b12d01";
20
23
  const config = {
@@ -59,7 +62,9 @@ describe("confirmRate", () => {
59
62
  fromChainId: "97",
60
63
  toChainId: "44",
61
64
  sender: "0x123",
62
- receiver: "0x456"
65
+ receiver: "0x456",
66
+ provider: ProviderType.None,
67
+ orderId: "123"
63
68
  };
64
69
  const nativeAuthToken = "";
65
70
  const config = {
@@ -102,7 +107,9 @@ describe("confirmRate", () => {
102
107
  fromChainId: "97",
103
108
  toChainId: "44",
104
109
  sender: "0x123",
105
- receiver: "0x456"
110
+ receiver: "0x456",
111
+ provider: ProviderType.None,
112
+ orderId: "123"
106
113
  };
107
114
  const nativeAuthToken = "";
108
115
  const config = {
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
3
  const axios = require("axios");
4
+ const types_providerType = require("../../types/providerType.js");
4
5
  const api_getRate = require("../getRate.js");
5
6
  jest.mock("axios");
6
7
  const mockedAxios = axios;
@@ -24,7 +25,9 @@ describe("getRate", () => {
24
25
  };
25
26
  const response = {
26
27
  fee: "5",
27
- amountOut: "100"
28
+ amountOut: "100",
29
+ provider: types_providerType.ProviderType.None,
30
+ orderId: "123"
28
31
  };
29
32
  mockedAxios.post.mockResolvedValue({ data: response });
30
33
  const result = await api_getRate.getRate({
@@ -50,7 +53,9 @@ describe("getRate", () => {
50
53
  };
51
54
  const response = {
52
55
  fee: "5",
53
- amountOut: "100"
56
+ amountOut: "100",
57
+ provider: types_providerType.ProviderType.None,
58
+ orderId: "123"
54
59
  };
55
60
  mockedAxios.post.mockResolvedValue({ data: response });
56
61
  const result = await api_getRate.getRate({
@@ -1,4 +1,5 @@
1
1
  import axios from "axios";
2
+ import { ProviderType } from "../../types/providerType.mjs";
2
3
  import { getRate } from "../getRate.mjs";
3
4
  jest.mock("axios");
4
5
  const mockedAxios = axios;
@@ -22,7 +23,9 @@ describe("getRate", () => {
22
23
  };
23
24
  const response = {
24
25
  fee: "5",
25
- amountOut: "100"
26
+ amountOut: "100",
27
+ provider: ProviderType.None,
28
+ orderId: "123"
26
29
  };
27
30
  mockedAxios.post.mockResolvedValue({ data: response });
28
31
  const result = await getRate({
@@ -48,7 +51,9 @@ describe("getRate", () => {
48
51
  };
49
52
  const response = {
50
53
  fee: "5",
51
- amountOut: "100"
54
+ amountOut: "100",
55
+ provider: ProviderType.None,
56
+ orderId: "123"
52
57
  };
53
58
  mockedAxios.post.mockResolvedValue({ data: response });
54
59
  const result = await getRate({
@@ -3,6 +3,7 @@
3
3
  const axios = require("axios");
4
4
  const api_sendTransactions = require("../sendTransactions.js");
5
5
  const helpers_serializeTransaction = require("../../helpers/serializeTransaction.js");
6
+ const types_providerType = require("../../types/providerType.js");
6
7
  jest.mock("axios");
7
8
  const mockedAxios = axios;
8
9
  describe("sendTransactions", () => {
@@ -24,7 +25,12 @@ describe("sendTransactions", () => {
24
25
  it("POST sendTransactions successfully", async () => {
25
26
  const response = { data: { transactions } };
26
27
  mockedAxios.post.mockResolvedValue(response);
27
- const result = await api_sendTransactions.sendTransactions({ transactions, url, token });
28
+ const result = await api_sendTransactions.sendTransactions({
29
+ transactions,
30
+ provider: types_providerType.ProviderType.None,
31
+ url,
32
+ token
33
+ });
28
34
  expect(mockedAxios.post).toHaveBeenCalledWith(
29
35
  "/transactions",
30
36
  transactions.map(
@@ -47,6 +53,7 @@ describe("sendTransactions", () => {
47
53
  mockedAxios.post.mockResolvedValue(response);
48
54
  const result = await api_sendTransactions.sendTransactions({
49
55
  transactions,
56
+ provider: types_providerType.ProviderType.None,
50
57
  url,
51
58
  token,
52
59
  axiosConfig
@@ -75,6 +82,7 @@ describe("sendTransactions", () => {
75
82
  transactions: transactions.map(
76
83
  (transaction) => JSON.parse(helpers_serializeTransaction.serializeTransaction(transaction))
77
84
  ),
85
+ provider: types_providerType.ProviderType.None,
78
86
  url,
79
87
  token
80
88
  })
@@ -1,6 +1,7 @@
1
1
  import axios from "axios";
2
2
  import { sendTransactions } from "../sendTransactions.mjs";
3
3
  import { serializeTransaction } from "../../helpers/serializeTransaction.mjs";
4
+ import { ProviderType } from "../../types/providerType.mjs";
4
5
  jest.mock("axios");
5
6
  const mockedAxios = axios;
6
7
  describe("sendTransactions", () => {
@@ -22,7 +23,12 @@ describe("sendTransactions", () => {
22
23
  it("POST sendTransactions successfully", async () => {
23
24
  const response = { data: { transactions } };
24
25
  mockedAxios.post.mockResolvedValue(response);
25
- const result = await sendTransactions({ transactions, url, token });
26
+ const result = await sendTransactions({
27
+ transactions,
28
+ provider: ProviderType.None,
29
+ url,
30
+ token
31
+ });
26
32
  expect(mockedAxios.post).toHaveBeenCalledWith(
27
33
  "/transactions",
28
34
  transactions.map(
@@ -45,6 +51,7 @@ describe("sendTransactions", () => {
45
51
  mockedAxios.post.mockResolvedValue(response);
46
52
  const result = await sendTransactions({
47
53
  transactions,
54
+ provider: ProviderType.None,
48
55
  url,
49
56
  token,
50
57
  axiosConfig
@@ -73,6 +80,7 @@ describe("sendTransactions", () => {
73
80
  transactions: transactions.map(
74
81
  (transaction) => JSON.parse(serializeTransaction(transaction))
75
82
  ),
83
+ provider: ProviderType.None,
76
84
  url,
77
85
  token
78
86
  })
@@ -1,11 +1,11 @@
1
- export interface ConfirmRateDto {
1
+ import { RateRequestResponse } from '../types';
2
+
3
+ export interface ConfirmRateDto extends RateRequestResponse {
2
4
  tokenIn: string;
3
5
  amountIn: string;
4
6
  fromChainId: string;
5
7
  tokenOut: string;
6
8
  toChainId: string;
7
- fee: string;
8
- amountOut: string;
9
9
  sender: string;
10
10
  receiver: string;
11
11
  }
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.0.3",
31
+ "version": "1.0.5",
32
32
  "main": "index.js",
33
33
  "module": "index.mjs",
34
34
  "types": "index.d.ts",
@@ -349,7 +349,10 @@ const BridgeForm = ({
349
349
  });
350
350
  };
351
351
  const onSubmit = require$$0.useCallback(
352
- async (transactions) => {
352
+ async ({
353
+ transactions,
354
+ provider
355
+ }) => {
353
356
  const signedTransactions = [];
354
357
  setPendingSigning(true);
355
358
  setSigningTransactionsCount(() => transactions.length);
@@ -392,6 +395,7 @@ const BridgeForm = ({
392
395
  }
393
396
  await sendTransactions({
394
397
  transactions: signedTransactions,
398
+ provider,
395
399
  url: helpers_getApiURL.getApiURL() ?? "",
396
400
  token: nativeAuthToken ?? ""
397
401
  });
@@ -431,7 +435,7 @@ const BridgeForm = ({
431
435
  resetSwapForm,
432
436
  setLastChangedField
433
437
  } = reactjs_hooks_useBridgeFormik.useBridgeFormik({
434
- fee: rate == null ? void 0 : rate.fee,
438
+ rate,
435
439
  nativeAuthToken,
436
440
  mvxAccountAddress: mvxAddress,
437
441
  firstToken,
@@ -472,6 +476,23 @@ const BridgeForm = ({
472
476
  };
473
477
  });
474
478
  }, [evmTokensWithBalances, firstToken == null ? void 0 : firstToken.address]);
479
+ require$$0.useEffect(() => {
480
+ const selectedTokenOption = mvxTokensWithBalances == null ? void 0 : mvxTokensWithBalances.find(
481
+ (x) => x.address === (secondToken == null ? void 0 : secondToken.address)
482
+ );
483
+ if (!selectedTokenOption) {
484
+ return;
485
+ }
486
+ setSecondToken((prevState) => {
487
+ if (!prevState) {
488
+ return prevState;
489
+ }
490
+ return {
491
+ ...prevState,
492
+ balance: selectedTokenOption == null ? void 0 : selectedTokenOption.balance
493
+ };
494
+ });
495
+ }, [mvxTokensWithBalances, secondToken == null ? void 0 : secondToken.address]);
475
496
  return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: /* @__PURE__ */ jsxRuntime.jsxs(
476
497
  "form",
477
498
  {
@@ -346,7 +346,10 @@ const BridgeForm = ({
346
346
  });
347
347
  };
348
348
  const onSubmit = useCallback(
349
- async (transactions) => {
349
+ async ({
350
+ transactions,
351
+ provider
352
+ }) => {
350
353
  const signedTransactions = [];
351
354
  setPendingSigning(true);
352
355
  setSigningTransactionsCount(() => transactions.length);
@@ -389,6 +392,7 @@ const BridgeForm = ({
389
392
  }
390
393
  await sendTransactions({
391
394
  transactions: signedTransactions,
395
+ provider,
392
396
  url: getApiURL() ?? "",
393
397
  token: nativeAuthToken ?? ""
394
398
  });
@@ -428,7 +432,7 @@ const BridgeForm = ({
428
432
  resetSwapForm,
429
433
  setLastChangedField
430
434
  } = useBridgeFormik({
431
- fee: rate == null ? void 0 : rate.fee,
435
+ rate,
432
436
  nativeAuthToken,
433
437
  mvxAccountAddress: mvxAddress,
434
438
  firstToken,
@@ -469,6 +473,23 @@ const BridgeForm = ({
469
473
  };
470
474
  });
471
475
  }, [evmTokensWithBalances, firstToken == null ? void 0 : firstToken.address]);
476
+ useEffect(() => {
477
+ const selectedTokenOption = mvxTokensWithBalances == null ? void 0 : mvxTokensWithBalances.find(
478
+ (x) => x.address === (secondToken == null ? void 0 : secondToken.address)
479
+ );
480
+ if (!selectedTokenOption) {
481
+ return;
482
+ }
483
+ setSecondToken((prevState) => {
484
+ if (!prevState) {
485
+ return prevState;
486
+ }
487
+ return {
488
+ ...prevState,
489
+ balance: selectedTokenOption == null ? void 0 : selectedTokenOption.balance
490
+ };
491
+ });
492
+ }, [mvxTokensWithBalances, secondToken == null ? void 0 : secondToken.address]);
472
493
  return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsxs(
473
494
  "form",
474
495
  {
@@ -1,5 +1,7 @@
1
1
  import { ServerTransaction } from '../../types/transaction';
2
2
  import { TokenType } from '../../types/token';
3
+ import { ProviderType } from '../../types/providerType';
4
+ import { RateRequestResponse } from '../../types';
3
5
 
4
6
  export declare enum BridgeFormikValuesEnum {
5
7
  firstToken = "firstToken",
@@ -17,7 +19,7 @@ export interface TradeFormikValuesType {
17
19
  fromChainId?: string;
18
20
  toChainId?: string;
19
21
  }
20
- export declare const useBridgeFormik: ({ nativeAuthToken, mvxAccountAddress, firstToken, firstAmount, secondToken, secondAmount, fromChainId, toChainId, fee, onSubmit }: {
22
+ export declare const useBridgeFormik: ({ nativeAuthToken, mvxAccountAddress, firstToken, firstAmount, secondToken, secondAmount, fromChainId, toChainId, rate, onSubmit }: {
21
23
  mvxAccountAddress?: string;
22
24
  nativeAuthToken?: string;
23
25
  firstAmount?: string;
@@ -26,8 +28,11 @@ export declare const useBridgeFormik: ({ nativeAuthToken, mvxAccountAddress, fir
26
28
  toChainId?: string;
27
29
  firstToken?: TokenType;
28
30
  secondToken?: TokenType;
29
- fee?: string;
30
- onSubmit: (transactions: ServerTransaction[]) => void;
31
+ rate?: RateRequestResponse;
32
+ onSubmit: ({ transactions, provider }: {
33
+ transactions: ServerTransaction[];
34
+ provider: ProviderType;
35
+ }) => void;
31
36
  }) => {
32
37
  formik: {
33
38
  initialValues: TradeFormikValuesType;
@@ -10,6 +10,7 @@ const reactjs_hooks_validation_useAmountSchema = require("./validation/useAmount
10
10
  const reactjs_hooks_validation_useSecondAmountSchema = require("./validation/useSecondAmountSchema.js");
11
11
  const api_confirmRate = require("../../api/confirmRate.js");
12
12
  const helpers_getApiURL = require("../../helpers/getApiURL.js");
13
+ const types_providerType = require("../../types/providerType.js");
13
14
  var BridgeFormikValuesEnum = /* @__PURE__ */ ((BridgeFormikValuesEnum2) => {
14
15
  BridgeFormikValuesEnum2["firstToken"] = "firstToken";
15
16
  BridgeFormikValuesEnum2["firstAmount"] = "firstAmount";
@@ -28,7 +29,7 @@ const useBridgeFormik = ({
28
29
  secondAmount,
29
30
  fromChainId,
30
31
  toChainId,
31
- fee = "0",
32
+ rate,
32
33
  onSubmit
33
34
  }) => {
34
35
  const [lastChangedField, setLastChangedField] = require$$0.useState(null);
@@ -67,10 +68,12 @@ const useBridgeFormik = ({
67
68
  fromChainId: values2.fromChainId ?? "",
68
69
  tokenOut: ((_b = values2.secondToken) == null ? void 0 : _b.address) ?? "",
69
70
  toChainId: values2.toChainId ?? "",
70
- fee: fee ?? "0",
71
71
  amountOut: (secondAmount == null ? void 0 : secondAmount.toString()) ?? "",
72
72
  sender: account.address ?? "",
73
- receiver: mvxAccountAddress ?? ""
73
+ receiver: mvxAccountAddress ?? "",
74
+ fee: (rate == null ? void 0 : rate.fee) ?? "0",
75
+ provider: (rate == null ? void 0 : rate.provider) ?? types_providerType.ProviderType.None,
76
+ orderId: (rate == null ? void 0 : rate.orderId) ?? ""
74
77
  }
75
78
  });
76
79
  const transactions = data;
@@ -79,7 +82,10 @@ const useBridgeFormik = ({
79
82
  return;
80
83
  }
81
84
  resetSwapForm();
82
- onSubmit(transactions);
85
+ onSubmit({
86
+ transactions,
87
+ provider: (rate == null ? void 0 : rate.provider) ?? types_providerType.ProviderType.None
88
+ });
83
89
  pendingSigningRef.current = false;
84
90
  };
85
91
  const formik$1 = formik.useFormik({
@@ -128,23 +134,23 @@ const useBridgeFormik = ({
128
134
  return;
129
135
  }
130
136
  if (lastChangedField === "firstAmount" && values.firstAmount && values.firstAmount !== "") {
131
- const calculatedSecondAmount = parseFloat(values.firstAmount) - Number(fee);
137
+ const calculatedSecondAmount = parseFloat(values.firstAmount) - Number((rate == null ? void 0 : rate.fee) ?? "0");
132
138
  setFieldValue(
133
139
  "secondAmount",
134
140
  calculatedSecondAmount > 0 ? calculatedSecondAmount : "0"
135
141
  );
136
142
  }
137
- }, [values.firstAmount, fee, lastChangedField, touched.firstAmount]);
143
+ }, [values.firstAmount, rate == null ? void 0 : rate.fee, lastChangedField, touched.firstAmount]);
138
144
  require$$0.useEffect(() => {
139
145
  if (!values.secondAmount && touched.secondAmount) {
140
146
  setFieldValue("firstAmount", 0, true);
141
147
  return;
142
148
  }
143
149
  if (lastChangedField === "secondAmount" && values.secondAmount && values.secondAmount !== "") {
144
- const calculatedFirstAmount = parseFloat(values.secondAmount) + Number(fee);
150
+ const calculatedFirstAmount = parseFloat(values.secondAmount) + Number((rate == null ? void 0 : rate.fee) ?? "0");
145
151
  setFieldValue("firstAmount", calculatedFirstAmount);
146
152
  }
147
- }, [values.secondAmount, fee, lastChangedField, touched.secondAmount]);
153
+ }, [values.secondAmount, rate == null ? void 0 : rate.fee, lastChangedField, touched.secondAmount]);
148
154
  require$$0.useEffect(() => {
149
155
  setFieldValue("firstToken", firstToken, true);
150
156
  }, [firstToken]);
@@ -7,6 +7,7 @@ import { useAmountSchema } from "./validation/useAmountSchema.mjs";
7
7
  import { useSecondAmountSchema } from "./validation/useSecondAmountSchema.mjs";
8
8
  import { confirmRate } from "../../api/confirmRate.mjs";
9
9
  import { getApiURL } from "../../helpers/getApiURL.mjs";
10
+ import { ProviderType } from "../../types/providerType.mjs";
10
11
  var BridgeFormikValuesEnum = /* @__PURE__ */ ((BridgeFormikValuesEnum2) => {
11
12
  BridgeFormikValuesEnum2["firstToken"] = "firstToken";
12
13
  BridgeFormikValuesEnum2["firstAmount"] = "firstAmount";
@@ -25,7 +26,7 @@ const useBridgeFormik = ({
25
26
  secondAmount,
26
27
  fromChainId,
27
28
  toChainId,
28
- fee = "0",
29
+ rate,
29
30
  onSubmit
30
31
  }) => {
31
32
  const [lastChangedField, setLastChangedField] = useState(null);
@@ -64,10 +65,12 @@ const useBridgeFormik = ({
64
65
  fromChainId: values2.fromChainId ?? "",
65
66
  tokenOut: ((_b = values2.secondToken) == null ? void 0 : _b.address) ?? "",
66
67
  toChainId: values2.toChainId ?? "",
67
- fee: fee ?? "0",
68
68
  amountOut: (secondAmount == null ? void 0 : secondAmount.toString()) ?? "",
69
69
  sender: account.address ?? "",
70
- receiver: mvxAccountAddress ?? ""
70
+ receiver: mvxAccountAddress ?? "",
71
+ fee: (rate == null ? void 0 : rate.fee) ?? "0",
72
+ provider: (rate == null ? void 0 : rate.provider) ?? ProviderType.None,
73
+ orderId: (rate == null ? void 0 : rate.orderId) ?? ""
71
74
  }
72
75
  });
73
76
  const transactions = data;
@@ -76,7 +79,10 @@ const useBridgeFormik = ({
76
79
  return;
77
80
  }
78
81
  resetSwapForm();
79
- onSubmit(transactions);
82
+ onSubmit({
83
+ transactions,
84
+ provider: (rate == null ? void 0 : rate.provider) ?? ProviderType.None
85
+ });
80
86
  pendingSigningRef.current = false;
81
87
  };
82
88
  const formik = useFormik({
@@ -125,23 +131,23 @@ const useBridgeFormik = ({
125
131
  return;
126
132
  }
127
133
  if (lastChangedField === "firstAmount" && values.firstAmount && values.firstAmount !== "") {
128
- const calculatedSecondAmount = parseFloat(values.firstAmount) - Number(fee);
134
+ const calculatedSecondAmount = parseFloat(values.firstAmount) - Number((rate == null ? void 0 : rate.fee) ?? "0");
129
135
  setFieldValue(
130
136
  "secondAmount",
131
137
  calculatedSecondAmount > 0 ? calculatedSecondAmount : "0"
132
138
  );
133
139
  }
134
- }, [values.firstAmount, fee, lastChangedField, touched.firstAmount]);
140
+ }, [values.firstAmount, rate == null ? void 0 : rate.fee, lastChangedField, touched.firstAmount]);
135
141
  useEffect(() => {
136
142
  if (!values.secondAmount && touched.secondAmount) {
137
143
  setFieldValue("firstAmount", 0, true);
138
144
  return;
139
145
  }
140
146
  if (lastChangedField === "secondAmount" && values.secondAmount && values.secondAmount !== "") {
141
- const calculatedFirstAmount = parseFloat(values.secondAmount) + Number(fee);
147
+ const calculatedFirstAmount = parseFloat(values.secondAmount) + Number((rate == null ? void 0 : rate.fee) ?? "0");
142
148
  setFieldValue("firstAmount", calculatedFirstAmount);
143
149
  }
144
- }, [values.secondAmount, fee, lastChangedField, touched.secondAmount]);
150
+ }, [values.secondAmount, rate == null ? void 0 : rate.fee, lastChangedField, touched.secondAmount]);
145
151
  useEffect(() => {
146
152
  setFieldValue("firstToken", firstToken, true);
147
153
  }, [firstToken]);
@@ -1,3 +1,3 @@
1
1
  import { SendTransactionsType } from '../../api/sendTransactions';
2
2
 
3
- export declare const useSendTransactions: () => ({ transactions, url, token, axiosConfig }: SendTransactionsType) => Promise<import('axios').AxiosResponse<import('../..').BatchTransactions, any>>;
3
+ export declare const useSendTransactions: () => ({ transactions, provider, url, token, axiosConfig }: SendTransactionsType) => Promise<import('axios').AxiosResponse<import('../..').BatchTransactions, any>>;
@@ -5,9 +5,16 @@ const require$$0 = require("react");
5
5
  const api_sendTransactions = require("../../api/sendTransactions.js");
6
6
  const useSendTransactions = () => {
7
7
  return require$$0.useCallback(
8
- async ({ transactions, url, token, axiosConfig }) => {
8
+ async ({
9
+ transactions,
10
+ provider,
11
+ url,
12
+ token,
13
+ axiosConfig
14
+ }) => {
9
15
  return await api_sendTransactions.sendTransactions({
10
16
  transactions,
17
+ provider,
11
18
  url,
12
19
  token,
13
20
  axiosConfig
@@ -2,9 +2,16 @@ import { useCallback } from "react";
2
2
  import { sendTransactions } from "../../api/sendTransactions.mjs";
3
3
  const useSendTransactions = () => {
4
4
  return useCallback(
5
- async ({ transactions, url, token, axiosConfig }) => {
5
+ async ({
6
+ transactions,
7
+ provider,
8
+ url,
9
+ token,
10
+ axiosConfig
11
+ }) => {
6
12
  return await sendTransactions({
7
13
  transactions,
14
+ provider,
8
15
  url,
9
16
  token,
10
17
  axiosConfig
@@ -46,6 +46,7 @@ const useGetMvxTokensBalancesQuery = ({
46
46
  refetchOnWindowFocus: false,
47
47
  refetchIntervalInBackground: true,
48
48
  refetchInterval: 2e4,
49
+ refetchOnReconnect: "always",
49
50
  gcTime: 0
50
51
  });
51
52
  };
@@ -43,6 +43,7 @@ const useGetMvxTokensBalancesQuery = ({
43
43
  refetchOnWindowFocus: false,
44
44
  refetchIntervalInBackground: true,
45
45
  refetchInterval: 2e4,
46
+ refetchOnReconnect: "always",
46
47
  gcTime: 0
47
48
  });
48
49
  };
@@ -13,7 +13,16 @@ const useGetRateMutation = () => {
13
13
  return data;
14
14
  };
15
15
  return reactQuery.useMutation({
16
- mutationFn
16
+ mutationFn,
17
+ onSuccess: (data) => {
18
+ const currentTime = (/* @__PURE__ */ new Date()).getTime();
19
+ if (data.expiresAt && new Date(data.expiresAt).getTime() < currentTime) {
20
+ throw new Error("Retrying due to expired rate");
21
+ }
22
+ },
23
+ retry: (failureCount, error) => {
24
+ return error.message === "Retrying due to expired rate" && failureCount < 2;
25
+ }
17
26
  });
18
27
  };
19
28
  exports.useGetRateMutation = useGetRateMutation;
@@ -10,7 +10,16 @@ const useGetRateMutation = () => {
10
10
  return data;
11
11
  };
12
12
  return useMutation({
13
- mutationFn
13
+ mutationFn,
14
+ onSuccess: (data) => {
15
+ const currentTime = (/* @__PURE__ */ new Date()).getTime();
16
+ if (data.expiresAt && new Date(data.expiresAt).getTime() < currentTime) {
17
+ throw new Error("Retrying due to expired rate");
18
+ }
19
+ },
20
+ retry: (failureCount, error) => {
21
+ return error.message === "Retrying due to expired rate" && failureCount < 2;
22
+ }
14
23
  });
15
24
  };
16
25
  export {
@@ -0,0 +1,5 @@
1
+ export declare enum ProviderType {
2
+ MultiversxBridge = "multiversx-bridge",
3
+ XMoney = "xmoney",
4
+ None = "none"
5
+ }
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
4
+ var ProviderType = /* @__PURE__ */ ((ProviderType2) => {
5
+ ProviderType2["MultiversxBridge"] = "multiversx-bridge";
6
+ ProviderType2["XMoney"] = "xmoney";
7
+ ProviderType2["None"] = "none";
8
+ return ProviderType2;
9
+ })(ProviderType || {});
10
+ exports.ProviderType = ProviderType;
@@ -0,0 +1,9 @@
1
+ var ProviderType = /* @__PURE__ */ ((ProviderType2) => {
2
+ ProviderType2["MultiversxBridge"] = "multiversx-bridge";
3
+ ProviderType2["XMoney"] = "xmoney";
4
+ ProviderType2["None"] = "none";
5
+ return ProviderType2;
6
+ })(ProviderType || {});
7
+ export {
8
+ ProviderType
9
+ };
package/types/rate.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { ProviderType } from './providerType';
2
+
1
3
  export interface RateRequestBody {
2
4
  tokenIn: string;
3
5
  amountIn: string;
@@ -8,4 +10,7 @@ export interface RateRequestBody {
8
10
  export interface RateRequestResponse {
9
11
  fee: string;
10
12
  amountOut: string;
13
+ provider: ProviderType;
14
+ orderId: string;
15
+ expiresAt?: number;
11
16
  }