@ledgerhq/coin-tron
Version:
Ledger Tron Coin integration
103 lines • 3.75 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.acceptTransaction = void 0;
const specs_1 = require("@ledgerhq/coin-framework/bot/specs");
function subAccount(subAccountId, account) {
const sub = (account.subAccounts || []).find(a => a.id === subAccountId);
if (!sub || sub.type !== "TokenAccount")
throw new Error("expected sub account id " + subAccountId);
return sub;
}
const resourceExpected = ({ transaction: { resource } }) => resource ? resource.slice(0, 1).toUpperCase() + resource.slice(1).toLowerCase() : "";
exports.acceptTransaction = (0, specs_1.deviceActionFlow)({
steps: [
{
title: "Review",
button: specs_1.SpeculosButton.RIGHT, // TODO define expectedValue
},
{
title: "Claim",
button: specs_1.SpeculosButton.RIGHT,
},
{
title: "Gain",
button: specs_1.SpeculosButton.RIGHT,
expectedValue: arg => resourceExpected(arg),
},
{
title: "Resource",
button: specs_1.SpeculosButton.RIGHT,
expectedValue: arg => resourceExpected(arg),
},
{
title: "Amount",
button: specs_1.SpeculosButton.RIGHT,
expectedValue: ({ account, status, transaction }) => (0, specs_1.formatDeviceAmount)(transaction.subAccountId
? subAccount(transaction.subAccountId, account).token
: account.currency, status.amount, {
hideCode: true,
}),
},
{
title: "Token",
button: specs_1.SpeculosButton.RIGHT,
expectedValue: ({ account, transaction }) => {
const isTokenTransaction = Boolean(transaction.subAccountId);
if (isTokenTransaction) {
const token = subAccount(transaction.subAccountId, account).token;
const [, tokenType, tokenId] = token.id.split("/");
if (tokenType === "trc10") {
return `${token.name.split(" ")[0]}[${tokenId}]`;
}
else {
return token.ticker;
}
}
return "TRX";
},
},
{
title: "From Address",
button: specs_1.SpeculosButton.RIGHT,
expectedValue: ({ account }) => account.freshAddress,
},
{
title: "Freeze To",
button: specs_1.SpeculosButton.RIGHT,
expectedValue: ({ account }) => account.freshAddress,
},
{
title: "Delegated To",
button: specs_1.SpeculosButton.RIGHT,
expectedValue: ({ account }) => account.freshAddress,
},
{
title: "To",
button: specs_1.SpeculosButton.RIGHT,
expectedValue: ({ transaction }) => transaction.recipient,
},
{
title: "Sign",
button: specs_1.SpeculosButton.BOTH,
final: true,
},
],
fallback: ({ event, transaction }) => {
if (transaction.mode === "vote") {
for (const vote of transaction.votes) {
const title = `${vote.address.slice(0, 5)}...${vote.address.slice(vote.address.length - 5)}`;
if (event.text === title) {
return voteAction(vote, title);
}
}
}
},
});
function voteAction(vote, title) {
return {
title,
button: specs_1.SpeculosButton.RIGHT,
expectedValue: () => String(vote.voteCount),
};
}
//# sourceMappingURL=bot-deviceActions.js.map