123ishaTest/ludiek
[Currency] Improve CurrencyPlugin to deal better with duplicate currencies
开放
#61 创建于 2025年7月26日
good first issueplugin
仓库指标
- 星标
- (12 个星标)
- PR 合并指标
- (30 天内没有已合并 PR)
描述
The CurrencyPlugin provides helper method that deal with lists of currencies. However this could lead to the following odd scenario
const currency = new CurrencyPlugin([{ id: 'money' }]);
currency.gainCurrency({ id: 'money', amount: 1 });
const isPaid = currency.payCurrencies([
{ id: 'money', amount: 1 },
{ id: 'money', amount: 1 },
]);
console.log(isPaid); // true
console.log(currency.getBalance('money')); // -1
We could merge these lists together with a new simplifyCurrencyList function before checking, so it becomes
[{ id: 'money', amount: 2 }]