@multiversx/sdk-dapp-liquidity 1.1.0-alpha.0 → 1.1.0-alpha.10

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 (147) hide show
  1. package/README.md +8 -3
  2. package/api/confirmFiatRate.d.ts +19 -0
  3. package/api/confirmFiatRate.js +34 -0
  4. package/api/confirmFiatRate.mjs +33 -0
  5. package/api/getTransactions.d.ts +8 -2
  6. package/api/getTransactions.js +23 -3
  7. package/api/getTransactions.mjs +23 -3
  8. package/api/tests/getChains.spec.js +1 -1
  9. package/api/tests/getChains.spec.mjs +1 -1
  10. package/api/tests/getTokens.spec.js +2 -2
  11. package/api/tests/getTokens.spec.mjs +2 -2
  12. package/api/tests/getTransactions.spec.js +80 -66
  13. package/api/tests/getTransactions.spec.mjs +80 -66
  14. package/api/tests/sendTransactions.spec.js +14 -8
  15. package/api/tests/sendTransactions.spec.mjs +14 -8
  16. package/constants/index.d.ts +2 -1
  17. package/constants/index.js +11 -1
  18. package/constants/index.mjs +12 -2
  19. package/dto/Chain.dto.d.ts +4 -2
  20. package/dto/ConfirmRate.dto.d.ts +1 -0
  21. package/dto/Token.dto.d.ts +3 -1
  22. package/dto/Transaction.dto.d.ts +3 -0
  23. package/index.js +45 -16
  24. package/index.mjs +16 -17
  25. package/package.json +10 -5
  26. package/reactjs/components/BridgeForm/BridgeForm.js +52 -39
  27. package/reactjs/components/BridgeForm/BridgeForm.mjs +23 -10
  28. package/reactjs/components/BridgeHistory/BridgeHistory.js +145 -46
  29. package/reactjs/components/BridgeHistory/BridgeHistory.mjs +141 -42
  30. package/reactjs/components/Connect/BridgeAccountDisplay.js +2 -5
  31. package/reactjs/components/Connect/BridgeAccountDisplay.mjs +2 -5
  32. package/reactjs/components/Connect/CustomConnectButton.js +2 -5
  33. package/reactjs/components/Connect/CustomConnectButton.mjs +1 -4
  34. package/reactjs/components/Connect/SwitchChainButton.js +2 -6
  35. package/reactjs/components/Connect/SwitchChainButton.mjs +1 -5
  36. package/reactjs/components/CopyButton/CopyButton.js +2 -2
  37. package/reactjs/components/CopyButton/CopyButton.mjs +2 -2
  38. package/reactjs/components/DisplayAmount/components/AnimateNumber/AnimateNumber.js +5 -5
  39. package/reactjs/components/Error/Error.d.ts +6 -0
  40. package/reactjs/components/Error/Error.js +67 -0
  41. package/reactjs/components/Error/Error.mjs +66 -0
  42. package/reactjs/components/Error/index.d.ts +1 -0
  43. package/reactjs/components/Error/index.js +5 -0
  44. package/reactjs/components/Error/index.mjs +4 -0
  45. package/reactjs/components/TokenSelector/TokenSelector.d.ts +1 -1
  46. package/reactjs/components/TokenSelector/TokenSelector.js +10 -5
  47. package/reactjs/components/TokenSelector/TokenSelector.mjs +6 -1
  48. package/reactjs/components/TokenSelector/components/ChainSelect/ChainSelect.js +3 -3
  49. package/reactjs/components/TokenSelector/components/SelectContent.js +8 -8
  50. package/reactjs/components/TokenSelector/components/TokenIcon.js +3 -3
  51. package/reactjs/components/TokenSelector/components/TokenItem.js +15 -10
  52. package/reactjs/components/TokenSelector/components/TokenItem.mjs +12 -7
  53. package/reactjs/components/base/MxCard/MxCard.js +2 -2
  54. package/reactjs/components/base/MxCircleLoader/MxCircleLoader.d.ts +4 -0
  55. package/reactjs/components/base/MxCircleLoader/MxCircleLoader.js +29 -0
  56. package/reactjs/components/base/MxCircleLoader/MxCircleLoader.mjs +28 -0
  57. package/reactjs/components/base/MxCircleLoader/index.d.ts +1 -0
  58. package/reactjs/components/base/MxCircleLoader/index.js +5 -0
  59. package/reactjs/components/base/MxCircleLoader/index.mjs +4 -0
  60. package/reactjs/components/base/MxLink/MxLink.js +2 -2
  61. package/reactjs/components/base/MxSearch/MxSearch.js +4 -4
  62. package/reactjs/components/base/MxSlideover/MxSlideover.js +4 -4
  63. package/reactjs/components/base/MxTooltip/MxTooltip.js +9 -9
  64. package/reactjs/components/base/MxTooltip/components/TooltipContainer/TooltipContainer.js +2 -2
  65. package/reactjs/components/index.d.ts +1 -0
  66. package/reactjs/components/index.js +2 -0
  67. package/reactjs/components/index.mjs +2 -0
  68. package/reactjs/context/Web3AppProvider.d.ts +3 -1
  69. package/reactjs/context/Web3AppProvider.js +7 -5
  70. package/reactjs/context/Web3AppProvider.mjs +4 -2
  71. package/reactjs/context/useWeb3App.js +2 -2
  72. package/reactjs/hooks/index.js +1 -1
  73. package/reactjs/hooks/index.mjs +1 -1
  74. package/reactjs/hooks/useAccount.js +1 -5
  75. package/reactjs/hooks/useAccount.mjs +1 -5
  76. package/reactjs/hooks/useBalances.d.ts +4 -3
  77. package/reactjs/hooks/useBalances.js +13 -1
  78. package/reactjs/hooks/useBalances.mjs +13 -1
  79. package/reactjs/hooks/useBridgeFormik.js +9 -16
  80. package/reactjs/hooks/useBridgeFormik.mjs +0 -7
  81. package/reactjs/hooks/useDebounce.js +3 -3
  82. package/reactjs/hooks/useFetchBridgeData.d.ts +56 -3
  83. package/reactjs/hooks/useFetchBridgeData.js +6 -2
  84. package/reactjs/hooks/useFetchBridgeData.mjs +6 -2
  85. package/reactjs/hooks/useFetchTokens.d.ts +40 -2
  86. package/reactjs/hooks/useFetchTokens.js +14 -9
  87. package/reactjs/hooks/useFetchTokens.mjs +8 -3
  88. package/reactjs/hooks/useFiatData.d.ts +61 -0
  89. package/reactjs/hooks/useFiatData.js +68 -0
  90. package/reactjs/hooks/useFiatData.mjs +67 -0
  91. package/reactjs/hooks/useGetChainId.js +3 -3
  92. package/reactjs/hooks/useGetChainId.mjs +1 -1
  93. package/reactjs/hooks/useResolveTokenChain.d.ts +16 -1
  94. package/reactjs/hooks/useResolveTokenChain.js +2 -2
  95. package/reactjs/hooks/useSendTransactions.js +2 -2
  96. package/reactjs/hooks/validation/useTestHasEnoughFunds.js +3 -3
  97. package/reactjs/hooks/validation/useTestIsConnected.js +2 -2
  98. package/reactjs/index.js +44 -16
  99. package/reactjs/index.mjs +14 -16
  100. package/reactjs/init/init.d.ts +221 -3
  101. package/reactjs/init/init.js +44 -10
  102. package/reactjs/init/init.mjs +41 -7
  103. package/reactjs/init/tests/init.spec.js +7 -8
  104. package/reactjs/init/tests/init.spec.mjs +7 -8
  105. package/reactjs/queries/index.d.ts +0 -1
  106. package/reactjs/queries/index.js +0 -2
  107. package/reactjs/queries/index.mjs +1 -3
  108. package/reactjs/queries/useGetAllTokens.query.d.ts +17 -1
  109. package/reactjs/queries/useGetAllTokens.query.js +5 -1
  110. package/reactjs/queries/useGetAllTokens.query.mjs +5 -1
  111. package/reactjs/queries/useGetChains.query.d.ts +16 -1
  112. package/reactjs/queries/useGetChains.query.js +5 -1
  113. package/reactjs/queries/useGetChains.query.mjs +5 -1
  114. package/reactjs/queries/useGetEvmTokensBalances.query.d.ts +4 -2
  115. package/reactjs/queries/useGetEvmTokensBalances.query.js +13 -17
  116. package/reactjs/queries/useGetEvmTokensBalances.query.mjs +13 -17
  117. package/reactjs/queries/useGetHistory.query.d.ts +9 -1
  118. package/reactjs/queries/useGetHistory.query.js +23 -5
  119. package/reactjs/queries/useGetHistory.query.mjs +23 -5
  120. package/reactjs/queries/useGetMvxTokensBalances.query.d.ts +3 -1
  121. package/reactjs/queries/useGetMvxTokensBalances.query.js +2 -2
  122. package/reactjs/queries/useGetRate.mutation.js +1 -12
  123. package/reactjs/queries/useGetRate.mutation.mjs +1 -12
  124. package/reactjs/reexports.d.ts +2 -1
  125. package/reactjs/reexports.js +41 -13
  126. package/reactjs/reexports.mjs +11 -13
  127. package/style.css +36 -9
  128. package/types/chainType.d.ts +6 -0
  129. package/types/chainType.js +11 -0
  130. package/types/chainType.mjs +10 -0
  131. package/{useBalances-C_69CFoa.mjs → useBalances-MNOkt0CT.mjs} +88 -22
  132. package/{useBalances-C4YhEYxy.js → useBalances-QuJwkRzs.js} +89 -23
  133. package/index-CYK46UPq.js +0 -329
  134. package/index-ColTMqTq.mjs +0 -67816
  135. package/index-Ct1WIDmD.mjs +0 -91
  136. package/index-D3h_0DdC.js +0 -107
  137. package/index-SjL1bsvE.js +0 -67737
  138. package/index-fUglKiv3.mjs +0 -107
  139. package/react-BDmrtlgL.mjs +0 -50
  140. package/react-CtPdHYsQ.js +0 -50
  141. package/react-D2FjNBgs.js +0 -3133
  142. package/react-DykKTu1E.mjs +0 -3133
  143. package/reactjs/queries/useGetTokens.query.d.ts +0 -3
  144. package/reactjs/queries/useGetTokens.query.js +0 -34
  145. package/reactjs/queries/useGetTokens.query.mjs +0 -33
  146. package/w3m-modal-C56iK3fa.js +0 -356
  147. package/w3m-modal-rwydRJct.mjs +0 -356
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # @multiversx/mx-sdk-dapp-liquidity
1
+ # @multiversx/sdk-dapp-liquidity
2
2
 
