Skip to content
Merged
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<!-- Badge section -->
[![CI](https://github.com/meseer/monarch-uploader/actions/workflows/ci.yml/badge.svg)](https://github.com/meseer/monarch-uploader/actions/workflows/ci.yml)
[![codecov](https://codecov.io/gh/meseer/monarch-uploader/branch/main/graph/badge.svg)](https://codecov.io/gh/meseer/monarch-uploader)
[![Version](https://img.shields.io/badge/version-6.11.2-blue)](https://github.com/meseer/monarch-uploader)
[![Version](https://img.shields.io/badge/version-6.12.0-blue)](https://github.com/meseer/monarch-uploader)
[![License: CC BY-NC-SA 4.0](https://img.shields.io/badge/License-CC%20BY--NC--SA%204.0-lightgrey.svg)](https://creativecommons.org/licenses/by-nc-sa/4.0/)

A userscript that automatically syncs balance history, transactions, holdings, and more from Canadian financial institutions to [Monarch Money](https://www.monarchmoney.com/).
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "monarch-uploader",
"version": "6.11.2",
"version": "6.12.0",
"description": "Violentmonkey userscript for uploading Questrade, Wealthsimple, Canada Life, and Rogers Bank data to Monarch Money",
"main": "dist/monarch-uploader.user.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/scriptInfo.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"version": "6.11.2",
"version": "6.12.0",
"gistUrl": "https://gist.github.com/meseer/f00fb552c96efeb3eb4e4e1fd520d4e7/raw/monarch-uploader.user.js"
}
45 changes: 40 additions & 5 deletions src/ui/questrade/components/uploadButton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import { debugLog, calculateFromDateWithLookback, getTodayLocal, formatDate } fr
import { STORAGE } from '../../../core/config';
import stateManager from '../../../core/state';
import toast from '../../toast';
import { processAccountBalanceHistory } from '../../../services/questrade/account';
import { ensureMonarchAuthentication } from '../../components/monarchLoginLink';
import { syncAllAccountsToMonarch } from '../../../services/questrade/sync';
import { showProgressDialog } from '../../components/progressDialog';
import syncService, { syncAllAccountsToMonarch } from '../../../services/questrade/sync';
import { uploadAllAccountsActivityToMonarch, uploadSingleAccountActivityToMonarch } from '../../../services/questrade/transactions';
import {
getAccountCreationDate,
Expand Down Expand Up @@ -156,6 +156,7 @@ function createButtonGroup(): HTMLDivElement {

/**
* Creates a single-account upload button that responds to state changes.
* Shows a progress dialog with step-by-step details (same as all-accounts sync).
* Automatically determines the start date using the same logic as the all-accounts sync:
* - Subsequent sync: last sync date minus lookback period
* - First sync: account creation date
Expand All @@ -180,21 +181,55 @@ function createSingleAccountUploadButton(fallbackAccountId: string, fallbackAcco
? currentState.currentAccount.nickname
: fallbackAccountName;

let progressDialog: ReturnType<typeof showProgressDialog> | null = null;

try {
// Automatically calculate dates (same logic as all-accounts sync)
const fromDate = calculateSingleAccountStartDate(currentAccountId);
const toDate = getTodayLocal();

// Process upload directly without date picker
await processAccountBalanceHistory(
// Create progress dialog for single account (same as Wealthsimple pattern)
const accountsForDialog = [{
key: currentAccountId,
nickname: currentAccountName,
name: currentAccountName,
}];
progressDialog = showProgressDialog(accountsForDialog, `Syncing ${currentAccountName} to Monarch`);

// Set up cancel callback
let isCancelled = false;
progressDialog.onCancel(() => {
debugLog('Single account sync cancellation requested');
isCancelled = true;
toast.show('Sync cancelled by user', 'info');
});

// Check for cancellation before sync
if (isCancelled) {
progressDialog.hideCancel();
return;
}

// Sync account with progress dialog (balance + positions + orders + activity)
await syncService.syncAccountToMonarch(
currentAccountId,
currentAccountName,
fromDate,
toDate,
progressDialog,
);

// Show success summary
progressDialog.showSummary({ success: 1, failed: 0, skipped: 0 });
progressDialog.hideCancel();
} catch (error) {
toast.show(`Error: ${(error as Error).message}`, 'error');
debugLog('Error in single account sync:', error);
toast.show(`Sync failed: ${(error as Error).message}`, 'error');

if (progressDialog) {
progressDialog.showSummary({ success: 0, failed: 1, skipped: 0 });
progressDialog.hideCancel();
}
}
});

Expand Down