@ledgerhq/coin-sui 0.15.0-nightly.4 → 0.15.1-nightly.0

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.
@@ -341,6 +341,10 @@ export function transactionToOperation(
341
341
  };
342
342
  }
343
343
 
344
+ function absoluteAmount(balanceChange: BalanceChange | undefined): BigNumber {
345
+ return new BigNumber(balanceChange?.amount || 0).abs();
346
+ }
347
+
344
348
  // This function is only used by alpaca code path
345
349
  // Logic is similar to getOperationAmount, but we guarantee to return a positive amount in any case
346
350
  // If there is need to display negative amount for staking or unstaking, the view can handle it based on the type of the operation
@@ -349,9 +353,6 @@ export const alpacaGetOperationAmount = (
349
353
  transaction: SuiTransactionBlockResponse,
350
354
  coinType: string,
351
355
  ): BigNumber => {
352
- const absoluteAmount = (balanceChange: BalanceChange | undefined) =>
353
- new BigNumber(balanceChange?.amount || 0).abs();
354
-
355
356
  const zero = BigNumber(0);
356
357
 
357
358
  const tx = transaction.transaction?.data.transaction;
@@ -443,7 +444,8 @@ export function toBlockTransaction(transaction: SuiTransactionBlockResponse): Bl
443
444
  return {
444
445
  hash: transaction.digest,
445
446
  failed: transaction.effects?.status.status !== "success",
446
- operations: transaction.balanceChanges?.flatMap(toBlockOperation) || [],
447
+ operations:
448
+ transaction.balanceChanges?.flatMap(change => toBlockOperation(transaction, change)) || [],
447
449
  fees: BigInt(getOperationFee(transaction).toString()),
448
450
  feesPayer: transaction.transaction?.data.sender || "",
449
451
  };
@@ -454,16 +456,38 @@ export function toBlockTransaction(transaction: SuiTransactionBlockResponse): Bl
454
456
  *
455
457
  * @param change balance change
456
458
  */
457
- export function toBlockOperation(change: BalanceChange): BlockOperation[] {
459
+ export function toBlockOperation(
460
+ transaction: SuiTransactionBlockResponse,
461
+ change: BalanceChange,
462
+ ): BlockOperation[] {
458
463
  if (typeof change.owner === "string" || !("AddressOwner" in change.owner)) return [];
459
- return [
460
- {
461
- type: "transfer",
462
- address: change.owner.AddressOwner,
463
- asset: toSuiAsset(change.coinType),
464
- amount: BigInt(change.amount),
465
- },
466
- ];
464
+ const address = change.owner.AddressOwner;
465
+ const operationType = getOperationType(address, transaction);
466
+ switch (operationType) {
467
+ case "IN":
468
+ case "OUT":
469
+ return [
470
+ {
471
+ type: "transfer",
472
+ address: change.owner.AddressOwner,
473
+ asset: toSuiAsset(change.coinType),
474
+ amount: BigInt(change.amount),
475
+ },
476
+ ];
477
+ case "DELEGATE":
478
+ case "UNDELEGATE":
479
+ return [
480
+ {
481
+ type: "other",
482
+ operationType: operationType,
483
+ address: change.owner.AddressOwner,
484
+ asset: toSuiAsset(change.coinType),
485
+ amount: BigInt(absoluteAmount(change).toString()),
486
+ },
487
+ ];
488
+ default:
489
+ return [];
490
+ }
467
491
  }
468
492
 
469
493
  /**