From 0678c3bf2713ea172728f5f62d39fee14cbdb3f7 Mon Sep 17 00:00:00 2001 From: N0VAN0M4LY <224130499+N0VAN0M4LY@users.noreply.github.com> Date: Thu, 26 Nov 2026 09:59:06 +0800 Subject: [PATCH] fix(marketplace): show trade results above item details Place the existing transaction notice above the item dialog and report unconfirmed results when a request fails or returns invalid data. Prevent older responses from overwriting the latest notice. Verified JavaScript syntax. --- .../local-service/src/inventory/web/app.js | 27 +++++++++++++++++-- .../src/inventory/web/index.html | 2 +- .../src/inventory/web/styles.css | 14 ++++++++-- 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/packages/local-service/src/inventory/web/app.js b/packages/local-service/src/inventory/web/app.js index 918edc1..4ad47c0 100644 --- a/packages/local-service/src/inventory/web/app.js +++ b/packages/local-service/src/inventory/web/app.js @@ -12,6 +12,7 @@ const T = { allCountries: '全部国家', allClasses: '全部', rank: '{rank} 级', from: '从', held: '库存 ×{n}', owned: '已拥有', buy: '购买', freeBuy: '老福爷付过了', sell: '出售', pickAccount: '请先在右上角选择账号', empty: '没有符合条件的物品', buyPrice: '系统售价:{price} GJN', sellPrice: '卖给系统:{price} GJN(扣 {fee}% 手续费)', youHave: '你拥有:{n}', + tradeUnconfirmed: '无法确认交易结果,请先查看余额和库存。', tagType: '物品类型', tagRarity: '稀有度', tagCountry: '国家', ticker: '离线交易所:按固定价格与系统交易,价格取自官方交易所快照。', }, en: { @@ -21,6 +22,7 @@ const T = { allCountries: 'All countries', allClasses: 'All', rank: 'Rank {rank}', from: 'from', held: 'Owned ×{n}', owned: 'Owned', buy: 'Buy', freeBuy: '老福爷付过了', sell: 'Sell', pickAccount: 'Pick an account at the top right', empty: 'Nothing matches the filters', buyPrice: 'System price: {price} GJN', sellPrice: 'Sell to system: {price} GJN ({fee}% fee)', youHave: 'You own: {n}', + tradeUnconfirmed: 'Could not confirm the trade. Check your balance and inventory.', tagType: 'Item type', tagRarity: 'Rarity', tagCountry: 'Country', ticker: 'Offline market: fixed-price trades with the system, prices from an official market snapshot.', }, }; @@ -35,6 +37,7 @@ const wantedItem = WtoUi.query.get('n') || ''; let state = { accounts: [], currentUserId: '', balance: { gjnCents: 0, goldenEagles: 0 }, sellFeeRate: 0.15, listings: [] }; const activeCats = new Set(); let openedWanted = false; +let tradeNoticeId = 0; function applyStaticTexts() { for (const el of document.querySelectorAll('[data-t]')) el.textContent = t(el.dataset.t); @@ -186,8 +189,28 @@ function html(className, markup) { function closeDetail() { $('modal').hidden = true; } async function trade(url, body, listing) { - const result = await WtoUi.postJson(url, { userId: state.currentUserId, ...body }); - WtoUi.showNotice($('notice'), WtoUi.text(result.message), result.ok); + const notice = $('notice'); + const noticeId = ++tradeNoticeId; + notice.textContent = ''; + notice.className = 'notice'; + + const showResult = (message, ok) => { + if (noticeId === tradeNoticeId) WtoUi.showNotice(notice, message, ok); + }; + + let result; + try { + result = await WtoUi.postJson(url, { userId: state.currentUserId, ...body }); + } catch { + showResult(t('tradeUnconfirmed'), false); + return; + } + const message = WtoUi.text(result?.message); + if (typeof result?.ok !== 'boolean' || !message) { + showResult(t('tradeUnconfirmed'), false); + return; + } + showResult(message, result.ok); await loadState(state.currentUserId); const fresh = state.listings.find((l) => l.itemdefId === listing.itemdefId); if (fresh && !$('modal').hidden) openDetail(fresh); diff --git a/packages/local-service/src/inventory/web/index.html b/packages/local-service/src/inventory/web/index.html index c3fe3f9..0b18e81 100644 --- a/packages/local-service/src/inventory/web/index.html +++ b/packages/local-service/src/inventory/web/index.html @@ -36,7 +36,6 @@
-