@ledgerhq/coin-sui 0.12.0 → 0.13.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 +23 -0
- package/lib/api/index.d.ts +1 -1
- package/lib/api/index.d.ts.map +1 -1
- package/lib/api/index.integration.test.js +9 -2
- package/lib/api/index.integration.test.js.map +1 -1
- package/lib/api/index.js +1 -1
- package/lib/api/index.js.map +1 -1
- package/lib/api/index.test.js +3 -3
- package/lib/api/index.test.js.map +1 -1
- package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -1
- package/lib/bridge/estimateMaxSpendable.js +9 -7
- package/lib/bridge/estimateMaxSpendable.js.map +1 -1
- package/lib/bridge/estimateMaxSpendable.test.js +2 -2
- package/lib/bridge/estimateMaxSpendable.test.js.map +1 -1
- package/lib/bridge/getTransactionStatus.d.ts.map +1 -1
- package/lib/bridge/getTransactionStatus.js +4 -1
- package/lib/bridge/getTransactionStatus.js.map +1 -1
- package/lib/bridge/utils.d.ts.map +1 -1
- package/lib/bridge/utils.js +2 -2
- package/lib/bridge/utils.js.map +1 -1
- package/lib/logic/listOperations.d.ts +1 -3
- package/lib/logic/listOperations.d.ts.map +1 -1
- package/lib/logic/listOperations.js +3 -3
- package/lib/logic/listOperations.js.map +1 -1
- package/lib/logic/listOperations.test.js +43 -39
- package/lib/logic/listOperations.test.js.map +1 -1
- package/lib/network/index.d.ts +1 -1
- package/lib/network/sdk.d.ts +9 -5
- package/lib/network/sdk.d.ts.map +1 -1
- package/lib/network/sdk.js +54 -27
- package/lib/network/sdk.js.map +1 -1
- package/lib/network/sdk.test.js +272 -170
- package/lib/network/sdk.test.js.map +1 -1
- package/lib-es/api/index.d.ts +1 -1
- package/lib-es/api/index.d.ts.map +1 -1
- package/lib-es/api/index.integration.test.js +9 -2
- package/lib-es/api/index.integration.test.js.map +1 -1
- package/lib-es/api/index.js +1 -1
- package/lib-es/api/index.js.map +1 -1
- package/lib-es/api/index.test.js +3 -3
- package/lib-es/api/index.test.js.map +1 -1
- package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -1
- package/lib-es/bridge/estimateMaxSpendable.js +9 -7
- package/lib-es/bridge/estimateMaxSpendable.js.map +1 -1
- package/lib-es/bridge/estimateMaxSpendable.test.js +2 -2
- package/lib-es/bridge/estimateMaxSpendable.test.js.map +1 -1
- package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -1
- package/lib-es/bridge/getTransactionStatus.js +4 -1
- package/lib-es/bridge/getTransactionStatus.js.map +1 -1
- package/lib-es/bridge/utils.d.ts.map +1 -1
- package/lib-es/bridge/utils.js +2 -2
- package/lib-es/bridge/utils.js.map +1 -1
- package/lib-es/logic/listOperations.d.ts +1 -3
- package/lib-es/logic/listOperations.d.ts.map +1 -1
- package/lib-es/logic/listOperations.js +4 -4
- package/lib-es/logic/listOperations.js.map +1 -1
- package/lib-es/logic/listOperations.test.js +44 -40
- package/lib-es/logic/listOperations.test.js.map +1 -1
- package/lib-es/network/index.d.ts +1 -1
- package/lib-es/network/sdk.d.ts +9 -5
- package/lib-es/network/sdk.d.ts.map +1 -1
- package/lib-es/network/sdk.js +54 -27
- package/lib-es/network/sdk.js.map +1 -1
- package/lib-es/network/sdk.test.js +272 -170
- package/lib-es/network/sdk.test.js.map +1 -1
- package/package.json +5 -5
- package/src/api/index.integration.test.ts +10 -2
- package/src/api/index.test.ts +3 -3
- package/src/api/index.ts +4 -3
- package/src/bridge/estimateMaxSpendable.test.ts +2 -2
- package/src/bridge/estimateMaxSpendable.ts +9 -8
- package/src/bridge/getTransactionStatus.ts +4 -2
- package/src/bridge/utils.ts +2 -2
- package/src/logic/listOperations.test.ts +45 -41
- package/src/logic/listOperations.ts +4 -4
- package/src/network/sdk.test.ts +312 -207
- package/src/network/sdk.ts +70 -32
package/src/network/sdk.ts
CHANGED
|
@@ -24,6 +24,7 @@ import type {
|
|
|
24
24
|
BlockTransaction,
|
|
25
25
|
BlockOperation,
|
|
26
26
|
Operation as Op,
|
|
27
|
+
Page,
|
|
27
28
|
Stake,
|
|
28
29
|
StakeState,
|
|
29
30
|
AssetInfo,
|
|
@@ -318,6 +319,7 @@ export function transactionToOperation(
|
|
|
318
319
|
return {
|
|
319
320
|
id: encodeOperationId(accountId, hash, type),
|
|
320
321
|
accountId,
|
|
322
|
+
// warning this is false:
|
|
321
323
|
blockHash: hash,
|
|
322
324
|
blockHeight: BLOCK_HEIGHT,
|
|
323
325
|
date: getOperationDate(transaction),
|
|
@@ -347,7 +349,6 @@ export function transactionToOp(address: string, transaction: SuiTransactionBloc
|
|
|
347
349
|
block: {
|
|
348
350
|
// agreed to return bigint
|
|
349
351
|
height: BigInt(transaction.checkpoint || "") as unknown as number,
|
|
350
|
-
hash,
|
|
351
352
|
time: getOperationDate(transaction),
|
|
352
353
|
},
|
|
353
354
|
},
|
|
@@ -449,14 +450,22 @@ export const getOperations = async (
|
|
|
449
450
|
accountId: string,
|
|
450
451
|
addr: string,
|
|
451
452
|
cursor?: QueryTransactionBlocksParams["cursor"],
|
|
453
|
+
order?: "asc" | "desc",
|
|
452
454
|
): Promise<Operation[]> =>
|
|
453
455
|
withApi(async api => {
|
|
454
|
-
|
|
456
|
+
let rpcOrder: "ascending" | "descending";
|
|
457
|
+
if (order) {
|
|
458
|
+
rpcOrder = order === "asc" ? "ascending" : "descending";
|
|
459
|
+
} else {
|
|
460
|
+
rpcOrder = cursor ? "ascending" : "descending";
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
const sendOps = await loadOperations({
|
|
455
464
|
api,
|
|
456
465
|
addr,
|
|
457
466
|
type: "OUT",
|
|
458
467
|
cursor,
|
|
459
|
-
order:
|
|
468
|
+
order: rpcOrder,
|
|
460
469
|
operations: [],
|
|
461
470
|
});
|
|
462
471
|
const receivedOps = await loadOperations({
|
|
@@ -464,38 +473,51 @@ export const getOperations = async (
|
|
|
464
473
|
addr,
|
|
465
474
|
type: "IN",
|
|
466
475
|
cursor,
|
|
467
|
-
order:
|
|
476
|
+
order: rpcOrder,
|
|
468
477
|
operations: [],
|
|
469
478
|
});
|
|
470
|
-
|
|
479
|
+
// When restoring state (no cursor provided) we filter out extra operations to maintain correct chronological order
|
|
480
|
+
const rawTransactions = filterOperations(sendOps, receivedOps, rpcOrder, !cursor);
|
|
471
481
|
|
|
472
|
-
return rawTransactions.map(transaction =>
|
|
482
|
+
return rawTransactions.operations.map(transaction =>
|
|
483
|
+
transactionToOperation(accountId, addr, transaction),
|
|
484
|
+
);
|
|
473
485
|
});
|
|
474
486
|
|
|
475
487
|
export const filterOperations = (
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
488
|
+
sendOps: LoadOperationResponse,
|
|
489
|
+
receiveOps: LoadOperationResponse,
|
|
490
|
+
order: "ascending" | "descending",
|
|
491
|
+
shouldFilter: boolean = true,
|
|
492
|
+
): LoadOperationResponse => {
|
|
493
|
+
let filterTimestamp: number = 0;
|
|
494
|
+
let nextCursor: string | null | undefined = undefined;
|
|
495
|
+
// When we've reached the limit for either sent or received operations,
|
|
483
496
|
// we filter out extra operations to maintain correct chronological order
|
|
484
497
|
if (
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
(
|
|
498
|
+
shouldFilter &&
|
|
499
|
+
sendOps.operations.length &&
|
|
500
|
+
receiveOps.operations.length &&
|
|
501
|
+
(sendOps.operations.length === TRANSACTIONS_LIMIT ||
|
|
502
|
+
receiveOps.operations.length === TRANSACTIONS_LIMIT)
|
|
489
503
|
) {
|
|
490
|
-
const
|
|
491
|
-
const
|
|
492
|
-
|
|
504
|
+
const sendTime = Number(sendOps.operations[sendOps.operations.length - 1].timestampMs ?? 0);
|
|
505
|
+
const receiveTime = Number(
|
|
506
|
+
receiveOps.operations[receiveOps.operations.length - 1].timestampMs ?? 0,
|
|
507
|
+
);
|
|
508
|
+
if (sendTime >= receiveTime) {
|
|
509
|
+
nextCursor = sendOps.cursor;
|
|
510
|
+
filterTimestamp = sendTime;
|
|
511
|
+
} else {
|
|
512
|
+
nextCursor = receiveOps.cursor;
|
|
513
|
+
filterTimestamp = receiveTime;
|
|
514
|
+
}
|
|
493
515
|
}
|
|
494
|
-
const result = [...
|
|
516
|
+
const result = [...sendOps.operations, ...receiveOps.operations]
|
|
495
517
|
.sort((a, b) => Number(b.timestampMs) - Number(a.timestampMs))
|
|
496
518
|
.filter(op => Number(op.timestampMs) >= filterTimestamp);
|
|
497
519
|
|
|
498
|
-
return uniqBy(result, tx => tx.digest);
|
|
520
|
+
return { operations: uniqBy(result, tx => tx.digest), cursor: nextCursor };
|
|
499
521
|
};
|
|
500
522
|
|
|
501
523
|
/**
|
|
@@ -505,14 +527,22 @@ export const getListOperations = async (
|
|
|
505
527
|
addr: string,
|
|
506
528
|
cursor: QueryTransactionBlocksParams["cursor"] = null,
|
|
507
529
|
withApiImpl: typeof withApi = withApi,
|
|
508
|
-
|
|
530
|
+
order?: "asc" | "desc",
|
|
531
|
+
): Promise<Page<Op>> =>
|
|
509
532
|
withApiImpl(async api => {
|
|
533
|
+
let rpcOrder: "ascending" | "descending";
|
|
534
|
+
if (order) {
|
|
535
|
+
rpcOrder = order === "asc" ? "ascending" : "descending";
|
|
536
|
+
} else {
|
|
537
|
+
rpcOrder = cursor ? "ascending" : "descending";
|
|
538
|
+
}
|
|
539
|
+
|
|
510
540
|
const opsOut = await loadOperations({
|
|
511
541
|
api,
|
|
512
542
|
addr,
|
|
513
543
|
type: "OUT",
|
|
514
544
|
cursor,
|
|
515
|
-
order:
|
|
545
|
+
order: rpcOrder,
|
|
516
546
|
operations: [],
|
|
517
547
|
});
|
|
518
548
|
const opsIn = await loadOperations({
|
|
@@ -520,12 +550,15 @@ export const getListOperations = async (
|
|
|
520
550
|
addr,
|
|
521
551
|
type: "IN",
|
|
522
552
|
cursor,
|
|
523
|
-
order:
|
|
553
|
+
order: rpcOrder,
|
|
524
554
|
operations: [],
|
|
525
555
|
});
|
|
526
|
-
const list = filterOperations(opsIn, opsOut,
|
|
556
|
+
const list = filterOperations(opsIn, opsOut, rpcOrder, true);
|
|
527
557
|
|
|
528
|
-
return
|
|
558
|
+
return {
|
|
559
|
+
items: list.operations.map(t => transactionToOp(addr, t)),
|
|
560
|
+
next: list.cursor ?? undefined,
|
|
561
|
+
};
|
|
529
562
|
});
|
|
530
563
|
|
|
531
564
|
/**
|
|
@@ -715,6 +748,11 @@ export const executeTransactionBlock = async (params: ExecuteTransactionBlockPar
|
|
|
715
748
|
return api.executeTransactionBlock(params);
|
|
716
749
|
});
|
|
717
750
|
|
|
751
|
+
type LoadOperationResponse = {
|
|
752
|
+
operations: SuiTransactionBlockResponse[];
|
|
753
|
+
cursor?: QueryTransactionBlocksParams["cursor"];
|
|
754
|
+
};
|
|
755
|
+
|
|
718
756
|
/**
|
|
719
757
|
* Fetch operations for a specific address and type until the limit is reached
|
|
720
758
|
*/
|
|
@@ -730,10 +768,10 @@ export const loadOperations = async ({
|
|
|
730
768
|
operations: PaginatedTransactionResponse["data"];
|
|
731
769
|
order: "ascending" | "descending";
|
|
732
770
|
cursor?: QueryTransactionBlocksParams["cursor"];
|
|
733
|
-
}): Promise<
|
|
771
|
+
}): Promise<LoadOperationResponse> => {
|
|
734
772
|
try {
|
|
735
|
-
if (
|
|
736
|
-
return operations;
|
|
773
|
+
if (operations.length >= TRANSACTIONS_LIMIT) {
|
|
774
|
+
return { operations, cursor };
|
|
737
775
|
}
|
|
738
776
|
|
|
739
777
|
const { data, nextCursor, hasNextPage } = await queryTransactions({
|
|
@@ -744,7 +782,7 @@ export const loadOperations = async ({
|
|
|
744
782
|
|
|
745
783
|
operations.push(...data);
|
|
746
784
|
if (!hasNextPage) {
|
|
747
|
-
return operations;
|
|
785
|
+
return { operations: operations, cursor: nextCursor };
|
|
748
786
|
}
|
|
749
787
|
|
|
750
788
|
await loadOperations({ ...params, cursor: nextCursor, operations, order });
|
|
@@ -759,7 +797,7 @@ export const loadOperations = async ({
|
|
|
759
797
|
}
|
|
760
798
|
}
|
|
761
799
|
|
|
762
|
-
return operations;
|
|
800
|
+
return { operations: operations, cursor: cursor };
|
|
763
801
|
};
|
|
764
802
|
|
|
765
803
|
/**
|