Show marketplace 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.
This commit is contained in:
1 parent
8b63cb5211
commit
1b86da28d2
3 files changed
+38
-5
No files matched your search
@@ -12,6 +12,7 @@ const T = {
|
||||
allCountries: '全部国家', allClasses: '全部', rank: '{rank} 级', from: '从', held: '库存 ×{n}', owned: '已拥有',
|
||||
buy: '购买', freeBuy: '老福爷付过了', sell: '出售', pickAccount: '请先在右上角选择账号', empty: '没有符合条件的物品',
|
||||
buyPrice: '系统售价:<b>{price}</b> GJN', sellPrice: '卖给系统:<b>{price}</b> GJN(扣 {fee}% 手续费)', youHave: '你拥有:<b>{n}</b>',
|
||||
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: <b>{price}</b> GJN', sellPrice: 'Sell to system: <b>{price}</b> GJN ({fee}% fee)', youHave: 'You own: <b>{n}</b>',
|
||||
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);
|
||||
|
||||
@@ -36,7 +36,6 @@
|
||||
</div>
|
||||
</aside>
|
||||
<main class="screen">
|
||||
<div id="notice" class="notice"></div>
|
||||
<div class="controls">
|
||||
<div class="search"><input id="searchInput" type="search" /></div>
|
||||
<select id="sortSelect" class="control">
|
||||
@@ -52,6 +51,7 @@
|
||||
<div class="modal" id="modal" hidden>
|
||||
<div class="card-detail" id="detail"></div>
|
||||
</div>
|
||||
<div id="notice" class="notice" role="status"></div>
|
||||
<script src="/_wto/ui/common.js"></script>
|
||||
<script src="/trade.gaijin.net/app.js"></script>
|
||||
</body>
|
||||
|
||||
@@ -57,8 +57,18 @@ body { background: var(--bg); color: var(--text); font: 14px/18px var(--font); m
|
||||
.lot-price small { color: #2dd4aa; font-size: 12px; font-weight: 400; margin-right: 4px; }
|
||||
.empty { color: var(--muted); padding: 40px 0; }
|
||||
|
||||
.notice { display: none; margin-bottom: 12px; padding: 10px 14px; border-radius: 8px; background: var(--surface); }
|
||||
.notice.ok { display: block; color: #2dd4aa; } .notice.err { display: block; color: #ff6b73; }
|
||||
.notice {
|
||||
position: fixed;
|
||||
z-index: 1001;
|
||||
top: 16px;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
max-width: calc(100% - 32px);
|
||||
pointer-events: none;
|
||||
}
|
||||
.notice.ok, .notice.err { padding: 10px 14px; border-radius: 8px; background: var(--surface); }
|
||||
.notice.ok { color: #2dd4aa; }
|
||||
.notice.err { color: #ff6b73; }
|
||||
|
||||
.modal { position: fixed; inset: 0; z-index: 1000; display: flex; justify-content: center; align-items: flex-start; overflow-y: auto; background: #0b0f16db; }
|
||||
.card-detail { position: relative; width: 960px; margin: 45px auto; border-radius: 5px; background: var(--surface); box-shadow: 0 24px 32px #00000061; overflow: hidden; }
|
||||
|
||||
Reference in new issue
Block a user