mirror of
https://github.com/we-promise/sure.git
synced 2026-05-30 15:59:02 +00:00
feat(goals): v2 architecture — drop ledger, derive balance, add pledge
Reshape the goals feature to live on top of linked-account balances. A goal's balance is now the live balance of every depository account linked to it — no parallel ledger, no "log a contribution" step. The "Add contribution" affordance is replaced by a 7-day GoalPledge (kind: transfer | manual_save). GoalPledge::Reconciler matches incoming Transactions (via Account::ProviderImportAdapter) and Valuations (via Account::ReconciliationManager) against open pledges within ±5 days, ±$0.50, or ±1% — single hook covers every provider (Plaid, SimpleFIN, Lunchflow, Enable Banking, Brex, IBKR, Kraken, SnapTrade) plus manual balance edits. A 15-minute Sidekiq cron sweeps expired pledges. Goal model: balance derived from linked_accounts.sum(&:balance), new pace (90-day net non-transfer inflow), months_of_runway, last_matched_pledge_*, pledge_action_label_key (the "I just transferred…" vs "I just saved…" verb switch). UI: - Index gets a 3-card KPI strip (Contributed last 30d / Needs this month / On track) plus a pending-pledges callout. - Show page swaps the "Add contribution" CTA for the pledge modal, replaces the contribution list with a pending-pledge banner, and rebuilds the funding widget into per-account rows with a 12-bucket weekly sparkline and last-30 inflow. - Projection chart adds a required-line (dashed light from today → target) and a translucent pending-pledge bump at today's X. Schema (3 migrations): 1. goal_pledges table with PG enums (goal_pledge_kind, goal_pledge_status), open-by-expiry index, and unique-when-not-null matched_transaction_id. 2. Drop goal_contributions. 3. Partial unique index on transactions ((extra -> 'goal' ->> 'pledge_id')) built CONCURRENTLY so it doesn't block prod. After pulling: run bin/rails db:migrate, then commit the schema.rb sync separately (or let CI regenerate). Deferred to v1.1: allocation columns, contention/archived banners, "why is this behind?" diagnostic, reallocate flow, refresh-sync + Plaid throttle, unallocated-cash chip, joint-account approval, goal_activities log, polymorphic matched_entry_id/type for manual pledge audit.
This commit is contained in:
@@ -113,7 +113,20 @@ export default class extends Controller {
|
||||
]
|
||||
: [];
|
||||
|
||||
const yMax = Math.max(targetAmount * 1.05, projectionEnd, currentAmount, 1);
|
||||
const requiredMonthly = data.required_monthly || 0;
|
||||
const requiredEnd = target && requiredMonthly > 0
|
||||
? currentAmount + requiredMonthly * Math.max(0, this._monthsBetween(today, target))
|
||||
: currentAmount;
|
||||
const requiredSeries = target && requiredMonthly > 0 && requiredEnd > currentAmount
|
||||
? [
|
||||
{ date: today, value: currentAmount },
|
||||
{ date: target, value: requiredEnd },
|
||||
]
|
||||
: [];
|
||||
|
||||
const pendingPledgeAmount = data.pending_pledge_amount || 0;
|
||||
|
||||
const yMax = Math.max(targetAmount * 1.05, projectionEnd, requiredEnd, currentAmount, 1);
|
||||
|
||||
const x = d3.scaleTime().domain([start, endDate]).range([margin.left, margin.left + innerWidth]);
|
||||
const y = d3.scaleLinear().domain([0, yMax]).range([margin.top + innerHeight, margin.top]);
|
||||
@@ -237,6 +250,21 @@ export default class extends Controller {
|
||||
.attr("stroke-linecap", "round")
|
||||
.attr("d", line);
|
||||
|
||||
if (requiredSeries.length) {
|
||||
// Light dashed line: the path needed to hit the target. Sits behind
|
||||
// the projection so the user sees both the goal and the ask.
|
||||
svg
|
||||
.append("path")
|
||||
.datum(requiredSeries)
|
||||
.attr("fill", "none")
|
||||
.attr("stroke", "var(--color-green-600)")
|
||||
.attr("stroke-width", 1.2)
|
||||
.attr("stroke-linecap", "round")
|
||||
.attr("stroke-dasharray", "2 4")
|
||||
.attr("opacity", 0.45)
|
||||
.attr("d", line);
|
||||
}
|
||||
|
||||
if (projectionSeries.length) {
|
||||
const willHit = projectionEnd >= targetAmount;
|
||||
const projColor = willHit ? "var(--color-green-600)" : "var(--color-yellow-600)";
|
||||
@@ -281,6 +309,42 @@ export default class extends Controller {
|
||||
}
|
||||
}
|
||||
|
||||
if (pendingPledgeAmount > 0 && target) {
|
||||
const willHit = projectionEnd >= targetAmount;
|
||||
const pendingColor = willHit ? "var(--color-green-600)" : "var(--color-yellow-600)";
|
||||
const pendingTop = Math.min(yMax, currentAmount + pendingPledgeAmount);
|
||||
svg
|
||||
.append("line")
|
||||
.attr("x1", x(today))
|
||||
.attr("x2", x(today))
|
||||
.attr("y1", y(currentAmount))
|
||||
.attr("y2", y(pendingTop))
|
||||
.attr("stroke", pendingColor)
|
||||
.attr("stroke-width", 3)
|
||||
.attr("stroke-linecap", "round")
|
||||
.attr("opacity", 0.4);
|
||||
|
||||
svg
|
||||
.append("circle")
|
||||
.attr("cx", x(today))
|
||||
.attr("cy", y(pendingTop))
|
||||
.attr("r", 5)
|
||||
.attr("fill", containerBg)
|
||||
.attr("stroke", pendingColor)
|
||||
.attr("stroke-width", 2)
|
||||
.attr("stroke-dasharray", "2 2");
|
||||
|
||||
if (innerWidth >= 320) {
|
||||
svg
|
||||
.append("text")
|
||||
.attr("x", x(today) + 10)
|
||||
.attr("y", y(pendingTop) + 4)
|
||||
.attr("font-size", 10)
|
||||
.attr("fill", textSecondary)
|
||||
.text(`+ pending ${this._fmtMoneyShort(pendingPledgeAmount, data.currency)}`);
|
||||
}
|
||||
}
|
||||
|
||||
svg
|
||||
.append("line")
|
||||
.attr("x1", x(today))
|
||||
|
||||
Reference in New Issue
Block a user