[econ] fix currency name

This commit is contained in:
Devin Zuczek
2026-10-03 20:29:47 -04:00
parent 739176a3ed
commit ec423b2eb9
2 changed files with 18 additions and 12 deletions
+12 -8
View File
@@ -59,8 +59,10 @@ export interface RoomPurchasable {
* so `ModifiedAt` is its `CreatedAt`. * so `ModifiedAt` is its `CreatedAt`.
* - A consumable records only `ModifiedAt`, which stands as its `CreatedAt` too. * - A consumable records only `ModifiedAt`, which stands as its `CreatedAt` too.
* - A purchase offer is a pack of the room's currency sold for TOKENS, so its * - A purchase offer is a pack of the room's currency sold for TOKENS, so its
* `PurchaseCurrencyId` is null; it has no description or art of its own, and the one * `PurchaseCurrencyId` is null, and the one timestamp it keeps serves as both. Its `Name`
* timestamp it keeps serves as both. * is `<amount> <currency name>` ("444 Gems"), NOT the stored `Name`: the client names an
* offer by a GUID when it creates one, and that is what the shop showed. It takes the
* currency's description and coin art, having none of its own.
*/ */
export async function getRoomPurchasables( export async function getRoomPurchasables(
db: D1Database, db: D1Database,
@@ -75,6 +77,7 @@ export async function getRoomPurchasables(
db, db,
currencies.map((currency) => currency.CurrencyId) currencies.map((currency) => currency.CurrencyId)
) )
const currencyById = new Map(currencies.map((currency) => [currency.CurrencyId, currency]))
return [ return [
...keys.map((key): RoomPurchasable => ({ ...keys.map((key): RoomPurchasable => ({
@@ -101,19 +104,20 @@ export async function getRoomPurchasables(
CreatedAt: consumable.ModifiedAt, CreatedAt: consumable.ModifiedAt,
ModifiedAt: consumable.ModifiedAt, ModifiedAt: consumable.ModifiedAt,
})), })),
...offers.flatMap((shop) => ...offers.flatMap((shop) => {
shop.PurchaseOffers.map((offer): RoomPurchasable => ({ const currency = currencyById.get(shop.CurrencyId)
return shop.PurchaseOffers.map((offer): RoomPurchasable => ({
ItemType: ROOM_PURCHASABLE_TYPE.roomCurrencyItem, ItemType: ROOM_PURCHASABLE_TYPE.roomCurrencyItem,
ItemId: offer.CurrencyPurchaseOfferId, ItemId: offer.CurrencyPurchaseOfferId,
Name: offer.Name, Name: `${offer.CurrencyAmount} ${currency?.Name ?? ''}`.trim(),
Description: '', Description: currency?.Description ?? '',
ImageName: null, ImageName: currency?.ImageName ?? null,
RoomId: roomId, RoomId: roomId,
Price: offer.Price, Price: offer.Price,
PurchaseCurrencyId: null, PurchaseCurrencyId: null,
CreatedAt: offer.ModifiedAt, CreatedAt: offer.ModifiedAt,
ModifiedAt: offer.ModifiedAt, ModifiedAt: offer.ModifiedAt,
})) }))
), }),
] ]
} }
+6 -4
View File
@@ -2940,13 +2940,14 @@ describe('econ endpoints', () => {
const currency = await createRoomCurrency(env.DB, { const currency = await createRoomCurrency(env.DB, {
RoomId: 93, RoomId: 93,
Name: 'Gems', Name: 'Gems',
Description: '', Description: 'Shiny',
Limit: 100, Limit: 100,
Shape: 0, Shape: 0,
Color: 0, Color: 0,
}) })
// The client names an offer by a GUID — not a label anyone should see.
const offer = await createPurchaseOffer(env.DB, currency.CurrencyId, { const offer = await createPurchaseOffer(env.DB, currency.CurrencyId, {
Name: '100 gems', Name: '5a1c3e4f-0000-4000-8000-000000000093',
CurrencyAmount: 100, CurrencyAmount: 100,
Price: 400, Price: 400,
Order: 0, Order: 0,
@@ -2982,8 +2983,9 @@ describe('econ endpoints', () => {
{ {
ItemType: 3, ItemType: 3,
ItemId: offer.CurrencyPurchaseOfferId, ItemId: offer.CurrencyPurchaseOfferId,
Name: '100 gems', // So a pack is labelled by what it is, and wears the currency's description.
Description: '', Name: '100 Gems',
Description: 'Shiny',
ImageName: null, ImageName: null,
RoomId: 93, RoomId: 93,
Price: 400, Price: 400,