3
3
  ## Overview
4
4
 
@@ -63,7 +63,7 @@ yarn publish-package-next
63
63
  ## Usage
64
64
 
65
65
  ```css
66
- @import 'node_modules/@multiversx/mx-sdk-dapp-liquidity/style.css';
66
+ @import 'node_modules/@multiversx/sdk-dapp-liquidity/style.css';
67
67
  ```
68
68
 
69
69
  ```tsx
@@ -183,4 +183,9 @@ const App = () => {
183
183
  </Web3AppProvider>
184
184
  )
185
185
  }
186
- ```
186
+ ```
187
+
188
+ ## Disclaimer
189
+
190
+ 1. This package is in active development and is subject to change. We recommend to check the latest version and update your code accordingly.
191
+ 2. This package is not fully supported on the Next.js framework. We are working on a solution to make it compatible with Next.js.
@@ -0,0 +1,19 @@
1
+ import { ConfirmRateDto } from '../dto/ConfirmRate.dto';
2
+ import { AxiosResponse } from 'axios';
3
+
4
+ type ConfirmFiatRateProps = {
5
+ url: string;
6
+ nativeAuthToken: string;
7
+ body: ConfirmRateDto;
8
+ };
9
+ type ConfirmFiatRateResponse = ConfirmRateDto & {
10
+ type: string;
11
+ content: string;
12
+ additionalInfo: {
13
+ url: string;
14
+ checksum: string;
15
+ jsonRequest: string;
16
+ };
17
+ }[];
18
+ export declare function confirmFiatRate({ url, nativeAuthToken, body }: ConfirmFiatRateProps): Promise<AxiosResponse<ConfirmFiatRateResponse>>;
19
+ export {};
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
4
+ const axios = require("axios");
5
+ const helpers_decodeToken = require("../helpers/decodeToken.js");
6
+ async function confirmFiatRate({
7
+ url,
8
+ nativeAuthToken,
9
+ body
10
+ }) {
11
+ var _a;
12
+ const config = {
13
+ baseURL: url,
14
+ headers: {
15
+ Authorization: `Bearer ${nativeAuthToken}`
16
+ }
17
+ };
18
+ if (!nativeAuthToken) {
19
+ (_a = config.headers) == null ? true : delete _a.Authorization;
20
+ }
21
+ const decodedToken = await helpers_decodeToken.decodeToken(nativeAuthToken);
22
+ if (config.headers.set) {
23
+ config.headers.set({
24
+ ...config.headers,
25
+ origin: (decodedToken == null ? void 0 : decodedToken.origin) ?? ""
26
+ });
27
+ }
28
+ return await axios.post(
29
+ `/rate/confirm`,
30
+ body,
31
+ config
32
+ );
33
+ }
34
+ exports.confirmFiatRate = confirmFiatRate;
@@ -0,0 +1,33 @@
1
+ import axios from "axios";
2
+ import { decodeToken } from "../helpers/decodeToken.mjs";
3
+ async function confirmFiatRate({
4
+ url,
5
+ nativeAuthToken,
6
+ body
7
+ }) {
8
+ var _a;
9
+ const config = {
10
+ baseURL: url,
11
+ headers: {
12
+ Authorization: `Bearer ${nativeAuthToken}`
13
+ }
14
+ };
15
+ if (!nativeAuthToken) {
16
+ (_a = config.headers) == null ? true : delete _a.Authorization;
17
+ }
18
+ const decodedToken = await decodeToken(nativeAuthToken);
19
+ if (config.headers.set) {
20
+ config.headers.set({
21
+ ...config.headers,
22
+ origin: (decodedToken == null ? void 0 : decodedToken.origin) ?? ""
23
+ });
24
+ }
25
+ return await axios.post(
26
+ `/rate/confirm`,
27
+ body,
28
+ config
29
+ );
30
+ }
31
+ export {
32
+ confirmFiatRate
33
+ };
@@ -1,7 +1,13 @@
1
+ import { ProviderType } from 'types/providerType';
1
2
  import { TransactionDTO } from 'dto/Transaction.dto';
2
3
  import { AxiosResponse } from 'axios';
3
4
 
4
- export declare function getTransactions({ url, userWalletAddress }: {
5
+ export declare function getTransactions({ url, address, sender, provider, status, tokenIn, tokenOut }: {
5
6
  url: string;
6
- userWalletAddress: string;
7
+ address: string;
8
+ sender?: string;
9
+ provider?: ProviderType;
10
+ status?: string;
11
+ tokenIn?: string;
12
+ tokenOut?: string;
7
13
  }): Promise<AxiosResponse<TransactionDTO[]>>;
@@ -4,10 +4,30 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
4
4
  const axios = require("axios");
5
5
  async function getTransactions({
6
6
  url,
7
- userWalletAddress
7
+ address,
8
+ sender,
9
+ provider,
10
+ status,
11
+ tokenIn,
12
+ tokenOut
8
13
  }) {
9
- const endpoint = userWalletAddress ? `/transactions/${userWalletAddress}` : "/transactions";
10
- return await axios.get(endpoint, {
14
+ const queryParams = new URLSearchParams({
15
+ receiver: address || "",
16
+ sender: sender || "",
17
+ provider: provider || "",
18
+ status: status || "",
19
+ tokenIn: tokenIn || "",
20
+ tokenOut: tokenOut || ""
21
+ });
22
+ const params = Object.entries(Object.fromEntries(queryParams.entries()));
23
+ for (const [key, value] of params) {
24
+ if (value === "") {
25
+ queryParams.delete(key);
26
+ }
27
+ }
28
+ const queryString = queryParams.toString();
29
+ const endpointWithParams = `/transactions?${queryString}`;
30
+ return await axios.get(endpointWithParams, {
11
31
  baseURL: url
12
32
  });
13
33
  }
@@ -1,10 +1,30 @@
1
1
  import axios from "axios";
2
2
  async function getTransactions({
3
3
  url,
4
- userWalletAddress
4
+ address,
5
+ sender,
6
+ provider,
7
+ status,
8
+ tokenIn,
9
+ tokenOut
5
10
  }) {
6
- const endpoint = userWalletAddress ? `/transactions/${userWalletAddress}` : "/transactions";
7
- return await axios.get(endpoint, {
11
+ const queryParams = new URLSearchParams({
12
+ receiver: address || "",
13
+ sender: sender || "",
14
+ provider: provider || "",
15
+ status: status || "",
16
+ tokenIn: tokenIn || "",
17
+ tokenOut: tokenOut || ""
18
+ });
19
+ const params = Object.entries(Object.fromEntries(queryParams.entries()));
20
+ for (const [key, value] of params) {
21
+ if (value === "") {
22
+ queryParams.delete(key);
23
+ }
24
+ }
25
+ const queryString = queryParams.toString();
26
+ const endpointWithParams = `/transactions?${queryString}`;
27
+ return await axios.get(endpointWithParams, {
8
28
  baseURL: url
9
29
  });
10
30
  }
@@ -9,7 +9,7 @@ describe("getChains", () => {
9
9
  it("fetches chains successfully", async () => {
10
10
  const response = [
11
11
  {
12
- chainId: 1,
12
+ chainId: "1",
13
13
  chainName: "msx",
14
14
  pngUrl: "https://devnet-tools.multiversx.com/liquidity-sdk/ethereum/icon.png",
15
15
  svgUrl: "https://devnet-tools.multiversx.com/liquidity-sdk/ethereum/icon.svg",
@@ -7,7 +7,7 @@ describe("getChains", () => {
7
7
  it("fetches chains successfully", async () => {
8
8
  const response = [
9
9
  {
10
- chainId: 1,
10
+ chainId: "1",
11
11
  chainName: "msx",
12
12
  pngUrl: "https://devnet-tools.multiversx.com/liquidity-sdk/ethereum/icon.png",
13
13
  svgUrl: "https://devnet-tools.multiversx.com/liquidity-sdk/ethereum/icon.svg",
@@ -9,7 +9,7 @@ describe("getTokens", () => {
9
9
  it("fetches tokens successfully without chainId", async () => {
10
10
  const response = [
11
11
  {
12
- chainId: 1,
12
+ chainId: "1",
13
13
  address: "0x123",
14
14
  name: "Token One",
15
15
  symbol: "T1",
@@ -32,7 +32,7 @@ describe("getTokens", () => {
32
32
  const chainId = 1;
33
33
  const response = [
34
34
  {
35
- chainId: 1,
35
+ chainId: "1",
36
36
  address: "0x123",
37
37
  name: "Token One",
38
38
  symbol: "T1",
@@ -7,7 +7,7 @@ describe("getTokens", () => {
7
7
  it("fetches tokens successfully without chainId", async () => {
8
8
  const response = [
9
9
  {
10
- chainId: 1,
10
+ chainId: "1",
11
11
  address: "0x123",
12
12
  name: "Token One",
13
13
  symbol: "T1",
@@ -30,7 +30,7 @@ describe("getTokens", () => {
30
30
  const chainId = 1;
31
31
  const response = [
32
32
  {
33
- chainId: 1,
33
+ chainId: "1",
34
34
  address: "0x123",
35
35
  name: "Token One",
36
36
  symbol: "T1",
@@ -1,89 +1,103 @@
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_getTransactions = require("../getTransactions.js");
5
6
  jest.mock("axios");
6
7
  const mockedAxios = axios;
7
8
  describe("getTransactions", () => {
8
9
  const url = "https://api.example.com";
9
- it("fetches transactions without userWalletAddress", async () => {
10
- const userWalletAddress = "";
11
- const response = [
12
- {
13
- fromChainId: "97",
14
- toChainId: "44",
15
- tokenIn: "0x063b637324e6115f8da67f761A99B7F00B7Fd908",
16
- tokenOut: "USDT-58d5d0",
17
- amountIn: "11000000",
18
- amountOut: "11000000",
19
- depositTimestamp: 1738054613,
20
- sender: "0x1009c2f59e03c383ca8f2766cfe305a1e79f4c8d",
21
- status: "success",
22
- receiver: "erd1sp0aaszznqnuvyvkmxkv2ultcvlf637c093sfc26dszks60jdqsqy2knqu",
23
- txHash: "0xe7e706c1793d06a252a3f040f07732989e4a6466d804cae17105c09818bc2994",
24
- fee: "0"
25
- }
26
- ];
27
- mockedAxios.get.mockResolvedValue({ data: response });
28
- const result = await api_getTransactions.getTransactions({ url, userWalletAddress });
29
- expect(mockedAxios.get).toHaveBeenCalledWith("/transactions", {
10
+ const mockResponse = [
11
+ {
12
+ fromChainId: "97",
13
+ toChainId: "44",
14
+ tokenIn: "0x063b637324e6115f8da67f761A99B7F00B7Fd908",
15
+ tokenOut: "USDT-58d5d0",
16
+ amountIn: "11000000",
17
+ amountOut: "11000000",
18
+ depositTimestamp: 1738054613,
19
+ sender: "0x1009c2f59e03c383ca8f2766cfe305a1e79f4c8d",
20
+ status: "success",
21
+ receiver: "erd1sp0aaszznqnuvyvkmxkv2ultcvlf637c093sfc26dszks60jdqsqy2knqu",
22
+ txHash: "0xe7e706c1793d06a252a3f040f07732989e4a6466d804cae17105c09818bc2994",
23
+ fee: "0",
24
+ provider: types_providerType.ProviderType.MultiversxBridge
25
+ }
26
+ ];
27
+ beforeEach(() => {
28
+ mockedAxios.get.mockClear();
29
+ mockedAxios.get.mockResolvedValue({ data: mockResponse });
30
+ });
31
+ it("fetches transactions with only address parameter", async () => {
32
+ const address = "0x123";
33
+ const result = await api_getTransactions.getTransactions({ url, address });
34
+ expect(mockedAxios.get).toHaveBeenCalledWith(
35
+ "/transactions?receiver=0x123",
36
+ { baseURL: url }
37
+ );
38
+ expect(result.data).toEqual(mockResponse);
39
+ });
40
+ it("fetches transactions with empty address", async () => {
41
+ const address = "";
42
+ const result = await api_getTransactions.getTransactions({ url, address });
43
+ expect(mockedAxios.get).toHaveBeenCalledWith("/transactions?", {
30
44
  baseURL: url
31
45
  });
32
- expect(result.data).toEqual(response);
46
+ expect(result.data).toEqual(mockResponse);
33
47
  });
34
- it("fetches transactions with userWalletAddress", async () => {
35
- const userWalletAddress = "0x123";
36
- const response = [
37
- {
38
- fromChainId: "97",
39
- toChainId: "44",
40
- tokenIn: "0x063b637324e6115f8da67f761A99B7F00B7Fd908",
41
- tokenOut: "USDT-58d5d0",
42
- amountIn: "11000000",
43
- amountOut: "11000000",
44
- depositTimestamp: 1738054613,
45
- sender: "0x1009c2f59e03c383ca8f2766cfe305a1e79f4c8d",
46
- status: "success",
47
- receiver: "erd1sp0aaszznqnuvyvkmxkv2ultcvlf637c093sfc26dszks60jdqsqy2knqu",
48
- txHash: "0xe7e706c1793d06a252a3f040f07732989e4a6466d804cae17105c09818bc2994",
49
- fee: "0"
50
- }
51
- ];
52
- mockedAxios.get.mockResolvedValue({ data: response });
53
- const result = await api_getTransactions.getTransactions({ url, userWalletAddress });
48
+ it("includes all non-empty parameters in the query", async () => {
49
+ const result = await api_getTransactions.getTransactions({
50
+ url,
51
+ address: "0x123",
52
+ sender: "0xABC",
53
+ provider: types_providerType.ProviderType.MultiversxBridge,
54
+ status: "success",
55
+ tokenIn: "0xTOKEN",
56
+ tokenOut: "WEGLD-123456"
57
+ });
54
58
  expect(mockedAxios.get).toHaveBeenCalledWith(
55
- `/transactions/${userWalletAddress}`,
59
+ "/transactions?receiver=0x123&sender=0xABC&provider=multiversx-bridge&status=success&tokenIn=0xTOKEN&tokenOut=WEGLD-123456",
56
60
  { baseURL: url }
57
61
  );
58
- expect(result.data).toEqual(response);
62
+ expect(result.data).toEqual(mockResponse);
59
63
  });
60
- it("fetches transactions with both transactionId and userWalletAddress", async () => {
61
- const userWalletAddress = "0x123";
62
- const response = [
63
- {
64
- fromChainId: "97",
65
- toChainId: "44",
66
- tokenIn: "0x063b637324e6115f8da67f761A99B7F00B7Fd908",
67
- tokenOut: "USDT-58d5d0",
68
- amountIn: "11000000",
69
- amountOut: "11000000",
70
- depositTimestamp: 1738054613,
71
- sender: "0x1009c2f59e03c383ca8f2766cfe305a1e79f4c8d",
72
- status: "success",
73
- receiver: "erd1sp0aaszznqnuvyvkmxkv2ultcvlf637c093sfc26dszks60jdqsqy2knqu",
74
- txHash: "0xe7e706c1793d06a252a3f040f07732989e4a6466d804cae17105c09818bc2994",
75
- fee: "0"
76
- }
77
- ];
78
- mockedAxios.get.mockResolvedValue({ data: response });
64
+ it("excludes empty parameters from the query", async () => {
79
65
  const result = await api_getTransactions.getTransactions({
80
66
  url,
81
- userWalletAddress
67
+ address: "0x123",
68
+ sender: "",
69
+ provider: types_providerType.ProviderType.MultiversxBridge,
70
+ status: "",
71
+ tokenIn: "0xTOKEN",
72
+ tokenOut: ""
82
73
  });
83
74
  expect(mockedAxios.get).toHaveBeenCalledWith(
84
- `/transactions/${userWalletAddress}`,
75
+ "/transactions?receiver=0x123&provider=multiversx-bridge&tokenIn=0xTOKEN",
85
76
  { baseURL: url }
86
77
  );
87
- expect(result.data).toEqual(response);
78
+ expect(result.data).toEqual(mockResponse);
79
+ });
80
+ it("handles axios error", async () => {
81
+ const error = new Error("Network error");
82
+ mockedAxios.get.mockRejectedValueOnce(error);
83
+ await expect(api_getTransactions.getTransactions({ url, address: "0x123" })).rejects.toThrow(
84
+ "Network error"
85
+ );
86
+ expect(mockedAxios.get).toHaveBeenCalledWith(
87
+ "/transactions?receiver=0x123",
88
+ { baseURL: url }
89
+ );
90
+ });
91
+ it("passes through axios response", async () => {
92
+ const axiosResponse = {
93
+ data: mockResponse,
94
+ status: 200,
95
+ statusText: "OK",
96
+ headers: {},
97
+ config: {}
98
+ };
99
+ mockedAxios.get.mockResolvedValueOnce(axiosResponse);
100
+ const result = await api_getTransactions.getTransactions({ url, address: "0x123" });
101
+ expect(result).toEqual(axiosResponse);
88
102
  });
89
103
  });
@@ -1,87 +1,101 @@
1
1
  import axios from "axios";
2
+ import { ProviderType } from "../../types/providerType.mjs";
2
3
  import { getTransactions } from "../getTransactions.mjs";
3
4
  jest.mock("axios");
4
5
  const mockedAxios = axios;
5
6
  describe("getTransactions", () => {
6
7
  const url = "https://api.example.com";
7
- it("fetches transactions without userWalletAddress", async () => {
8
- const userWalletAddress = "";
9
- const response = [
10
- {
11
- fromChainId: "97",
12
- toChainId: "44",
13
- tokenIn: "0x063b637324e6115f8da67f761A99B7F00B7Fd908",
14
- tokenOut: "USDT-58d5d0",
15
- amountIn: "11000000",
16
- amountOut: "11000000",
17
- depositTimestamp: 1738054613,
18
- sender: "0x1009c2f59e03c383ca8f2766cfe305a1e79f4c8d",
19
- status: "success",
20
- receiver: "erd1sp0aaszznqnuvyvkmxkv2ultcvlf637c093sfc26dszks60jdqsqy2knqu",
21
- txHash: "0xe7e706c1793d06a252a3f040f07732989e4a6466d804cae17105c09818bc2994",
22
- fee: "0"
23
- }
24
- ];
25
- mockedAxios.get.mockResolvedValue({ data: response });
26
- const result = await getTransactions({ url, userWalletAddress });
27
- expect(mockedAxios.get).toHaveBeenCalledWith("/transactions", {
8
+ const mockResponse = [
9
+ {
10
+ fromChainId: "97",
11
+ toChainId: "44",
12
+ tokenIn: "0x063b637324e6115f8da67f761A99B7F00B7Fd908",
13
+ tokenOut: "USDT-58d5d0",
14
+ amountIn: "11000000",
15
+ amountOut: "11000000",
16
+ depositTimestamp: 1738054613,
17
+ sender: "0x1009c2f59e03c383ca8f2766cfe305a1e79f4c8d",
18
+ status: "success",
19
+ receiver: "erd1sp0aaszznqnuvyvkmxkv2ultcvlf637c093sfc26dszks60jdqsqy2knqu",
20
+ txHash: "0xe7e706c1793d06a252a3f040f07732989e4a6466d804cae17105c09818bc2994",
21
+ fee: "0",
22
+ provider: ProviderType.MultiversxBridge
23
+ }
24
+ ];
25
+ beforeEach(() => {
26
+ mockedAxios.get.mockClear();
27
+ mockedAxios.get.mockResolvedValue({ data: mockResponse });
28
+ });
29
+ it("fetches transactions with only address parameter", async () => {
30
+ const address = "0x123";
31
+ const result = await getTransactions({ url, address });
32
+ expect(mockedAxios.get).toHaveBeenCalledWith(
33
+ "/transactions?receiver=0x123",
34
+ { baseURL: url }
35
+ );
36
+ expect(result.data).toEqual(mockResponse);
37
+ });
38
+ it("fetches transactions with empty address", async () => {
39
+ const address = "";
40
+ const result = await getTransactions({ url, address });
41
+ expect(mockedAxios.get).toHaveBeenCalledWith("/transactions?", {
28
42
  baseURL: url
29
43
  });
30
- expect(result.data).toEqual(response);
44
+ expect(result.data).toEqual(mockResponse);
31
45
  });
32
- it("fetches transactions with userWalletAddress", async () => {
33
- const userWalletAddress = "0x123";
34
- const response = [
35
- {
36
- fromChainId: "97",
37
- toChainId: "44",
38
- tokenIn: "0x063b637324e6115f8da67f761A99B7F00B7Fd908",
39
- tokenOut: "USDT-58d5d0",
40
- amountIn: "11000000",
41
- amountOut: "11000000",
42
- depositTimestamp: 1738054613,
43
- sender: "0x1009c2f59e03c383ca8f2766cfe305a1e79f4c8d",
44
- status: "success",
45
- receiver: "erd1sp0aaszznqnuvyvkmxkv2ultcvlf637c093sfc26dszks60jdqsqy2knqu",
46
- txHash: "0xe7e706c1793d06a252a3f040f07732989e4a6466d804cae17105c09818bc2994",
47
- fee: "0"
48
- }
49
- ];
50
- mockedAxios.get.mockResolvedValue({ data: response });
51
- const result = await getTransactions({ url, userWalletAddress });
46
+ it("includes all non-empty parameters in the query", async () => {
47
+ const result = await getTransactions({
48
+ url,
49
+ address: "0x123",
50
+ sender: "0xABC",
51
+ provider: ProviderType.MultiversxBridge,
52
+ status: "success",
53
+ tokenIn: "0xTOKEN",
54
+ tokenOut: "WEGLD-123456"
55
+ });
52
56
  expect(mockedAxios.get).toHaveBeenCalledWith(
53
- `/transactions/${userWalletAddress}`,
57
+ "/transactions?receiver=0x123&sender=0xABC&provider=multiversx-bridge&status=success&tokenIn=0xTOKEN&tokenOut=WEGLD-123456",
54
58
  { baseURL: url }
55
59
  );
56
- expect(result.data).toEqual(response);
60
+ expect(result.data).toEqual(mockResponse);
57
61
  });
58
- it("fetches transactions with both transactionId and userWalletAddress", async () => {
59
- const userWalletAddress = "0x123";
60
- const response = [
61
- {
62
- fromChainId: "97",
63
- toChainId: "44",
64
- tokenIn: "0x063b637324e6115f8da67f761A99B7F00B7Fd908",
65
- tokenOut: "USDT-58d5d0",
66
- amountIn: "11000000",
67
- amountOut: "11000000",
68
- depositTimestamp: 1738054613,
69
- sender: "0x1009c2f59e03c383ca8f2766cfe305a1e79f4c8d",
70
- status: "success",
71
- receiver: "erd1sp0aaszznqnuvyvkmxkv2ultcvlf637c093sfc26dszks60jdqsqy2knqu",
72
- txHash: "0xe7e706c1793d06a252a3f040f07732989e4a6466d804cae17105c09818bc2994",
73
- fee: "0"
74
- }
75
- ];
76
- mockedAxios.get.mockResolvedValue({ data: response });
62
+ it("excludes empty parameters from the query", async () => {
77
63
  const result = await getTransactions({
78
64
  url,
79
- userWalletAddress
65
+ address: "0x123",
66
+ sender: "",
67
+ provider: ProviderType.MultiversxBridge,
68
+ status: "",
69
+ tokenIn: "0xTOKEN",
70
+ tokenOut: ""
80
71
  });
81
72
  expect(mockedAxios.get).toHaveBeenCalledWith(
82
- `/transactions/${userWalletAddress}`,
73
+ "/transactions?receiver=0x123&provider=multiversx-bridge&tokenIn=0xTOKEN",
83
74
  { baseURL: url }
84
75
  );
85
- expect(result.data).toEqual(response);
76
+ expect(result.data).toEqual(mockResponse);
77
+ });
78
+ it("handles axios error", async () => {
79
+ const error = new Error("Network error");
80
+ mockedAxios.get.mockRejectedValueOnce(error);
81
+ await expect(getTransactions({ url, address: "0x123" })).rejects.toThrow(
82
+ "Network error"
83
+ );
84
+ expect(mockedAxios.get).toHaveBeenCalledWith(
85
+ "/transactions?receiver=0x123",
86
+ { baseURL: url }
87
+ );
88
+ });
89
+ it("passes through axios response", async () => {
90
+ const axiosResponse = {
91
+ data: mockResponse,
92
+ status: 200,
93
+ statusText: "OK",
94
+ headers: {},
95
+ config: {}
96
+ };
97
+ mockedAxios.get.mockResolvedValueOnce(axiosResponse);
98
+ const result = await getTransactions({ url, address: "0x123" });
99
+ expect(result).toEqual(axiosResponse);
86
100
  });
87
101
  });
@@ -23,7 +23,7 @@ describe("sendTransactions", () => {
23
23
  }
24
24
  ];
25
25
  it("POST sendTransactions successfully", async () => {
26
- const response = { data: { transactions } };
26
+ const response = { data: { transactions, provider: types_providerType.ProviderType.None } };
27
27
  mockedAxios.post.mockResolvedValue(response);
28
28
  const result = await api_sendTransactions.sendTransactions({
29
29
  transactions,
@@ -33,9 +33,12 @@ describe("sendTransactions", () => {
33
33
  });
34
34
  expect(mockedAxios.post).toHaveBeenCalledWith(
35
35
  "/transactions",
36
- transactions.map(
37
- (transaction) => JSON.parse(helpers_serializeTransaction.serializeTransaction(transaction))
38
- ),
36
+ {
37
+ transactions: transactions.map(
38
+ (transaction) => JSON.parse(helpers_serializeTransaction.serializeTransaction(transaction))
39
+ ),
40
+ provider: types_providerType.ProviderType.None
41
+ },
39
42
  {
40
43
  baseURL: url,
41
44
  headers: {
@@ -49,7 +52,7 @@ describe("sendTransactions", () => {
49
52
  });
50
53
  it("POST sendTransactions with additional axiosConfig", async () => {
51
54
  const axiosConfig = { timeout: 1e3 };
52
- const response = { data: { transactions } };
55
+ const response = { data: { transactions, provider: types_providerType.ProviderType.None } };
53
56
  mockedAxios.post.mockResolvedValue(response);
54
57
  const result = await api_sendTransactions.sendTransactions({
55
58
  transactions,
@@ -60,9 +63,12 @@ describe("sendTransactions", () => {
60
63
  });
61
64
  expect(mockedAxios.post).toHaveBeenCalledWith(
62
65
  "/transactions",
63
- transactions.map(
64
- (transaction) => JSON.parse(helpers_serializeTransaction.serializeTransaction(transaction))
65
- ),
66
+ {
67
+ transactions: transactions.map(
68
+ (transaction) => JSON.parse(helpers_serializeTransaction.serializeTransaction(transaction))
69
+ ),
70
+ provider: types_providerType.ProviderType.None
71
+ },
66
72
  {
67
73
  baseURL: url,
68
74
  headers: {