@ledgerhq/coin-stellar
Version:
Ledger Stellar Coin integration
103 lines • 3.73 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.acceptTransaction = void 0;
const index_1 = require("@ledgerhq/coin-framework/account/index");
const formatCurrencyUnit_1 = require("@ledgerhq/coin-framework/currencies/formatCurrencyUnit");
const specs_1 = require("@ledgerhq/coin-framework/bot/specs");
function expectedAmount({ account, status, transaction, }) {
if (transaction.assetReference && transaction.assetOwner) {
const amount = (0, specs_1.formatDeviceAmount)(account.currency, status.amount, {
hideCode: true,
});
return `${amount} ${transaction.assetReference}@${truncateAddress(transaction.assetOwner, 3, 4)}`;
}
return (0, specs_1.formatDeviceAmount)(account.currency, status.amount, {
postfixCode: true,
});
}
function truncateAddress(stellarAddress, start = 6, end = 6) {
return `${stellarAddress.slice(0, start)}..${stellarAddress.slice(-end)}`;
}
exports.acceptTransaction = (0, specs_1.deviceActionFlow)({
steps: [
{
title: "Review",
button: specs_1.SpeculosButton.RIGHT,
},
{
title: "Memo Text",
button: specs_1.SpeculosButton.RIGHT,
expectedValue: ({ transaction }) => transaction.memoValue || "",
},
{
title: "Max Fee",
button: specs_1.SpeculosButton.RIGHT,
expectedValue: ({ account, status }) => (0, formatCurrencyUnit_1.formatCurrencyUnit)((0, index_1.getAccountCurrency)(account).units[0], status.estimatedFees, {
disableRounding: true,
}) + " XLM",
},
{
title: "Sequence Num",
button: specs_1.SpeculosButton.RIGHT,
},
{
title: "Tx Source",
button: specs_1.SpeculosButton.RIGHT,
expectedValue: ({ account }) => truncateAddress(account.freshAddress),
},
{
title: "Operation Type",
button: specs_1.SpeculosButton.RIGHT,
// Operation type can be Payment (or Create Account) or Change Trust.
// Create Account type is coming from operation, not transaction.
// Testing in `specs.ts`.
},
{
title: "Change Trust",
button: specs_1.SpeculosButton.RIGHT,
expectedValue: ({ transaction }) => `${transaction.assetReference || ""}@${truncateAddress(transaction.assetOwner || "", 3, 4)}`,
maxY: 5,
},
{
title: "Create Account",
button: specs_1.SpeculosButton.RIGHT,
expectedValue: ({ transaction }) => transaction.recipient,
maxY: 5,
},
{
title: "Send",
button: specs_1.SpeculosButton.RIGHT,
expectedValue: expectedAmount,
},
{
title: "Destination",
button: specs_1.SpeculosButton.RIGHT,
expectedValue: ({ transaction }) => transaction.recipient,
},
{
title: "Finalize",
button: specs_1.SpeculosButton.BOTH,
},
{
title: "Starting Balance",
button: specs_1.SpeculosButton.RIGHT,
},
{
title: "Network",
button: specs_1.SpeculosButton.RIGHT,
},
{
title: "Valid Before (UTC)",
button: specs_1.SpeculosButton.RIGHT,
},
{
title: "Valid After (UTC)",
button: specs_1.SpeculosButton.RIGHT,
},
{
title: "Sign",
button: specs_1.SpeculosButton.BOTH,
},
],
});
//# sourceMappingURL=bot-deviceActions.js.map