Update index.min.html

This commit is contained in:
tripathyr 2025-08-20 12:46:16 +05:30 committed by GitHub
parent 7b2dae1b07
commit a7504d6248
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -2500,43 +2500,80 @@
} }
async function checkBalance(address) { async function checkBalance(address) {
try { try {
getRef('address_details_wrapper').classList.remove('hidden') const queriedFloId = address || getRef('search_query_input').value.trim(); // define first
floWebWallet.getLabels().then(allLabels => {
if (allLabels[queriedFloId]) { getRef('address_details_wrapper').classList.remove('hidden');
getRef('queried_flo_address').innerHTML = `<h4>${allLabels[queriedFloId]}</h4> <sm-copy clip-text value=${queriedFloId}></sm-copy>`; getRef('token_list_wrapper').classList.add('hidden');
} else { getRef('token_list').innerHTML = '';
getRef('queried_flo_address').innerHTML = ` getRef('flo_balance').innerHTML = `<sm-spinner></sm-spinner>`;
<p class="label">FLO Address </p>
<h4><sm-copy clip-text value=${queriedFloId}></sm-copy></h4> // Show label (if any)
`; floWebWallet.getLabels().then(allLabels => {
} if (allLabels?.[queriedFloId]) {
}) getRef('queried_flo_address').innerHTML =
const queriedFloId = address || getRef('search_query_input').value.trim() `<h4>${allLabels[queriedFloId]}</h4> <sm-copy clip-text value=${queriedFloId}></sm-copy>`;
getRef('token_list_wrapper').classList.add('hidden') } else {
getRef('flo_balance').innerHTML = `<sm-spinner></sm-spinner>`; getRef('queried_flo_address').innerHTML = `
const [floBalance, tokenBalances] = await Promise.all([ <p class="label">FLO Address</p>
floWebWallet.getBalance(queriedFloId), <h4><sm-copy clip-text value=${queriedFloId}></sm-copy></h4>
fetchJson(`${floGlobals.tokenURL}api/v2/floAddressBalance/${queriedFloId}`).then(({ floAddressBalances }) => floAddressBalances) `;
]) }
let ownedTokens = [] }).catch(() => {
for (const token in tokenBalances) { // non-fatal
ownedTokens.push(html` getRef('queried_flo_address').innerHTML = `
<li class="token-item"> <p class="label">FLO Address</p>
<span>${token}: </span><span>${parseFloat((tokenBalances[token].balance || 0).toFixed(8))}</span> <h4><sm-copy clip-text value=${queriedFloId}></sm-copy></h4>
</li> `;
`) });
}
if (ownedTokens.length) { // Fetch both, but don't let one failure block the other
renderElem(getRef('token_list'), html`${ownedTokens}`) const [floBalRes, tokenRes] = await Promise.allSettled([
getRef('token_list_wrapper').classList.remove('hidden') floWebWallet.getBalance(queriedFloId),
} fetchJson(`${floGlobals.tokenURL}api/v2/floAddressBalance/${queriedFloId}`)
// retrieve FLO balance ]);
getRef('flo_balance').textContent = `${parseFloat(floBalance.toFixed(8))} FLO`;
} catch (e) { // --- FLO coin ---
console.error(e) if (floBalRes.status === 'fulfilled') {
const floBal = Number(floBalRes.value || 0);
getRef('flo_balance').textContent = `${floBal.toFixed(8)} FLO`;
} else {
// show fallback, but don't throw
getRef('flo_balance').textContent = `—`;
} }
// --- FLO-based tokens ---
if (tokenRes.status === 'fulfilled') {
const tokenBalances = tokenRes.value?.floAddressBalances || {};
const ownedTokens = [];
for (const token in tokenBalances) {
const bal = Number(tokenBalances[token]?.balance || 0);
// Only list tokens you want (optionally filter > 0)
ownedTokens.push(html`
<li class="token-item">
<span>${token}: </span><span>${bal.toFixed(8)}</span>
</li>
`);
}
if (ownedTokens.length) {
renderElem(getRef('token_list'), html`${ownedTokens}`);
getRef('token_list_wrapper').classList.remove('hidden');
} else {
getRef('token_list_wrapper').classList.add('hidden');
}
} else {
// token call failed — keep tokens hidden
getRef('token_list_wrapper').classList.add('hidden');
}
} catch (e) {
console.error(e);
// optional: show an error toast / keep current UI as-is
}
} }
function categorizeText(text) { function categorizeText(text) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (text.length == 34 && floCrypto.validateFloID(text)) { if (text.length == 34 && floCrypto.validateFloID(text)) {