@multiversx/sdk-dapp-liquidity 1.1.0-alpha.7 → 1.1.0-alpha.8
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/api/getTransactions.d.ts +8 -2
- package/api/getTransactions.js +23 -6
- package/api/getTransactions.mjs +23 -6
- package/api/tests/getTransactions.spec.js +3 -5
- package/api/tests/getTransactions.spec.mjs +3 -5
- package/package.json +1 -1
- package/reactjs/queries/useGetHistory.query.d.ts +7 -1
- package/reactjs/queries/useGetHistory.query.js +23 -3
- package/reactjs/queries/useGetHistory.query.mjs +23 -3
package/api/getTransactions.d.ts
CHANGED
|
@@ -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,
|
|
5
|
+
export declare function getTransactions({ url, address, sender, provider, status, tokenIn, tokenOut }: {
|
|
5
6
|
url: string;
|
|
6
|
-
|
|
7
|
+
address: string;
|
|
8
|
+
sender?: string;
|
|
9
|
+
provider?: ProviderType;
|
|
10
|
+
status?: string;
|
|
11
|
+
tokenIn?: string;
|
|
12
|
+
tokenOut?: string;
|
|
7
13
|
}): Promise<AxiosResponse<TransactionDTO[]>>;
|
package/api/getTransactions.js
CHANGED
|
@@ -4,13 +4,30 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
4
4
|
const axios = require("axios");
|
|
5
5
|
async function getTransactions({
|
|
6
6
|
url,
|
|
7
|
-
|
|
7
|
+
address,
|
|
8
|
+
sender,
|
|
9
|
+
provider,
|
|
10
|
+
status,
|
|
11
|
+
tokenIn,
|
|
12
|
+
tokenOut
|
|
8
13
|
}) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
+
for (const [key, value] of queryParams.entries()) {
|
|
23
|
+
if (!value) {
|
|
24
|
+
queryParams.delete(key);
|
|
13
25
|
}
|
|
14
|
-
|
|
26
|
+
}
|
|
27
|
+
const queryString = queryParams.toString();
|
|
28
|
+
const endpointWithParams = `/transactions/?${queryString}`;
|
|
29
|
+
return await axios.get(endpointWithParams, {
|
|
30
|
+
baseURL: url
|
|
31
|
+
});
|
|
15
32
|
}
|
|
16
33
|
exports.getTransactions = getTransactions;
|
package/api/getTransactions.mjs
CHANGED
|
@@ -1,14 +1,31 @@
|
|
|
1
1
|
import axios from "axios";
|
|
2
2
|
async function getTransactions({
|
|
3
3
|
url,
|
|
4
|
-
|
|
4
|
+
address,
|
|
5
|
+
sender,
|
|
6
|
+
provider,
|
|
7
|
+
status,
|
|
8
|
+
tokenIn,
|
|
9
|
+
tokenOut
|
|
5
10
|
}) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
+
for (const [key, value] of queryParams.entries()) {
|
|
20
|
+
if (!value) {
|
|
21
|
+
queryParams.delete(key);
|
|
10
22
|
}
|
|
11
|
-
|
|
23
|
+
}
|
|
24
|
+
const queryString = queryParams.toString();
|
|
25
|
+
const endpointWithParams = `/transactions/?${queryString}`;
|
|
26
|
+
return await axios.get(endpointWithParams, {
|
|
27
|
+
baseURL: url
|
|
28
|
+
});
|
|
12
29
|
}
|
|
13
30
|
export {
|
|
14
31
|
getTransactions
|
|
@@ -8,7 +8,6 @@ const mockedAxios = axios;
|
|
|
8
8
|
describe("getTransactions", () => {
|
|
9
9
|
const url = "https://api.example.com";
|
|
10
10
|
it("fetches transactions without userWalletAddress", async () => {
|
|
11
|
-
const userWalletAddress = "";
|
|
12
11
|
const response = [
|
|
13
12
|
{
|
|
14
13
|
fromChainId: "97",
|
|
@@ -27,7 +26,7 @@ describe("getTransactions", () => {
|
|
|
27
26
|
}
|
|
28
27
|
];
|
|
29
28
|
mockedAxios.get.mockResolvedValue({ data: response });
|
|
30
|
-
const result = await api_getTransactions.getTransactions({ url
|
|
29
|
+
const result = await api_getTransactions.getTransactions({ url });
|
|
31
30
|
expect(mockedAxios.get).toHaveBeenCalledWith("/transactions", {
|
|
32
31
|
baseURL: url
|
|
33
32
|
});
|
|
@@ -53,7 +52,7 @@ describe("getTransactions", () => {
|
|
|
53
52
|
}
|
|
54
53
|
];
|
|
55
54
|
mockedAxios.get.mockResolvedValue({ data: response });
|
|
56
|
-
const result = await api_getTransactions.getTransactions({ url
|
|
55
|
+
const result = await api_getTransactions.getTransactions({ url });
|
|
57
56
|
expect(mockedAxios.get).toHaveBeenCalledWith(
|
|
58
57
|
`/transactions/${userWalletAddress}`,
|
|
59
58
|
{ baseURL: url }
|
|
@@ -81,8 +80,7 @@ describe("getTransactions", () => {
|
|
|
81
80
|
];
|
|
82
81
|
mockedAxios.get.mockResolvedValue({ data: response });
|
|
83
82
|
const result = await api_getTransactions.getTransactions({
|
|
84
|
-
url
|
|
85
|
-
userWalletAddress
|
|
83
|
+
url
|
|
86
84
|
});
|
|
87
85
|
expect(mockedAxios.get).toHaveBeenCalledWith(
|
|
88
86
|
`/transactions/${userWalletAddress}`,
|
|
@@ -6,7 +6,6 @@ const mockedAxios = axios;
|
|
|
6
6
|
describe("getTransactions", () => {
|
|
7
7
|
const url = "https://api.example.com";
|
|
8
8
|
it("fetches transactions without userWalletAddress", async () => {
|
|
9
|
-
const userWalletAddress = "";
|
|
10
9
|
const response = [
|
|
11
10
|
{
|
|
12
11
|
fromChainId: "97",
|
|
@@ -25,7 +24,7 @@ describe("getTransactions", () => {
|
|
|
25
24
|
}
|
|
26
25
|
];
|
|
27
26
|
mockedAxios.get.mockResolvedValue({ data: response });
|
|
28
|
-
const result = await getTransactions({ url
|
|
27
|
+
const result = await getTransactions({ url });
|
|
29
28
|
expect(mockedAxios.get).toHaveBeenCalledWith("/transactions", {
|
|
30
29
|
baseURL: url
|
|
31
30
|
});
|
|
@@ -51,7 +50,7 @@ describe("getTransactions", () => {
|
|
|
51
50
|
}
|
|
52
51
|
];
|
|
53
52
|
mockedAxios.get.mockResolvedValue({ data: response });
|
|
54
|
-
const result = await getTransactions({ url
|
|
53
|
+
const result = await getTransactions({ url });
|
|
55
54
|
expect(mockedAxios.get).toHaveBeenCalledWith(
|
|
56
55
|
`/transactions/${userWalletAddress}`,
|
|
57
56
|
{ baseURL: url }
|
|
@@ -79,8 +78,7 @@ describe("getTransactions", () => {
|
|
|
79
78
|
];
|
|
80
79
|
mockedAxios.get.mockResolvedValue({ data: response });
|
|
81
80
|
const result = await getTransactions({
|
|
82
|
-
url
|
|
83
|
-
userWalletAddress
|
|
81
|
+
url
|
|
84
82
|
});
|
|
85
83
|
expect(mockedAxios.get).toHaveBeenCalledWith(
|
|
86
84
|
`/transactions/${userWalletAddress}`,
|
package/package.json
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
|
+
import { ProviderType } from 'types/providerType';
|
|
1
2
|
import { AxiosError } from 'axios';
|
|
2
3
|
|
|
3
|
-
export declare const useGetHistoryQuery: ({ address }: {
|
|
4
|
+
export declare const useGetHistoryQuery: ({ address, sender, provider, status, tokenIn, tokenOut }: {
|
|
4
5
|
address?: string;
|
|
6
|
+
sender?: string;
|
|
7
|
+
provider?: ProviderType;
|
|
8
|
+
status?: string;
|
|
9
|
+
tokenIn?: string;
|
|
10
|
+
tokenOut?: string;
|
|
5
11
|
}) => import('@tanstack/react-query').UseQueryResult<import('../..').TransactionDTO[], AxiosError<unknown, any>>;
|
|
6
12
|
export declare const invalidateHistoryQuery: () => void;
|
|
@@ -5,7 +5,14 @@ const reactQuery = require("@tanstack/react-query");
|
|
|
5
5
|
const api_getTransactions = require("../../api/getTransactions.js");
|
|
6
6
|
const helpers_getApiURL = require("../../helpers/getApiURL.js");
|
|
7
7
|
const reactjs_context_queryClient = require("../context/queryClient.js");
|
|
8
|
-
const useGetHistoryQuery = ({
|
|
8
|
+
const useGetHistoryQuery = ({
|
|
9
|
+
address,
|
|
10
|
+
sender,
|
|
11
|
+
provider,
|
|
12
|
+
status,
|
|
13
|
+
tokenIn,
|
|
14
|
+
tokenOut
|
|
15
|
+
}) => {
|
|
9
16
|
const queryFn = async () => {
|
|
10
17
|
if (!address) {
|
|
11
18
|
throw new Error("User is not connected");
|
|
@@ -13,7 +20,12 @@ const useGetHistoryQuery = ({ address }) => {
|
|
|
13
20
|
try {
|
|
14
21
|
const { data } = await api_getTransactions.getTransactions({
|
|
15
22
|
url: helpers_getApiURL.getApiURL(),
|
|
16
|
-
|
|
23
|
+
address,
|
|
24
|
+
sender,
|
|
25
|
+
provider,
|
|
26
|
+
status,
|
|
27
|
+
tokenIn,
|
|
28
|
+
tokenOut
|
|
17
29
|
});
|
|
18
30
|
return data;
|
|
19
31
|
} catch (error) {
|
|
@@ -25,7 +37,15 @@ const useGetHistoryQuery = ({ address }) => {
|
|
|
25
37
|
return ((_a = error.response) == null ? void 0 : _a.status) === 404;
|
|
26
38
|
};
|
|
27
39
|
return reactQuery.useQuery({
|
|
28
|
-
queryKey: [
|
|
40
|
+
queryKey: [
|
|
41
|
+
"user-history",
|
|
42
|
+
address,
|
|
43
|
+
sender,
|
|
44
|
+
provider,
|
|
45
|
+
status,
|
|
46
|
+
tokenIn,
|
|
47
|
+
tokenOut
|
|
48
|
+
],
|
|
29
49
|
queryFn,
|
|
30
50
|
retry,
|
|
31
51
|
enabled: Boolean(address),
|
|
@@ -2,7 +2,14 @@ import { useQuery } from "@tanstack/react-query";
|
|
|
2
2
|
import { getTransactions } from "../../api/getTransactions.mjs";
|
|
3
3
|
import { getApiURL } from "../../helpers/getApiURL.mjs";
|
|
4
4
|
import { getQueryClient } from "../context/queryClient.mjs";
|
|
5
|
-
const useGetHistoryQuery = ({
|
|
5
|
+
const useGetHistoryQuery = ({
|
|
6
|
+
address,
|
|
7
|
+
sender,
|
|
8
|
+
provider,
|
|
9
|
+
status,
|
|
10
|
+
tokenIn,
|
|
11
|
+
tokenOut
|
|
12
|
+
}) => {
|
|
6
13
|
const queryFn = async () => {
|
|
7
14
|
if (!address) {
|
|
8
15
|
throw new Error("User is not connected");
|
|
@@ -10,7 +17,12 @@ const useGetHistoryQuery = ({ address }) => {
|
|
|
10
17
|
try {
|
|
11
18
|
const { data } = await getTransactions({
|
|
12
19
|
url: getApiURL(),
|
|
13
|
-
|
|
20
|
+
address,
|
|
21
|
+
sender,
|
|
22
|
+
provider,
|
|
23
|
+
status,
|
|
24
|
+
tokenIn,
|
|
25
|
+
tokenOut
|
|
14
26
|
});
|
|
15
27
|
return data;
|
|
16
28
|
} catch (error) {
|
|
@@ -22,7 +34,15 @@ const useGetHistoryQuery = ({ address }) => {
|
|
|
22
34
|
return ((_a = error.response) == null ? void 0 : _a.status) === 404;
|
|
23
35
|
};
|
|
24
36
|
return useQuery({
|
|
25
|
-
queryKey: [
|
|
37
|
+
queryKey: [
|
|
38
|
+
"user-history",
|
|
39
|
+
address,
|
|
40
|
+
sender,
|
|
41
|
+
provider,
|
|
42
|
+
status,
|
|
43
|
+
tokenIn,
|
|
44
|
+
tokenOut
|
|
45
|
+
],
|
|
26
46
|
queryFn,
|
|
27
47
|
retry,
|
|
28
48
|
enabled: Boolean(address),
|