SHA256
Исправить отображение и учёт поддержки сообщений
This commit is contained in:
@@ -3,27 +3,40 @@ import { formatStars } from './shine-support-amount.js';
|
||||
|
||||
// Один запрос на канал; только сервер проверяет привязку транзакции к блоку.
|
||||
const cache = new Map();
|
||||
const pending = new Map();
|
||||
export function loadVerifiedSupportTotals(selector) {
|
||||
const number = Number(selector?.channelRootBlockNumber);
|
||||
const hash = String(selector?.channelRootBlockHash || '').toLowerCase();
|
||||
if (!Number.isSafeInteger(number) || !/^[0-9a-f]{64}$/.test(hash)) return Promise.resolve(null);
|
||||
const key = `${number}:${hash}`;
|
||||
if (!cache.has(key)) {
|
||||
const promise = authService.getSupportTotals({ channelRootBlockNumber: number, channelRootBlockHash: hash })
|
||||
.then((response) => {
|
||||
const messages = new Map();
|
||||
for (const row of response?.messages || []) {
|
||||
const id = `${String(row.blockNumber)}:${String(row.blockHash).toLowerCase()}`;
|
||||
messages.set(id, String(row.receivedStarCents));
|
||||
}
|
||||
return { channelReceivedStarCents: String(response?.channelReceivedStarCents || '0'), messages };
|
||||
})
|
||||
.catch(() => { cache.delete(key); return null; });
|
||||
cache.set(key, promise);
|
||||
}
|
||||
if (pending.has(key)) return pending.get(key);
|
||||
if (!cache.has(key)) return refreshVerifiedSupportTotals(selector);
|
||||
return cache.get(key);
|
||||
}
|
||||
|
||||
export function refreshVerifiedSupportTotals(selector) {
|
||||
const number = Number(selector?.channelRootBlockNumber);
|
||||
const hash = String(selector?.channelRootBlockHash || '').toLowerCase();
|
||||
if (!Number.isSafeInteger(number) || !/^[0-9a-f]{64}$/.test(hash)) return Promise.resolve(null);
|
||||
const key = `${number}:${hash}`;
|
||||
if (pending.has(key)) return pending.get(key);
|
||||
const promise = authService.getSupportTotals({ channelRootBlockNumber: number, channelRootBlockHash: hash })
|
||||
.then((response) => {
|
||||
const messages = new Map();
|
||||
for (const row of response?.messages || []) {
|
||||
const id = `${String(row.blockNumber)}:${String(row.blockHash).toLowerCase()}`;
|
||||
messages.set(id, String(row.receivedStarCents));
|
||||
}
|
||||
const totals = { channelReceivedStarCents: String(response?.channelReceivedStarCents || '0'), messages };
|
||||
cache.set(key, totals);
|
||||
return totals;
|
||||
})
|
||||
.catch(() => null)
|
||||
.finally(() => pending.delete(key));
|
||||
pending.set(key, promise);
|
||||
return promise;
|
||||
}
|
||||
|
||||
export function formatVerifiedSupportStars(value) {
|
||||
try {
|
||||
const n = BigInt(value);
|
||||
|
||||
Reference in New Issue
Block a user