*/ (function () { "use strict"; // ─── State ─────────────────────────────────────────────────────────────── let ratesData = null; let balance = 25000; const QUICK_AMOUNTS = [5000, 10000, 25000, 50000, 100000, 250000]; // ─── DOM refs (populated after render) ─────────────────────────────────── let balanceInput, quickBtns, rateRows, deltaAmount, deltaLabel, updatedEl; // ─── Data loading ───────────────────────────────────────────────────────── async function loadRates() { if (window.MBR_RATES) return window.MBR_RATES; const container = document.getElementById("mbr-snapshot"); const url = (container && container.dataset.ratesUrl) || window.MBR_RATES_URL || "rates.json"; const resp = await fetch(url); if (!resp.ok) throw new Error(`HTTP ${resp.status} fetching ${url}`); return resp.json(); } // ─── Calculation ───────────────────────────────────────────────────────── function annualEarnings(rate, bal) { return (rate / 100) * bal; } function fmt(n) { if (n < 1) return "$" + n.toFixed(2); return "$" + Math.round(n).toLocaleString("en-CA"); } function fmtRate(r) { if (r < 0.1) return r.toFixed(3) + "%"; return r.toFixed(2) + "%"; } // ─── Build display products from rates.json ─────────────────────────────── function getDisplayRows(data) { const inertia = data.inertia_baseline; // Only use non-reference_only products for recommendations const products = (data.products || []).filter((p) => !p.reference_only); // Best HISA / chequable const bestHisa = products.find( (p) => p.category === "hisa" || p.category === "chequable" ); // Best 1-year GIC const best1yr = products.find( (p) => p.category === "gic_term" && p.name.toLowerCase().includes("1-year") ); // Best multi-year GIC (highest rate among 3yr+) const bestLong = products .filter((p) => p.category === "gic_term") .sort((a, b) => (b.rate || 0) - (a.rate || 0))[0]; const rows = []; // Inertia baseline always first (shown in red) — Big 6 standard savings rate if (inertia) { rows.push({ type: "inertia", rate: inertia.rate, name: inertia.product_name, institution: inertia.institution, apply_url: null, label: "Typical Big 6 bank rate", }); } // Best HISA if (bestHisa) { rows.push({ type: "best", rate: bestHisa.rate, name: bestHisa.name, institution: bestHisa.institution, apply_url: bestHisa.apply_url, label: "Best savings account (liquid)", }); } // Best 1yr GIC (if different from bestLong) if (best1yr && best1yr !== bestLong) { rows.push({ type: "alt", rate: best1yr.rate, name: best1yr.name, institution: best1yr.institution, apply_url: best1yr.apply_url, label: "1-Year GIC", }); } // Best long GIC if (bestLong) { rows.push({ type: bestLong === bestHisa ? "best" : "alt", rate: bestLong.rate, name: bestLong.name, institution: bestLong.institution, apply_url: bestLong.apply_url, label: "Best GIC (locked)", }); } return rows; } // ─── Render ─────────────────────────────────────────────────────────────── function renderWidget(data) { ratesData = data; const rows = getDisplayRows(data); const inertiaRow = rows.find((r) => r.type === "inertia"); const bestRow = rows.find((r) => r.type === "best"); const container = document.getElementById("mbr-snapshot"); container.innerHTML = `
Your Better Rate Snapshot
See how much more your savings could earn — instantly.
Your savings balance
$
${QUICK_AMOUNTS.map( (a) => `
$${a >= 1000 ? (a / 1000) + "k" : a}
` ).join("")}
Rate comparison
${rows .map( (r) => `
${fmtRate(r.rate)}
${r.name}
${r.institution} · ${r.label}
${fmt(annualEarnings(r.rate, balance))}/yr
` ) .join("")}
${ inertiaRow && bestRow ? `
💡
${fmt( annualEarnings(bestRow.rate, balance) - annualEarnings(inertiaRow.rate, balance) )}/yr
more with ${bestRow.institution} vs. ${inertiaRow.institution} on ${fmt(balance)}
` : "" }
See My Full Rate Report →
Free · No credit check · No obligation
`; // Attach events balanceInput = document.getElementById("balance-input"); balanceInput.addEventListener("input", onBalanceChange); document.querySelectorAll(".quick-btn").forEach((btn) => { btn.addEventListener("click", () => { balance = parseInt(btn.dataset.amount, 10); balanceInput.value = balance; updateNumbers(); document.querySelectorAll(".quick-btn").forEach((b) => b.classList.toggle("active", parseInt(b.dataset.amount, 10) === balance) ); }); }); } function onBalanceChange() { const val = parseFloat(balanceInput.value.replace(/[^0-9.]/g, "")); balance = isNaN(val) ? 0 : val; updateNumbers(); document.querySelectorAll(".quick-btn").forEach((b) => b.classList.toggle("active", parseInt(b.dataset.amount, 10) === balance) ); } function updateNumbers() { const rows = getDisplayRows(ratesData); const inertiaRow = rows.find((r) => r.type === "inertia"); const bestRow = rows.find((r) => r.type === "best"); document.querySelectorAll(".annual-earn[data-rate]").forEach((el) => { const rate = parseFloat(el.dataset.rate); el.textContent = fmt(annualEarnings(rate, balance)) + "/yr"; }); const deltaEl = document.getElementById("delta-amount"); const deltaLblEl = document.getElementById("delta-label"); if (deltaEl && inertiaRow && bestRow) { const delta = annualEarnings(bestRow.rate, balance) - annualEarnings(inertiaRow.rate, balance); deltaEl.textContent = fmt(delta) + "/yr"; deltaLblEl.textContent = `more with ${bestRow.institution} vs. ${inertiaRow.institution} on ${fmt(balance)}`; } } // ─── Error / loading UI ─────────────────────────────────────────────────── function showLoading() { document.getElementById("mbr-snapshot").innerHTML = '
Loading rates…
'; } function showError(msg) { document.getElementById("mbr-snapshot").innerHTML = `
⚠ ${msg}
`; } // ─── Init ───────────────────────────────────────────────────────────────── async function init() { // Ensure container exists if (!document.getElementById("mbr-snapshot")) { const div = document.createElement("div"); div.id = "mbr-snapshot"; document.body.appendChild(div); } showLoading(); try { const data = await loadRates(); renderWidget(data); } catch (e) { showError("Could not load rate data. " + e.message); } } if (document.readyState === "loading") { document.addEventListener("DOMContentLoaded", init); } else { init(); } })();