123ishaTest/ludiek

[Currency] Improve CurrencyPlugin to deal better with duplicate currencies

Aperta

#61 aperta il 26 lug 2025

 (2 commenti) (1 reazione) (0 assegnatari)TypeScript (4 fork)auto 404
good first issueplugin

Metriche repository

Star
 (12 stelle)
Metriche merge PR
 (Metriche PR in attesa)

Descrizione

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 }]

Guida contributor