From ec423b2eb960d2cacdf07e39017899664111e332 Mon Sep 17 00:00:00 2001 From: Devin Zuczek Date: Sat, 3 Oct 2026 20:29:47 -0400 Subject: [PATCH] [econ] fix currency name --- apps/econ/src/room-purchasables-db.ts | 20 ++++++++++++-------- apps/econ/src/test/integration/api.test.ts | 10 ++++++---- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/apps/econ/src/room-purchasables-db.ts b/apps/econ/src/room-purchasables-db.ts index 47c4c49..259891a 100644 --- a/apps/econ/src/room-purchasables-db.ts +++ b/apps/econ/src/room-purchasables-db.ts @@ -59,8 +59,10 @@ export interface RoomPurchasable { * so `ModifiedAt` is its `CreatedAt`. * - 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 - * `PurchaseCurrencyId` is null; it has no description or art of its own, and the one - * timestamp it keeps serves as both. + * `PurchaseCurrencyId` is null, and the one timestamp it keeps serves as both. Its `Name` + * is ` ` ("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( db: D1Database, @@ -75,6 +77,7 @@ export async function getRoomPurchasables( db, currencies.map((currency) => currency.CurrencyId) ) + const currencyById = new Map(currencies.map((currency) => [currency.CurrencyId, currency])) return [ ...keys.map((key): RoomPurchasable => ({ @@ -101,19 +104,20 @@ export async function getRoomPurchasables( CreatedAt: consumable.ModifiedAt, ModifiedAt: consumable.ModifiedAt, })), - ...offers.flatMap((shop) => - shop.PurchaseOffers.map((offer): RoomPurchasable => ({ + ...offers.flatMap((shop) => { + const currency = currencyById.get(shop.CurrencyId) + return shop.PurchaseOffers.map((offer): RoomPurchasable => ({ ItemType: ROOM_PURCHASABLE_TYPE.roomCurrencyItem, ItemId: offer.CurrencyPurchaseOfferId, - Name: offer.Name, - Description: '', - ImageName: null, + Name: `${offer.CurrencyAmount} ${currency?.Name ?? ''}`.trim(), + Description: currency?.Description ?? '', + ImageName: currency?.ImageName ?? null, RoomId: roomId, Price: offer.Price, PurchaseCurrencyId: null, CreatedAt: offer.ModifiedAt, ModifiedAt: offer.ModifiedAt, })) - ), + }), ] } diff --git a/apps/econ/src/test/integration/api.test.ts b/apps/econ/src/test/integration/api.test.ts index c38abdf..c9164d1 100644 --- a/apps/econ/src/test/integration/api.test.ts +++ b/apps/econ/src/test/integration/api.test.ts @@ -2940,13 +2940,14 @@ describe('econ endpoints', () => { const currency = await createRoomCurrency(env.DB, { RoomId: 93, Name: 'Gems', - Description: '', + Description: 'Shiny', Limit: 100, Shape: 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, { - Name: '100 gems', + Name: '5a1c3e4f-0000-4000-8000-000000000093', CurrencyAmount: 100, Price: 400, Order: 0, @@ -2982,8 +2983,9 @@ describe('econ endpoints', () => { { ItemType: 3, ItemId: offer.CurrencyPurchaseOfferId, - Name: '100 gems', - Description: '', + // So a pack is labelled by what it is, and wears the currency's description. + Name: '100 Gems', + Description: 'Shiny', ImageName: null, RoomId: 93, Price: 400,