Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/lib/receiptsCsv.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export interface ReceiptCsvRow {
id: string;
date: string;
repository: string;
issueNumber: string;
issueTitle: string;
pullRequest: string;
amount: number;
asset: string;
payoutAddress: string;
}

export function receiptsToCsv(rows: readonly ReceiptCsvRow[]): string;
33 changes: 33 additions & 0 deletions src/lib/receiptsCsv.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const COLUMNS = [
'receipt id',
'date',
'repository',
'issue number',
'issue title',
'pull request',
'amount',
'asset',
'payout address',
];

function cell(value) {
let text = value == null ? '' : String(value);
if (/^[\s]*[=+@-]/.test(text)) text = `'${text}`;
return `"${text.replaceAll('"', '""')}"`;
}

/** Build a spreadsheet-safe CSV document from enriched receipt rows. */
export function receiptsToCsv(rows) {
const records = [COLUMNS, ...rows.map(row => [
row.id,
row.date,
row.repository,
row.issueNumber,
row.issueTitle,
row.pullRequest,
row.amount,
row.asset,
row.payoutAddress,
])];
return `${records.map(record => record.map(cell).join(',')).join('\r\n')}\r\n`;
}
38 changes: 35 additions & 3 deletions src/pages/contributor.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { useState } from 'react';
import { Link, useNavigate } from 'react-router-dom';
import { ArrowRight, GitPullRequest } from 'lucide-react';
import { ArrowRight, Download, GitPullRequest } from 'lucide-react';
import {
dateLabel, formatMoney, initialState, isOwnApplication, isStellarAddress, repoName, shortAddress, statusTone,
} from '../lib/model';
import { PLATFORM } from '../lib/platform';
import { useApp } from '../lib/store';
import { receiptsToCsv } from '../lib/receiptsCsv.js';
import { Chip, Empty, Item, ModalHost, Page, PageHead, Stagger } from '../components/ui';

export function ContributorWork() {
Expand Down Expand Up @@ -88,11 +89,36 @@ export function ContributorWork() {
}

export function ContributorReceipts() {
const { state } = useApp();
const { state, notify } = useApp();
const me = state.session.contributor;
const mine = state.receipts.filter(r => r.contributor === me);
const total = mine.reduce((sum, r) => sum + r.amount, 0);

const exportCsv = () => {
const csv = receiptsToCsv(mine.map(receipt => {
const issue = state.issues.find(item => item.id === receipt.issueId);
const repo = state.repos.find(item => item.id === receipt.repoId);
return {
id: receipt.id,
date: receipt.paidAt,
repository: repo ? repoName(repo) : '',
issueNumber: receipt.issueId,
issueTitle: issue?.title ?? `Issue #${receipt.issueId}`,
pullRequest: receipt.pr,
amount: receipt.amount,
asset: PLATFORM.asset,
payoutAddress: receipt.address ?? '',
};
}));
const url = URL.createObjectURL(new Blob([csv], { type: 'text/csv;charset=utf-8' }));
const link = document.createElement('a');
link.href = url;
link.download = 'parallax-receipts.csv';
link.click();
window.setTimeout(() => URL.revokeObjectURL(url), 0);
notify('Receipts exported as CSV.');
};

return (
<Page>
<PageHead title="Receipts" sub={`One for every bounty released to you. Portable proof of the work you shipped.`} />
Expand All @@ -114,7 +140,13 @@ export function ContributorReceipts() {
</div>
</div>
<section className="section">
<div className="row section-head"><h2>Ledger</h2></div>
<div className="row section-head">
<h2>Ledger</h2>
<span className="spacer" />
<button className="btn sm" type="button" onClick={exportCsv} disabled={!mine.length}>
<Download size={13} />Export CSV
</button>
</div>
{mine.length ? (
<Stagger className="list">
{mine.map(r => {
Expand Down
27 changes: 27 additions & 0 deletions tests/receipts-csv.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import { receiptsToCsv } from '../src/lib/receiptsCsv.js';

test('writes the required receipt columns and safely escapes punctuation', () => {
const csv = receiptsToCsv([{
id: 'rcpt-1',
date: '2026-10-06',
repository: 'stellar, sdk',
issueNumber: '842',
issueTitle: 'Fix "quoted"\nissue',
pullRequest: 'https://github.com/stellar/sdk/pull/2',
amount: 450,
asset: 'USDC',
payoutAddress: 'GADDRESS',
}]);

assert.equal(
csv,
'"receipt id","date","repository","issue number","issue title","pull request","amount","asset","payout address"\r\n'
+ '"rcpt-1","2026-10-06","stellar, sdk","842","Fix ""quoted""\nissue","https://github.com/stellar/sdk/pull/2","450","USDC","GADDRESS"\r\n',
);
});

test('returns headers without a data row for an empty ledger', () => {
assert.equal(receiptsToCsv([]).split('\r\n').length, 2);
});