UNPKG

@ledgerhq/coin-tron

Version:
54 lines 2.03 kB
import { fromBigNumberToBigInt } from "@ledgerhq/coin-module-framework/utils"; export function fromTrongridTxInfoToOperation(trongridTxInfo, block, userAddress) { return { id: trongridTxInfo.txID, tx: { hash: trongridTxInfo.txID, block: { height: block.height, hash: block.hash, time: block.time || new Date(0), }, fees: fromBigNumberToBigInt(trongridTxInfo.fee, BigInt(0)), feesPayer: trongridTxInfo.feesPayer ?? trongridTxInfo.from, date: trongridTxInfo.date, failed: trongridTxInfo.hasFailed, }, type: inferOperationType(trongridTxInfo, userAddress), value: fromBigNumberToBigInt(trongridTxInfo.value, BigInt(0)), senders: [trongridTxInfo.from], recipients: trongridTxInfo.to ? [trongridTxInfo.to] : [], asset: inferAssetInfo(trongridTxInfo), }; } function inferOperationType(trongridTxInfo, userAddress) { switch (true) { case trongridTxInfo.from === userAddress && trongridTxInfo.to && trongridTxInfo.to !== userAddress: return "OUT"; case trongridTxInfo.to === userAddress && trongridTxInfo.from !== userAddress: return "IN"; default: return "UNKNOWN"; } } export function inferAssetInfo(trongridTxInfo) { switch (true) { case trongridTxInfo.tokenType === "trc10": return { type: "trc10", // if tokenType is trc10, tokenId is always defined assetReference: trongridTxInfo.tokenId, }; case trongridTxInfo.tokenType === "trc20": return { type: "trc20", // if tokenType is trc20, contractAddress is always defined assetReference: trongridTxInfo.tokenAddress, }; default: return { type: "native" }; } } //# sourceMappingURL=trongrid-adapters.js.map