979 lines
52 KiB
HTML
979 lines
52 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>RanchiMall Dapps</title>
|
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
<link
|
|
href="https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:ital,wght@0,400;0,500;0,600;0,700;1,400;1,500;1,600;1,700&display=swap"
|
|
rel="stylesheet">
|
|
<link rel="stylesheet" href="css/main.min.css">
|
|
|
|
</head>
|
|
|
|
<body class="hidden">
|
|
<sm-notifications id="notification_drawer"></sm-notifications>
|
|
<header id="main_header" class="flex align-center">
|
|
<a class="flex flex-items-center gap-0-3" href="#/home">
|
|
<svg id="main_logo" class="icon" viewBox="0 0 27.25 32">
|
|
<title>RanchiMall</title>
|
|
<path
|
|
d="M27.14,30.86c-.74-2.48-3-4.36-8.25-6.94a20,20,0,0,1-4.2-2.49,6,6,0,0,1-1.25-1.67,4,4,0,0,1,0-2.26c.37-1.08.79-1.57,3.89-4.55a11.66,11.66,0,0,0,3.34-4.67,6.54,6.54,0,0,0,.05-2.82C20,3.6,18.58,2,16.16.49c-.89-.56-1.29-.64-1.3-.24a3,3,0,0,1-.3.72l-.3.55L13.42.94C13,.62,12.4.26,12.19.15c-.4-.2-.73-.18-.72.05a9.39,9.39,0,0,1-.61,1.33s-.14,0-.27-.13C8.76.09,8-.27,8,.23A11.73,11.73,0,0,1,6.76,2.6C4.81,5.87,2.83,7.49.77,7.49c-.89,0-.88,0-.61,1,.22.85.33.92,1.09.69A5.29,5.29,0,0,0,3,8.33c.23-.17.45-.29.49-.26a2,2,0,0,1,.22.63A1.31,1.31,0,0,0,4,9.34a5.62,5.62,0,0,0,2.27-.87L7,8l.13.55c.19.74.32.82,1,.65a7.06,7.06,0,0,0,3.46-2.47l.6-.71-.06.64c-.17,1.63-1.3,3.42-3.39,5.42L6.73,14c-3.21,3.06-3,5.59.6,8a46.77,46.77,0,0,0,4.6,2.41c.28.13,1,.52,1.59.87,3.31,2,4.95,3.92,4.95,5.93a2.49,2.49,0,0,0,.07.77h0c.09.09,0,.1.9-.14a2.61,2.61,0,0,0,.83-.32,3.69,3.69,0,0,0-.55-1.83A11.14,11.14,0,0,0,17,26.81a35.7,35.7,0,0,0-5.1-2.91C9.37,22.64,8.38,22,7.52,21.17a3.53,3.53,0,0,1-1.18-2.48c0-1.38.71-2.58,2.5-4.23,2.84-2.6,3.92-3.91,4.67-5.65a3.64,3.64,0,0,0,.42-2A3.37,3.37,0,0,0,13.61,5l-.32-.74.29-.48c.17-.27.37-.63.46-.8l.15-.3.44.64a5.92,5.92,0,0,1,1,2.81,5.86,5.86,0,0,1-.42,1.94c0,.12-.12.3-.15.4a9.49,9.49,0,0,1-.67,1.1,28,28,0,0,1-4,4.29C8.62,15.49,8.05,16.44,8,17.78a3.28,3.28,0,0,0,1.11,2.76c.95,1,2.07,1.74,5.25,3.32,3.64,1.82,5.22,2.9,6.41,4.38A4.78,4.78,0,0,1,21.94,31a3.21,3.21,0,0,0,.14.92,1.06,1.06,0,0,0,.43-.05l.83-.22.46-.12-.06-.46c-.21-1.53-1.62-3.25-3.94-4.8a37.57,37.57,0,0,0-5.22-2.82A13.36,13.36,0,0,1,11,21.19a3.36,3.36,0,0,1-.8-4.19c.41-.85.83-1.31,3.77-4.15,2.39-2.31,3.43-4.13,3.43-6a5.85,5.85,0,0,0-2.08-4.29c-.23-.21-.44-.43-.65-.65A2.5,2.5,0,0,1,15.27.69a10.6,10.6,0,0,1,2.91,2.78A4.16,4.16,0,0,1,19,6.16a4.91,4.91,0,0,1-.87,3c-.71,1.22-1.26,1.82-4.27,4.67a9.47,9.47,0,0,0-2.07,2.6,2.76,2.76,0,0,0-.33,1.54,2.76,2.76,0,0,0,.29,1.47c.57,1.21,2.23,2.55,4.65,3.73a32.41,32.41,0,0,1,5.82,3.24c2.16,1.6,3.2,3.16,3.2,4.8a1.94,1.94,0,0,0,.09.76,4.54,4.54,0,0,0,1.66-.4C27.29,31.42,27.29,31.37,27.14,30.86ZM6.1,7h0a3.77,3.77,0,0,1-1.46.45L4,7.51l.68-.83a25.09,25.09,0,0,0,3-4.82A12,12,0,0,1,8.28.76c.11-.12.77.32,1.53,1l.63.58-.57.84A10.34,10.34,0,0,1,6.1,7Zm5.71-1.78A9.77,9.77,0,0,1,9.24,7.18h0a5.25,5.25,0,0,1-1.17.28l-.58,0,.65-.78a21.29,21.29,0,0,0,2.1-3.12c.22-.41.42-.76.44-.79s.5.43.9,1.24L12,5ZM13.41,3a2.84,2.84,0,0,1-.45.64,11,11,0,0,1-.9-.91l-.84-.9.19-.45c.34-.79.39-.8,1-.31A9.4,9.4,0,0,1,13.8,2.33q-.18.34-.39.69Z">
|
|
</path>
|
|
</svg>
|
|
<h4>
|
|
RanchiMall Dapps
|
|
</h4>
|
|
</a>
|
|
<theme-toggle></theme-toggle>
|
|
</header>
|
|
<main id="page_container" class="grid"></main>
|
|
<sm-popup id="download_info_popup">
|
|
<div class="grid gap-1-5">
|
|
<h2>
|
|
Integrity check passed. <br>
|
|
Starting download...
|
|
</h2>
|
|
<div class="grid gap-1">
|
|
<h4>
|
|
What to do after you download the dapp?
|
|
</h4>
|
|
<ol>
|
|
<li>
|
|
Unzip the downloaded file
|
|
</li>
|
|
<li>
|
|
Open the unzipped folder
|
|
</li>
|
|
<li>
|
|
Open the<strong> index.html</strong> file in your browser
|
|
</li>
|
|
</ol>
|
|
</div>
|
|
<div class="flex align-center gap-0-5 margin-left-auto">
|
|
<button class="button button--colored" onclick="dontShowInfoAgain()">
|
|
Don't show this again
|
|
</button>
|
|
<button class="button button--primary button--small" style="padding: 0.5rem 1rem;"
|
|
onclick="closePopup()">
|
|
Close
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</sm-popup>
|
|
<sm-popup id="integrity_check_popup">
|
|
<header slot="header" class="popup__header">
|
|
<div class="flex align-center">
|
|
<button class="popup__header__close" onclick="closePopup()">
|
|
<svg class="icon" xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px"
|
|
fill="#000000">
|
|
<path d="M0 0h24v24H0V0z" fill="none" />
|
|
<path
|
|
d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41z" />
|
|
</svg>
|
|
</button>
|
|
</div>
|
|
</header>
|
|
<div id="integrity_check_popup__content" class="grid gap-1-5"></div>
|
|
</sm-popup>
|
|
<script src="scripts/components.min.js"></script>
|
|
<script src="https://unpkg.com/uhtml@3.0.1/es.js"></script>
|
|
<script src="scripts/dappList.js"></script>
|
|
<script>
|
|
const { html, svg, render: renderElem } = uhtml;
|
|
const uiGlobals = {}
|
|
uiGlobals.connectionErrorNotification = []
|
|
//Checks for internet connection status
|
|
if (!navigator.onLine)
|
|
uiGlobals.connectionErrorNotification.push(notify('There seems to be a problem connecting to the internet, Please check you internet connection.', 'error'))
|
|
window.addEventListener('offline', () => {
|
|
uiGlobals.connectionErrorNotification.push(notify('There seems to be a problem connecting to the internet, Please check you internet connection.', 'error'))
|
|
})
|
|
window.addEventListener('online', () => {
|
|
uiGlobals.connectionErrorNotification.forEach(notification => {
|
|
getRef('notification_drawer').remove(notification)
|
|
})
|
|
notify('We are back online.', 'success')
|
|
})
|
|
// Use instead of document.getElementById
|
|
function getRef(elementId) {
|
|
return document.getElementById(elementId)
|
|
}
|
|
let zIndex = 50
|
|
// function required for popups or modals to appear
|
|
function openPopup(popupId, pinned) {
|
|
if (popupStack.peek() === undefined) {
|
|
document.addEventListener('keydown', (e) => {
|
|
if (e.key === 'Escape') {
|
|
closePopup()
|
|
}
|
|
})
|
|
}
|
|
zIndex++
|
|
getRef(popupId).setAttribute('style', `z-index: ${zIndex}`)
|
|
return getRef(popupId).show({ pinned })
|
|
}
|
|
|
|
// hides the popup or modal
|
|
function closePopup(options = {}) {
|
|
if (popupStack.peek() === undefined)
|
|
return;
|
|
popupStack.peek().popup.hide(options)
|
|
}
|
|
|
|
document.addEventListener('popupopened', async e => {
|
|
switch (e.target.id) {
|
|
|
|
}
|
|
})
|
|
document.addEventListener('popupclosed', e => {
|
|
zIndex--
|
|
switch (e.target.id) {
|
|
}
|
|
})
|
|
//Function for displaying toast notifications. pass in error for mode param if you want to show an error.
|
|
function notify(message, mode, options = {}) {
|
|
let icon
|
|
switch (mode) {
|
|
case 'success':
|
|
icon = `<svg class="icon icon--success" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><path fill="none" d="M0 0h24v24H0z"/><path d="M10 15.172l9.192-9.193 1.415 1.414L10 18l-6.364-6.364 1.414-1.414z"/></svg>`
|
|
break;
|
|
case 'error':
|
|
icon = `<svg class="icon icon--error" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><path fill="none" d="M0 0h24v24H0z"/><path d="M12 22C6.477 22 2 17.523 2 12S6.477 2 12 2s10 4.477 10 10-4.477 10-10 10zm-1-7v2h2v-2h-2zm0-8v6h2V7h-2z"/></svg>`
|
|
if (!options.hasOwnProperty('timeout'))
|
|
options.pinned = true
|
|
break;
|
|
}
|
|
if (mode === 'error') {
|
|
console.error(message)
|
|
}
|
|
return getRef("notification_drawer").push(message, { icon, ...options });
|
|
}
|
|
// displays a popup for asking permission. Use this instead of JS confirm
|
|
/**
|
|
@param {string} title - Title of the popup
|
|
@param {object} options - Options for the popup
|
|
@param {string} options.message - Message to be displayed in the popup
|
|
@param {string} options.cancelText - Text for the cancel button
|
|
@param {string} options.confirmText - Text for the confirm button
|
|
@param {boolean} options.danger - If true, confirm button will be red
|
|
*/
|
|
const getConfirmation = (title, options = {}) => {
|
|
return new Promise(resolve => {
|
|
const { message = '', cancelText = 'Cancel', confirmText = 'OK', danger = false } = options
|
|
getRef('confirm_title').innerText = title;
|
|
getRef('confirm_message').innerText = message;
|
|
const cancelButton = getRef('confirmation_popup').querySelector('.cancel-button');
|
|
const confirmButton = getRef('confirmation_popup').querySelector('.confirm-button')
|
|
confirmButton.textContent = confirmText
|
|
cancelButton.textContent = cancelText
|
|
if (danger)
|
|
confirmButton.classList.add('button--danger')
|
|
else
|
|
confirmButton.classList.remove('button--danger')
|
|
const { opened, closed } = openPopup('confirmation_popup')
|
|
confirmButton.onclick = () => {
|
|
closePopup({ payload: true })
|
|
}
|
|
cancelButton.onclick = () => {
|
|
closePopup()
|
|
}
|
|
closed.then((payload) => {
|
|
confirmButton.onclick = null
|
|
cancelButton.onclick = null
|
|
if (payload)
|
|
resolve(true)
|
|
else
|
|
resolve(false)
|
|
})
|
|
})
|
|
}
|
|
function createRipple(event, target) {
|
|
const circle = document.createElement("span");
|
|
const diameter = Math.max(target.clientWidth, target.clientHeight);
|
|
const radius = diameter / 2;
|
|
const targetDimensions = target.getBoundingClientRect();
|
|
circle.style.width = circle.style.height = `${diameter}px`;
|
|
circle.style.left = `${event.clientX - (targetDimensions.left + radius)}px`;
|
|
circle.style.top = `${event.clientY - (targetDimensions.top + radius)}px`;
|
|
circle.classList.add("ripple");
|
|
const rippleAnimation = circle.animate(
|
|
[
|
|
{
|
|
opacity: 1,
|
|
transform: `scale(0)`
|
|
},
|
|
{
|
|
transform: "scale(4)",
|
|
opacity: 0,
|
|
},
|
|
],
|
|
{
|
|
duration: 600,
|
|
fill: "forwards",
|
|
easing: "ease-out",
|
|
}
|
|
);
|
|
target.append(circle);
|
|
rippleAnimation.onfinish = () => {
|
|
circle.remove();
|
|
};
|
|
}
|
|
function buttonLoader(id, show) {
|
|
const button = typeof id === 'string' ? document.getElementById(id) : id;
|
|
if (!button) return
|
|
if (!button.dataset.hasOwnProperty('wasDisabled'))
|
|
button.dataset.wasDisabled = button.disabled
|
|
const animOptions = {
|
|
duration: 200,
|
|
fill: 'forwards',
|
|
easing: 'ease'
|
|
}
|
|
if (show) {
|
|
button.disabled = true
|
|
button.parentNode.append(document.createElement('sm-spinner'))
|
|
button.animate([
|
|
{
|
|
clipPath: 'circle(100%)',
|
|
},
|
|
{
|
|
clipPath: 'circle(0)',
|
|
},
|
|
], animOptions)
|
|
} else {
|
|
button.disabled = button.dataset.wasDisabled === 'true';
|
|
button.animate([
|
|
{
|
|
clipPath: 'circle(0)',
|
|
},
|
|
{
|
|
clipPath: 'circle(100%)',
|
|
},
|
|
], animOptions).onfinish = (e) => {
|
|
button.removeAttribute('data-original-state')
|
|
}
|
|
const potentialTarget = button.parentNode.querySelector('sm-spinner')
|
|
if (potentialTarget) potentialTarget.remove();
|
|
}
|
|
}
|
|
class Router {
|
|
/**
|
|
* @constructor {object} options - options for the router
|
|
* @param {object} options.routes - routes for the router
|
|
* @param {object} options.state - initial state for the router
|
|
* @param {function} options.routingStart - function to be called before routing
|
|
* @param {function} options.routingEnd - function to be called after routing
|
|
*/
|
|
constructor(options = {}) {
|
|
const { routes = {}, state = {}, routingStart, routingEnd } = options
|
|
this.routes = routes
|
|
this.state = state
|
|
this.routingStart = routingStart
|
|
this.routingEnd = routingEnd
|
|
this.lastPage = null
|
|
window.addEventListener('hashchange', e => this.routeTo(window.location.hash))
|
|
}
|
|
/**
|
|
* @param {string} route - route to be added
|
|
* @param {function} callback - function to be called when route is matched
|
|
*/
|
|
addRoute(route, callback) {
|
|
this.routes[route] = callback
|
|
}
|
|
/**
|
|
* @param {string} route
|
|
*/
|
|
handleRouting = async (page) => {
|
|
if (this.routingStart) {
|
|
this.routingStart(this.state)
|
|
}
|
|
if (this.routes[page]) {
|
|
await this.routes[page](this.state)
|
|
this.lastPage = page
|
|
} else {
|
|
if (this.routes['404']) {
|
|
this.routes['404'](this.state);
|
|
} else {
|
|
console.error(`No route found for '${page}' and no '404' route is defined.`);
|
|
}
|
|
}
|
|
if (this.routingEnd) {
|
|
this.routingEnd(this.state)
|
|
}
|
|
}
|
|
async routeTo(destination) {
|
|
try {
|
|
let page
|
|
let wildcards = []
|
|
let params = {}
|
|
let [path, queryString] = destination.split('?');
|
|
if (path.includes('#'))
|
|
path = path.split('#')[1];
|
|
if (path.includes('/'))
|
|
[, page, ...wildcards] = path.split('/')
|
|
else
|
|
page = path
|
|
this.state = { page, wildcards, lastPage: this.lastPage, params }
|
|
if (queryString) {
|
|
params = new URLSearchParams(queryString)
|
|
this.state.params = Object.fromEntries(params)
|
|
}
|
|
if (document.startViewTransition) {
|
|
const viewTransition = document.startViewTransition(async () => {
|
|
await this.handleRouting(page)
|
|
})
|
|
this.state.viewTransition = viewTransition
|
|
} else {
|
|
// Fallback for browsers that don't support View transition API:
|
|
await this.handleRouting(page)
|
|
}
|
|
} catch (e) {
|
|
console.error(e)
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
<script>
|
|
const router = new Router({
|
|
routingStart(state) {
|
|
},
|
|
routingEnd(state) {
|
|
let { page } = state
|
|
if (!page)
|
|
page = 'home'
|
|
const preventDownloadInfoPopup = localStorage.getItem('dontShowDownloadInfo')
|
|
document.querySelectorAll('.dapp-download-button').forEach(elem => {
|
|
elem.onclick = (e) => {
|
|
e.preventDefault()
|
|
// check dapp hash before downloading and show error if hash doesn't match
|
|
const { repoHash: knownHash, appLink } = elem.closest('.dapp-card').dataset;
|
|
getRepoHash(appLink.split('/').pop()).then(latestHash => {
|
|
if (latestHash !== knownHash) {
|
|
notify(`The dapp you are trying to download has failed integrity check. Dapp won't be downloaded.`, 'error')
|
|
} else {
|
|
if (preventDownloadInfoPopup === null || preventDownloadInfoPopup === 'false')
|
|
openPopup('download_info_popup')
|
|
// initiate download
|
|
window.location.href = elem.href
|
|
}
|
|
}).catch(e => {
|
|
console.error(e)
|
|
notify('There was an error while trying to download the dapp. Please try again later.', 'error', {
|
|
timeout: 10000,
|
|
})
|
|
})
|
|
}
|
|
})
|
|
}
|
|
})
|
|
function dontShowInfoAgain() {
|
|
localStorage.setItem('dontShowDownloadInfo', true);
|
|
closePopup()
|
|
}
|
|
window.addEventListener('load', () => {
|
|
router.routeTo(location.hash)
|
|
document.body.classList.remove('hidden')
|
|
document.addEventListener('copy', () => {
|
|
notify('copied', 'success')
|
|
})
|
|
document.addEventListener("pointerdown", (e) => {
|
|
if (e.target.closest("button:not(:disabled), .interactive:not(:disabled)")) {
|
|
createRipple(e, e.target.closest("button, .interactive"));
|
|
}
|
|
});
|
|
})
|
|
router.addRoute('404', () => {
|
|
renderElem(getRef('page_container'), html`
|
|
<h1>Page not found</h1>
|
|
`)
|
|
})
|
|
router.addRoute('home', renderHome)
|
|
router.addRoute('', renderHome)
|
|
dappsList = dappsList.sort((a, b) => a.name.localeCompare(b.name));
|
|
function renderDappCard(dapp) {
|
|
let { name, description, icon, appLink, moreLink, tags, category, repoHash, allowDownload = true } = dapp;
|
|
if (!icon || icon === '')
|
|
icon = `<svg class="icon" xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 24 24" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"><g><rect fill="none" height="24" width="24"/></g><g><g/><path d="M11.99,2C6.47,2,2,6.48,2,12c0,5.52,4.47,10,9.99,10C17.52,22,22,17.52,22,12C22,6.48,17.52,2,11.99,2z M8.5,8 C9.33,8,10,8.67,10,9.5S9.33,11,8.5,11S7,10.33,7,9.5S7.67,8,8.5,8z M12,18c-2.28,0-4.22-1.66-5-4h10C16.22,16.34,14.28,18,12,18z M15.5,11c-0.83,0-1.5-0.67-1.5-1.5S14.67,8,15.5,8S17,8.67,17,9.5S16.33,11,15.5,11z"/></g></svg>`;
|
|
const iconWrapper = document.createElement('div')
|
|
iconWrapper.className = 'dapp-card__icon';
|
|
if (icon.startsWith('http://') || icon.startsWith('https://')) {
|
|
const img = document.createElement('img');
|
|
img.src = icon;
|
|
img.alt = name + ' logo';
|
|
img.className = 'icon';
|
|
iconWrapper.appendChild(img);
|
|
} else {
|
|
iconWrapper.innerHTML = icon;
|
|
}
|
|
return html`
|
|
<li class="dapp-card" .dataset=${{ appLink, repoHash }}>
|
|
<div class="flex space-between">
|
|
${iconWrapper}
|
|
<a class="dapp-card__category capitalize" href=${`#/home?category=${category}`}>
|
|
${category.replace('-', ' ')}
|
|
</a>
|
|
</div>
|
|
<div class="dapp-card__content grid gap-0-5">
|
|
<a class="flex align-center dapp-card__title__wrapper" href=${moreLink}>
|
|
<h3 class="dapp-card__title">${name}</h3>
|
|
<svg class="icon" xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"><path d="M0 0h24v24H0V0z" fill="none"/><path d="M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6-6-6z"/></svg>
|
|
</a>
|
|
<p class="dapp-card__description">${description}</p>
|
|
</div>
|
|
<div class="flex gap-0-5 align-center flex-wrap">
|
|
<button class="button dapp-card__link" onclick=${(e) => checkIntegrity(appLink, e)}>
|
|
Check integrity
|
|
</button>
|
|
${allowDownload ? html`
|
|
<a href=${`https://github.com/ranchimall/${appLink.split('/').pop()}/archive/refs/heads/master.zip`} class="button dapp-card__link dapp-download-button" title="Download dapp Zip">
|
|
<svg class="icon" xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 24 24" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"><g><rect fill="none" height="24" width="24"/></g><g><path d="M18,15v3H6v-3H4v3c0,1.1,0.9,2,2,2h12c1.1,0,2-0.9,2-2v-3H18z M17,11l-1.41-1.41L13,12.17V4h-2v8.17L8.41,9.59L7,11l5,5 L17,11z"/></g></svg>
|
|
</a>`: ''}
|
|
<a href=${appLink} class="button dapp-card__link dapp-card__link--primary" target="_blank" onclick=${checkLinkBeforeVisiting}>
|
|
Try it
|
|
<svg class="icon" xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"> <path d="M0 0h24v24H0z" fill="none"></path> <path d="M19 19H5V5h7V3H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2v-7h-2v7zM14 3v2h3.59l-9.83 9.83 1.41 1.41L19 6.41V10h2V3h-7z"></path> </svg>
|
|
</a>
|
|
</div>
|
|
</li>
|
|
`
|
|
}
|
|
function pseudoDisable(element, disable) {
|
|
if (disable) {
|
|
element.dataset.disabled = true
|
|
element.style.pointerEvents = 'none'
|
|
element.tabIndex = -1
|
|
} else {
|
|
if (!element)
|
|
return
|
|
delete element.dataset.disabled
|
|
element.style.pointerEvents = 'auto'
|
|
element.tabIndex = 0
|
|
}
|
|
}
|
|
async function checkIntegrity(appLink, e) {
|
|
try {
|
|
if (!appLink) return console.error('appLink not provided')
|
|
renderElem(getRef('integrity_check_popup__content'), html`
|
|
<div class="flex gap-0-5 align-center">
|
|
<sm-spinner></sm-spinner>
|
|
<h4>Checking integrity...</h4>
|
|
</div>
|
|
`)
|
|
openPopup('integrity_check_popup')
|
|
pseudoDisable(e.target, true)
|
|
renderElem(e.target, html`Checking...`)
|
|
const { hasValidHash, knownHash, latestHash } = await hasAKnownHash(appLink)
|
|
const hashes = latestHash && knownHash && html`
|
|
<div class="flex flex-direction-column gap-1">
|
|
<div class="flex flex-direction-column gap-0-3">
|
|
<h4>Authorized hash for private key usage</h4>
|
|
<sm-copy value=${knownHash}><p>${knownHash}</p></sm-copy>
|
|
</div>
|
|
<div class="flex flex-direction-column gap-0-3">
|
|
<h4>Hash of the link we just computed</h4>
|
|
<sm-copy value=${latestHash}><p>${latestHash}</p></sm-copy>
|
|
</div>
|
|
</div>
|
|
`;
|
|
let dappActions
|
|
if (e.target) {
|
|
dappActions = e.target.parentNode.cloneNode(true)
|
|
dappActions.firstElementChild.remove()
|
|
}
|
|
if (!hasValidHash) {
|
|
renderElem(e.target.closest('.flex'), html`
|
|
<strong style="color: var(--danger-color)">Failed integrity check</strong>
|
|
`)
|
|
renderElem(getRef('integrity_check_popup__content'), html`
|
|
<div class="grid gap-2">
|
|
<div class="grid gap-0-5">
|
|
<div class="flex flex-direction-column gap-0-5">
|
|
<svg class="icon icon--big icon--danger" style="fill: var(--danger-color)" xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"><path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z"/></svg>
|
|
<h2 style="color: var(--danger-color)">Failed integrity check</h2>
|
|
</div>
|
|
<p>
|
|
The dapp has failed integrity check. Please don't use it.
|
|
</p>
|
|
</div>
|
|
<div class="grid gap-1">
|
|
<h4>Failed checks</h4>
|
|
<ol class="grid gap-0-5">
|
|
${!latestHash ? html`
|
|
<li>
|
|
Couldn't generate hash for the link.
|
|
</li>
|
|
` : ''}
|
|
${latestHash && latestHash !== knownHash ? html`
|
|
<li>
|
|
The content of the site has been modified through unauthorized means.
|
|
</li>
|
|
`: ''}
|
|
</ol>
|
|
</div>
|
|
${hashes}
|
|
</div>
|
|
`)
|
|
} else {
|
|
renderElem(getRef('integrity_check_popup__content'), html`
|
|
<div class="flex flex-direction-column gap-0-5">
|
|
<svg class="icon icon--big icon--green" xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 24 24" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"><g><rect fill="none" height="24" width="24"/></g><g><path d="M23,12l-2.44-2.79l0.34-3.69l-3.61-0.82L15.4,1.5L12,2.96L8.6,1.5L6.71,4.69L3.1,5.5L3.44,9.2L1,12l2.44,2.79l-0.34,3.7 l3.61,0.82L8.6,22.5l3.4-1.47l3.4,1.46l1.89-3.19l3.61-0.82l-0.34-3.69L23,12z M10.09,16.72l-3.8-3.81l1.48-1.48l2.32,2.33 l5.85-5.87l1.48,1.48L10.09,16.72z"/></g></svg>
|
|
<h2 style="color: var(--success-color)">Passed integrity check</h2>
|
|
</div>
|
|
<p>
|
|
The dapp has passed integrity check. You can use it safely.
|
|
</p>
|
|
${hashes}
|
|
${dappActions}
|
|
`)
|
|
renderElem(e.target, html`Check integrity`)
|
|
pseudoDisable(e.target, false)
|
|
}
|
|
} catch (e) {
|
|
console.error(e)
|
|
notify('There was an error while checking integrity. Please try again later.', 'error', {
|
|
timeout: 10000,
|
|
})
|
|
}
|
|
}
|
|
function renderHome(state) {
|
|
const { params: { category = 'all', query = '' }, page, viewTransition, lastPage } = state
|
|
getRef('page_container').dataset.page = 'home';
|
|
const renderedDappsList = filterDapps(query, category)
|
|
.map((dapp) => renderDappCard(dapp))
|
|
renderElem(getRef('page_container'), html`
|
|
<section id="hero_section">
|
|
<svg id="hero_section__svg" xmlns="http://www.w3.org/2000/svg" width="50" height="103" viewBox="0 0 50 103" fill="none"> <path d="M49.919 65.4057L12.7647 28.2514V102.56L49.919 65.4057Z" fill="#ABECDB"/> <path d="M49.919 49.0706L0.913757 0.0653687V98.0758L49.919 49.0706Z" fill="#CFF3EA"/> </svg>
|
|
<h1>
|
|
Securely discover the world of <br>
|
|
exciting new blockchain apps
|
|
</h1>
|
|
</section>
|
|
<section id="verification_section" class="grid">
|
|
<div class="flex align-center gap-0-5">
|
|
<svg class="icon" style="fill: var(--yellow)" xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"><path d="M1 21h22L12 2 1 21zm12-3h-2v-2h2v2zm0-4h-2v-4h2v4z"/></svg>
|
|
<h2>
|
|
Always verify RanchiMall Dapp links before entering your private keys
|
|
</h2>
|
|
</div>
|
|
<sm-form id="verification_form" oninvalid=${removeInvalidLinkResult} skip-submit>
|
|
<sm-input id="link_verification__input" class="flex-1" placeholder="Enter a link to verify" style="min-width: 16rem" required></sm-input>
|
|
<div class="multi-state-button">
|
|
<button class="button button--colored h-100" onclick=${verifyLink} type="submit">
|
|
Verify link
|
|
</button>
|
|
</div>
|
|
</sm-form>
|
|
</section>
|
|
</ul>
|
|
<div id="list_header" class="flex align-center gap-1 flex-wrap">
|
|
<h4>Our offerings</h4>
|
|
<sm-input id="dapp_search_input" type="search" placeholder="Search Dapps" oninput=${searchDapps} value=${query}>
|
|
<svg slot="icon" class="icon" xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"> <path d="M0 0h24v24H0V0z" fill="none"></path> <path d="M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"> </path> </svg>
|
|
</sm-input>
|
|
<a id="download_all_button" class="button button--colored margin-left-auto" href="https://github.com/ranchimall/dappbundle/archive/refs/heads/master.zip">
|
|
Download all
|
|
</a>
|
|
</div>
|
|
<sm-chips id="category_selector" onchange=${handleFilterCategory}>
|
|
${['all', 'blockchain-explorer', 'content', 'finance', 'identity', 'management', 'social', 'wallet'].map((value, index) => html`
|
|
<sm-chip value=${value} ?selected=${value === category}>${value.replace('-', ' ')}</sm-chip>
|
|
`)}
|
|
</sm-chips>
|
|
${renderedDappsList.length === 0 ? html`
|
|
<div class="text-center">
|
|
No dapps related to <strong>'${query}'</strong> ${category === 'all' ? '' : `in ${category.replace('-', ' ')}`} found.
|
|
</div>
|
|
` : html`
|
|
<ul id="dapp_list">${renderedDappsList}</ul>
|
|
`}
|
|
`)
|
|
if (!viewTransition || lastPage === page) return
|
|
viewTransition.ready.then(() => {
|
|
document.documentElement.animate(
|
|
[
|
|
{ transform: 'translateX(0)' },
|
|
{ transform: 'translateX(1rem)' },
|
|
],
|
|
{
|
|
duration: 300,
|
|
easing: 'ease',
|
|
pseudoElement: '::view-transition-old(root)',
|
|
}
|
|
);
|
|
document.documentElement.animate(
|
|
[
|
|
{ transform: 'translateX(-1rem)' },
|
|
{ transform: 'translateX(0)' },
|
|
],
|
|
{
|
|
duration: 300,
|
|
easing: 'ease',
|
|
pseudoElement: '::view-transition-new(root)',
|
|
}
|
|
);
|
|
})
|
|
}
|
|
function addProtocolToUrl(url) {
|
|
if (!url.startsWith('http://') && !url.startsWith('https://')) {
|
|
url = 'https://' + url;
|
|
}
|
|
return url;
|
|
}
|
|
function parseUrlWithoutHashAndQuery(fullUrl) {
|
|
fullUrl = addProtocolToUrl(fullUrl);
|
|
const parsedUrl = new URL(fullUrl);
|
|
|
|
// Set the hash and search/query to empty strings
|
|
parsedUrl.hash = '';
|
|
parsedUrl.search = '';
|
|
|
|
// Reconstruct the URL without hash and query
|
|
const urlWithoutHashAndQuery = parsedUrl.toString();
|
|
|
|
return urlWithoutHashAndQuery;
|
|
}
|
|
async function hasAKnownHash(linkToVerify) {
|
|
try {
|
|
linkToVerify = addProtocolToUrl(linkToVerify);
|
|
linkToVerify = parseUrlWithoutHashAndQuery(linkToVerify)
|
|
let knownHash, latestHash, hasValidHash
|
|
const dappInfo = dappsList.find(({ appLink }) => linkToVerify.includes(appLink))
|
|
if (!dappInfo) return false
|
|
const { appHash, repoHash, automatedChecking = false, appLink, repoLink, allowDownload = true } = dappInfo
|
|
if (linkToVerify.includes('https://blockbook.ranchimall.net')) {
|
|
// blockbook is special case
|
|
// it is a server side rendered app
|
|
// so we need to check the hash of the repo
|
|
// and not the hash of the link content
|
|
latestHash = await getRepoHash('blockbook')
|
|
knownHash = repoHash
|
|
hasValidHash = latestHash === knownHash
|
|
} else {
|
|
if (automatedChecking || !allowDownload) {
|
|
const latestRepoHash = await getRepoHash((repoLink || appLink).split('/').pop())
|
|
latestHash = knownHash = latestRepoHash
|
|
hasValidHash = true
|
|
} else {
|
|
const [contentHash, latestRepoHash] = await Promise.all([
|
|
getLinkContentHash(linkToVerify),
|
|
getRepoHash((repoLink || appLink).split('/').pop())
|
|
])
|
|
console.log(contentHash, latestRepoHash)
|
|
latestHash = contentHash[0].hash
|
|
knownHash = appHash
|
|
hasValidHash = latestHash === knownHash && repoHash === latestRepoHash;
|
|
if (!hasValidHash && repoHash !== latestRepoHash) {
|
|
latestHash = latestRepoHash
|
|
knownHash = repoHash
|
|
}
|
|
}
|
|
}
|
|
return { hasValidHash, latestHash, knownHash }
|
|
} catch (e) {
|
|
console.error(e)
|
|
return false
|
|
}
|
|
}
|
|
async function verifyLink(e) {
|
|
try {
|
|
let linkToVerify = getRef('link_verification__input').value.trim();
|
|
if (linkToVerify === '')
|
|
return notify('Please enter a link to verify', 'error', {
|
|
timeout: 5000
|
|
})
|
|
linkToVerify = parseUrlWithoutHashAndQuery(linkToVerify)
|
|
buttonLoader(e.target, true)
|
|
const linkIsAuthorized = dappsList.some(({ appLink }) => linkToVerify.includes(appLink))
|
|
removeInvalidLinkResult()
|
|
let verification = linkIsAuthorized
|
|
let latestHash, knownHash
|
|
if (verification) {
|
|
const result = await hasAKnownHash(linkToVerify)
|
|
latestHash = result.latestHash
|
|
knownHash = result.knownHash
|
|
verification = verification && result.hasValidHash
|
|
}
|
|
const hashes = latestHash && knownHash && html`
|
|
<div class="flex flex-direction-column gap-1">
|
|
<div class="flex flex-direction-column gap-0-3">
|
|
<h4>Authorized hash for private key usage</h4>
|
|
<sm-copy value=${knownHash}><p>${knownHash}</p></sm-copy>
|
|
</div>
|
|
<div class="flex flex-direction-column gap-0-3">
|
|
<h4>Hash of the link we just computed</h4>
|
|
<sm-copy value=${latestHash}><p>${latestHash}</p></sm-copy>
|
|
</div>
|
|
</div>
|
|
`;
|
|
while (getRef('verification_form').nextElementSibling)
|
|
getRef('verification_form').nextElementSibling.remove()
|
|
if (verification) {
|
|
getRef('verification_form').after(html.node/*html*/`
|
|
<div class="flex align-center gap-0-5">
|
|
<svg class="icon" style="fill: var(--green)" xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 24 24" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"><g><rect fill="none" height="24" width="24"/></g><g><g><path d="M23,11.99l-2.44-2.79l0.34-3.69l-3.61-0.82L15.4,1.5L12,2.96L8.6,1.5L6.71,4.69L3.1,5.5L3.44,9.2L1,11.99l2.44,2.79 l-0.34,3.7l3.61,0.82L8.6,22.5l3.4-1.47l3.4,1.46l1.89-3.19l3.61-0.82l-0.34-3.69L23,11.99z M19.05,13.47l-0.56,0.65l0.08,0.85 l0.18,1.95l-1.9,0.43l-0.84,0.19l-0.44,0.74l-0.99,1.68l-1.78-0.77L12,18.85l-0.79,0.34l-1.78,0.77l-0.99-1.67l-0.44-0.74 l-0.84-0.19l-1.9-0.43l0.18-1.96l0.08-0.85l-0.56-0.65l-1.29-1.47l1.29-1.48l0.56-0.65L5.43,9.01L5.25,7.07l1.9-0.43l0.84-0.19 l0.44-0.74l0.99-1.68l1.78,0.77L12,5.14l0.79-0.34l1.78-0.77l0.99,1.68l0.44,0.74l0.84,0.19l1.9,0.43l-0.18,1.95l-0.08,0.85 l0.56,0.65l1.29,1.47L19.05,13.47z"/><polygon points="10.09,13.75 7.77,11.42 6.29,12.91 10.09,16.72 17.43,9.36 15.95,7.87"/></g></g></svg>
|
|
<h4>Yay!</h4>
|
|
</div>
|
|
<ol>
|
|
<li>
|
|
There is no phishing done on this link. You can safely enter your private key.
|
|
</li>
|
|
<li>
|
|
The code powering this site is not modified through unauthorized means.
|
|
</li>
|
|
</ol>
|
|
${hashes}
|
|
`)
|
|
} else {
|
|
getRef('verification_form').after(html.node/*html*/`
|
|
<div class="grid gap-2">
|
|
<div class="grid gap-0-5">
|
|
<div class="flex align-center gap-0-5">
|
|
<svg class="icon" style="fill: var(--danger-color)" xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 24 24" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"><g><path d="M0,0h24v24H0V0z" fill="none"/></g><g><path d="M15.73,3H8.27L3,8.27v7.46L8.27,21h7.46L21,15.73V8.27L15.73,3z M19,14.9L14.9,19H9.1L5,14.9V9.1L9.1,5h5.8L19,9.1V14.9z M14.83,7.76L12,10.59L9.17,7.76L7.76,9.17L10.59,12l-2.83,2.83l1.41,1.41L12,13.41l2.83,2.83l1.41-1.41L13.41,12l2.83-2.83 L14.83,7.76z"/></g></svg>
|
|
<h4>Danger!</h4>
|
|
</div>
|
|
<p>
|
|
Please don't enter your private key on this link.
|
|
</p>
|
|
</div>
|
|
<div class="grid gap-1">
|
|
<h4> Failed checks</h4>
|
|
<ol class="grid gap-0-5">
|
|
${!linkIsAuthorized ? html`
|
|
<li>
|
|
This link is not authorized by us.
|
|
</li>
|
|
` : ''}
|
|
${linkIsAuthorized && !latestHash ? html`
|
|
<li>
|
|
Couldn't generate hash for the link.
|
|
</li>
|
|
` : ''}
|
|
${linkIsAuthorized && latestHash && latestHash !== knownHash ? html`
|
|
<li>
|
|
The content of the site has been modified through unauthorized means.
|
|
</li>
|
|
`: ''}
|
|
</ol>
|
|
${hashes}
|
|
</div>
|
|
</div>
|
|
`)
|
|
}
|
|
} catch (e) {
|
|
console.error(e)
|
|
notify(e.message, 'error', {
|
|
timeout: 10000,
|
|
})
|
|
} finally {
|
|
buttonLoader(e.target, false)
|
|
}
|
|
}
|
|
function removeInvalidLinkResult() {
|
|
while (getRef('verification_form').nextElementSibling)
|
|
getRef('verification_form').nextElementSibling.remove()
|
|
getRef('verification_form').after(
|
|
html.node/*html*/`<div class="flex flex-direction-column gap-0-5" >
|
|
<h4>Checks we will perform</h4>
|
|
<ol>
|
|
<li>
|
|
Whether the contents of an app have been tampered with.
|
|
</li>
|
|
<li>
|
|
The link itself has not been tampered with.
|
|
</li>
|
|
</ol>
|
|
</div>`
|
|
)
|
|
}
|
|
function handleFilterCategory(e) {
|
|
const query = getRef('dapp_search_input')?.value.trim().toLowerCase() || '';
|
|
location.hash = `#/home?category=${e.target.value}${query ? `&query=${query}` : ''}`
|
|
}
|
|
function filterDapps(query = '', category = 'all') {
|
|
const filtered = dappsList.filter(dapp => {
|
|
if (category === 'all') {
|
|
return dapp.name.toLowerCase().includes(query) || dapp.description.toLowerCase().includes(query) || dapp.tags.some(tag => tag.includes(query))
|
|
} else {
|
|
return dapp.category.toLowerCase().includes(category) && (dapp.name.toLowerCase().includes(query) || dapp.description.toLowerCase().includes(query) || dapp.tags.some(tag => tag.includes(query)))
|
|
}
|
|
})
|
|
return filtered
|
|
}
|
|
function searchDapps(e) {
|
|
const query = e.target.value.trim().toLowerCase() || '';
|
|
const category = getRef('category_selector').value || 'all';
|
|
location.hash = `#/home?category=${category}&query=${query}`
|
|
}
|
|
const appHamburgerMenu = (activePage) => html`
|
|
<aside class="hamburger-menu-wrapper">
|
|
<nav id="dapps_menu" class="flex flex-direction-column gap-1 hamburger-menu">
|
|
<h4>Dapps</h4>
|
|
<ul class="flex flex-direction-column gap-0-3">
|
|
${dappsList.map(dapp => html`
|
|
<li>
|
|
<a class=${`hamburger-menu__item interactive ${dapp.moreLink.includes(activePage) ? 'hamburger-menu__item--active' : ''}`} href=${dapp.moreLink}>${dapp.name}</a>
|
|
</li>
|
|
`)}
|
|
</ul>
|
|
</nav>
|
|
<div class="hamburger-menu__overlay" onclick=${closeHamburgerMenu}></div>
|
|
</aside>
|
|
`
|
|
function openHamburgerMenu() {
|
|
if (getRef('dapps_menu'))
|
|
getRef('dapps_menu').parentElement.classList.add('hamburger-menu--open')
|
|
}
|
|
function closeHamburgerMenu() {
|
|
if (getRef('dapps_menu'))
|
|
getRef('dapps_menu').parentElement.classList.remove('hamburger-menu--open')
|
|
}
|
|
router.addRoute('dapps', (state) => {
|
|
const { wildcards: [page], viewTransition } = state;
|
|
getRef('page_container').dataset.page = 'dapps';
|
|
const { name, description, icon, appLink, moreLink, allowDownload = true } = dappsList.find(dapp => dapp.moreLink.includes(page));
|
|
closeHamburgerMenu()
|
|
let dappPage = [
|
|
appHamburgerMenu(page),
|
|
html`
|
|
<section class="flex flex-direction-column gap-1-5">
|
|
<button id="hamburger_menu_trigger" class="margin-right-auto hide-on-large" onclick=${openHamburgerMenu}>
|
|
<svg class="icon" xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"><path d="M0 0h24v24H0V0z" fill="none"/><path d="M3 18h18v-2H3v2zm0-5h18v-2H3v2zm0-7v2h18V6H3z"/></svg>
|
|
</button>
|
|
<div class="flex flex-direction-column gap-0-5">
|
|
<a href="#/home" class="flex align-center" style="margin-left: -0.3rem;">
|
|
<svg class="icon" style="fill: var(--accent-color)" xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"><path d="M0 0h24v24H0V0z" fill="none"/><path d="M15.41 7.41L14 6l-6 6 6 6 1.41-1.41L10.83 12l4.58-4.59z"/></svg>
|
|
<span>Home</span>
|
|
</a>
|
|
<h1>${name}</h1>
|
|
</div>
|
|
<p>${description}</p>
|
|
<div class="flex align-center gap-0-5">
|
|
<button class="button dapp-card__link" onclick=${(e) => checkIntegrity(appLink, e)}>
|
|
Check integrity
|
|
</button>
|
|
${allowDownload ? html`
|
|
<a href=${`https://github.com/ranchimall/${appLink.split('/').pop()}/archive/refs/heads/master.zip`} class="button dapp-card__link dapp-download-button" title="Download dapp Zip">
|
|
Download
|
|
<svg class="icon" xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 24 24" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"><g><rect fill="none" height="24" width="24"/></g><g><path d="M18,15v3H6v-3H4v3c0,1.1,0.9,2,2,2h12c1.1,0,2-0.9,2-2v-3H18z M17,11l-1.41-1.41L13,12.17V4h-2v8.17L8.41,9.59L7,11l5,5 L17,11z"/></g></svg>
|
|
</a>
|
|
`: ''}
|
|
<a href=${appLink} class="button dapp-card__link dapp-card__link--primary margin-right-auto" target="_blank" onclick=${checkLinkBeforeVisiting}>
|
|
Try it
|
|
<svg class="icon" xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"> <path d="M0 0h24v24H0z" fill="none"></path> <path d="M19 19H5V5h7V3H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2v-7h-2v7zM14 3v2h3.59l-9.83 9.83 1.41 1.41L19 6.41V10h2V3h-7z"></path> </svg>
|
|
</a>
|
|
</div>
|
|
</section>
|
|
`
|
|
]
|
|
switch (page) {
|
|
case 'messenger':
|
|
dappPage.push(html`
|
|
`)
|
|
break;
|
|
case 'flo-wallet':
|
|
dappPage.push(html`
|
|
`)
|
|
break;
|
|
}
|
|
renderElem(getRef('page_container'), html`${dappPage}`)
|
|
if (!viewTransition) return
|
|
viewTransition.ready.then(() => {
|
|
document.documentElement.animate(
|
|
[
|
|
{ transform: 'translateX(0)' },
|
|
{ transform: 'translateX(-1rem)' },
|
|
],
|
|
{
|
|
duration: 300,
|
|
easing: 'ease',
|
|
pseudoElement: '::view-transition-old(root)',
|
|
}
|
|
);
|
|
document.documentElement.animate(
|
|
[
|
|
{ transform: 'translateX(1rem)' },
|
|
{ transform: 'translateX(0)' },
|
|
],
|
|
{
|
|
duration: 300,
|
|
easing: 'ease',
|
|
pseudoElement: '::view-transition-new(root)',
|
|
}
|
|
);
|
|
})
|
|
})
|
|
|
|
async function getRepoHash(repoName) {
|
|
if (!repoName) return null
|
|
const response = await fetch(`https://api.github.com/repos/ranchimall/${repoName}/contents/`)
|
|
const json = await response.json()
|
|
const combinedSHA = json.reduce((acc, { sha }) => acc + sha, '')
|
|
return await calculateSHA256(new Blob([combinedSHA]))
|
|
}
|
|
|
|
async function calculateSHA256(blob) {
|
|
const buffer = await blob.arrayBuffer();
|
|
const hashBuffer = await crypto.subtle.digest('SHA-256', buffer);
|
|
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
const hashHex = hashArray.map(byte => byte.toString(16).padStart(2, '0')).join('');
|
|
return hashHex;
|
|
}
|
|
|
|
/**
|
|
* @param { string | []} a single link or array of links
|
|
*/
|
|
async function getLinkContentHash(link) {
|
|
try {
|
|
if (!link) return null
|
|
if (!Array.isArray(link))
|
|
link = [link]
|
|
const data = JSON.stringify({ urls: link })
|
|
return await (await fetch('https://utility-api.ranchimall.net/hash', {
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
method: "POST",
|
|
body: data
|
|
})).json()
|
|
} catch (e) {
|
|
console.error(e)
|
|
return null
|
|
}
|
|
}
|
|
async function checkLinkBeforeVisiting(e) {
|
|
try {
|
|
e.preventDefault();
|
|
const anchor = e.target.closest('a')
|
|
const originalInnerHTML = anchor.innerHTML;
|
|
const link = anchor.href;
|
|
const wrapper = e.target.closest('.flex')
|
|
anchor.classList.remove('dapp-card__link--primary')
|
|
renderElem(anchor, html`
|
|
<sm-spinner></sm-spinner>
|
|
<h4>Checking integrity...</h4>
|
|
`)
|
|
const { hasValidHash, knownHash, latestHash } = await hasAKnownHash(link)
|
|
if (!hasValidHash) {
|
|
renderElem(wrapper, html`
|
|
<strong style="color: var(--danger-color)">Failed integrity check</strong>
|
|
`)
|
|
return
|
|
}
|
|
// restore the original element
|
|
anchor.innerHTML = originalInnerHTML;
|
|
anchor.classList.add('dapp-card__link--primary')
|
|
// open link in new tab
|
|
window.open(link, '_blank')
|
|
}
|
|
catch (e) {
|
|
notify('Integrity check failed. Please try again later.', 'error', {
|
|
timeout: 10000,
|
|
})
|
|
}
|
|
}
|
|
</script>
|
|
</body>
|
|
|
|
</html> |