-
-
Notifications
You must be signed in to change notification settings - Fork 0
feat(split-meow): 搶救每筆支出幣別與匯率快照 #445
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+103
−15
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@app/split-meow': patch | ||
| --- | ||
|
|
||
| 每筆支出記錄記帳當下的幣別與匯率,切換顯示幣別後歷史金額不再被錯誤換算;以韓元(₩)記帳的支出會同時顯示對應的台幣參考金額。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| import { useTranslation } from 'react-i18next'; | ||
| import { useStore, type Member, type ExpenseRecord } from '../store/useStore'; | ||
| import { formatAmount, getCurrencySymbol } from '../config/currencies'; | ||
| import { formatAmount, getCurrencySymbol, formatKrwAsTwd } from '../config/currencies'; | ||
| import type { CurrencyCode } from '../config/currencies'; | ||
| import { format } from 'date-fns'; | ||
| import { useRef, useState } from 'react'; | ||
| import { cn } from '../lib/utils'; | ||
|
|
@@ -177,6 +178,12 @@ export function HistoryTab() { | |
| }); | ||
| const totalSpent = tripExpenses.reduce((sum, e) => sum + e.totalAmount, 0); | ||
|
|
||
| // trip 主導幣別:採用該行程最舊一筆記錄的幣別(trip 建立時的幣別), | ||
| // 舊資料無幣別時 fallback 至當前全域幣別。彙總與結算統一以此幣別顯示。 | ||
| const tripCurrency: CurrencyCode = tripExpenses[tripExpenses.length - 1]?.currency ?? currency; | ||
| // 取得單筆記錄的顯示幣別(優先使用記帳當下快照,舊資料 fallback 主導幣別)。 | ||
| const expenseCurrency = (exp: ExpenseRecord): CurrencyCode => exp.currency ?? tripCurrency; | ||
|
|
||
| // 計算各人餘額 | ||
| const balances: Record<string, number> = {}; | ||
| tripExpenses.forEach((exp) => { | ||
|
|
@@ -215,7 +222,7 @@ export function HistoryTab() { | |
| const lines: string[] = [ | ||
| `🐾 喵喵分帳 — ${tripName}`, | ||
| `${'─'.repeat(24)}`, | ||
| `💰 總花費:${formatAmount(totalSpent, currency)}`, | ||
| `💰 總花費:${formatAmount(totalSpent, tripCurrency)}`, | ||
| '', | ||
| ]; | ||
| if (tripExpenses.length > 0) { | ||
|
|
@@ -226,7 +233,9 @@ export function HistoryTab() { | |
| const label = | ||
| exp.note || | ||
| (exp.type === 'split_evenly' ? t('history.split_evenly') : t('history.itemized')); | ||
| lines.push(`${emoji} ${label} ${formatAmount(exp.totalAmount, currency)}(${payer} 付)`); | ||
| lines.push( | ||
| `${emoji} ${label} ${formatAmount(exp.totalAmount, expenseCurrency(exp))}(${payer} 付)`, | ||
| ); | ||
| }); | ||
| lines.push(''); | ||
| } | ||
|
|
@@ -235,7 +244,7 @@ export function HistoryTab() { | |
| settlements.forEach((s) => { | ||
| const from = members.find((m) => m.id === s.from)?.name ?? s.from; | ||
| const to = members.find((m) => m.id === s.to)?.name ?? s.to; | ||
| lines.push(`${from} → ${to} ${formatAmount(s.amount, currency)}`); | ||
| lines.push(`${from} → ${to} ${formatAmount(s.amount, tripCurrency)}`); | ||
| }); | ||
| lines.push(''); | ||
| } | ||
|
|
@@ -273,7 +282,7 @@ export function HistoryTab() { | |
| {t('history.total_spent')} | ||
| </span> | ||
| <h2 className="text-4xl font-medium text-on-surface tracking-tight"> | ||
| {formatAmount(totalSpent, currency)} | ||
| {formatAmount(totalSpent, tripCurrency)} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| </h2> | ||
| </div> | ||
| <div className="mt-6 flex items-center justify-between gap-2"> | ||
|
|
@@ -376,7 +385,7 @@ export function HistoryTab() { | |
| check_circle | ||
| </span> | ||
| ) : ( | ||
| formatAmount(s.amount, currency) | ||
| formatAmount(s.amount, tripCurrency) | ||
| )} | ||
| </span> | ||
| </div> | ||
|
|
@@ -451,7 +460,7 @@ export function HistoryTab() { | |
| )} | ||
| > | ||
| {isOwed ? '+' : '-'} | ||
| {formatAmount(Math.abs(amount), currency)} | ||
| {formatAmount(Math.abs(amount), tripCurrency)} | ||
| </span> | ||
| <span | ||
| className="material-symbols-outlined text-on-surface-variant text-lg transition-transform duration-300" | ||
|
|
@@ -513,7 +522,7 @@ export function HistoryTab() { | |
| {t('history.balance_paid')} | ||
| </span> | ||
| <span className="font-semibold text-secondary"> | ||
| +{formatAmount(exp.totalAmount, currency)} | ||
| +{formatAmount(exp.totalAmount, expenseCurrency(exp))} | ||
| </span> | ||
| </div> | ||
| )} | ||
|
|
@@ -528,7 +537,7 @@ export function HistoryTab() { | |
| {t('history.balance_share')} | ||
| </span> | ||
| <span className="font-semibold text-error"> | ||
| -{formatAmount(share, currency)} | ||
| -{formatAmount(share, expenseCurrency(exp))} | ||
| </span> | ||
| </div> | ||
| )} | ||
|
|
@@ -549,7 +558,7 @@ export function HistoryTab() { | |
| )} | ||
| > | ||
| {net > 0.01 ? '+' : net < -0.01 ? '-' : ''} | ||
| {formatAmount(Math.abs(net), currency)} | ||
| {formatAmount(Math.abs(net), expenseCurrency(exp))} | ||
| </span> | ||
| </div> | ||
| </div> | ||
|
|
@@ -568,7 +577,7 @@ export function HistoryTab() { | |
| )} | ||
| > | ||
| {isOwed ? '+' : '-'} | ||
| {formatAmount(Math.abs(amount), currency)} | ||
| {formatAmount(Math.abs(amount), tripCurrency)} | ||
| </span> | ||
| </div> | ||
| </div> | ||
|
|
@@ -708,8 +717,14 @@ export function HistoryTab() { | |
| <div className="text-right flex items-center gap-2 sm:gap-3 shrink-0"> | ||
| <div className="shrink-0"> | ||
| <p className="font-bold text-on-surface whitespace-nowrap text-base sm:text-lg"> | ||
| {formatAmount(exp.totalAmount, currency)} | ||
| {formatAmount(exp.totalAmount, expenseCurrency(exp))} | ||
| </p> | ||
| {expenseCurrency(exp) === 'KRW' && | ||
| formatKrwAsTwd(exp.totalAmount, exp.exchangeRateKrwPerTwd) && ( | ||
| <p className="text-[10px] font-medium text-on-surface-variant/70 whitespace-nowrap"> | ||
| ≈ {formatKrwAsTwd(exp.totalAmount, exp.exchangeRateKrwPerTwd)} | ||
| </p> | ||
| )} | ||
| <p className="text-[10px] font-medium text-secondary uppercase tracking-wider"> | ||
| {t('history.participants', { count: exp.participantIds.length })} | ||
| </p> | ||
|
|
@@ -830,7 +845,7 @@ export function HistoryTab() { | |
| <span className="font-medium text-on-surface">{m.name}</span> | ||
| </div> | ||
| <span className="font-semibold text-on-surface"> | ||
| {formatAmount(amt, currency)} | ||
| {formatAmount(amt, expenseCurrency(exp))} | ||
| </span> | ||
| </div> | ||
| ); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
這裡把沒有
currency快照的舊資料回退到目前全域currency,因此既有使用者升級後只要在設定切到 KRW,升級前以 TWD 記下的費用仍會被顯示/分享為 ₩,與ExpenseRecord註解「舊資料缺此欄位時視為 TWD」相反,也沒有真正修復這次要救回的舊 TWD→切 KRW 場景。請將 legacy fallback 固定為 TWD(或在 persist migrate 補上 TWD 快照)。Useful? React with 👍 / 👎.