@ledgerhq/coin-tron
Version:
Ledger Tron Coin integration
58 lines • 2.22 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.fromTrongridTxInfoToOperation = fromTrongridTxInfoToOperation;
exports.inferAssetInfo = inferAssetInfo;
const utils_1 = require("@ledgerhq/coin-module-framework/utils");
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: (0, utils_1.fromBigNumberToBigInt)(trongridTxInfo.fee, BigInt(0)),
feesPayer: trongridTxInfo.feesPayer ?? trongridTxInfo.from,
date: trongridTxInfo.date,
failed: trongridTxInfo.hasFailed,
},
type: inferOperationType(trongridTxInfo, userAddress),
value: (0, utils_1.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";
}
}
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