Download a CSV!!
This commit is contained in:
parent
a8cfd41892
commit
763f207651
|
@ -112,6 +112,21 @@ const getAllTransactions = async (message: DownloadTransactionsAction) =>
|
|||
|
||||
const mapToCsv = (transactions: GroupedRawTransaction[]) => Papa.unparse(transactions);
|
||||
|
||||
function createdDownload(csv: string, filename: string = 'transactions.csv') {
|
||||
const blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' });
|
||||
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = filename;
|
||||
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
document.body.removeChild(a);
|
||||
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
|
||||
async function downloadStatements(
|
||||
message: DownloadTransactionsMessage
|
||||
): Promise<DownloadTransactionReply> {
|
||||
|
@ -122,7 +137,9 @@ async function downloadStatements(
|
|||
// Should always be populated, but we can be careful anyway.
|
||||
if (isStatePopulated(state)) {
|
||||
const transactions = (await getAllTransactions(message)).flat();
|
||||
return { csv: mapToCsv(transactions), error: null };
|
||||
const csv = mapToCsv(transactions);
|
||||
createdDownload(csv);
|
||||
return { csv: csv, error: null }; // TODO return useful info or something.
|
||||
} else {
|
||||
return {
|
||||
csv: undefined,
|
||||
|
|
14
todo.org
14
todo.org
|
@ -1,9 +1,9 @@
|
|||
How to get it working:
|
||||
- [X] Landsbankinn API client for arbitrary transaction lists
|
||||
- [ ] Transform raw transactions into friendlier ones (i.e. date objects)
|
||||
- [X] Transform raw transactions into friendlier ones (i.e. date objects)
|
||||
- [X] Content script that can run all the time and puts a button somewhere (statements tab, and extension icon)
|
||||
- [X] Use config.ts to set TTL for state
|
||||
- [ ] Background page that downloads all the shit and combines into CSV, then 'downloads' file.
|
||||
- [X] Background page that downloads all the shit and combines into CSV, then 'downloads' file.
|
||||
- [X] Build up communication message passing to background page for downloads
|
||||
- [X] Don't run level on client.
|
||||
- [-] Investigate persistent = false + setTimeout
|
||||
|
@ -14,3 +14,13 @@ How to get it working:
|
|||
- [X] Set API key
|
||||
- [X] Set bearer token
|
||||
- [X] Intercept bearer token by yoinking it out of a request
|
||||
- [ ] Deal with state disappearing after 15 sec (I think 15 sec was a test).
|
||||
- We should always reload state if it's not present. And we are doing this.
|
||||
- Why does state not re-build itself properly? It auths but does not set itself to "ready to request" mode.
|
||||
- [ ] Make the date picker and download button nice to use.
|
||||
- [ ] Validate date picker options when downloading.
|
||||
- [ ] Show a download status on the web page to indicate where it is in the download process.
|
||||
- [ ] Error handling: try-catch in various places, send messages back to content script that error occurred.
|
||||
- [ ] Txn download
|
||||
- [ ] CSV creation
|
||||
- [ ] Ensure auth state API calls
|
||||
|
|
Loading…
Reference in New Issue