dapps/index.html
2023-11-29 01:36:44 +05:30

588 lines
26 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 href="#/home">
<h4>
RanchiMall Dapps
</h4>
</a>
<theme-toggle></theme-toggle>
</header>
<main id="page_container" class="grid"></main>
<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>`
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) {
const { page } = state
if (!page)
page = 'home'
}
})
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>
`)
})
const dappsList = [
{
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'
},
{
name: 'FLO Wallet',
description: 'A wallet for FLO',
icon: ``,
appLink: 'https://ranchimall.github.io/flowallet',
moreLink: '#/dapps/flo-wallet',
tags: ['flo', 'wallet'],
category: 'Wallet'
},
{
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'
},
{
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'
},
{
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'
},
{
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'
},
{
name: 'KYC',
description: 'An app to verify your identity',
icon: ``,
appLink: 'https://ranchimall.github.io/kyc',
moreLink: '#/dapps/kyc',
tags: ['kyc', 'identity'],
category: 'Identity'
},
{
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'
},
{
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'
},
{
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'
},
{
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'
},
{
name: 'LogSheet',
description: 'Create and manage public and private log sheets',
icon: ``,
appLink: 'https://ranchimall.github.io/logsheet',
moreLink: '#/dapps/log-sheet',
tags: ['log', 'sheet', 'logsheets'],
category: 'Content'
},
{
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'
},
{
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'
},
].sort((a, b) => a.name.localeCompare(b.name))
router.addRoute('home', renderHome)
router.addRoute('', renderHome)
function renderDappCard(dapp) {
const { name, description, icon, appLink, moreLink } = dapp;
return html`
<li class="dapp-card">
<div class="dapp-card__icon">
${icon}
</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">
<a href=${`https://github.com/ranchimall/${appLink.split('/').pop()}/archive/refs/heads/master.zip`} class="button dapp-card__link" 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 renderHome(state) {
const { wildcards: [page], viewTransition } = state
getRef('page_container').dataset.page = 'home';
const renderedDappsList = dappsList.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>
<div class="flex align-center space-between gap-1 flex-wrap">
<h4>Our offerings</h4>
<sm-input id="dapp_search_input" type="search" placeholder="Search Dapps" oninput=${searchDapps}>
<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>
</div>
<ul id="dapp_list">${renderedDappsList}</ul>
`)
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)',
}
);
})
}
function searchDapps() {
const searchQuery = getRef('dapp_search_input').value.trim().toLowerCase()
const filtered = dappsList.filter(dapp => dapp.name.toLowerCase().includes(searchQuery))
if (filtered.length === 0) {
renderElem(getRef('dapp_list'), html`
<p>No Dapp related to '${searchQuery}'</p>
`)
} else {
const renderedDappsList = filtered.map((dapp) => renderDappCard(dapp))
renderElem(getRef('dapp_list'), html`${renderedDappsList}`)
}
}
const appHamburgerMenu = (activePage) => html`
<nav id="dapps_menu" class="grid gap-1">
<h4>Dapps</h4>
<ul class="flex flex-direction-column hamburger-menu gap-0-3">
${dappsList.map(dapp => html`
<li>
<a class=${`hamburger-menu__item ${dapp.moreLink.includes(activePage) ? 'hamburger-menu__item--active' : ''}`} href=${dapp.moreLink}>${dapp.name}</a>
</li>
`)}
</ul>
</nav>
`
router.addRoute('dapps', (state) => {
const { wildcards: [page], viewTransition } = state
getRef('page_container').dataset.page = 'dapps';
const { name, description, icon, appLink, moreLink } = dappsList.find(dapp => dapp.moreLink.includes(page))
let dappPage = [
appHamburgerMenu(page),
html`
<section class="flex flex-direction-column gap-1-5">
<h1>${name}</h1>
<p>${description}</p>
</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)',
}
);
})
})
</script>
</body>
</html>