@ledgerhq/coin-tron
Version:
Ledger Tron Coin integration
52 lines • 2.05 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.fromTrongridTxInfoToOperation = fromTrongridTxInfoToOperation;
const utils_1 = require("@ledgerhq/coin-framework/utils");
function fromTrongridTxInfoToOperation(trongridTxInfo, userAddress) {
return {
operationIndex: 0,
tx: {
hash: trongridTxInfo.txID,
block: { height: trongridTxInfo.blockHeight || 0, time: trongridTxInfo.date },
fees: (0, utils_1.fromBigNumberToBigInt)(trongridTxInfo.fee, BigInt(0)),
date: trongridTxInfo.date,
},
type: inferOperationType(trongridTxInfo, userAddress),
value: (0, utils_1.fromBigNumberToBigInt)(trongridTxInfo.value, BigInt(0)),
senders: [trongridTxInfo.from],
recipients: trongridTxInfo.to != null ? [trongridTxInfo.to] : [],
asset: inferAssetInfo(trongridTxInfo),
};
}
function inferOperationType(trongridTxInfo, userAddress) {
switch (true) {
case trongridTxInfo.from === userAddress &&
trongridTxInfo.to != null &&
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 {
standard: "trc10",
// if tokenType is trc10, tokenId is always defined
tokenId: trongridTxInfo.tokenId,
};
case trongridTxInfo.tokenType === "trc20":
return {
standard: "trc20",
// if tokenType is trc20, contractAddress is always defined
contractAddress: trongridTxInfo.tokenAddress,
};
default:
// asset is undefined when dealing with native currency
return undefined;
}
}
//# sourceMappingURL=trongrid-adapters.js.map