From 854262186bd9a06e041b7e4ec518b81887be4c1c Mon Sep 17 00:00:00 2001 From: zhx Date: Mon, 15 Jun 2026 01:28:53 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BD=AC=E8=B4=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/api.js | 9 ++ gonghui/withdraw-exchange/index.html | 10 --- gonghui/withdraw-exchange/script.js | 124 +++++++++++++++++++++++---- gonghui/withdraw-exchange/style.css | 4 - 4 files changed, 114 insertions(+), 33 deletions(-) diff --git a/common/api.js b/common/api.js index b5b3afd..164a3d6 100644 --- a/common/api.js +++ b/common/api.js @@ -398,6 +398,15 @@ var default_api = 'https://api.global-interaction.com/'; query: { identity: identity }, }); }, + history: function (identity, limit) { + return request('/api/v1/salary-wallet/history', { + method: 'GET', + query: { + identity: identity, + page_size: limit || 30, + }, + }); + }, searchCoinSeller: function (displayUserID, identity) { return request('/api/v1/salary-wallet/coin-sellers/search', { method: 'GET', diff --git a/gonghui/withdraw-exchange/index.html b/gonghui/withdraw-exchange/index.html index d3d295e..a265ce4 100644 --- a/gonghui/withdraw-exchange/index.html +++ b/gonghui/withdraw-exchange/index.html @@ -224,16 +224,6 @@ /> - diff --git a/gonghui/withdraw-exchange/script.js b/gonghui/withdraw-exchange/script.js index d0a2b7f..d4b53ee 100644 --- a/gonghui/withdraw-exchange/script.js +++ b/gonghui/withdraw-exchange/script.js @@ -106,6 +106,7 @@ function normalizeIdentity(value) { value = String(value || '').trim().toUpperCase().replace(/-/g, '_'); + if (value === 'ADMIN') return 'BD_LEADER'; if (['HOST', 'AGENCY', 'BD', 'BD_LEADER'].indexOf(value) >= 0) return value; if (salaryAssetType === 'AGENCY_SALARY_USD') return 'AGENCY'; @@ -163,12 +164,6 @@ }); } - function estimatedTransferCoins(value) { - var rate = findTransferRate(value); - if (!rate) return 0; - return Math.round(Number(value || 0) * Number(rate.coin_per_usd || 0)); - } - function delay(value) { return new Promise(function (resolve) { window.setTimeout(function () { @@ -241,6 +236,103 @@ return 'Host salary'; } + function firstValue(source, keys) { + if (!source) return ''; + for (var i = 0; i < keys.length; i += 1) { + var value = source[keys[i]]; + if (value !== undefined && value !== null && value !== '') + return value; + } + return ''; + } + + function timeLabelFromMS(value) { + var number = Number(value || 0); + if (!Number.isFinite(number) || number <= 0) return ''; + var date = new Date(number); + if (Number.isNaN(date.getTime())) return ''; + return ( + date.getFullYear() + + '-' + + String(date.getMonth() + 1).padStart(2, '0') + + '-' + + String(date.getDate()).padStart(2, '0') + + ' ' + + String(date.getHours()).padStart(2, '0') + + ':' + + String(date.getMinutes()).padStart(2, '0') + ); + } + + function historyLabelForBizType(bizType, delta) { + if (bizType === 'salary_exchange_to_coin') { + return { + key: 'withdraw_exchange.history_exchange_to_golds', + title: 'Exchange to golds', + }; + } + if (bizType === 'salary_transfer_to_coin_seller') { + return { + key: 'withdraw_exchange.transfer', + title: 'Transfer', + }; + } + if (bizType === 'host_salary_settlement' || delta >= 0) { + return { + key: historyTitleKey(), + title: historyTitle(), + }; + } + return { + key: 'withdraw_exchange.withdraw', + title: 'Withdraw', + }; + } + + function normalizeHistoryItem(item, index) { + var delta = Number( + firstValue(item, ['available_delta', 'availableDelta']) + ); + if (!Number.isFinite(delta)) delta = 0; + var balance = Number( + firstValue(item, ['available_after', 'availableAfter']) + ); + if (!Number.isFinite(balance)) balance = 0; + var label = historyLabelForBizType( + String(firstValue(item, ['biz_type', 'bizType']) || ''), + delta + ); + return { + id: + firstValue(item, ['transaction_id', 'transactionId']) || + String(firstValue(item, ['entry_id', 'entryId']) || index), + key: label.key, + title: label.title, + amount: Math.abs(usdMinorToNumber(delta)), + balance: usdMinorToNumber(balance), + type: delta < 0 ? 1 : 0, + date: timeLabelFromMS(firstValue(item, ['created_at_ms', 'createdAtMs'])), + }; + } + + function normalizeHistoryItems(payload) { + var source = payload || {}; + if (source.identity) identity = normalizeIdentity(source.identity); + if (source.salary_asset_type) { + salaryAssetType = source.salary_asset_type; + } + var items = Array.isArray(source.items) + ? source.items + : Array.isArray(source.transactions) + ? source.transactions + : Array.isArray(source) + ? source + : []; + return items.map(function (item, index) { + return normalizeHistoryItem(item || {}, index); + }); + } + function isValidTrc20(value) { return /^T[1-9A-HJ-NP-Za-km-z]{33}$/.test(String(value || '').trim()); } @@ -337,17 +429,6 @@ updateSubmit(); } - function renderTransferPreview() { - var preview = $('transferPreview'); - if (!preview) return; - var value = inputs.transfer ? Number(inputs.transfer.value || 0) : 0; - var coins = estimatedTransferCoins(value); - preview.hidden = !(currentMode === 'transfer' && value > 0 && coins > 0); - if (!preview.hidden) { - $('transferPreviewText').textContent = coins.toLocaleString('en-US'); - } - } - function renderHistory() { $('salaryHistoryTotal').textContent = '$' + money(state.balance); var list = $('salaryHistoryList'); @@ -415,7 +496,6 @@ (!state.selectedPayee || transferRateMissing)); button.textContent = activeSubmitLabel(); button.disabled = disabled; - renderTransferPreview(); } function normalizeAmount(event) { @@ -445,10 +525,16 @@ ); var historyRequest = isMock ? mockRequest('history') - : Promise.resolve([]); + : api() && api().history + ? api().history(identity, 30).then(normalizeHistoryItems) + : Promise.resolve([]); historyRequest.then(function (items) { state.historyItems = items || []; renderHistory(); + }).catch(function (err) { + state.historyItems = []; + renderHistory(); + toast(err && err.message ? err.message : t('withdraw_exchange.load_failed', 'Load failed. Try again later.')); }); } diff --git a/gonghui/withdraw-exchange/style.css b/gonghui/withdraw-exchange/style.css index 9c589a9..b20a007 100644 --- a/gonghui/withdraw-exchange/style.css +++ b/gonghui/withdraw-exchange/style.css @@ -402,10 +402,6 @@ input { font-weight: 950; } -.transfer-preview { - margin-top: 12px; -} - .search-payee-button:disabled { background: var(--button-disabled); color: var(--button-disabled-text);