dapps/index.html
2023-12-11 04:45:58 +05:30

1186 lines
60 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>
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>
`)
})
let dappsList = [
{
"name": "BTC Mortgage",
"description": "Borrow or Lend USD against Bitcoin",
"icon": "",
"appLink": "https://ranchimall.github.io/btcmortgage",
"moreLink": "#/dapps/btc-mortgage",
"tags": [
"bitcoin",
"mortgage",
"lend",
"borrow"
],
"category": "finance",
"repoHash": "197f0c491e8cabf866603d03c437f9b96ad5b58ce55de2f6bc0d39a633fdf5e1",
"appHash": "8a0cc53e479a1c7fb205b38d53a61b670f1b809c82ef1e5bcfddb39b5488d473"
},
{
"name": "BTC Wallet",
"description": "Send and receive Bitcoin and track transactions.",
"icon": "",
"appLink": "https://ranchimall.github.io/btcwallet",
"moreLink": "#/dapps/btc-wallet",
"tags": [
"bitcoin",
"wallet"
],
"category": "wallet",
"repoHash": "15908cd7e375d577132d22309a8d85f801dcb9c6b838ddc8ee2d6da590c6a0fc",
"appHash": "37d7002211272d841b93803c69e79351758bc89c348167805b216ecfd85a5289"
},
{
"name": "Certify",
"description": "Create and distribute blockchain based certificates",
"icon": "",
"appLink": "https://ranchimall.github.io/certify",
"moreLink": "#/dapps/certify",
"tags": [
"certificates",
"certify",
"certification"
],
"category": "identity",
"repoHash": "99f2b66dcd62b2156b4f64cd4eab8a4efc182284fe13cdb8e2a9876d865c0123",
"appHash": "563a97cc5be968d5ffc1511925766bc624df5ae3f71dca5ef48a5030ebe3b5ba"
},
{
"name": "Content Collaboration",
"description": "A writing app that allows you to collaborate with others",
"icon": "",
"appLink": "https://ranchimall.github.io/cc",
"moreLink": "#/dapps/content-collaboration",
"tags": [
"collaboration",
"writing",
"content"
],
"category": "content",
"repoHash": "debdda5bd18f0f4d06876967de5f6dd55f514b9048ec978d435acdbe720a5ff8",
"appHash": "78834ea328f5f3ed247c76cf92086f711dc7e56a14d2e4548d7ef36f358d3380"
},
{
"name": "Exchange",
"description": "Trade FLO and FLO tokens with rupee tokens",
"icon": "",
"appLink": "https://ranchimall.github.io/exchangemarket",
"moreLink": "#/dapps/exchange",
"tags": [
"exchange",
"trade",
"flo",
"rupee"
],
"category": "finance",
"repoHash": "a5dbba6043d82ae04e99a8a522f4ab2d1ba2a2779cdcf4f28c1da2b2acf11df6",
"appHash": "1af17ee38d4b6c7c0ae4ca08fe526899c05fe56074ccac633183e400e039c9f2"
},
{
"name": "FLO Ethereum",
"description": "A Ethereum wallet that works with FLO",
"icon": "",
"appLink": "https://ranchimall.github.io/floethereum",
"moreLink": "#/dapps/flo-ethereum",
"tags": [
"ethereum",
"wallet",
"flo"
],
"category": "wallet",
"repoHash": "6e647729eb0f179045f764d08c44d61178bb84e36e327d026c34a701a9875132",
"appHash": "2f55bd07e27cf2e869854b41883b733b9cd6eb6e4809f6a92e66d62d747a2f91"
},
{
"name": "FLO Scout",
"description": "Track FLO token transactions and utilize smart contracts.",
"icon": "",
"appLink": "https://ranchimall.github.io/floscout",
"moreLink": "#/dapps/flo-scout",
"tags": [
"flo",
"scout",
"smart contracts"
],
"category": "blockchain-explorer",
"repoHash": "cb84c51f35d03e224b4a76d1a27dd19a75f4ac9b785e059696c16206557cfee3",
"appHash": "0d81003141a2b586bd2272a64341e118b70746da35ef7d66662c282173c1752e"
},
{
"name": "FLO Wallet",
"description": "A wallet for FLO",
"icon": "",
"appLink": "https://ranchimall.github.io/flowallet",
"moreLink": "#/dapps/flo-wallet",
"tags": [
"flo",
"wallet"
],
"category": "wallet",
"repoHash": "a6ba8112b57a033cc0124aa3f1761e27b2066226b6604d035e8596d2c662b6b6",
"appHash": "b1ec2cca4c2e083dc9154608224d9b254fb9c4635743b59ccec6363828ca8a39"
},
{
"name": "FLOpay",
"description": "A rupee token payments app based on FLO",
"icon": "",
"appLink": "https://ranchimall.github.io/flopay",
"moreLink": "#/dapps/flopay",
"tags": [
"flo",
"payments",
"rupee"
],
"category": "wallet",
"repoHash": "8cc4313d43468138f26cf13a776876fc21560714d8e5eb1217599af585105a8f",
"appHash": "255b4d1c89974fdd59463d92e84cf8fee3d095be9f1e17f6ff8e1ee52bc24a58"
},
{
"name": "KYC",
"description": "An app to verify your identity",
"icon": "",
"appLink": "https://ranchimall.github.io/kyc",
"moreLink": "#/dapps/kyc",
"tags": [
"kyc",
"identity"
],
"category": "identity",
"repoHash": "247423654e501dab943296ab9a55e60bf4204164aee469f401cecf0b53290671",
"appHash": "4d683316fdc512b375bfc529d5a9aa7eb291ade7460bdf080db6450dc3fb430e"
},
{
"name": "LogSheet",
"description": "Create and manage public and private log sheets",
"icon": "",
"appLink": "https://ranchimall.github.io/flologsheet",
"moreLink": "#/dapps/log-sheet",
"tags": [
"log",
"sheet",
"logsheets"
],
"category": "content",
"repoHash": "5c04711bbeaede85010e26d281a0a246a6f7f104e07a7bfcc5bc5208908647b6",
"appHash": "1650c9888e9b418507d41af3ba76ee14753cfa0faa4f9753dff46fcd2a44047d"
},
{
"name": "Messenger",
"description": "Chat with your Bitcoin, Ethereum and FLO friends or use Bitcoin and FLO multisig.",
"icon": "",
"appLink": "https://ranchimall.github.io/messenger",
"moreLink": "#/dapps/messenger",
"tags": [
"messenger",
"chat",
"bitcoin",
"ethereum",
"flo",
"multisig"
],
"category": "social",
"repoHash": "8713c516c826f10a5258a0962c87e3a26bd54f25d9034d7d2b7dbb7a33e4e914",
"appHash": "188174ab439516d25fe3ba30b18ca7fae07277f97c6df019331b8300d1f68c14"
},
{
"name": "RanchiMall Times",
"description": "A news app that showcases articles created with Content Collaboration app",
"icon": "",
"appLink": "https://ranchimall.github.io/rmtimes",
"moreLink": "#/dapps/ranchimall-times",
"tags": [
"news",
"articles",
"content"
],
"category": "content",
"repoHash": "840823abe525a8be560d58e45af2499de6f45eaf973ce69a500b1df31ca295be",
"appHash": "d63d7fbd5ba8795977a30178ee426705ec41f58ce26a5fd0c6e281492a012766"
},
{
"name": "RIBC",
"description": "RanchiMall Internship Blockchain Contract (RIBC) allows you hire and manage interns.",
"icon": "",
"appLink": "https://ranchimall.github.io/ribc",
"moreLink": "#/dapps/ribc",
"tags": [
"internship",
"contract",
"ribc"
],
"category": "management",
"repoHash": "9e0e44c5d50d7a0f28fb0f8ac4a168b5a1ec93a6e29e41503e1a6a579c567ed8",
"appHash": "ad5145d8526868fe5358ce00d64fc98b1f3f2b02b5e2ee482ef7068a044055ef"
},
{
"name": "Taproot wallet",
"description": "A Bitcoin wallet with Taproot support.",
"icon": "",
"appLink": "https://ranchimall.github.io/taprootwallet",
"moreLink": "#/dapps/taproot-wallet",
"tags": [
"bitcoin",
"wallet",
"taproot"
],
"category": "wallet",
"repoHash": "592bdad38e1b45e41247f054de33b9d71c58d4178d70ca03c22f1def7c97e2c0",
"appHash": "ecad64071b9c4026e94d4e57e76ade152b63f2619d44025f6a7f4f9f31184bc2"
},
{
"name": "Blockchain Bonds",
"description": "Monitor Bitcoin bonds performance",
"icon": "",
"appLink": "https://ranchimall.github.io/blockchainbonds",
"moreLink": "#/dapps/blockchain-bonds",
"tags": [
"bitcoin",
"bonds",
"blockchain"
],
"category": "finance",
"appHash": "5a8795102c2914a2bbf7c4755de288062e1fddfdfa9eef22a52b8f86f92e3fb3",
"repoHash": "661ebe8b28bcf0a14ffe3a485e44dbc65cceab77d1de3bf8f6b2bccfdb1d57b5"
},
{
"name": "Bob's Fund",
"description": "A 20 year Bitcoin fund with 100% profit sharing",
"icon": "",
"appLink": "https://ranchimall.github.io/bobsfund",
"moreLink": "#/dapps/bobs-fund",
"tags": [
"fund",
"bobs",
"bitcoin"
],
"category": "finance",
"appHash": "012c2ef05a0d2d0d551b068cad4aadc2a80c1019d741110f4f94da1bae742825",
"repoHash": "b5b466e8b3e818ad8c95710edc9a770e4964b0ed74cb32366edec646a8f3372d"
},
{
"name": "Blockbook",
"description": "A blockchain explorer for FLO",
"icon": "",
"appLink": "https://blockbook.ranchimall.net/",
"moreLink": "#/dapps/blockbook",
"tags": [
"blockbook",
"flo",
"blockchain"
],
"category": "blockchain-explorer",
"allowDownload": false,
"appHash": "012cd0b6bcb6de664cdecfb93bbdeb4bce53497bf549917dc717ef8b8d35858d",
"repoHash": "1d5cc442744f429fba5ad97ada001bfed2556d0ec7e1443b4ededb65f6ba5c61",
"repoLink": "https://github.com/ranchimall/blockbook"
}
].sort((a, b) => a.name.localeCompare(b.name));
router.addRoute('home', renderHome)
router.addRoute('', renderHome)
function renderDappCard(dapp) {
const { name, description, icon, appLink, moreLink, tags, category, repoHash, allowDownload = true } = dapp;
return html`
<li class="dapp-card" .dataset=${{ appLink, repoHash }}>
<div class="flex space-between">
<div class="dapp-card__icon">
${icon}
</div>
<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">
Try it
<svg class="icon margin-left-0-5" 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 = html`
<div class="flex flex-direction-column gap-1">
<div class="flex flex-direction-column gap-0-3">
<h4>Authorized hash</h4>
<sm-copy value=${knownHash}><p>${knownHash}</p></sm-copy>
</div>
<div class="flex flex-direction-column gap-0-3">
<h4>Latest hash</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>
`)
} else {
renderElem(getRef('integrity_check_popup__content'), html`
<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>
${hashes}
`)
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>
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>
<h4>
Always verify links before entering your private keys
</h4>
</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 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>
<button id="download_all_button" class="button button--colored margin-left-auto" onclick=${downloadAllDapps}>
Download all
</button>
</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)',
}
);
})
}
async function downloadAllDapps() {
const downloadAllButton = getRef('download_all_button')
const downloadAllButtonContent = downloadAllButton.innerHTML
downloadAllButton.innerHTML = 'Downloading...<sm-spinner></sm-spinner>'
pseudoDisable(downloadAllButton, true)
const verificationPromises = dappsList.map(({ appLink }) => {
return new Promise((resolve, reject) => {
const appRepoName = appLink.split('/').pop()
getRepoHash(appRepoName).then(latestHash => {
const { repoHash: knownHash } = dappsList.find(dapp => dapp.appLink === appLink)
if (latestHash !== knownHash) {
notify(`The dapp '${appRepoName}' has failed integrity check. Dapp won't be downloaded.`, 'error')
reject()
} else {
resolve(`https://github.com/ranchimall/${appRepoName}`)
}
}).catch(e => {
console.error(e)
notify('There was an error while trying to download the dapp. Please try again later.', 'error', {
timeout: 10000,
})
reject()
})
})
})
try {
let downloadLinks = await Promise.allSettled(verificationPromises)
downloadLinks = downloadLinks.filter(({ status }) => status === 'fulfilled').map(({ value }) => value)
await downloadReposZipped(downloadLinks)
notify('All verified dapps have been downloaded', 'success')
} catch (e) {
console.error(e)
notify('There was an error while trying to download the dapps. Please try again later.', 'error', {
timeout: 10000,
})
} finally {
downloadAllButton.innerHTML = downloadAllButtonContent
pseudoDisable(downloadAllButton, false)
}
}
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, hasValidHash
const dappInfo = dappsList.find(({ appLink }) => linkToVerify.includes(appLink))
if (!dappInfo) return false
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 = dappInfo.repoHash
} else {
latestHash = await getLinkContentHash(linkToVerify)
latestHash = latestHash[linkToVerify]
knownHash = dappInfo.appHash
}
return { hasValidHash: latestHash === knownHash, 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</h4>
<sm-copy value=${knownHash}><p>${knownHash}</p></sm-copy>
</div>
<div class="flex flex-direction-column gap-0-3">
<h4>Latest hash</h4>
<sm-copy value=${latestHash}><p>${latestHash}</p></sm-copy>
</div>
</div>
`;
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>
<p>The link you provided is genuine</p>
${hashes}
`)
} else {
getRef('verification_form').after(html.node/*html*/`
<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>Link you provided is not genuine</p>
${hashes}
`)
}
} 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()
}
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 margin-left-0-5" 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">
Try it
<svg class="icon margin-left-0-5" 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 = 'messenger') {
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 {
const data = JSON.stringify({ urls: link })
return await (await fetch('https://integrity-api.ranchimall.net/hash', {
headers: {
"Content-Type": "application/json",
},
method: "POST",
body: data
})).json()
} catch (e) {
console.error(e)
return null
}
}
async function downloadReposZipped(repoUrls) {
try {
const data = JSON.stringify({ urls: repoUrls })
const blob = await (await fetch('https://integrity-api.ranchimall.net/download-repos', {
headers: {
"Content-Type": "application/json",
},
method: "POST",
body: data
})).blob()
// download as zip
const a = document.createElement('a')
a.href = URL.createObjectURL(blob)
a.download = 'dapps.zip'
a.click()
URL.revokeObjectURL(a.href)
} catch (e) {
console.error(e)
return null
}
}
</script>
</body>
</html>