@ledgerhq/coin-tron 3.0.1-nightly.0 → 3.1.0-nightly.1
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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +6 -0
- package/lib/api/index.d.ts.map +1 -1
- package/lib/api/index.js +6 -1
- package/lib/api/index.js.map +1 -1
- package/lib/api/index.test.js +7 -2
- package/lib/api/index.test.js.map +1 -1
- package/lib/logic/listOperations.d.ts +7 -1
- package/lib/logic/listOperations.d.ts.map +1 -1
- package/lib/logic/listOperations.integ.test.js +56 -4
- package/lib/logic/listOperations.integ.test.js.map +1 -1
- package/lib/logic/listOperations.js +20 -7
- package/lib/logic/listOperations.js.map +1 -1
- package/lib/logic/listOperations.unit.test.js +5 -3
- package/lib/logic/listOperations.unit.test.js.map +1 -1
- package/lib/network/index.d.ts +5 -1
- package/lib/network/index.d.ts.map +1 -1
- package/lib/network/index.js +8 -5
- package/lib/network/index.js.map +1 -1
- package/lib-es/api/index.d.ts.map +1 -1
- package/lib-es/api/index.js +6 -1
- package/lib-es/api/index.js.map +1 -1
- package/lib-es/api/index.test.js +7 -2
- package/lib-es/api/index.test.js.map +1 -1
- package/lib-es/logic/listOperations.d.ts +7 -1
- package/lib-es/logic/listOperations.d.ts.map +1 -1
- package/lib-es/logic/listOperations.integ.test.js +57 -5
- package/lib-es/logic/listOperations.integ.test.js.map +1 -1
- package/lib-es/logic/listOperations.js +19 -7
- package/lib-es/logic/listOperations.js.map +1 -1
- package/lib-es/logic/listOperations.unit.test.js +6 -4
- package/lib-es/logic/listOperations.unit.test.js.map +1 -1
- package/lib-es/network/index.d.ts +5 -1
- package/lib-es/network/index.d.ts.map +1 -1
- package/lib-es/network/index.js +8 -5
- package/lib-es/network/index.js.map +1 -1
- package/package.json +1 -1
- package/src/api/index.test.ts +7 -2
- package/src/api/index.ts +7 -1
- package/src/logic/listOperations.integ.test.ts +74 -5
- package/src/logic/listOperations.ts +31 -7
- package/src/logic/listOperations.unit.test.ts +8 -4
- package/src/network/index.ts +13 -6
|
@@ -2,7 +2,7 @@ import BigNumber from "bignumber.js";
|
|
|
2
2
|
import { defaultFetchParams, fetchTronAccountTxs, getBlock } from "../network";
|
|
3
3
|
import { fromTrongridTxInfoToOperation } from "../network/trongrid/trongrid-adapters";
|
|
4
4
|
import { TrongridTxInfo, TronAsset } from "../types";
|
|
5
|
-
import { listOperations } from "./listOperations";
|
|
5
|
+
import { defaultOptions, listOperations } from "./listOperations";
|
|
6
6
|
import type { Operation } from "@ledgerhq/coin-framework/api/index";
|
|
7
7
|
|
|
8
8
|
// Mock the fetchTronAccountTxs and fromTrongridTxInfoToOperation functions
|
|
@@ -30,6 +30,8 @@ describe("listOperations", () => {
|
|
|
30
30
|
const expectedFetchParams = {
|
|
31
31
|
...defaultFetchParams,
|
|
32
32
|
minTimestamp: mockBlockTimestamp,
|
|
33
|
+
hintGlobalLimit: 1000,
|
|
34
|
+
order: "desc",
|
|
33
35
|
};
|
|
34
36
|
|
|
35
37
|
it("should fetch transactions and return operations", async () => {
|
|
@@ -51,7 +53,7 @@ describe("listOperations", () => {
|
|
|
51
53
|
};
|
|
52
54
|
});
|
|
53
55
|
|
|
54
|
-
const [operations, token] = await listOperations(mockAddress,
|
|
56
|
+
const [operations, token] = await listOperations(mockAddress, defaultOptions);
|
|
55
57
|
|
|
56
58
|
expect(fetchTronAccountTxs).toHaveBeenCalledWith(
|
|
57
59
|
mockAddress,
|
|
@@ -71,7 +73,7 @@ describe("listOperations", () => {
|
|
|
71
73
|
(fetchTronAccountTxs as jest.Mock).mockResolvedValue(mockTxs);
|
|
72
74
|
(fromTrongridTxInfoToOperation as jest.Mock).mockImplementation(() => null);
|
|
73
75
|
|
|
74
|
-
const [operations, token] = await listOperations(mockAddress,
|
|
76
|
+
const [operations, token] = await listOperations(mockAddress, defaultOptions);
|
|
75
77
|
|
|
76
78
|
expect(fetchTronAccountTxs).toHaveBeenCalledWith(
|
|
77
79
|
mockAddress,
|
|
@@ -87,6 +89,8 @@ describe("listOperations", () => {
|
|
|
87
89
|
const exampleError = new Error("Network error!");
|
|
88
90
|
(fetchTronAccountTxs as jest.Mock).mockRejectedValue(exampleError);
|
|
89
91
|
|
|
90
|
-
await expect(listOperations(mockAddress,
|
|
92
|
+
await expect(listOperations(mockAddress, defaultOptions)).rejects.toThrow(
|
|
93
|
+
new Error(exampleError.message),
|
|
94
|
+
);
|
|
91
95
|
});
|
|
92
96
|
});
|
package/src/network/index.ts
CHANGED
|
@@ -483,13 +483,18 @@ export type FetchTxsStopPredicate = (
|
|
|
483
483
|
) => boolean;
|
|
484
484
|
|
|
485
485
|
export type FetchParams = {
|
|
486
|
-
|
|
486
|
+
/** The maximum number of transactions to fetch per call. */
|
|
487
|
+
limitPerCall: number;
|
|
488
|
+
/** Hint about the number of transactions to be fetched in total (hint to optimize `limitPerCall`) */
|
|
489
|
+
hintGlobalLimit?: number;
|
|
487
490
|
minTimestamp: number;
|
|
491
|
+
order: "asc" | "desc";
|
|
488
492
|
};
|
|
489
493
|
|
|
490
494
|
export const defaultFetchParams: FetchParams = {
|
|
491
|
-
|
|
495
|
+
limitPerCall: 100,
|
|
492
496
|
minTimestamp: 0,
|
|
497
|
+
order: "desc",
|
|
493
498
|
} as const;
|
|
494
499
|
|
|
495
500
|
export async function fetchTronAccountTxs(
|
|
@@ -498,12 +503,15 @@ export async function fetchTronAccountTxs(
|
|
|
498
503
|
cacheTransactionInfoById: Record<string, TronTransactionInfo>,
|
|
499
504
|
params: FetchParams,
|
|
500
505
|
): Promise<TrongridTxInfo[]> {
|
|
501
|
-
const
|
|
506
|
+
const adjustedLimitPerCall = params.hintGlobalLimit
|
|
507
|
+
? Math.min(params.limitPerCall, params.hintGlobalLimit)
|
|
508
|
+
: params.limitPerCall;
|
|
509
|
+
const queryParams = `limit=${adjustedLimitPerCall}&min_timestamp=${params.minTimestamp}&order_by=block_timestamp,${params.order}`;
|
|
502
510
|
const nativeTxs = (
|
|
503
511
|
await getAllTransactions<
|
|
504
512
|
(TransactionTronAPI & { detail?: TronTransactionInfo }) | MalformedTransactionTronAPI
|
|
505
513
|
>(
|
|
506
|
-
`${getBaseApiUrl()}/v1/accounts/${addr}/transactions?${
|
|
514
|
+
`${getBaseApiUrl()}/v1/accounts/${addr}/transactions?${queryParams}`,
|
|
507
515
|
shouldFetchMoreTxs,
|
|
508
516
|
getTransactions(cacheTransactionInfoById),
|
|
509
517
|
)
|
|
@@ -528,10 +536,9 @@ export async function fetchTronAccountTxs(
|
|
|
528
536
|
|
|
529
537
|
// we need to fetch and filter trc20 transactions from another endpoint
|
|
530
538
|
// doc https://developers.tron.network/reference/get-trc20-transaction-info-by-account-address
|
|
531
|
-
const queryParamsTrc20Txs = `limit=${params.limit}&min_timestamp=${params.minTimestamp}`;
|
|
532
539
|
const trc20Txs = (
|
|
533
540
|
await getAllTransactions<Trc20API>(
|
|
534
|
-
`${getBaseApiUrl()}/v1/accounts/${addr}/transactions/trc20?${
|
|
541
|
+
`${getBaseApiUrl()}/v1/accounts/${addr}/transactions/trc20?${queryParams}&get_detail=true`,
|
|
535
542
|
shouldFetchMoreTxs,
|
|
536
543
|
getTrc20,
|
|
537
544
|
)
|