Files
firewalletbrowser/templates/assets/js/script.min.js
Nathan Woodburn 5f46f1e3bf
All checks were successful
Build Docker / Build Images (map[dockerfile:Dockerfile.hsd tag_suffix:-hsd target:hsd]) (push) Successful in 3m0s
Build Docker / Build Images (map[dockerfile:Dockerfile tag_suffix: target:default]) (push) Successful in 3m1s
Tests and Linting / Tests-Linting (3.11) (push) Successful in 3m10s
Tests and Linting / Tests-Linting (3.13) (push) Successful in 3m15s
Tests and Linting / Tests-Linting (3.10) (push) Successful in 3m20s
fix: Try to sort unknown domains together
2025-09-24 12:04:06 +10:00

1 line
5.6 KiB
JavaScript

async function request(e){try{const t=await fetch(`/api/v1/${e}`);if(!t.ok)throw new Error(`HTTP error! Status: ${t.status}`);const n=await t.json();return void 0!==n.error?`Error: ${n.error}`:n.result}catch(e){return console.error("Request failed:",e),"Error"}}function sortTable(e,t=!1){const n=document.getElementById("data-table"),l=n.querySelector("tbody"),a=Array.from(l.querySelectorAll("tr")),o=n.querySelectorAll("th");let r=n.getAttribute("data-sort-order")||"asc",i=n.getAttribute("data-sort-column")||"-1";r=t||i!=e?"asc":"asc"===r?"desc":"asc",n.setAttribute("data-sort-order",r),n.setAttribute("data-sort-column",e);const d=determineColumnDataType(a,e);a.sort(((t,n)=>{let l=t.cells[e].innerText.trim(),a=n.cells[e].innerText.trim();if("number"===d){let e=parseFloat(l.replace(/[^0-9.,]/g,"").replace(/,/g,"")),t=parseFloat(a.replace(/[^0-9.,]/g,"").replace(/,/g,""));const n=isNaN(e),o=isNaN(t);return n&&!o?"asc"===r?-1:1:!n&&o?"asc"===r?1:-1:n&&o?0:"asc"===r?e-t:t-e}if("date"===d){let e=new Date(l),t=new Date(a);return"asc"===r?e-t:t-e}return"asc"===r?l.localeCompare(a,void 0,{sensitivity:"base"}):a.localeCompare(l,void 0,{sensitivity:"base"})})),l.innerHTML="",a.forEach((e=>l.appendChild(e))),updateSortIndicators(o,e,r)}function determineColumnDataType(e,t){const n=Math.min(5,e.length);let l=0,a=0;for(let o=0;o<n&&!(o>=e.length);o++){const n=e[o].cells[t].innerText.trim(),r=n.replace(/,/g,"").replace(/[^0-9.\-]+$/g,""),i=parseFloat(r);if(!isNaN(i)){l++;continue}const d=new Date(n);isNaN(d)||"Invalid Date"===d.toString()||a++}return l>=n/2?"number":a>=n/2?"date":"text"}function updateSortIndicators(e,t,n){e.forEach(((e,l)=>{let a=e.querySelector(".sort-indicator");a.innerHTML=l===t?"asc"===n?" ▲":" ▼":""}))}function isMobileView(){return window.innerWidth<768}function handleResize(){const e=isMobileView(),t=document.getElementById("wallet-total"),n=document.getElementById("wallet-available");if(t&&n){var l=t;for(let e=0;e<7;e++)l=l.parentElement;t.innerHTML===n.innerHTML&&e?l.style.display="none":l.style.display="block"}const a=document.getElementById("wallet-pending");if(a){var o=a;for(let e=0;e<6;e++)o=o.parentElement;"0"===a.innerHTML&&e?o.style.display="none":o.style.display="block"}["wallet-pendingReveal","wallet-pendingRegister","wallet-pendingRedeem"].forEach((t=>{const n=document.getElementById(t);if(n){var l=n;for(let e=0;e<8;e++)l=l.parentElement;"0"===n.innerHTML&&e?l.style.display="none":l.style.display="block"}}))}window.addEventListener("load",(async()=>{const e=["wallet-available","wallet-total","wallet-locked"],t=["wallet-pendingReveal","wallet-pendingRegister","wallet-pendingRedeem"],n=["hsd-sync","hsd-version","hsd-height","wallet-sync","wallet-available","wallet-total","wallet-locked","wallet-pending","wallet-domainCount","wallet-bidCount","wallet-pendingReveal","wallet-pendingRegister","wallet-pendingRedeem","hsd-sync-mobile","wallet-sync-mobile"].filter((e=>document.getElementById(e)));if(0!==n.length)for(const l of n){const n=document.getElementById(l),a=l.replace(/-/g,"/");let o=await request(a);t.includes(l)&&"Error"!=o&&(o=o.length),e.includes(l)&&(o=Number(o).toFixed(2)),o=o.toString().replace(/\B(?=(\d{3})+(?!\d))/g,","),n.innerHTML=o,handleResize()}})),document.addEventListener("DOMContentLoaded",(function(){const e=document.querySelector("#data-table tbody");e&&fetch("/api/v1/wallet/domains").then((e=>e.json())).then((t=>{e.innerHTML="",t.result.forEach((t=>{const n=document.createElement("tr"),l=document.createElement("td"),a=document.createElement("a");a.href=`/manage/${t.name}`,a.textContent=t.nameRender,a.classList.add("domain-name"),l.appendChild(a),n.appendChild(l);var o="Unknown";"stats"in t&&"daysUntilExpire"in t.stats&&(o=t.stats.daysUntilExpire);const r=document.createElement("td");r.classList.add("hide-mobile"),r.textContent=`${o} days`,n.appendChild(r);const i=document.createElement("td");i.classList.add("hide-mobile"),i.textContent=`${(t.value/1e6).toFixed(2).replace(/\B(?=(\d{3})+(?!\d))/g,",")} HNS`,n.appendChild(i),e.appendChild(n)})),sortTable(0,!0)})).catch((e=>console.error("Error fetching data:",e)))})),setInterval((async function(){const e=["hsd-sync","hsd-height","wallet-sync","wallet-pending","wallet-available","wallet-total"].filter((e=>document.getElementById(e)));if(0!==e.length)for(const t of e){const e=document.getElementById(t),n=t.replace(/-/g,"/");let l=await request(n);["wallet-available","wallet-total"].includes(t)&&(l=Number(l).toFixed(2)),l=l.toString().replace(/\B(?=(\d{3})+(?!\d))/g,","),e.innerHTML=l,handleResize()}}),2e4),window.addEventListener("resize",handleResize),function(){"use strict";var e=document.querySelector(".sidebar"),t=document.querySelectorAll("#sidebarToggle, #sidebarToggleTop");if(e){e.querySelector(".collapse");var n=[].slice.call(document.querySelectorAll(".sidebar .collapse")).map((function(e){return new bootstrap.Collapse(e,{toggle:!1})}));for(var l of t)l.addEventListener("click",(function(t){if(document.body.classList.toggle("sidebar-toggled"),e.classList.toggle("toggled"),e.classList.contains("toggled"))for(var l of n)l.hide()}));window.addEventListener("resize",(function(){if(Math.max(document.documentElement.clientWidth||0,window.innerWidth||0)<768)for(var e of n)e.hide()}))}var a=document.querySelector("body.fixed-nav .sidebar");a&&a.on("mousewheel DOMMouseScroll wheel",(function(e){if(Math.max(document.documentElement.clientWidth||0,window.innerWidth||0)>768){var t=e.originalEvent,n=t.wheelDelta||-t.detail;this.scrollTop+=30*(n<0?1:-1),e.preventDefault()}}));var o=document.querySelector(".scroll-to-top");o&&window.addEventListener("scroll",(function(){var e=window.pageYOffset;o.style.display=e>100?"block":"none"}))}();