@ledgerhq/live-common
Version:
Common ground for the Ledger Live apps
82 lines • 2.86 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.mappedSwapOperationsToCSV = void 0;
const currencies_1 = require("../../currencies");
const account_1 = require("../../account");
const accountName_1 = require("@ledgerhq/live-wallet/accountName");
const newLine = "\r\n";
const fields = [
{
title: "Operator",
cell: ({ provider }) => provider,
},
{
title: "Swap ID",
cell: ({ swapId }) => swapId,
},
{
title: "From",
cell: ({ fromAccount }) => (0, account_1.getAccountCurrency)(fromAccount).ticker,
},
{
title: "To",
cell: ({ toAccount }) => (0, account_1.getAccountCurrency)(toAccount).ticker,
},
{
title: "From Value",
cell: ({ fromAccount, fromAmount }) => (0, currencies_1.formatCurrencyUnit)((0, account_1.getAccountCurrency)(fromAccount).units[0], fromAmount, {
disableRounding: true,
useGrouping: false,
}),
},
{
title: "To Value",
cell: ({ toAccount, toAmount }) => (0, currencies_1.formatCurrencyUnit)((0, account_1.getAccountCurrency)(toAccount).units[0], toAmount, {
disableRounding: true,
useGrouping: false,
}),
},
{
title: "Status",
cell: ({ status }) => status,
},
{
title: "Date",
cell: ({ operation }) => operation.date.toISOString(),
},
{
title: "From account",
cell: ({ fromAccount, fromParentAccount }) => (0, accountName_1.getDefaultAccountName)((0, account_1.getMainAccount)(fromAccount, fromParentAccount)),
},
{
title: "From account address",
cell: ({ fromAccount, fromParentAccount }) => {
const main = (0, account_1.getMainAccount)(fromAccount, fromParentAccount);
return main.freshAddress;
},
},
{
title: "To account",
cell: ({ toAccount, toParentAccount }) => (0, accountName_1.getDefaultAccountName)((0, account_1.getMainAccount)(toAccount, toParentAccount)),
},
{
title: "To account address",
cell: ({ toAccount, toParentAccount }) => {
const main = (0, account_1.getMainAccount)(toAccount, toParentAccount);
return main.freshAddress;
},
},
];
const mappedSwapOperationsToCSV = (swapHistorySections) => {
const mappedSwapOperations = [];
for (const section of swapHistorySections) {
mappedSwapOperations.push(...section.data);
}
return (fields.map(field => field.title).join(",") +
newLine +
mappedSwapOperations
.map(op => fields.map(field => field.cell(op).replace(/[,\n\r]/g, "")).join(","))
.join(newLine));
};
exports.mappedSwapOperationsToCSV = mappedSwapOperationsToCSV;
//# sourceMappingURL=csvExport.js.map