diff --git a/static/js/index.js b/static/js/index.js index 1f6ccb9..3905bf3 100644 --- a/static/js/index.js +++ b/static/js/index.js @@ -1645,6 +1645,31 @@ window.app = Vue.createApp({ isIncomeEntry(entry) { return Array.isArray(entry.tags) && entry.tags.includes('income-entry') }, + // Per-currency split for multi-currency balances. Sign convention from the + // super-user perspective: positive fiat = user owes Libra (Receivable), + // negative fiat = Libra owes user (Payable). Distinct currencies can't be + // netted across each other (no spot rate), so we render them grouped by + // direction instead of one collapsed label. + owesYouFiat(fiatBalances) { + if (!fiatBalances) return {} + return Object.fromEntries( + Object.entries(fiatBalances).filter(([_, amount]) => Number(amount) > 0.005) + ) + }, + youOweFiat(fiatBalances) { + if (!fiatBalances) return {} + return Object.fromEntries( + Object.entries(fiatBalances) + .filter(([_, amount]) => Number(amount) < -0.005) + .map(([cur, amount]) => [cur, Math.abs(Number(amount))]) + ) + }, + hasOwesYouFiat(fiatBalances) { + return Object.keys(this.owesYouFiat(fiatBalances)).length > 0 + }, + hasYouOweFiat(fiatBalances) { + return Object.keys(this.youOweFiat(fiatBalances)).length > 0 + }, formatFiat(amount, currency) { return new Intl.NumberFormat('en-US', { style: 'currency', diff --git a/templates/libra/index.html b/templates/libra/index.html index 04e7688..01de17a 100644 --- a/templates/libra/index.html +++ b/templates/libra/index.html @@ -187,16 +187,27 @@