2188 lines
87 KiB
HTML
2188 lines
87 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Bitcoin Bonds on Blockchain</title>
|
|
<script id="floGlobals">
|
|
/* Constants for FLO blockchain operations !!Make sure to add this at begining!! */
|
|
const floGlobals = {
|
|
blockchain: "FLO",
|
|
adminID: "FBBstZ2GretgQqDP55yt8iVd4KNZkdvEzH",
|
|
application: "BlockchainBonds"
|
|
}
|
|
</script>
|
|
<link rel="stylesheet" href="css/main.min.css">
|
|
<link rel="preconnect" href="https://fonts.gstatic.com">
|
|
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400..900&display=swap" rel="stylesheet">
|
|
<script src="scripts/lib.js"></script>
|
|
<script src="scripts/floCrypto.js"></script>
|
|
<script src="scripts/floBlockchainAPI.js"></script>
|
|
<script src="scripts/floExchangeAPI.js"></script>
|
|
<script src="scripts/compactIDB.js"></script>
|
|
<script src="scripts/bonds.js"></script>
|
|
<script>
|
|
function onLoadStartUp() {
|
|
floExchangeAPI.init().then(result => {
|
|
console.debug(result)
|
|
compactIDB.initDB(floGlobals.application, {
|
|
bonds: {},
|
|
closings: {},
|
|
appendix: {}
|
|
}).then(result => getRef('refresh_button').click())
|
|
.catch(error => console.error(error))
|
|
}).catch(error => reject(error))
|
|
}
|
|
</script>
|
|
</head>
|
|
<body onload="onLoadStartUp()" data-theme="light">
|
|
<sm-notifications id="notification_drawer"></sm-notifications>
|
|
<article id="loading_page" class="page">
|
|
<h2 class="h2">Bitcoin Bonds</h2>
|
|
<svg id="loader" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><polygon points="17.76 23.78 17.76 40.22 32 48.44 46.24 40.22 46.24 23.78 32 15.56 17.76 23.78"/><polyline points="17.76 23.78 32 32 46.24 23.78"/><line x1="32" y1="48.44" x2="32" y2="32"/><polyline points="32 2 6.02 17 6.02 47"/><polyline points="57.98 47 57.98 17 32 2"/><polyline points="6.02 47 32 62 57.98 47"/></svg>
|
|
<h4>Loading data from blockchain</h4>
|
|
<footer class="page__footer flex align-center">
|
|
<svg id="rm_logo" class="icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20.46,21.32C20,19.78,18.6,18.59,15.3,17a12.67,12.67,0,0,1-2.64-1.56,4.27,4.27,0,0,1-.79-1,2.6,2.6,0,0,1,0-1.41c.24-.68.49-1,2.43-2.85a7.18,7.18,0,0,0,2.09-2.92,4.25,4.25,0,0,0,0-1.77,6.52,6.52,0,0,0-2.85-3.11c-.56-.36-.81-.4-.81-.15a2.33,2.33,0,0,1-.18.45L12.4,3l-.53-.36c-.28-.21-.64-.41-.77-.49s-.46-.11-.46,0a6.21,6.21,0,0,1-.37.83s-.08,0-.17-.08c-1.15-.83-1.64-1-1.64-.73A7.33,7.33,0,0,1,7.7,3.65C6.48,5.68,5.24,6.7,4,6.7c-.56,0-.54,0-.37.64s.2.58.68.43a3.37,3.37,0,0,0,1.09-.54.86.86,0,0,1,.3-.17,1.34,1.34,0,0,1,.13.39.79.79,0,0,0,.17.4A3.5,3.5,0,0,0,7.37,7.3L7.8,7l.09.34c.12.45.19.51.62.39a4.25,4.25,0,0,0,2.17-1.54l.38-.45,0,.39A5.92,5.92,0,0,1,8.89,9.54L7.67,10.71c-2,1.93-1.89,3.51.37,5a27.41,27.41,0,0,0,2.89,1.51c.17.07.62.32,1,.54C14,19,15,20.23,15,21.48a2,2,0,0,0,0,.49h0c0,.05,0,.05.56-.1a1.89,1.89,0,0,0,.53-.21,2.41,2.41,0,0,0-.34-1.15,7.05,7.05,0,0,0-1.68-1.77,21.91,21.91,0,0,0-3.2-1.83A9.53,9.53,0,0,1,8.16,15.2a2.18,2.18,0,0,1-.74-1.55C7.42,12.79,7.86,12,9,11c1.77-1.64,2.45-2.45,2.92-3.55a2.28,2.28,0,0,0,.26-1.26A2,2,0,0,0,12,5.06l-.2-.45L12,4.3l.28-.49.09-.18L12.6,4a3.69,3.69,0,0,1,.61,1.76A3.47,3.47,0,0,1,12.94,7l-.09.25s-.21.37-.41.69A17.78,17.78,0,0,1,9.91,10.6c-1.07,1-1.43,1.62-1.47,2.47a2.05,2.05,0,0,0,.7,1.73,10.47,10.47,0,0,0,3.28,2.08c2.28,1.13,3.26,1.81,4,2.73a2.94,2.94,0,0,1,.74,1.75,1.26,1.26,0,0,0,.09.57.48.48,0,0,0,.26,0l.51-.13.29-.08,0-.28c-.13-1-1-2-2.47-3a25.52,25.52,0,0,0-3.26-1.77,8.59,8.59,0,0,1-2.23-1.43,2.09,2.09,0,0,1-.5-2.62c.26-.53.5-.83,2.35-2.6,1.51-1.45,2.15-2.58,2.15-3.79A3.67,3.67,0,0,0,13,3.48a3,3,0,0,1-.4-.42A1.85,1.85,0,0,1,13,2.33a6.74,6.74,0,0,1,1.83,1.73,2.62,2.62,0,0,1,.47,1.68,3,3,0,0,1-.55,1.84c-.45.78-.79,1.14-2.67,2.93a5.56,5.56,0,0,0-1.3,1.64,1.77,1.77,0,0,0-.21,1,1.76,1.76,0,0,0,.19.92,6.28,6.28,0,0,0,2.9,2.34,21.6,21.6,0,0,1,3.66,2c1.35,1,2,2,2,3a1.06,1.06,0,0,0,.05.47,2.83,2.83,0,0,0,1-.24C20.56,21.68,20.56,21.66,20.46,21.32ZM7.29,6.4h0a2.23,2.23,0,0,1-.9.28L6,6.72l.43-.53a15.22,15.22,0,0,0,1.89-3,3.52,3.52,0,0,1,.38-.67c.07-.08.49.2,1,.64l.39.35L9.66,4A6.7,6.7,0,0,1,7.29,6.4Zm3.58-1.11A5.8,5.8,0,0,1,9.25,6.51h0a3.3,3.3,0,0,1-.74.17l-.35,0,.39-.49a15.64,15.64,0,0,0,1.32-2,4.63,4.63,0,0,1,.28-.49c.06-.08.33.26.57.77l.28.57Zm1-1.4a1.63,1.63,0,0,1-.28.4A6.63,6.63,0,0,1,11,3.72l-.53-.56.12-.29c.2-.49.24-.51.64-.19a5.57,5.57,0,0,1,.85.78A2.78,2.78,0,0,1,11.87,3.89Z"/></svg>
|
|
<h4 class="h4 color-0-8 weight-500">RanchiMall</h4>
|
|
</footer>
|
|
</article>
|
|
<article id="error_page" class="page hide-completely">
|
|
<h2 class="h2">Bitcoin Bonds</h2>
|
|
<svg class="sad-face" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 500 500">
|
|
<g class="face">
|
|
<g class="eyes">
|
|
<circle cx="187.52" cy="249.17" r="13.42"/>
|
|
<circle cx="312.48" cy="249.17" r="13.42"/>
|
|
</g>
|
|
<path d="M288,349.35a6.07,6.07,0,0,1-3.81-1.34c-.09-.07-12.31-9.4-34.14-9.4S216,347.94,215.83,348a6.1,6.1,0,0,1-7.59-9.55c.61-.5,15.4-12.08,41.76-12.08s41.15,11.58,41.76,12.08A6.1,6.1,0,0,1,288,349.35Z"/>
|
|
<path d="M344.21,237.41a52,52,0,0,1-23.45-6c-15.91-8.09-21.28-19.61-21.5-20.1a4.07,4.07,0,0,1,7.41-3.36c0,.08,4.56,9.49,17.77,16.21S347.93,229,348,229a4.07,4.07,0,0,1,1.63,8A29.26,29.26,0,0,1,344.21,237.41Z"/>
|
|
<path d="M155.79,237.41a29.26,29.26,0,0,1-5.45-.43,4.07,4.07,0,0,1,1.63-8c.2,0,10.43,1.87,23.59-4.81s17.73-16.13,17.78-16.23a4.07,4.07,0,0,1,7.4,3.38c-.22.49-5.59,12-21.5,20.1A52,52,0,0,1,155.79,237.41Z"/>
|
|
</g>
|
|
<path d="M450.16,220.16A200.16,200.16,0,0,0,108.46,78.63,200.69,200.69,0,0,0,57.61,275.68V407.4a10.17,10.17,0,1,0,20.33,0V322.6a201.91,201.91,0,0,0,99.41,84.19v52.27l-11.45.62a10.17,10.17,0,0,0,.54,20.32H167l30.69-1.66V413.45a202.3,202.3,0,0,0,104.62,0v64.88L333,480h.56a10.17,10.17,0,0,0,.54-20.32l-11.45-.62V406.79a201.91,201.91,0,0,0,99.41-84.19v84.8a10.17,10.17,0,1,0,20.33,0V275.68A200.81,200.81,0,0,0,450.16,220.16ZM250,400c-99.16,0-179.83-80.67-179.83-179.83S150.84,40.34,250,40.34,429.83,121,429.83,220.16,349.16,400,250,400Z"/></svg>
|
|
<h4 class="margin-bottom-0-5r">Oops, Couldn't get data from blockchain</h4>
|
|
<footer class="page__footer flex align-center">
|
|
<svg id="rm_logo" class="icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20.46,21.32C20,19.78,18.6,18.59,15.3,17a12.67,12.67,0,0,1-2.64-1.56,4.27,4.27,0,0,1-.79-1,2.6,2.6,0,0,1,0-1.41c.24-.68.49-1,2.43-2.85a7.18,7.18,0,0,0,2.09-2.92,4.25,4.25,0,0,0,0-1.77,6.52,6.52,0,0,0-2.85-3.11c-.56-.36-.81-.4-.81-.15a2.33,2.33,0,0,1-.18.45L12.4,3l-.53-.36c-.28-.21-.64-.41-.77-.49s-.46-.11-.46,0a6.21,6.21,0,0,1-.37.83s-.08,0-.17-.08c-1.15-.83-1.64-1-1.64-.73A7.33,7.33,0,0,1,7.7,3.65C6.48,5.68,5.24,6.7,4,6.7c-.56,0-.54,0-.37.64s.2.58.68.43a3.37,3.37,0,0,0,1.09-.54.86.86,0,0,1,.3-.17,1.34,1.34,0,0,1,.13.39.79.79,0,0,0,.17.4A3.5,3.5,0,0,0,7.37,7.3L7.8,7l.09.34c.12.45.19.51.62.39a4.25,4.25,0,0,0,2.17-1.54l.38-.45,0,.39A5.92,5.92,0,0,1,8.89,9.54L7.67,10.71c-2,1.93-1.89,3.51.37,5a27.41,27.41,0,0,0,2.89,1.51c.17.07.62.32,1,.54C14,19,15,20.23,15,21.48a2,2,0,0,0,0,.49h0c0,.05,0,.05.56-.1a1.89,1.89,0,0,0,.53-.21,2.41,2.41,0,0,0-.34-1.15,7.05,7.05,0,0,0-1.68-1.77,21.91,21.91,0,0,0-3.2-1.83A9.53,9.53,0,0,1,8.16,15.2a2.18,2.18,0,0,1-.74-1.55C7.42,12.79,7.86,12,9,11c1.77-1.64,2.45-2.45,2.92-3.55a2.28,2.28,0,0,0,.26-1.26A2,2,0,0,0,12,5.06l-.2-.45L12,4.3l.28-.49.09-.18L12.6,4a3.69,3.69,0,0,1,.61,1.76A3.47,3.47,0,0,1,12.94,7l-.09.25s-.21.37-.41.69A17.78,17.78,0,0,1,9.91,10.6c-1.07,1-1.43,1.62-1.47,2.47a2.05,2.05,0,0,0,.7,1.73,10.47,10.47,0,0,0,3.28,2.08c2.28,1.13,3.26,1.81,4,2.73a2.94,2.94,0,0,1,.74,1.75,1.26,1.26,0,0,0,.09.57.48.48,0,0,0,.26,0l.51-.13.29-.08,0-.28c-.13-1-1-2-2.47-3a25.52,25.52,0,0,0-3.26-1.77,8.59,8.59,0,0,1-2.23-1.43,2.09,2.09,0,0,1-.5-2.62c.26-.53.5-.83,2.35-2.6,1.51-1.45,2.15-2.58,2.15-3.79A3.67,3.67,0,0,0,13,3.48a3,3,0,0,1-.4-.42A1.85,1.85,0,0,1,13,2.33a6.74,6.74,0,0,1,1.83,1.73,2.62,2.62,0,0,1,.47,1.68,3,3,0,0,1-.55,1.84c-.45.78-.79,1.14-2.67,2.93a5.56,5.56,0,0,0-1.3,1.64,1.77,1.77,0,0,0-.21,1,1.76,1.76,0,0,0,.19.92,6.28,6.28,0,0,0,2.9,2.34,21.6,21.6,0,0,1,3.66,2c1.35,1,2,2,2,3a1.06,1.06,0,0,0,.05.47,2.83,2.83,0,0,0,1-.24C20.56,21.68,20.56,21.66,20.46,21.32ZM7.29,6.4h0a2.23,2.23,0,0,1-.9.28L6,6.72l.43-.53a15.22,15.22,0,0,0,1.89-3,3.52,3.52,0,0,1,.38-.67c.07-.08.49.2,1,.64l.39.35L9.66,4A6.7,6.7,0,0,1,7.29,6.4Zm3.58-1.11A5.8,5.8,0,0,1,9.25,6.51h0a3.3,3.3,0,0,1-.74.17l-.35,0,.39-.49a15.64,15.64,0,0,0,1.32-2,4.63,4.63,0,0,1,.28-.49c.06-.08.33.26.57.77l.28.57Zm1-1.4a1.63,1.63,0,0,1-.28.4A6.63,6.63,0,0,1,11,3.72l-.53-.56.12-.29c.2-.49.24-.51.64-.19a5.57,5.57,0,0,1,.85.78A2.78,2.78,0,0,1,11.87,3.89Z"/></svg>
|
|
<h4 class="h4 color-0-8 weight-500">RanchiMall</h4>
|
|
</footer>
|
|
</article>
|
|
<header id="main_header" class="hide-completely">
|
|
<div class="flex align-center">
|
|
<svg id="main_header__logo" class="icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20.46,21.32C20,19.78,18.6,18.59,15.3,17a12.67,12.67,0,0,1-2.64-1.56,4.27,4.27,0,0,1-.79-1,2.6,2.6,0,0,1,0-1.41c.24-.68.49-1,2.43-2.85a7.18,7.18,0,0,0,2.09-2.92,4.25,4.25,0,0,0,0-1.77,6.52,6.52,0,0,0-2.85-3.11c-.56-.36-.81-.4-.81-.15a2.33,2.33,0,0,1-.18.45L12.4,3l-.53-.36c-.28-.21-.64-.41-.77-.49s-.46-.11-.46,0a6.21,6.21,0,0,1-.37.83s-.08,0-.17-.08c-1.15-.83-1.64-1-1.64-.73A7.33,7.33,0,0,1,7.7,3.65C6.48,5.68,5.24,6.7,4,6.7c-.56,0-.54,0-.37.64s.2.58.68.43a3.37,3.37,0,0,0,1.09-.54.86.86,0,0,1,.3-.17,1.34,1.34,0,0,1,.13.39.79.79,0,0,0,.17.4A3.5,3.5,0,0,0,7.37,7.3L7.8,7l.09.34c.12.45.19.51.62.39a4.25,4.25,0,0,0,2.17-1.54l.38-.45,0,.39A5.92,5.92,0,0,1,8.89,9.54L7.67,10.71c-2,1.93-1.89,3.51.37,5a27.41,27.41,0,0,0,2.89,1.51c.17.07.62.32,1,.54C14,19,15,20.23,15,21.48a2,2,0,0,0,0,.49h0c0,.05,0,.05.56-.1a1.89,1.89,0,0,0,.53-.21,2.41,2.41,0,0,0-.34-1.15,7.05,7.05,0,0,0-1.68-1.77,21.91,21.91,0,0,0-3.2-1.83A9.53,9.53,0,0,1,8.16,15.2a2.18,2.18,0,0,1-.74-1.55C7.42,12.79,7.86,12,9,11c1.77-1.64,2.45-2.45,2.92-3.55a2.28,2.28,0,0,0,.26-1.26A2,2,0,0,0,12,5.06l-.2-.45L12,4.3l.28-.49.09-.18L12.6,4a3.69,3.69,0,0,1,.61,1.76A3.47,3.47,0,0,1,12.94,7l-.09.25s-.21.37-.41.69A17.78,17.78,0,0,1,9.91,10.6c-1.07,1-1.43,1.62-1.47,2.47a2.05,2.05,0,0,0,.7,1.73,10.47,10.47,0,0,0,3.28,2.08c2.28,1.13,3.26,1.81,4,2.73a2.94,2.94,0,0,1,.74,1.75,1.26,1.26,0,0,0,.09.57.48.48,0,0,0,.26,0l.51-.13.29-.08,0-.28c-.13-1-1-2-2.47-3a25.52,25.52,0,0,0-3.26-1.77,8.59,8.59,0,0,1-2.23-1.43,2.09,2.09,0,0,1-.5-2.62c.26-.53.5-.83,2.35-2.6,1.51-1.45,2.15-2.58,2.15-3.79A3.67,3.67,0,0,0,13,3.48a3,3,0,0,1-.4-.42A1.85,1.85,0,0,1,13,2.33a6.74,6.74,0,0,1,1.83,1.73,2.62,2.62,0,0,1,.47,1.68,3,3,0,0,1-.55,1.84c-.45.78-.79,1.14-2.67,2.93a5.56,5.56,0,0,0-1.3,1.64,1.77,1.77,0,0,0-.21,1,1.76,1.76,0,0,0,.19.92,6.28,6.28,0,0,0,2.9,2.34,21.6,21.6,0,0,1,3.66,2c1.35,1,2,2,2,3a1.06,1.06,0,0,0,.05.47,2.83,2.83,0,0,0,1-.24C20.56,21.68,20.56,21.66,20.46,21.32ZM7.29,6.4h0a2.23,2.23,0,0,1-.9.28L6,6.72l.43-.53a15.22,15.22,0,0,0,1.89-3,3.52,3.52,0,0,1,.38-.67c.07-.08.49.2,1,.64l.39.35L9.66,4A6.7,6.7,0,0,1,7.29,6.4Zm3.58-1.11A5.8,5.8,0,0,1,9.25,6.51h0a3.3,3.3,0,0,1-.74.17l-.35,0,.39-.49a15.64,15.64,0,0,0,1.32-2,4.63,4.63,0,0,1,.28-.49c.06-.08.33.26.57.77l.28.57Zm1-1.4a1.63,1.63,0,0,1-.28.4A6.63,6.63,0,0,1,11,3.72l-.53-.56.12-.29c.2-.49.24-.51.64-.19a5.57,5.57,0,0,1,.85.78A2.78,2.78,0,0,1,11.87,3.89Z"/></svg>
|
|
<div class="grid">
|
|
<h5 class="header__company-name">RanchiMall</h5>
|
|
<h3 class="header__app-name">Bitcoin Bonds</h3>
|
|
</div>
|
|
</div>
|
|
<div id="current_price" class="grid gap-1 flow-column align-center">
|
|
<span id="btc-usd-rate" class="weight-700"></span>
|
|
<span id="usd-rate" class="weight-700"></span>
|
|
</div>
|
|
<div class="dropdown">
|
|
<button id="profile_button" onclick="changeDropdownState('profile_dropdown', 'toggle', this)">
|
|
<svg class="icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M11.93,0a4.8,4.8,0,0,0-4.8,4.8s.13,3.74.54,4.53c.5,1,3,3,4.26,3s3.72-2,4.22-3c.41-.79.58-4.53.58-4.53A4.8,4.8,0,0,0,11.93,0Z"/><path d="M14.47,12.59a4.38,4.38,0,0,1-2.54,1,4.38,4.38,0,0,1-2.53-1c-1,1.78-4,2.69-6.21,3.68-.91.37-1.67,5.3-.61,5.3A18.4,18.4,0,0,0,12.12,24a16.76,16.76,0,0,0,9.17-2.42c1.06,0,.3-4.89-.61-5.3C18.45,15.28,15.42,14.37,14.47,12.59Z"/></svg>
|
|
</button>
|
|
<ul id="profile_dropdown" class="dropdown__panel hide-completely">
|
|
<li class="grid gap-0-5">
|
|
<h4 class="weight-700 margin-bottom-0-5r">Preferred currency</h4>
|
|
<p>This will convert all amounts to preferred currency.</p>
|
|
<sm-select id="currency_selector" align-select="right" class="justify-self-start">
|
|
<sm-option value="inr">INR</sm-option>
|
|
<sm-option value="usd">USD</sm-option>
|
|
</sm-select>
|
|
</li>
|
|
<li>
|
|
<sm-switch id="theme_switcher">
|
|
<div slot="left" class="flex weight-700">Dark theme</div>
|
|
</sm-switch>
|
|
</li>
|
|
<li class="interact weight-700" onclick="showPage('add_bond_page')">
|
|
Add Bond (Admin only!)
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
</header>
|
|
|
|
<main id="home_page" class="page page-layout hide-completely">
|
|
<section id="homepage__hero-section" class="full-bleed page-layout">
|
|
<h2 class="h2 weight-700 margin-bottom-1r">Bitcoin Bonds <br>on FLO Blockchain</h2>
|
|
<p>Bondholders get a minimum guarantee of typically 13% interest per annum during the lock-in period or typically 50% of all Bitcoin price gains whichever is higher. <br> <strong> It offers full capital protection if Bitcoin prices fall below acquisition price.</strong></p>
|
|
</section>
|
|
<header class="bond-list__header grid">
|
|
<h4 class="h4">Recent</h4>
|
|
<sm-input id="search_bonds" type="search" placeholder="Search bonds with FLO ID">
|
|
<svg slot="icon" class="icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><path fill="none" d="M0 0h24v24H0z"/><path d="M18.031 16.617l4.283 4.282-1.415 1.415-4.282-4.283A8.96 8.96 0 0 1 11 20c-4.968 0-9-4.032-9-9s4.032-9 9-9 9 4.032 9 9a8.96 8.96 0 0 1-1.969 5.617zm-2.006-.742A6.977 6.977 0 0 0 18 11c0-3.868-3.133-7-7-7-3.868 0-7 3.132-7 7 0 3.867 3.132 7 7 7a6.977 6.977 0 0 0 4.875-1.975l.15-.15z"/></svg>
|
|
</sm-input>
|
|
<button id="refresh_button" class="justify-right button--primary">Refresh</button>
|
|
</header>
|
|
<ul id="bond_list"></ul>
|
|
<div id="bond_list__empty-state" class="grid hide-completely">
|
|
<svg class="icon icon--big" 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 10zm0-2a8 8 0 1 0 0-16 8 8 0 0 0 0 16zm-4-6h8v2H8v-2zm0-3a1.5 1.5 0 1 1 0-3 1.5 1.5 0 0 1 0 3zm8 0a1.5 1.5 0 1 1 0-3 1.5 1.5 0 0 1 0 3z"/></svg>
|
|
<h4>No bonds found</h4>
|
|
</div>
|
|
</main>
|
|
<article id="add_bond_page" class="page page-layout hide-completely">
|
|
<header class="flex margin-top-1-5 align-center margin-bottom-1-5r">
|
|
<button class="back-button" onclick="showPage('home_page')">
|
|
<svg class="icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><path fill="none" d="M0 0h24v24H0z"/><path d="M7.828 11H20v2H7.828l5.364 5.364-1.414 1.414L4 12l7.778-7.778 1.414 1.414z"/></svg>
|
|
</button>
|
|
<h3>Admin Panel</h3>
|
|
</header>
|
|
<form id="add_bond_form" class="grid gap-1-5">
|
|
<label class="grid gap-0-5">
|
|
FLO ID
|
|
<input type="text" name="floid" pattern="[0-9a-zA-Z]{34}" required>
|
|
</label>
|
|
<label class="grid gap-0-5">
|
|
Amount (₹)
|
|
<input type="text" inputmode="numeric" name="amount" pattern="\d.+" required>
|
|
</label>
|
|
<label class="grid gap-0-5">
|
|
Bond start date
|
|
<input type="date" name="start_date" required>
|
|
</label>
|
|
<label class="grid gap-0-5">
|
|
Base BTC value ($)
|
|
<input type="text" name="base" pattern="[\d,]+(.\d+)?" required>
|
|
</label>
|
|
<label class="grid gap-0-5">
|
|
Base USD rate (₹)
|
|
<input type="number" inputmode="numeric" name="usd_rate" min=0 step="0.01" required>
|
|
</label>
|
|
<label class="grid gap-0-5">
|
|
Guaranteed interest rate (%)
|
|
<input type="number" inputmode="numeric" name="gi_r" min=0 max=100 step="0.01" required>
|
|
</label>
|
|
<div class="grid gap-0-5">
|
|
Guaranteed interest period
|
|
<div class="flex">
|
|
<input type="number" inputmode="numeric" name="gi_pv" required>
|
|
<sm-select id="gi_pt" align-select="right">
|
|
<sm-option value="year(s)" selected>year(s)</sm-option>
|
|
<sm-option value="month(s)">month(s)</sm-option>
|
|
<sm-option value="week(s)">week(s)</sm-option>
|
|
<sm-option value="day(s)">day(s)</sm-option>
|
|
</sm-select>
|
|
</div>
|
|
</div>
|
|
<label class="grid gap-0-5">
|
|
Gain share (%)
|
|
<input type="number" inputmode="numeric" name="cut" min=0 max=100 required>
|
|
</label>
|
|
<div class="grid gap-0-5">
|
|
Lock-in period
|
|
<div class="flex">
|
|
<input type="number" inputmode="numeric" name="lockin_v" required>
|
|
<sm-select id="lockin_t" align-select="right">
|
|
<sm-option value="year(s)" selected>year(s)</sm-option>
|
|
<sm-option value="month(s)">month(s)</sm-option>
|
|
<sm-option value="week(s)">week(s)</sm-option>
|
|
<sm-option value="day(s)">day(s)</sm-option>
|
|
</sm-select>
|
|
</div>
|
|
</div>
|
|
<div class="grid flow-column align-center gap-1 justify-start">
|
|
<button type="submit" class="button--primary">Continue</button>
|
|
<button type="reset">Clear</button>
|
|
</div>
|
|
</form>
|
|
</article>
|
|
<article id="confirm_bond_page" class="page page-layout hide-completely">
|
|
<header class="flex margin-top-1-5 align-center margin-bottom-1-5r">
|
|
<button class="back-button" onclick="showPage('add_bond_page')">
|
|
<svg class="icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><path fill="none" d="M0 0h24v24H0z"/><path d="M7.828 11H20v2H7.828l5.364 5.364-1.414 1.414L4 12l7.778-7.778 1.414 1.414z"/></svg>
|
|
</button>
|
|
<h3>Confirm Details</h3>
|
|
</header>
|
|
<form class="grid gap-1-5" onsubmit="return false">
|
|
<section id="bond_details"></section>
|
|
<div class="grid">
|
|
<h4 class="weight-400 margin-bottom-1r" id="admin_id"></h4>
|
|
<sm-input id="get_private_key" type="password" placeholder="Private key"></sm-input>
|
|
</div>
|
|
<button id="add_bond_button" type="submit" class="button--primary justify-self-start">Add Bond</button>
|
|
</form>
|
|
</article>
|
|
<script id="ui">
|
|
|
|
const render = {
|
|
bondPlaceholder(){
|
|
const bond = document.createElement('li')
|
|
bond.classList.add('bond-placeholder', 'grid')
|
|
bond.innerHTML = `
|
|
<div class="placeholder__block"></div>
|
|
<div class="placeholder__block"></div>
|
|
<div class="flex-grid justify-start">
|
|
<div class="placeholder__block"></div>
|
|
<div class="placeholder__block"></div>
|
|
<div class="placeholder__block"></div>
|
|
</div>
|
|
<div class="grid flow-column gap-1 justify-end">
|
|
<div class="placeholder__block"></div>
|
|
<div class="placeholder__block"></div>
|
|
</div>
|
|
`
|
|
return bond
|
|
}
|
|
}
|
|
|
|
const bondTemplate = document.createElement('template')
|
|
bondTemplate.innerHTML = `
|
|
<style>
|
|
a:any-link,
|
|
button{
|
|
position: relative;
|
|
display: inline-flex;
|
|
align-items: center;
|
|
background: none;
|
|
cursor: pointer;
|
|
outline: none;
|
|
color: inherit;
|
|
font-weight: 500;
|
|
font-size: 0.8rem;
|
|
border-radius: 0.3rem;
|
|
padding: 0.4rem 0.6rem;
|
|
align-self: flex-start;
|
|
text-decoration: none;
|
|
-webkit-tap-highlight-color: transparent;
|
|
border: 1px solid rgba(var(--text-color), 0.8);
|
|
}
|
|
a:any-link:focus-visible,
|
|
button:focus-visible{
|
|
outline: rgba(var(--text-color), 1) 0.1rem solid;
|
|
}
|
|
.flex{
|
|
display: flex;
|
|
}
|
|
.grid{
|
|
display: grid;
|
|
}
|
|
.gap-1{
|
|
gap: 1rem;
|
|
}
|
|
.flow-column{
|
|
grid-auto-flow: column;
|
|
}
|
|
.justify-end{
|
|
justify-content: flex-end;
|
|
}
|
|
.hide-completely{
|
|
display: none !important;
|
|
}
|
|
.flex-grid{
|
|
display: grid;
|
|
gap: 1rem;
|
|
justify-content: start;
|
|
grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr));
|
|
}
|
|
.bond-transaction{
|
|
display: grid;
|
|
gap: 1rem;
|
|
padding: 1rem;
|
|
border-radius: 0.3rem;
|
|
background-color: rgba(var(--foreground-color), 1);
|
|
}
|
|
.transaction-column{
|
|
display: flex;
|
|
flex-direction: column;
|
|
}
|
|
.label{
|
|
font-weight: 500;
|
|
font-size: 0.75rem;
|
|
margin-bottom: 0.2rem;
|
|
color: rgba(var(--text-color), 0.8);
|
|
}
|
|
.value{
|
|
font-weight: 600;
|
|
font-size: 0.9rem;
|
|
overflow-wrap: break-word;
|
|
word-wrap: break-word;
|
|
-ms-word-break: break-all;
|
|
word-break: break-word;
|
|
-ms-hyphens: auto;
|
|
-moz-hyphens: auto;
|
|
-webkit-hyphens: auto;
|
|
hyphens: auto;
|
|
}
|
|
@media only screen and (min-width: 640px) {
|
|
.bond-transaction{
|
|
gap: 1.5rem;
|
|
padding: 1.5rem;
|
|
grid-template-columns: 1fr auto;
|
|
}
|
|
.justify-self-end{
|
|
justify-self: flex-end;
|
|
text-align: right;
|
|
}
|
|
}
|
|
</style>
|
|
<li class="bond-transaction">
|
|
<div class="transaction-column">
|
|
<span class="label">FLO ID</span>
|
|
<span class="value flo-id"></span>
|
|
</div>
|
|
<div class="transaction-column justify-self-end">
|
|
<span class="label">Bond starting date</span>
|
|
<span class="value bond-start-date"></span>
|
|
</div>
|
|
<div class="flex-grid">
|
|
<div class="transaction-column">
|
|
<span class="label">Invested</span>
|
|
<span class="value amount-invested-primary"></span>
|
|
</div>
|
|
<div class="transaction-column">
|
|
<span class="label">Present bond value</span>
|
|
<span class="value net-value-primary" style="color: var(--green)"></span>
|
|
</div>
|
|
<div class="transaction-column">
|
|
<span class="label">Guaranteed interest</span>
|
|
<span class="value guaranteed-interest"></span>
|
|
</div>
|
|
</div>
|
|
<div class="grid gap-1 flow-column justify-end">
|
|
<a class="link" target="_blank">View on blockchain</a>
|
|
<button>More details</button>
|
|
</div>
|
|
<div class="more-details flex-grid hide-completely">
|
|
<div class="transaction-column">
|
|
<span class="label">Gain share</span>
|
|
<span class="value gain-share"></span>
|
|
</div>
|
|
<div class="transaction-column">
|
|
<span class="label">Lock-in period</span>
|
|
<span class="value lock-in-period"></span>
|
|
</div>
|
|
<div class="transaction-column">
|
|
<span class="label">Lock-in end date</span>
|
|
<span class="value bond-end-date"></span>
|
|
</div>
|
|
<div class="transaction-column">
|
|
<span class="label">Base BTC rate</span>
|
|
<span class="value base-btc-rate"></span>
|
|
</div>
|
|
<div class="transaction-column">
|
|
<span class="label">USD rate</span>
|
|
<span class="value usd-rate"></span>
|
|
</div>
|
|
<div class="transaction-column">
|
|
<span class="label"></span>
|
|
<span class="value amount-invested-sec"></span>
|
|
</div>
|
|
<div class="transaction-column">
|
|
<span class="label"></span>
|
|
<span class="value net-value-sec" style="color: var(--green)"></span>
|
|
</div>
|
|
</div>
|
|
</li>
|
|
`
|
|
customElements.define('bond-transaction', class extends HTMLElement {
|
|
constructor() {
|
|
super()
|
|
this.shadow = this.attachShadow({
|
|
mode: 'open'
|
|
})
|
|
this.shadow.append(bondTemplate.content.cloneNode(true))
|
|
this.amountInvested = {}
|
|
this.netValue = {}
|
|
this.moreDetailsButton = this.shadow.querySelector('button')
|
|
this.moreDetails = this.shadow.querySelector('.more-details')
|
|
this.areDetailsOpen = false
|
|
}
|
|
set data(obj){
|
|
const {
|
|
href,
|
|
floId,
|
|
bondStartDate,
|
|
amountInvested,
|
|
netValue,
|
|
guaranteedInterest,
|
|
guaranteedInterestDuration,
|
|
gainShare,
|
|
lockinPeriod,
|
|
lockinEnd,
|
|
baseBtcRate,
|
|
usdRate
|
|
} = obj
|
|
|
|
|
|
this.amountInvested = amountInvested
|
|
this.netValue = netValue
|
|
|
|
for (let item in this.amountInvested){
|
|
this.amountInvested[item] = parseFloat(this.amountInvested[item])
|
|
}
|
|
|
|
for (let item in this.netValue){
|
|
this.netValue[item] = parseFloat(this.netValue[item])
|
|
}
|
|
|
|
this.dataset.floId = floId
|
|
this.shadow.querySelector('.link').href = href
|
|
this.shadow.querySelector('.flo-id').textContent = floId
|
|
this.shadow.querySelector('.bond-start-date').textContent = bondStartDate
|
|
this.shadow.querySelector('.bond-end-date').textContent = lockinEnd
|
|
this.shadow.querySelector('.guaranteed-interest').textContent = `${guaranteedInterest} P.A for ${guaranteedInterestDuration}`
|
|
this.shadow.querySelector('.gain-share').textContent = gainShare
|
|
this.shadow.querySelector('.lock-in-period').textContent = lockinPeriod
|
|
this.shadow.querySelector('.base-btc-rate').textContent = `${parseFloat(baseBtcRate).toLocaleString(`en-US`, {style: 'currency', currency: 'USD'})}`
|
|
this.shadow.querySelector('.usd-rate').textContent = `₹${usdRate}`
|
|
this.toggleCurrency()
|
|
}
|
|
|
|
toggleCurrency = () => {
|
|
const secCurrency = preferredCurrency === 'usd' ? 'inr' : 'usd'
|
|
this.shadow.querySelector('.amount-invested-primary').textContent = `${this.amountInvested[preferredCurrency].toLocaleString(`en-${preferredCurrency.substring(0,2)}`, {style: 'currency', currency: preferredCurrency})}`
|
|
this.shadow.querySelector('.amount-invested-sec').textContent = `${this.amountInvested[secCurrency].toLocaleString(`en-${secCurrency.substring(0,2)}`, {style: 'currency', currency: secCurrency})}`
|
|
this.shadow.querySelector('.amount-invested-sec').previousElementSibling.textContent = `Invested(${secCurrency.toUpperCase()})`
|
|
this.shadow.querySelector('.net-value-primary').textContent = `${this.netValue[preferredCurrency].toLocaleString(`en-${preferredCurrency.substring(0,2)}`, {style: 'currency', currency: preferredCurrency})}`
|
|
this.shadow.querySelector('.net-value-sec').textContent = `${this.netValue[secCurrency].toLocaleString(`en-${secCurrency.substring(0,2)}`, {style: 'currency', currency: secCurrency})}`
|
|
this.shadow.querySelector('.net-value-sec').previousElementSibling.textContent = `Present bond value(${secCurrency.toUpperCase()})`
|
|
}
|
|
|
|
toggleDetails = () => {
|
|
if(this.areDetailsOpen){
|
|
this.moreDetailsButton.textContent = 'More details'
|
|
this.moreDetails.classList.add('hide-completely')
|
|
this.areDetailsOpen = false
|
|
}
|
|
else{
|
|
this.moreDetailsButton.textContent = 'Less details'
|
|
this.moreDetails.classList.remove('hide-completely')
|
|
this.areDetailsOpen = true
|
|
}
|
|
}
|
|
|
|
connectedCallback(){
|
|
this.moreDetailsButton.addEventListener('click', this.toggleDetails)
|
|
}
|
|
|
|
disconnectedCallback(){
|
|
this.moreDetailsButton.removeEventListener('click', this.toggleDetails)
|
|
}
|
|
})
|
|
|
|
//Input
|
|
const smInput = document.createElement('template')
|
|
smInput.innerHTML = `
|
|
<style>
|
|
*{
|
|
padding: 0;
|
|
margin: 0;
|
|
-webkit-box-sizing: border-box;
|
|
box-sizing: border-box;
|
|
}
|
|
input[type="search"]::-webkit-search-decoration,
|
|
input[type="search"]::-webkit-search-cancel-button,
|
|
input[type="search"]::-webkit-search-results-button,
|
|
input[type="search"]::-webkit-search-results-decoration { display: none; }
|
|
input[type=number] {
|
|
-moz-appearance:textfield;
|
|
}
|
|
input[type=number]::-webkit-inner-spin-button,
|
|
input[type=number]::-webkit-outer-spin-button {
|
|
-webkit-appearance: none;
|
|
-moz-appearance: none;
|
|
appearance: none;
|
|
margin: 0;
|
|
}
|
|
input::-ms-reveal,
|
|
input::-ms-clear {
|
|
display: none;
|
|
}
|
|
input:invalid{
|
|
outline: none;
|
|
-webkit-box-shadow: none;
|
|
box-shadow: none;
|
|
}
|
|
::-moz-focus-inner{
|
|
border: none;
|
|
}
|
|
:host{
|
|
display: -webkit-box;
|
|
display: -ms-flexbox;
|
|
display: flex;
|
|
--font-size: 1rem;
|
|
--border-radius: 0.3rem;
|
|
--padding: 0.7rem 1rem;
|
|
--background: rgba(var(--text-color), 0.06);
|
|
}
|
|
.hide{
|
|
opacity: 0 !important;
|
|
pointer-events: none !important;
|
|
}
|
|
.hide-completely{
|
|
display: none;
|
|
}
|
|
.icon {
|
|
fill: rgba(var(--text-color), 0.6);
|
|
height: 1.4rem;
|
|
width: 1.4rem;
|
|
border-radius: 1rem;
|
|
cursor: pointer;
|
|
min-width: 0;
|
|
}
|
|
|
|
:host(.round) .input{
|
|
border-radius: 10rem;
|
|
}
|
|
.input {
|
|
display: -webkit-box;
|
|
display: -ms-flexbox;
|
|
display: flex;
|
|
cursor: text;
|
|
min-width: 0;
|
|
text-align: left;
|
|
-webkit-box-align: center;
|
|
-ms-flex-align: center;
|
|
align-items: center;
|
|
position: relative;
|
|
gap: 0.5rem;
|
|
padding: var(--padding);
|
|
border-radius: var(--border-radius);
|
|
-webkit-transition: opacity 0.3s;
|
|
-o-transition: opacity 0.3s;
|
|
transition: opacity 0.3s;
|
|
background: var(--background);
|
|
width: 100%;
|
|
outline: none;
|
|
}
|
|
.input.readonly .clear{
|
|
opacity: 0 !important;
|
|
margin-right: -2rem;
|
|
pointer-events: none !important;
|
|
}
|
|
.readonly{
|
|
pointer-events: none;
|
|
}
|
|
.input:focus-within:not(.readonly){
|
|
box-shadow: 0 0 0 0.1rem var(--accent-color) inset !important;
|
|
}
|
|
.disabled{
|
|
pointer-events: none;
|
|
opacity: 0.6;
|
|
}
|
|
.label {
|
|
opacity: .7;
|
|
font-size: var(--font-size);
|
|
font-weight: var(--font-weight);
|
|
position: absolute;
|
|
top: 0;
|
|
-webkit-transition: -webkit-transform 0.3s;
|
|
transition: -webkit-transform 0.3s;
|
|
-o-transition: transform 0.3s;
|
|
transition: transform 0.3s;
|
|
transition: transform 0.3s, -webkit-transform 0.3s;
|
|
-webkit-transform-origin: left;
|
|
-ms-transform-origin: left;
|
|
transform-origin: left;
|
|
pointer-events: none;
|
|
white-space: nowrap;
|
|
overflow: hidden;
|
|
-o-text-overflow: ellipsis;
|
|
text-overflow: ellipsis;
|
|
width: 100%;
|
|
user-select: none;
|
|
will-change: transform;
|
|
}
|
|
.outer-container{
|
|
position: relative;
|
|
width: 100%;
|
|
}
|
|
.container{
|
|
width: 100%;
|
|
display: -webkit-box;
|
|
display: -ms-flexbox;
|
|
display: flex;
|
|
position: relative;
|
|
-webkit-box-align: center;
|
|
-ms-flex-align: center;
|
|
align-items: center;
|
|
-webkit-box-flex: 1;
|
|
-ms-flex: 1;
|
|
flex: 1;
|
|
}
|
|
input{
|
|
font-size: var(--font-size);
|
|
border: none;
|
|
background: transparent;
|
|
outline: none;
|
|
color: rgba(var(--text-color), 1);
|
|
width: 100%;
|
|
font-weight: var(--font-weight);
|
|
}
|
|
:host(:not(.outlined)) .animate-label .container input {
|
|
-webkit-transform: translateY(0.6rem);
|
|
-ms-transform: translateY(0.6rem);
|
|
transform: translateY(0.6rem);
|
|
}
|
|
|
|
:host(:not(.outlined)) .animate-label .label {
|
|
-webkit-transform: translateY(-0.7em) scale(0.8);
|
|
-ms-transform: translateY(-0.7em) scale(0.8);
|
|
transform: translateY(-0.7em) scale(0.8);
|
|
opacity: 1;
|
|
color: var(--accent-color)
|
|
}
|
|
:host(.outlined) .input {
|
|
box-shadow: 0 0 0 0.1rem rgba(var(--text-color), 0.4) inset;
|
|
background: rgba(var(--foreground-color), 1);
|
|
}
|
|
:host(.outlined) .label {
|
|
width: max-content;
|
|
margin-left: -0.5rem;
|
|
padding: 0 0.5rem;
|
|
}
|
|
:host(.outlined) .animate-label .label {
|
|
-webkit-transform: translate(0.1rem, -1.5rem) scale(0.8);
|
|
-ms-transform: translate(0.1rem, -1.5rem) scale(0.8);
|
|
transform: translate(0.1rem, -1.5rem) scale(0.8);
|
|
opacity: 1;
|
|
background: rgba(var(--foreground-color), 1);
|
|
}
|
|
.animate-label:focus-within:not(.readonly) .label{
|
|
color: var(--accent-color)
|
|
}
|
|
.feedback-text{
|
|
font-size: 0.9rem;
|
|
width: 100%;
|
|
color: var(--error-color);
|
|
padding: 0.6rem 1rem;
|
|
text-align: left;
|
|
}
|
|
.feedback-text:empty{
|
|
padding: 0;
|
|
}
|
|
@media (any-hover: hover){
|
|
.icon:hover{
|
|
background: rgba(var(--text-color), 0.1);
|
|
}
|
|
}
|
|
</style>
|
|
<div class="outer-container">
|
|
<label part="input" class="input">
|
|
<slot name="icon"></slot>
|
|
<div class="container">
|
|
<input/>
|
|
<div part="placeholder" class="label"></div>
|
|
</div>
|
|
<svg class="icon clear hide" 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 10zm0-11.414L9.172 7.757 7.757 9.172 10.586 12l-2.829 2.828 1.415 1.415L12 13.414l2.828 2.829 1.415-1.415L13.414 12l2.829-2.828-1.415-1.415L12 10.586z"/></svg>
|
|
</label>
|
|
<div class="feedback-text"></div>
|
|
</div>
|
|
`;
|
|
customElements.define('sm-input',
|
|
class extends HTMLElement {
|
|
|
|
constructor() {
|
|
super()
|
|
this.attachShadow({
|
|
mode: 'open'
|
|
}).append(smInput.content.cloneNode(true))
|
|
}
|
|
|
|
static get observedAttributes() {
|
|
return ['placeholder']
|
|
}
|
|
|
|
get value() {
|
|
return this.shadowRoot.querySelector('input').value
|
|
}
|
|
|
|
set value(val) {
|
|
this.shadowRoot.querySelector('input').value = val;
|
|
this.checkInput()
|
|
this.fireEvent()
|
|
}
|
|
|
|
get placeholder() {
|
|
return this.getAttribute('placeholder')
|
|
}
|
|
|
|
set placeholder(val) {
|
|
this.setAttribute('placeholder', val)
|
|
}
|
|
|
|
get type() {
|
|
return this.getAttribute('type')
|
|
}
|
|
|
|
get isValid() {
|
|
return this.shadowRoot.querySelector('input').checkValidity()
|
|
}
|
|
|
|
get validity() {
|
|
return this.shadowRoot.querySelector('input').validity
|
|
}
|
|
|
|
set disabled(value) {
|
|
if (value)
|
|
this.shadowRoot.querySelector('.input').classList.add('disabled')
|
|
else
|
|
this.shadowRoot.querySelector('.input').classList.remove('disabled')
|
|
}
|
|
set readOnly(value) {
|
|
if (value) {
|
|
this.shadowRoot.querySelector('input').setAttribute('readonly', '')
|
|
this.shadowRoot.querySelector('.input').classList.add('readonly')
|
|
} else {
|
|
this.shadowRoot.querySelector('input').removeAttribute('readonly')
|
|
this.shadowRoot.querySelector('.input').classList.remove('readonly')
|
|
}
|
|
}
|
|
|
|
setValidity = (message) => {
|
|
this.feedbackText.textContent = message
|
|
}
|
|
|
|
showValidity = () => {
|
|
this.feedbackText.classList.remove('hide-completely')
|
|
}
|
|
|
|
hideValidity = () => {
|
|
this.feedbackText.classList.add('hide-completely')
|
|
}
|
|
|
|
focusIn = () => {
|
|
this.input.focus()
|
|
}
|
|
|
|
focusOut = () => {
|
|
this.input.blur()
|
|
}
|
|
|
|
fireEvent = () => {
|
|
let event = new Event('input', {
|
|
bubbles: true,
|
|
cancelable: true,
|
|
composed: true
|
|
});
|
|
this.dispatchEvent(event);
|
|
}
|
|
|
|
checkInput = (e) => {
|
|
if (!this.readonly) {
|
|
if (this.input.value !== '') {
|
|
this.clearBtn.classList.remove('hide')
|
|
} else {
|
|
this.clearBtn.classList.add('hide')
|
|
}
|
|
}
|
|
if (!this.hasAttribute('placeholder') || this.getAttribute('placeholder') === '') return;
|
|
if (this.input.value !== '') {
|
|
if (this.animate)
|
|
this.inputParent.classList.add('animate-label')
|
|
else
|
|
this.label.classList.add('hide')
|
|
} else {
|
|
if (this.animate)
|
|
this.inputParent.classList.remove('animate-label')
|
|
else
|
|
this.label.classList.remove('hide')
|
|
}
|
|
}
|
|
|
|
|
|
connectedCallback() {
|
|
this.inputParent = this.shadowRoot.querySelector('.input')
|
|
this.clearBtn = this.shadowRoot.querySelector('.clear')
|
|
this.label = this.shadowRoot.querySelector('.label')
|
|
this.feedbackText = this.shadowRoot.querySelector('.feedback-text')
|
|
this.valueChanged = false;
|
|
this.readonly = false
|
|
this.isNumeric = false
|
|
this.min
|
|
this.max
|
|
this.animate = this.hasAttribute('animate')
|
|
this.input = this.shadowRoot.querySelector('input')
|
|
this.shadowRoot.querySelector('.label').textContent = this.getAttribute('placeholder')
|
|
if (this.hasAttribute('value')) {
|
|
this.input.value = this.getAttribute('value')
|
|
this.checkInput()
|
|
}
|
|
if (this.hasAttribute('required')) {
|
|
this.input.setAttribute('required', '')
|
|
}
|
|
if (this.hasAttribute('min')) {
|
|
let minValue = this.getAttribute('min')
|
|
this.input.setAttribute('min', minValue)
|
|
this.min = parseInt(minValue)
|
|
}
|
|
if (this.hasAttribute('max')) {
|
|
let maxValue = this.getAttribute('max')
|
|
this.input.setAttribute('max', maxValue)
|
|
this.max = parseInt(maxValue)
|
|
}
|
|
if (this.hasAttribute('minlength')) {
|
|
const minValue = this.getAttribute('minlength')
|
|
this.input.setAttribute('minlength', minValue)
|
|
}
|
|
if (this.hasAttribute('maxlength')) {
|
|
const maxValue = this.getAttribute('maxlength')
|
|
this.input.setAttribute('maxlength', maxValue)
|
|
}
|
|
if (this.hasAttribute('step')) {
|
|
const steps = this.getAttribute('step')
|
|
this.input.setAttribute('step', steps)
|
|
}
|
|
if (this.hasAttribute('pattern')) {
|
|
this.input.setAttribute('pattern', this.getAttribute('pattern'))
|
|
}
|
|
if (this.hasAttribute('readonly')) {
|
|
this.input.setAttribute('readonly', '')
|
|
this.readonly = true
|
|
}
|
|
if (this.hasAttribute('disabled')) {
|
|
this.inputParent.classList.add('disabled')
|
|
}
|
|
if (this.hasAttribute('error-text')) {
|
|
this.feedbackText.textContent = this.getAttribute('error-text')
|
|
}
|
|
if (this.hasAttribute('type')) {
|
|
if (this.getAttribute('type') === 'number') {
|
|
this.input.setAttribute('inputmode', 'numeric')
|
|
this.input.setAttribute('type', 'number')
|
|
this.isNumeric = true
|
|
} else
|
|
this.input.setAttribute('type', this.getAttribute('type'))
|
|
} else
|
|
this.input.setAttribute('type', 'text')
|
|
this.input.addEventListener('input', e => {
|
|
this.checkInput(e)
|
|
})
|
|
this.clearBtn.addEventListener('click', e => {
|
|
this.value = ''
|
|
})
|
|
}
|
|
|
|
attributeChangedCallback(name, oldValue, newValue) {
|
|
if (oldValue !== newValue) {
|
|
if (name === 'placeholder') {
|
|
this.shadowRoot.querySelector('.label').textContent = newValue;
|
|
this.setAttribute('aria-label', newValue);
|
|
}
|
|
}
|
|
}
|
|
})
|
|
|
|
|
|
|
|
const smSelect = document.createElement('template')
|
|
smSelect.innerHTML = `
|
|
<style>
|
|
*{
|
|
padding: 0;
|
|
margin: 0;
|
|
-webkit-box-sizing: border-box;
|
|
box-sizing: border-box;
|
|
}
|
|
:host{
|
|
display: -webkit-inline-box;
|
|
display: -ms-inline-flexbox;
|
|
display: inline-flex;
|
|
--max-height: auto;
|
|
--border: solid 1px rgba(var(--text-color), 0.2);
|
|
--arrow-fill: rgba(var(--text-color), 0.7);
|
|
--selection-font-size: inherit;
|
|
}
|
|
.icon {
|
|
height: 1.4rem;
|
|
width: 1.4rem;
|
|
margin-left: 0.5rem;
|
|
fill: var(--arrow-fill);
|
|
}
|
|
.hide{
|
|
opacity: 0;
|
|
pointer-events: none;
|
|
}
|
|
.select{
|
|
position: relative;
|
|
display: -webkit-box;
|
|
display: -ms-flexbox;
|
|
display: flex;
|
|
-webkit-box-orient: vertical;
|
|
-webkit-box-direction: normal;
|
|
-ms-flex-direction: column;
|
|
flex-direction: column;
|
|
cursor: pointer;
|
|
width: 100%;
|
|
-webkit-tap-highlight-color: transparent;
|
|
}
|
|
.option-text{
|
|
overflow: hidden;
|
|
-o-text-overflow: ellipsis;
|
|
text-overflow: ellipsis;
|
|
white-space: nowrap;
|
|
font-weight: 700;
|
|
font-size: var(--selection-font-size);
|
|
}
|
|
.selection{
|
|
border-radius: 0.3rem;
|
|
display: -ms-grid;
|
|
display: grid;
|
|
-ms-grid-columns: 1fr auto;
|
|
grid-template-columns: 1fr auto;
|
|
grid-template-areas: 'heading heading' '. .';
|
|
padding: 0.4rem 1rem;
|
|
background: rgba(var(--text-color), 0.06);
|
|
border: var(--border);
|
|
-webkit-box-align: center;
|
|
-ms-flex-align: center;
|
|
align-items: center;
|
|
outline: none;
|
|
}
|
|
.selection:focus-visible{
|
|
-webkit-box-shadow: 0 0 0 0.1rem rgba(var(--text-color), 1);
|
|
box-shadow: 0 0 0 0.1rem rgba(var(--text-color), 1);
|
|
}
|
|
:host([align-select="left"]) .options{
|
|
left: 0;
|
|
}
|
|
:host([align-select="right"]) .options{
|
|
right: 0;
|
|
}
|
|
.options{
|
|
top: 100%;
|
|
margin-top: 0.5rem;
|
|
overflow: hidden auto;
|
|
position: absolute;
|
|
grid-area: options;
|
|
display: -webkit-box;
|
|
display: -ms-flexbox;
|
|
display: flex;
|
|
-webkit-box-orient: vertical;
|
|
-webkit-box-direction: normal;
|
|
-ms-flex-direction: column;
|
|
flex-direction: column;
|
|
min-width: 100%;
|
|
max-height: var(--max-height);
|
|
background: rgba(var(--foreground-color), 1);
|
|
-webkit-transition: opacity 0.3s, top 0.3s;
|
|
-o-transition: opacity 0.3s, top 0.3s;
|
|
transition: opacity 0.3s, top 0.3s;
|
|
border: solid 1px rgba(var(--text-color), 0.2);
|
|
border-radius: 0.3rem;
|
|
z-index: 2;
|
|
-webkit-box-shadow: 0.4rem 0.8rem 1.2rem #00000030;
|
|
box-shadow: 0.4rem 0.8rem 1.2rem #00000030;
|
|
}
|
|
.rotate{
|
|
-webkit-transform: rotate(180deg);
|
|
-ms-transform: rotate(180deg);
|
|
transform: rotate(180deg)
|
|
}
|
|
</style>
|
|
<div class="select" >
|
|
<div class="selection" tabindex="0">
|
|
<div class="option-text"></div>
|
|
<svg class="icon toggle" 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 13.172l4.95-4.95 1.414 1.414L12 16 5.636 9.636 7.05 8.222z"/></svg>
|
|
</div>
|
|
<div part="options" aria-hidden="true" class="options hide">
|
|
<slot></slot>
|
|
</div>
|
|
</div>`;
|
|
customElements.define('sm-select', class extends HTMLElement {
|
|
constructor() {
|
|
super()
|
|
this.attachShadow({
|
|
mode: 'open'
|
|
}).append(smSelect.content.cloneNode(true))
|
|
this.availableOptions
|
|
this.optionList = this.shadowRoot.querySelector('.options')
|
|
this.chevron = this.shadowRoot.querySelector('.toggle')
|
|
this.optionText = this.shadowRoot.querySelector('.option-text')
|
|
}
|
|
static get observedAttributes() {
|
|
return ['value']
|
|
}
|
|
get value() {
|
|
return this.getAttribute('value')
|
|
}
|
|
set value(val) {
|
|
this.setAttribute('value', val)
|
|
this.optionText.textContent = val;
|
|
}
|
|
|
|
open = () => {
|
|
this.optionList.classList.remove('hide')
|
|
this.optionList.animate(this.slideDown, this.animationOptions)
|
|
this.availableOptions.forEach((element, index) => {
|
|
element.setAttribute('tabindex', "0");
|
|
})
|
|
this.chevron.classList.add('rotate')
|
|
this.isOpen = true
|
|
}
|
|
|
|
collapse = () => {
|
|
this.optionList.animate(this.slideUp, this.animationOptions)
|
|
this.optionList.setAttribute('aria-hidden', 'true')
|
|
this.availableOptions.forEach((element, index) => {
|
|
element.setAttribute('tabindex', "-1");
|
|
})
|
|
this.optionList.classList.add('hide')
|
|
this.chevron.classList.remove('rotate')
|
|
this.isOpen = false
|
|
}
|
|
connectedCallback() {
|
|
let slot = this.shadowRoot.querySelector('.options slot'),
|
|
selection = this.shadowRoot.querySelector('.selection'),
|
|
previousOption
|
|
this.isOpen = false;
|
|
this.slideDown = [{
|
|
transform: `translateY(-0.5rem)`
|
|
},
|
|
{
|
|
transform: `translateY(0)`
|
|
}
|
|
],
|
|
this.slideUp = [{
|
|
transform: `translateY(0)`
|
|
},
|
|
{
|
|
transform: `translateY(-0.5rem)`
|
|
}
|
|
],
|
|
this.animationOptions = {
|
|
duration: 300,
|
|
fill: "forwards",
|
|
easing: 'ease'
|
|
}
|
|
selection.addEventListener('click', e => {
|
|
if (!this.isOpen) {
|
|
this.open()
|
|
} else {
|
|
this.collapse()
|
|
}
|
|
})
|
|
selection.addEventListener('keydown', e => {
|
|
if (e.code === 'ArrowDown' || e.code === 'ArrowRight') {
|
|
e.preventDefault()
|
|
this.availableOptions[0].focus()
|
|
}
|
|
if (e.code === 'Enter' || e.code === 'Space')
|
|
if (!this.isOpen) {
|
|
this.open()
|
|
} else {
|
|
this.collapse()
|
|
}
|
|
})
|
|
this.optionList.addEventListener('keydown', e => {
|
|
if (e.code === 'ArrowUp' || e.code === 'ArrowRight') {
|
|
e.preventDefault()
|
|
if (document.activeElement.previousElementSibling) {
|
|
document.activeElement.previousElementSibling.focus()
|
|
}
|
|
}
|
|
if (e.code === 'ArrowDown' || e.code === 'ArrowLeft') {
|
|
e.preventDefault()
|
|
if (document.activeElement.nextElementSibling)
|
|
document.activeElement.nextElementSibling.focus()
|
|
}
|
|
})
|
|
this.addEventListener('optionSelected', e => {
|
|
if (previousOption !== e.target) {
|
|
this.setAttribute('value', e.detail.value)
|
|
this.optionText.textContent = e.detail.text;
|
|
this.dispatchEvent(new CustomEvent('change', {
|
|
bubbles: true,
|
|
composed: true,
|
|
detail: {
|
|
value: e.detail.value
|
|
}
|
|
}))
|
|
if (previousOption) {
|
|
previousOption.classList.remove('check-selected')
|
|
}
|
|
previousOption = e.target;
|
|
}
|
|
if (!e.detail.switching)
|
|
this.collapse()
|
|
|
|
e.target.classList.add('check-selected')
|
|
})
|
|
slot.addEventListener('slotchange', e => {
|
|
this.availableOptions = slot.assignedElements()
|
|
if (this.availableOptions[0]) {
|
|
this.availableOptions.forEach(option => {
|
|
if(option.hasAttribute('selected')){
|
|
this.optionText.textContent = option.textContent
|
|
this.setAttribute('value', option.getAttribute('value'))
|
|
option.classList.add('check-selected')
|
|
previousOption = option
|
|
}
|
|
})
|
|
}
|
|
});
|
|
document.addEventListener('mousedown', e => {
|
|
if (!this.contains(e.target) && this.isOpen) {
|
|
this.collapse()
|
|
}
|
|
})
|
|
}
|
|
})
|
|
|
|
// option
|
|
const smOption = document.createElement('template')
|
|
smOption.innerHTML = `
|
|
<style>
|
|
*{
|
|
padding: 0;
|
|
margin: 0;
|
|
-webkit-box-sizing: border-box;
|
|
box-sizing: border-box;
|
|
}
|
|
:host{
|
|
display: -webkit-box;
|
|
display: -ms-flexbox;
|
|
display: flex;
|
|
--color: inherit;
|
|
}
|
|
.option{
|
|
min-width: 100%;
|
|
padding: 0.8rem 1.2rem;
|
|
cursor: pointer;
|
|
overflow-wrap: break-word;
|
|
outline: none;
|
|
display: -webkit-box;
|
|
display: -ms-flexbox;
|
|
display: flex;
|
|
color: var(--color);
|
|
-webkit-box-align: center;
|
|
-ms-flex-align: center;
|
|
align-items: center;
|
|
}
|
|
:host(:focus){
|
|
outline: none;
|
|
background: rgba(var(--text-color), 0.1);
|
|
}
|
|
:host(:focus) .option .icon{
|
|
opacity: 0.4
|
|
}
|
|
:host(.check-selected) .icon{
|
|
opacity: 1 !important
|
|
}
|
|
.icon {
|
|
margin-right: 0.8rem;
|
|
fill: none;
|
|
height: 0.8rem;
|
|
width: 0.8rem;
|
|
stroke: rgba(var(--text-color), 0.7);
|
|
stroke-width: 10;
|
|
overflow: visible;
|
|
stroke-linecap: round;
|
|
border-radius: 1rem;
|
|
stroke-linejoin: round;
|
|
opacity: 0;
|
|
}
|
|
@media (hover: hover){
|
|
.option:hover{
|
|
background: rgba(var(--text-color), 0.1);
|
|
}
|
|
.option:hover .icon{
|
|
opacity: 0.4
|
|
}
|
|
}
|
|
</style>
|
|
<div class="option">
|
|
<svg class="icon" viewBox="0 0 64 64">
|
|
<polyline points="0.35 31.82 21.45 52.98 63.65 10.66"/>
|
|
</svg>
|
|
<slot></slot>
|
|
</div>`;
|
|
customElements.define('sm-option', class extends HTMLElement {
|
|
constructor() {
|
|
super()
|
|
this.attachShadow({
|
|
mode: 'open'
|
|
}).append(smOption.content.cloneNode(true))
|
|
}
|
|
|
|
sendDetails(switching) {
|
|
let optionSelected = new CustomEvent('optionSelected', {
|
|
bubbles: true,
|
|
composed: true,
|
|
detail: {
|
|
text: this.textContent,
|
|
value: this.getAttribute('value'),
|
|
switching: switching
|
|
}
|
|
})
|
|
this.dispatchEvent(optionSelected)
|
|
}
|
|
|
|
connectedCallback() {
|
|
let validKey = [
|
|
'ArrowUp',
|
|
'ArrowDown',
|
|
'ArrowLeft',
|
|
'ArrowRight'
|
|
]
|
|
this.addEventListener('click', e => {
|
|
this.sendDetails()
|
|
})
|
|
this.addEventListener('keyup', e => {
|
|
if (e.code === 'Enter' || e.code === 'Space') {
|
|
e.preventDefault()
|
|
this.sendDetails(false)
|
|
}
|
|
if (validKey.includes(e.code)) {
|
|
e.preventDefault()
|
|
this.sendDetails(true)
|
|
}
|
|
})
|
|
}
|
|
})
|
|
|
|
const smSwitch = document.createElement('template')
|
|
smSwitch.innerHTML = `
|
|
<style>
|
|
*{
|
|
-webkit-box-sizing: border-box;
|
|
box-sizing: border-box;
|
|
padding: 0;
|
|
margin: 0;
|
|
}
|
|
|
|
:host{
|
|
display: -webkit-inline-box;
|
|
display: -ms-inline-flexbox;
|
|
display: inline-flex;
|
|
}
|
|
label{
|
|
display: -webkit-box;
|
|
display: -ms-flexbox;
|
|
display: flex;
|
|
-webkit-box-align: center;
|
|
-ms-flex-align: center;
|
|
align-items: center;
|
|
width: 100%;
|
|
outline: none;
|
|
cursor: pointer;
|
|
-webkit-tap-highlight-color: transparent;
|
|
}
|
|
:host(:not([disabled])) label:focus-visible{
|
|
-webkit-box-shadow: 0 0 0 0.1rem var(--accent-color);
|
|
box-shadow: 0 0 0 0.1rem var(--accent-color);
|
|
}
|
|
:host([disabled]) {
|
|
cursor: not-allowed;
|
|
opacity: 0.6;
|
|
pointer-events: none;
|
|
}
|
|
.switch {
|
|
position: relative;
|
|
display: -webkit-box;
|
|
display: -ms-flexbox;
|
|
display: flex;
|
|
-webkit-box-align: center;
|
|
-ms-flex-align: center;
|
|
align-items: center;
|
|
width: 2.4rem;
|
|
flex-shrink: 0;
|
|
margin-left: auto;
|
|
padding: 0.2rem;
|
|
cursor: pointer;
|
|
border-radius: 2rem;
|
|
}
|
|
|
|
input {
|
|
display: none;
|
|
}
|
|
|
|
.track {
|
|
position: absolute;
|
|
left: 0;
|
|
right: 0;
|
|
height: 1.4rem;
|
|
-webkit-transition: background 0.3s;
|
|
-o-transition: background 0.3s;
|
|
transition: background 0.3s;
|
|
background: rgba(var(--text-color), 0.4);
|
|
-webkit-box-shadow: 0 0.1rem 0.3rem #00000040 inset;
|
|
box-shadow: 0 0.1rem 0.3rem #00000040 inset;
|
|
border-radius: 1rem;
|
|
}
|
|
|
|
.switch:active .button::after,
|
|
.switch:focus .button::after{
|
|
opacity: 1
|
|
}
|
|
.switch:focus-visible .button::after{
|
|
opacity: 1
|
|
}
|
|
|
|
.button::after{
|
|
content: '';
|
|
display: -webkit-box;
|
|
display: -ms-flexbox;
|
|
display: flex;
|
|
position: absolute;
|
|
height: 2.6rem;
|
|
width: 2.6rem;
|
|
background: rgba(var(--text-color), 0.2);
|
|
border-radius: 2rem;
|
|
opacity: 0;
|
|
-webkit-transition: opacity 0.3s;
|
|
-o-transition: opacity 0.3s;
|
|
transition: opacity 0.3s;
|
|
}
|
|
|
|
.button {
|
|
position: relative;
|
|
display: -webkit-inline-box;
|
|
display: -ms-inline-flexbox;
|
|
display: inline-flex;
|
|
height: 1rem;
|
|
width: 1rem;
|
|
-webkit-box-pack: center;
|
|
-ms-flex-pack: center;
|
|
justify-content: center;
|
|
-webkit-box-align: center;
|
|
-ms-flex-align: center;
|
|
align-items: center;
|
|
border-radius: 1rem;
|
|
-webkit-box-shadow: 0 0.1rem 0.4rem #00000060;
|
|
box-shadow: 0 0.1rem 0.4rem #00000060;
|
|
-webkit-transition: -webkit-transform 0.3s;
|
|
transition: -webkit-transform 0.3s;
|
|
-o-transition: transform 0.3s;
|
|
transition: transform 0.3s;
|
|
transition: transform 0.3s, -webkit-transform 0.3s;
|
|
border: solid 0.3rem white;
|
|
}
|
|
|
|
input:checked ~ .button {
|
|
-webkit-transform: translateX(100%);
|
|
-ms-transform: translateX(100%);
|
|
transform: translateX(100%);
|
|
}
|
|
|
|
input:checked ~ .track {
|
|
background: var(--accent-color);
|
|
}
|
|
</style>
|
|
<label tabindex="0">
|
|
<slot name="left"></slot>
|
|
<div part="switch" class="switch">
|
|
<input type="checkbox">
|
|
<div class="track"></div>
|
|
<div class="button"></div>
|
|
</div>
|
|
</label>`
|
|
|
|
customElements.define('sm-switch', class extends HTMLElement {
|
|
constructor() {
|
|
super()
|
|
this.attachShadow({
|
|
mode: 'open'
|
|
}).append(smSwitch.content.cloneNode(true))
|
|
this.switch = this.shadowRoot.querySelector('.switch');
|
|
this.input = this.shadowRoot.querySelector('input')
|
|
this.isChecked = false
|
|
this.isDisabled = false
|
|
}
|
|
|
|
static get observedAttributes() {
|
|
return ['disabled', 'checked']
|
|
}
|
|
|
|
get disabled() {
|
|
return this.isDisabled
|
|
}
|
|
|
|
set disabled(val) {
|
|
if (val) {
|
|
this.setAttribute('disabled', '')
|
|
} else {
|
|
this.removeAttribute('disabled')
|
|
}
|
|
}
|
|
|
|
get checked() {
|
|
return this.isChecked
|
|
}
|
|
|
|
set checked(value) {
|
|
if (value) {
|
|
this.setAttribute('checked', '')
|
|
} else {
|
|
this.removeAttribute('checked')
|
|
}
|
|
}
|
|
|
|
dispatch = () => {
|
|
this.dispatchEvent(new CustomEvent('change', {
|
|
bubbles: true,
|
|
composed: true
|
|
}))
|
|
}
|
|
|
|
connectedCallback() {
|
|
this.addEventListener('keyup', e => {
|
|
if ((e.code === "Enter" || e.code === "Space") && !this.isDisabled) {
|
|
this.input.click()
|
|
}
|
|
})
|
|
this.input.addEventListener('click', e => {
|
|
if (this.input.checked)
|
|
this.checked = true
|
|
else
|
|
this.checked = false
|
|
this.dispatch()
|
|
})
|
|
}
|
|
attributeChangedCallback(name, oldValue, newValue) {
|
|
if (oldValue !== newValue) {
|
|
if (name === 'disabled') {
|
|
if (this.hasAttribute('disabled')) {
|
|
this.disabled = true
|
|
}
|
|
else {
|
|
this.disabled = false
|
|
}
|
|
}
|
|
else if (name === 'checked') {
|
|
if (this.hasAttribute('checked')) {
|
|
this.isChecked = true
|
|
this.input.checked = true
|
|
}
|
|
else {
|
|
this.isChecked = false
|
|
this.input.checked = false
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
})
|
|
|
|
//notifications
|
|
|
|
const smNotifications = document.createElement('template')
|
|
smNotifications.innerHTML = `
|
|
<style>
|
|
*{
|
|
padding: 0;
|
|
margin: 0;
|
|
-webkit-box-sizing: border-box;
|
|
box-sizing: border-box;
|
|
}
|
|
:host{
|
|
display: -webkit-box;
|
|
display: -ms-flexbox;
|
|
display: flex;
|
|
}
|
|
.hide{
|
|
opacity: 0 !important;
|
|
pointer-events: none !important;
|
|
}
|
|
.notification-panel{
|
|
display: -ms-grid;
|
|
display: grid;
|
|
width: 100%;
|
|
position: fixed;
|
|
top: 0;
|
|
right: 0;
|
|
z-index: 100;
|
|
max-height: 100%;
|
|
overflow: hidden auto;
|
|
-ms-scroll-chaining: none;
|
|
overscroll-behavior: contain;
|
|
}
|
|
.no-transformations{
|
|
-webkit-transform: none;
|
|
-ms-transform: none;
|
|
transform: none;
|
|
opacity: 1;
|
|
}
|
|
.notification-panel:empty{
|
|
display:none;
|
|
}
|
|
.notification{
|
|
display: -webkit-box;
|
|
display: -ms-flexbox;
|
|
display: flex;
|
|
opacity: 0;
|
|
padding: 1rem 1.5rem;
|
|
margin-bottom: 0.5rem;
|
|
-webkit-transform: translateY(-1rem);
|
|
-ms-transform: translateY(-1rem);
|
|
transform: translateY(-1rem);
|
|
position: relative;
|
|
border-radius: 0.3rem;
|
|
-webkit-box-shadow: 0 0.1rem 0.2rem rgba(0, 0, 0, 0.1),
|
|
0.5rem 1rem 2rem rgba(0, 0, 0, 0.1);
|
|
box-shadow: 0 0.1rem 0.2rem rgba(0, 0, 0, 0.1),
|
|
0.5rem 1rem 2rem rgba(0, 0, 0, 0.1);
|
|
background: rgba(var(--foreground-color), 1);
|
|
-webkit-transition: height 0.3s, opacity 0.3s, -webkit-transform 0.3s;
|
|
transition: height 0.3s, opacity 0.3s, -webkit-transform 0.3s;
|
|
-o-transition: height 0.3s, transform 0.3s, opacity 0.3s;
|
|
transition: height 0.3s, transform 0.3s, opacity 0.3s;
|
|
transition: height 0.3s, transform 0.3s, opacity 0.3s, -webkit-transform 0.3s;
|
|
overflow: hidden;
|
|
overflow-wrap: break-word;
|
|
word-wrap: break-word;
|
|
-ms-word-break: break-all;
|
|
word-break: break-all;
|
|
word-break: break-word;
|
|
-ms-hyphens: auto;
|
|
-webkit-hyphens: auto;
|
|
hyphens: auto;
|
|
max-width: 100%;
|
|
touch-action: none;
|
|
}
|
|
h4:first-letter,
|
|
p:first-letter{
|
|
text-transform: uppercase;
|
|
}
|
|
h4{
|
|
font-weight: 400;
|
|
}
|
|
p{
|
|
line-height: 1.6;
|
|
-webkit-box-flex: 1;
|
|
-ms-flex: 1;
|
|
flex: 1;
|
|
color: rgba(var(--text-color), 0.9);
|
|
overflow-wrap: break-word;
|
|
overflow-wrap: break-word;
|
|
word-wrap: break-word;
|
|
-ms-word-break: break-all;
|
|
word-break: break-all;
|
|
word-break: break-word;
|
|
-ms-hyphens: auto;
|
|
-webkit-hyphens: auto;
|
|
hyphens: auto;
|
|
max-width: 100%;
|
|
}
|
|
.notification:last-of-type{
|
|
margin-bottom: 0;
|
|
}
|
|
.icon {
|
|
fill: none;
|
|
height: 1.6rem;
|
|
width: 1.6rem;
|
|
stroke: rgba(var(--text-color), 0.7);
|
|
overflow: visible;
|
|
stroke-linecap: round;
|
|
border-radius: 1rem;
|
|
stroke-linejoin: round;
|
|
cursor: pointer;
|
|
}
|
|
.error-icon{
|
|
stroke: #E53935;
|
|
}
|
|
.success-icon{
|
|
stroke: #00C853;
|
|
}
|
|
.close{
|
|
margin-left: 1rem;
|
|
padding: 0.5rem;
|
|
stroke-width: 10;
|
|
}
|
|
.notification-icon{
|
|
height: 1.4rem;
|
|
width: 1.4rem;
|
|
margin: 0.3em 1rem 0 0;
|
|
stroke-width: 6;
|
|
}
|
|
@media screen and (min-width: 640px){
|
|
.notification-panel{
|
|
max-width: 28rem;
|
|
width: max-content;
|
|
-webkit-box-pack: end;
|
|
-ms-flex-pack: end;
|
|
justify-content: flex-end;
|
|
}
|
|
.notification{
|
|
-ms-grid-column-align: end;
|
|
justify-self: end;
|
|
width: auto;
|
|
margin-right: 1.5rem;
|
|
margin-bottom: 1rem;
|
|
border-bottom: none;
|
|
border: solid 1px rgba(var(--text-color), 0.2);
|
|
-webkit-transform: translateX(1rem);
|
|
-ms-transform: translateX(1rem);
|
|
transform: translateX(1rem);
|
|
}
|
|
}
|
|
@media screen and (any-hover: none){
|
|
.close{
|
|
display: none
|
|
}
|
|
}
|
|
</style>
|
|
<div class="notification-panel"></div>
|
|
`
|
|
|
|
customElements.define('sm-notifications', class extends HTMLElement {
|
|
constructor() {
|
|
super()
|
|
this.shadow = this.attachShadow({
|
|
mode: 'open'
|
|
}).append(smNotifications.content.cloneNode(true))
|
|
}
|
|
|
|
handleTouchStart = (e) => {
|
|
this.notification = e.target.closest('.notification')
|
|
this.touchStartX = e.changedTouches[0].clientX
|
|
this.notification.style.transition = 'initial'
|
|
this.touchStartTime = e.timeStamp
|
|
}
|
|
|
|
handleTouchMove = (e) => {
|
|
e.preventDefault()
|
|
if (this.touchStartX < e.changedTouches[0].clientX) {
|
|
this.offset = e.changedTouches[0].clientX - this.touchStartX;
|
|
this.touchEndAnimataion = requestAnimationFrame(this.movePopup)
|
|
} else {
|
|
this.offset = -(this.touchStartX - e.changedTouches[0].clientX);
|
|
this.touchEndAnimataion = requestAnimationFrame(this.movePopup)
|
|
}
|
|
}
|
|
|
|
handleTouchEnd = (e) => {
|
|
this.notification.style.transition = 'transform 0.3s, opacity 0.3s'
|
|
this.touchEndTime = e.timeStamp
|
|
cancelAnimationFrame(this.touchEndAnimataion)
|
|
this.touchEndX = e.changedTouches[0].clientX
|
|
if (this.touchEndTime - this.touchStartTime > 200) {
|
|
if (this.touchEndX - this.touchStartX > this.threshold) {
|
|
this.removeNotification(this.notification)
|
|
} else if (this.touchStartX - this.touchEndX > this.threshold) {
|
|
this.removeNotification(this.notification, true)
|
|
} else {
|
|
this.resetPosition()
|
|
}
|
|
} else {
|
|
if (this.touchEndX > this.touchStartX) {
|
|
this.removeNotification(this.notification)
|
|
} else {
|
|
this.removeNotification(this.notification, true)
|
|
}
|
|
}
|
|
}
|
|
|
|
movePopup = () => {
|
|
this.notification.style.transform = `translateX(${this.offset}px)`
|
|
}
|
|
|
|
resetPosition = () => {
|
|
this.notification.style.transform = `translateX(0)`
|
|
}
|
|
|
|
push = (messageBody, type, pinned) => {
|
|
let notification = document.createElement('div'),
|
|
composition = ``
|
|
notification.classList.add('notification')
|
|
if (pinned)
|
|
notification.classList.add('pinned')
|
|
if (type === 'error') {
|
|
composition += `
|
|
<svg class="notification-icon icon error-icon" viewBox="0 0 64 64">
|
|
<path d="M32,4.73a3.17,3.17,0,0,1,2.76,1.59l13.9,24.09L62.57,54.49a3.19,3.19,0,0,1-2.76,4.78H4.19a3.19,3.19,0,0,1-2.76-4.78L15.34,30.41,29.24,6.32A3.17,3.17,0,0,1,32,4.73m0-1a4.14,4.14,0,0,0-3.62,2.09L14.47,29.91.57,54a4.19,4.19,0,0,0,3.62,6.28H59.81A4.19,4.19,0,0,0,63.43,54L49.53,29.91,35.62,5.82A4.14,4.14,0,0,0,32,3.73Z"/>
|
|
<line x1="32" y1="24" x2="32" y2="36"/>
|
|
<line x1="32" y1="46" x2="32" y2="48"/>
|
|
</svg>`
|
|
} else if (type === 'success') {
|
|
composition += `
|
|
<svg class="notification-icon icon success-icon" viewBox="0 0 64 64">
|
|
<polyline points="0.35 31.82 21.45 52.98 63.65 10.66"/>
|
|
</svg>`
|
|
}
|
|
composition += `
|
|
<p>${messageBody}</p>
|
|
<svg class="icon close" viewBox="0 0 64 64">
|
|
<title>Close</title>
|
|
<line x1="64" y1="0" x2="0" y2="64"/>
|
|
<line x1="64" y1="64" x2="0" y2="0"/>
|
|
</svg>`
|
|
notification.innerHTML = composition
|
|
this.notificationPanel.prepend(notification)
|
|
if (window.innerWidth > 640) {
|
|
notification.animate([{
|
|
transform: `translateX(1rem)`,
|
|
opacity: '0'
|
|
},
|
|
{
|
|
transform: 'translateX(0)',
|
|
opacity: '1'
|
|
}
|
|
], this.animationOptions).onfinish = () => {
|
|
notification.setAttribute('style', `transform: none;`);
|
|
}
|
|
} else {
|
|
notification.setAttribute('style', `transform: translateY(0); opacity: 1`)
|
|
}
|
|
notification.addEventListener('touchstart', this.handleTouchStart)
|
|
notification.addEventListener('touchmove', this.handleTouchMove)
|
|
notification.addEventListener('touchend', this.handleTouchEnd)
|
|
}
|
|
|
|
removeNotification = (notification, toLeft) => {
|
|
if (!this.offset)
|
|
this.offset = 0;
|
|
|
|
if (toLeft)
|
|
notification.animate([{
|
|
transform: `translateX(${this.offset}px)`,
|
|
opacity: '1'
|
|
},
|
|
{
|
|
transform: `translateX(-100%)`,
|
|
opacity: '0'
|
|
}
|
|
], this.animationOptions).onfinish = () => {
|
|
notification.remove()
|
|
}
|
|
else {
|
|
notification.animate([{
|
|
transform: `translateX(${this.offset}px)`,
|
|
opacity: '1'
|
|
},
|
|
{
|
|
transform: `translateX(100%)`,
|
|
opacity: '0'
|
|
}
|
|
], this.animationOptions).onfinish = () => {
|
|
notification.remove()
|
|
}
|
|
}
|
|
}
|
|
|
|
clearAll = () => {
|
|
Array.from(this.notificationPanel.children).forEach(child => {
|
|
this.removeNotification(child)
|
|
})
|
|
}
|
|
|
|
connectedCallback() {
|
|
this.notificationPanel = this.shadowRoot.querySelector('.notification-panel')
|
|
this.animationOptions = {
|
|
duration: 300,
|
|
fill: "forwards",
|
|
easing: "ease"
|
|
}
|
|
this.fontSize = Number(window.getComputedStyle(document.body).getPropertyValue('font-size').match(/\d+/)[0])
|
|
this.notification
|
|
this.offset
|
|
this.touchStartX = 0
|
|
this.touchEndX = 0
|
|
this.touchStartTime = 0
|
|
this.touchEndTime = 0
|
|
this.threshold = this.notificationPanel.getBoundingClientRect().width * 0.3
|
|
this.touchEndAnimataion;
|
|
|
|
this.notificationPanel.addEventListener('click', e => {
|
|
if (e.target.closest('.close'))(
|
|
this.removeNotification(e.target.closest('.notification'))
|
|
)
|
|
})
|
|
|
|
const observer = new MutationObserver(mutationList => {
|
|
mutationList.forEach(mutation => {
|
|
if (mutation.type === 'childList') {
|
|
if (mutation.addedNodes.length) {
|
|
if (!mutation.addedNodes[0].classList.contains('pinned'))
|
|
setTimeout(() => {
|
|
this.removeNotification(mutation.addedNodes[0])
|
|
}, 5000);
|
|
if (window.innerWidth > 640)
|
|
this.notificationPanel.style.padding = '1.5rem 0 3rem 1.5rem';
|
|
else
|
|
this.notificationPanel.style.padding = '1rem 1rem 2rem 1rem';
|
|
} else if (mutation.removedNodes.length && !this.notificationPanel.children.length) {
|
|
this.notificationPanel.style.padding = 0;
|
|
}
|
|
}
|
|
})
|
|
})
|
|
observer.observe(this.notificationPanel, {
|
|
attributes: true,
|
|
childList: true,
|
|
subtree: true
|
|
})
|
|
}
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const domRefs = {};
|
|
|
|
function getRef(elementId) {
|
|
if (!domRefs.hasOwnProperty(elementId)) {
|
|
domRefs[elementId] = {
|
|
count: 1,
|
|
ref: null,
|
|
};
|
|
return document.getElementById(elementId);
|
|
} else {
|
|
if (domRefs[elementId].count < 3) {
|
|
domRefs[elementId].count = domRefs[elementId].count + 1;
|
|
return document.getElementById(elementId);
|
|
} else {
|
|
if (!domRefs[elementId].ref)
|
|
domRefs[elementId].ref = document.getElementById(elementId);
|
|
return domRefs[elementId].ref;
|
|
}
|
|
}
|
|
}
|
|
|
|
//Checks for internet connection status
|
|
if (!navigator.onLine)
|
|
notify(
|
|
"There seems to be a problem connecting to the internet, Please check you internet connection.",
|
|
"error",
|
|
"",
|
|
true
|
|
);
|
|
window.addEventListener("offline", () => {
|
|
notify(
|
|
"There seems to be a problem connecting to the internet, Please check you internet connection.",
|
|
"error",
|
|
true,
|
|
true
|
|
);
|
|
});
|
|
window.addEventListener("online", () => {
|
|
getRef("notification_drawer").clearAll();
|
|
notify("We are back online.", "success");
|
|
});
|
|
|
|
const themeSwitcher = getRef("theme_switcher");
|
|
|
|
if (themeSwitcher) {
|
|
if (localStorage.theme === "dark") {
|
|
nightlight();
|
|
themeSwitcher.checked = true;
|
|
} else {
|
|
daylight();
|
|
themeSwitcher.checked = false;
|
|
}
|
|
|
|
function daylight() {
|
|
document.body.setAttribute("data-theme", "light");
|
|
}
|
|
|
|
function nightlight() {
|
|
document.body.setAttribute("data-theme", "dark");
|
|
}
|
|
themeSwitcher.addEventListener("change", function (e) {
|
|
if (this.checked) {
|
|
nightlight();
|
|
localStorage.setItem("theme", "dark");
|
|
} else {
|
|
daylight();
|
|
localStorage.setItem("theme", "light");
|
|
}
|
|
});
|
|
}
|
|
|
|
//Function for displaying toast notifications. pass in error for mode param if you want to show an error.
|
|
function notify(message, mode, pinned, sound) {
|
|
if (mode === "error") console.error(message);
|
|
else console.log(message);
|
|
getRef("notification_drawer").push(message, mode, pinned);
|
|
if (navigator.onLine && sound) {
|
|
getRef("notification_sound").currentTime = 0;
|
|
getRef("notification_sound").play();
|
|
}
|
|
}
|
|
|
|
window.addEventListener("load", () => {
|
|
|
|
document.addEventListener("pointerdown", (e) => {
|
|
if (e.target.closest("button, sm-button:not([disable]), .interact")) {
|
|
createRipple(e, e.target.closest("button, sm-button, .interact"));
|
|
}
|
|
else if(isDropdownOpen && !e.target.closest('.dropdown')){
|
|
changeDropdownState('profile_dropdown', 'hide')
|
|
}
|
|
});
|
|
});
|
|
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(
|
|
[
|
|
{
|
|
transform: "scale(3)",
|
|
opacity: 0,
|
|
},
|
|
],
|
|
{
|
|
duration: 1000,
|
|
fill: "forwards",
|
|
easing: "ease-out",
|
|
}
|
|
);
|
|
target.append(circle);
|
|
rippleAnimation.onfinish = () => {
|
|
circle.remove();
|
|
};
|
|
}
|
|
|
|
let timerId;
|
|
function throttle(func, delay) {
|
|
// If setTimeout is already scheduled, no need to do anything
|
|
if (timerId) {
|
|
return;
|
|
}
|
|
|
|
// Schedule a setTimeout after delay seconds
|
|
timerId = setTimeout(function () {
|
|
func();
|
|
|
|
// Once setTimeout function execution is finished, timerId = undefined so that in
|
|
// the next scroll event function execution can be scheduled by the setTimeout
|
|
timerId = undefined;
|
|
}, delay);
|
|
}
|
|
|
|
|
|
let preferredCurrency
|
|
|
|
if(localStorage.getItem('preferred-currency')){
|
|
preferredCurrency = localStorage.getItem('preferred-currency')
|
|
document.querySelector(`sm-option[value="${localStorage.getItem('preferred-currency')}"]`).setAttribute('selected', '')
|
|
}
|
|
else{
|
|
preferredCurrency = 'inr'
|
|
localStorage.setItem('preferred-currency', 'inr')
|
|
getRef('currency_selector').value = 'INR'
|
|
document.querySelector(`sm-option[value="inr"]`).setAttribute('selected', '')
|
|
}
|
|
|
|
|
|
getRef('currency_selector').addEventListener('change', e => {
|
|
preferredCurrency = e.detail.value
|
|
localStorage.setItem('preferred-currency', e.detail.value)
|
|
document.querySelectorAll('bond-transaction').forEach(bond => bond.toggleCurrency())
|
|
})
|
|
|
|
|
|
let isDropdownOpen = false
|
|
|
|
function changeDropdownState(target, mode, trigger){
|
|
const options = {
|
|
duration: 300,
|
|
easing: 'ease',
|
|
fill: 'both',
|
|
}
|
|
if(mode === 'show'){
|
|
showDropdown(target, options, trigger)
|
|
}
|
|
else if(mode === 'toggle'){
|
|
if(isDropdownOpen){
|
|
hideDropdown(target, options)
|
|
}
|
|
else{
|
|
showDropdown(target, options, trigger)
|
|
}
|
|
}
|
|
else if (mode === 'hide'){
|
|
hideDropdown(target, options)
|
|
}
|
|
}
|
|
|
|
function showDropdown(target, options, trigger){
|
|
if(isDropdownOpen) return
|
|
if(trigger){
|
|
const triggerDimensions = trigger.getBoundingClientRect()
|
|
getRef(target).setAttribute('style', `top: ${triggerDimensions.top + triggerDimensions.height + document.documentElement.scrollTop}px; right: calc(${window.innerWidth - triggerDimensions.right}px - 1.5rem)`)
|
|
}
|
|
getRef(target).classList.remove('hide-completely')
|
|
getRef(target).animate([
|
|
{transform: 'translateY(-1rem)', opacity: 0},
|
|
{transform: 'translateY(0)', opacity: 1},
|
|
], options)
|
|
.onfinish = () => {
|
|
isDropdownOpen = true
|
|
}
|
|
}
|
|
|
|
function hideDropdown(target, options){
|
|
if(!isDropdownOpen) return
|
|
getRef(target).animate([
|
|
{transform: 'translateY(0)', opacity: 1},
|
|
{transform: 'translateY(-1rem)', opacity: 0},
|
|
], options)
|
|
.onfinish = () => {
|
|
isDropdownOpen = false
|
|
getRef(target).classList.add('hide-completely')
|
|
}
|
|
}
|
|
|
|
function showPage(target){
|
|
document.querySelector('.page:not(.hide-completely)')?.classList.add('hide-completely')
|
|
getRef(target).classList.remove('hide-completely')
|
|
if(target !== 'confirm_bond_page'){
|
|
getRef('get_private_key').value = ''
|
|
}
|
|
if(target === 'home_page'){
|
|
getRef("add_bond_form").reset()
|
|
}
|
|
if(target === 'loading_page' || target === 'error_page'){
|
|
getRef('main_header').classList.add('hide-completely')
|
|
}
|
|
else{
|
|
getRef('main_header').classList.remove('hide-completely')
|
|
}
|
|
}
|
|
|
|
getRef('search_bonds').addEventListener('input', e => {
|
|
throttle(() => {
|
|
let hiddenElements = 0
|
|
for(child of getRef('bond_list').children){
|
|
if(child.dataset.floId.toLowerCase().includes(getRef('search_bonds').value.toLowerCase())){
|
|
child.classList.remove('hide-completely')
|
|
}
|
|
else{
|
|
child.classList.add('hide-completely')
|
|
hiddenElements++
|
|
}
|
|
}
|
|
console.log(hiddenElements, getRef('bond_list').children.length)
|
|
if(hiddenElements === getRef('bond_list').children.length){
|
|
getRef('bond_list__empty-state').classList.remove('hide-completely')
|
|
}
|
|
else{
|
|
getRef('bond_list__empty-state').classList.add('hide-completely')
|
|
}
|
|
}, 100)
|
|
})
|
|
|
|
function renderBondPlaceholder(){
|
|
getRef('bond_list').innerHTML = ``
|
|
const frag = document.createDocumentFragment()
|
|
for (let index = 0; index < 4; index++) {
|
|
frag.append(render.bondPlaceholder())
|
|
}
|
|
getRef('bond_list').append(frag)
|
|
}
|
|
|
|
async function renderBondData(data, wipe) {
|
|
const period = duration => {
|
|
let y = parseInt(duration.match(/\d+Y/)),
|
|
m = parseInt(duration.match(/\d+M/)),
|
|
d = parseInt(duration.match(/\d+D/));
|
|
let r = "";
|
|
if (!isNaN(y))
|
|
r += y + ` Year${y > 1 ? 's' : ''}`;
|
|
if (!isNaN(m))
|
|
r += m + ` Month${m > 1 ? 's' : ''}`;
|
|
if (!isNaN(d))
|
|
r += d + ` Day${d > 1 ? 's' : ''}`;
|
|
return r;
|
|
}
|
|
|
|
const frag = document.createDocumentFragment()
|
|
|
|
for (let i in data) {
|
|
let b = blockchainBond.parse.main(data[i]);
|
|
b.netValue = blockchainBond.calcNetValue(b.BTC_base, BTC_current, b.startDate, b.minIpa, b.maxPeriod, b.cut, b.amount, b.USD_base, USD_current);
|
|
console.info(b);
|
|
const obj = {
|
|
href: `${floBlockchainAPI.current_server}tx/${i}`,
|
|
floId: b.floID,
|
|
bondStartDate: blockchainBond.dateFormat(b.startDate),
|
|
amountInvested: {
|
|
inr: b.amount.toFixed(2),
|
|
usd: (b.amount / b.USD_base).toFixed(2)
|
|
},
|
|
netValue: {
|
|
inr: b.netValue.toFixed(2),
|
|
usd: (b.netValue / USD_current).toFixed(2)
|
|
},
|
|
guaranteedInterest: b.minIpa * 100 + '%',
|
|
guaranteedInterestDuration: period(b.maxPeriod),
|
|
gainShare: b.cut * 100 + '%',
|
|
lockinPeriod: period(b.lockinPeriod),
|
|
lockinEnd: blockchainBond.dateFormat(blockchainBond.dateAdder(b.startDate, b.lockinPeriod)),
|
|
baseBtcRate: b.BTC_base,
|
|
usdRate: b.USD_base
|
|
}
|
|
|
|
const bond = document.createElement('bond-transaction')
|
|
bond.data = obj
|
|
//bond.setAttribute("title", data[i].replace(/\|/g, "\n"))
|
|
frag.append(bond)
|
|
}
|
|
getRef('bond_list').append(frag)
|
|
}
|
|
|
|
async function renderBondClosingData(data){
|
|
for(let i in data){
|
|
let b = blockchainBond.parse.end(data[i]);
|
|
//TODO render bond closing (should be mapped with bond details that were rendered)
|
|
}
|
|
}
|
|
|
|
var USD_current, BTC_current;
|
|
getRef('refresh_button').addEventListener("click", evt => {
|
|
showPage('loading_page')
|
|
getCurrentRates().then(rates => {
|
|
USD_current = rates.USD_INR;
|
|
BTC_current = rates.BTC_USD;
|
|
console.log(`USD rate: ${USD_current} INR\nBTC rate: ${BTC_current} USD`);
|
|
getRef("usd-rate").textContent = `USD: ₹${rates.USD_INR.toFixed(2)}`;
|
|
getRef("btc-usd-rate").textContent = `BTC: ${parseFloat(rates.BTC_USD.toFixed(2)).toLocaleString(`en-US`, { style: 'currency', currency: 'USD' })}`;
|
|
refreshBlockchainData().then(result => {
|
|
compactIDB.readAllData("bonds").then(result => {
|
|
renderBondData(result);
|
|
compactIDB.readAllData('closings').then(result => {
|
|
//TODO:
|
|
renderBondClosingData(result);
|
|
showPage('home_page')
|
|
}).catch(error => console.error(error))
|
|
}).catch(error => console.error(error))
|
|
}).catch(error => {
|
|
console.error(error)
|
|
showPage('error_page')
|
|
})
|
|
});
|
|
});
|
|
|
|
getRef("add_bond_form").addEventListener("submit", evt => {
|
|
evt.preventDefault()
|
|
let f = evt.target;
|
|
|
|
let bondStr = blockchainBond.stringify.main(f["base"].value, f["start_date"].value, f["gi_r"].value, f["gi_pv"].value + " " + getRef("gi_pt").value, f["cut"].value, f["amount"].value, f["usd_rate"].value, f["lockin_v"].value + " " + getRef("lockin_t").value, f["floid"].value);
|
|
|
|
getRef('bond_details').innerHTML = bondStr.replace(/\|/g, "<br>")
|
|
|
|
getRef('admin_id').innerHTML = `Enter Private key of adminID <h5 class="weight-400 marg">${floGlobals.adminID}</h5>`
|
|
|
|
showPage('confirm_bond_page')
|
|
// bond_details = prompt(bondStr + `\n\nEnter Private key of adminID (${floGlobals.adminID})`);
|
|
|
|
getRef('add_bond_button').onclick = () => {
|
|
const privKey = getRef('get_private_key').value
|
|
if (!floCrypto.verifyPrivKey(privKey, floGlobals.adminID)) {
|
|
notify("Access Denied! incorrect private key", 'error');
|
|
return
|
|
}
|
|
console.log(bondStr);
|
|
floBlockchainAPI.writeData(floGlobals.adminID, bondStr, privKey, f["floid"].value).then(result => {
|
|
console.log(result);
|
|
showPage('add_bond_page')
|
|
notify("Bond added in blockchain", 'success');
|
|
getRef("add_bond_form").reset()
|
|
}).catch(error => reject(error))
|
|
}
|
|
})
|
|
|
|
</script>
|
|
</body>
|
|
</html> |