exchangemarket/docs/index.html
2022-05-11 16:18:27 +05:30

2570 lines
141 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>RanchiMall exchange</title>
<meta name="description" content="Trade FLO and FLO based RanchiMall tokens.">
<script src="scripts/components.js" defer></script>
<link rel="stylesheet" href="css/main.min.css">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap" rel="stylesheet">
<script src="scripts/floGlobals.js"></script>
<script src="scripts/lib.js"></script>
<script src="scripts/floCrypto.js"></script>
<script src="scripts/floBlockchainAPI.js"></script>
<script src="scripts/floTokenAPI.js"></script>
<script src="scripts/floExchangeAPI.js"></script>
<script src="https://unpkg.com/lightweight-charts/dist/lightweight-charts.standalone.production.js"></script>
<script>
const DEFAULT_TRADE_PRICE_DEVIATION = 15 / 100;
const deviation = {
'buy': 1 + DEFAULT_TRADE_PRICE_DEVIATION,
'sell': 1 - DEFAULT_TRADE_PRICE_DEVIATION
}
</script>
</head>
<body class="hide">
<sm-notifications id="notification_drawer"></sm-notifications>
<sm-popup id="confirmation_popup">
<h4 id="confirm_title"></h4>
<p id="confirm_message"></p>
<div class="flex align-center">
<sm-button variant="no-outline" class="cancel-btn">Cancel</sm-button>
<sm-button variant="no-outline" class="submit-btn">OK</sm-button>
</div>
</sm-popup>
<sm-popup id="prompt_popup">
<h4 id="prompt_title"></h4>
<p id="prompt_message"></p>
<sm-form>
<sm-input id="prompt_input"></sm-input>
<div class="flex align-center">
<sm-button variant="no-outline" class="cancel-btn">Cancel</sm-button>
<sm-button variant="no-outline" class="submit-btn" type="submit">OK</sm-button>
</div>
</sm-form>
</sm-popup>
<div id="loading" class="page flex align-center justify-center">
<div class="grid gap-2 text-center">
<line-loader></line-loader>
<div class="grid gap-0-5">
<h4>RanchiMall Exchange</h4>
<p>Getting everything ready</p>
</div>
<sm-button onclick="floExchangeAPI.clearAllLocalData()">Reset</sm-button>
</div>
</div>
<article id="home" class="page hide">
<header id="main_header">
<div class="logo">
<svg class="main-logo" 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" />
</svg>
<div class="grid">
<h4>RanchiMall Exchange</h4>
</div>
</div>
<theme-toggle id="theme_toggle"></theme-toggle>
<button id="user_popup_button" class="hide" onclick="showPopup('user_popup')">
<svg xmlns="http://www.w3.org/2000/svg" class="icon" height="24px" viewBox="0 0 24 24" width="24px"
fill="#000000">
<path d="M0 0h24v24H0V0z" fill="none" />
<path
d="M12 5.9c1.16 0 2.1.94 2.1 2.1s-.94 2.1-2.1 2.1S9.9 9.16 9.9 8s.94-2.1 2.1-2.1m0 9c2.97 0 6.1 1.46 6.1 2.1v1.1H5.9V17c0-.64 3.13-2.1 6.1-2.1M12 4C9.79 4 8 5.79 8 8s1.79 4 4 4 4-1.79 4-4-1.79-4-4-4zm0 9c-2.67 0-8 1.34-8 4v3h16v-3c0-2.66-5.33-4-8-4z" />
</svg>
</button>
</header>
<section id="pages_container">
<section id="exchange" class="mobile-page hide">
<sm-form id="login_form">
<div class="grid gap-0-5">
<h2>Login</h2>
<p>Please login for exchange.</p>
</div>
<sm-input type="password" id="login_form__priv_key" placeholder="Private key"
error-text="Invalid private key" data-private-key autofocus animate required>
</sm-input>
<sm-checkbox id="remember_me" checked>
<span class="margin-left-0-5">
Remember me
</span>
</sm-checkbox>
<input type="text" id="sign_in_code" style="display: none;" hidden />
<input type="text" id="sign_in_hash" style="display: none;" hidden />
<div id="login_button_wrapper" class="stateful-button-wrapper">
<sm-button variant="primary" onclick="UI_evt.login();">Log in</sm-button>
</div>
<sm-button onclick="showPopup('registration_popup')" style="display: none;" disabled>Not registered?
click here!</sm-button>
<div class="grid gap-0-5">
<p>Don't have FLO credentials?</p>
<sm-button onclick="showPopup('sign_up_popup')">Generate FLO credentials</sm-button>
</div>
<sm-button onclick="floExchangeAPI.clearAllLocalData()">Reset</sm-button>
</sm-form>
<section id="exchange_wrapper" class="hide user-content">
<div id="asset_list_wrapper" class="grid gap-1 align-start">
<div class="grid gap-0-3">
<div class="flex align-center space-between">
<h5>ASSETS</h5>
<h5>PRICE</h5>
</div>
<p>Countdown shows est. time until asset prices are updated</p>
</div>
<ul id="listed_assets" class="user-content hide"></ul>
</div>
<div id="asset_page" class="hide-on-mobile">
<nav id="asset_page__nav" class="hide-on-desktop">
<a href="#/exchange" class="button icon-only">
<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="M20 11H7.83l5.59-5.59L12 4l-8 8 8 8 1.41-1.41L7.83 13H20v-2z" />
</svg>
</a>
<strip-select id="trading_view_switcher">
<strip-option value="trade" selected>Trade</strip-option>
<strip-option value="chart">Chart</strip-option>
</strip-select>
</nav>
<div id="price_chart_container" class="flex direction-column gap-0-5 hide-on-mobile">
<div id="chart_header" class="flex align-center space-between">
<H4 id="chart_asset"></H4>
<strip-select id="price_duration_selector">
<strip-option value="hour" title="1 Hour price interval" selected>Hour
</strip-option>
<strip-option value="day" title="1 Day price interval">Day</strip-option>
</strip-select>
</div>
<div id="price_chart_wrapper" class="flex" style="position: relative; flex: 1">
<div id="price_history_chart"></div>
</div>
</div>
<sm-form id="trade_form">
<div class="flex space-between align-center">
<h4 id="traded_asset">Trade FLO</h4>
<strip-select id="trade_type_selector" class="tab">
<strip-option value="buy" selected>Buy</strip-option>
<strip-option value="sell">Sell</strip-option>
</strip-select>
</div>
<div id="get_price" class="flex align-center space-between"></div>
<sm-input id="get_quantity" placeholder="Quantity" type="number" step="0.00000001" required
animate>
</sm-input>
</sm-input>
<sm-input id="get_total" placeholder="Locked amount (₹)" type="number" min="0.00000001"
step="0.00000001" required animate>
</sm-input>
<div class="grid gap-0-5">
<div id="quantity_selector" class="flex align-center quantity-selector">
<span id="quantity_type">Rupee</span>
<button class="button" value="0.25"
title="Buy FLO worth 25% of total rupee">25%</button>
<button class="button" value="0.5"
title="Buy FLO worth 50% of total rupee">50%</button>
<button class="button" value="0.75"
title="Buy FLO worth 75% of total rupee">75%</button>
<button class="button" value="1"
title="Buy FLO worth 100% of total rupee">100%</button>
</div>
<div class="flex align-center tip">
<svg class="icon margin-right-0-5" style="height: 1em; width: 1em;"
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">
<rect fill="none" height="24" width="24" y="0" />
<path
d="M7,20h4c0,1.1-0.9,2-2,2S7,21.1,7,20z M5,19h8v-2H5V19z M16.5,9.5c0,3.82-2.66,5.86-3.77,6.5H5.27 C4.16,15.36,1.5,13.32,1.5,9.5C1.5,5.36,4.86,2,9,2S16.5,5.36,16.5,9.5z M14.5,9.5C14.5,6.47,12.03,4,9,4S3.5,6.47,3.5,9.5 c0,2.47,1.49,3.89,2.35,4.5h6.3C13.01,13.39,14.5,11.97,14.5,9.5z M21.37,7.37L20,8l1.37,0.63L22,10l0.63-1.37L24,8l-1.37-0.63L22,6 L21.37,7.37z M19,6l0.94-2.06L22,3l-2.06-0.94L19,0l-0.94,2.06L16,3l2.06,0.94L19,6z" />
</svg>
<p id="quantity_selector_tip" style="font-size: inherit;">
Buy FLO worth of the above percentage rupee
</p>
</div>
</div>
<div id="trade_button_wrapper"
class="stateful-button-wrapper flex align-center justify-center">
<sm-button id="trade_button" class="uppercase w-100" variant="primary"
onclick="showPopup('confirm_trade_popup')">BUY FLO
</sm-button>
</div>
</sm-form>
</div>
</section>
</section>
<section id="my_orders" class="grid gap-1 hide mobile-page">
<div id="my_orders_section__header" class="orders_section__header flex">
<div id="orders_section__header--primary" class="flex w-100 align-center space-between">
<h4 id="my_orders__title">
My orders
</h4>
<strip-select id="my_orders_category_selector" class="tab">
<strip-option value="open" selected>Live</strip-option>
<strip-option value="completed">Trades</strip-option>
</strip-select>
</div>
<div id="orders_section__header--secondary" class="flex w-100 align-center space-between hide">
<button class="" onclick="clearSelection()" title="Clear all selection">
<svg xmlns="http://www.w3.org/2000/svg" class="icon margin-right-0-5" height="24px"
viewBox="0 0 24 24" width="24px">
<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>
<span id="selected_orders"></span>
</button>
<div class="options">
<button class="button" title="Cancel selected orders" onclick="cancelAll()">
Cancel all
</button>
</div>
</div>
</div>
<ul id="orders_list" class="observe-empty-state"></ul>
<div class="grid gap-0-5 empty-state">
<svg class="icon empty-state__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="M13 3c-4.97 0-9 4.03-9 9H1l3.89 3.89.07.14L9 12H6c0-3.87 3.13-7 7-7s7 3.13 7 7-3.13 7-7 7c-1.93 0-3.68-.79-4.94-2.06l-1.42 1.42C8.27 19.99 10.51 21 13 21c4.97 0 9-4.03 9-9s-4.03-9-9-9zm-1 5v5l4.25 2.52.77-1.28-3.52-2.09V8z" />
</svg>
<h4>
No orders placed yet
</h4>
<p>My orders will only show completed orders</p>
</div>
</section>
<section id="market" class="grid gap-1-5 hide mobile-page">
<div class="grid gap-1 align-start">
<div class="flex align-center space-between">
<h5>ASSETS</h5>
<h5>PRICE</h5>
</div>
<ul id="market_asset_rates"></ul>
</div>
<div class="grid gap-0-5 align-start">
<div class="orders_section__header flex align-center">
<h4 id="market_orders__title" class="flex align-center">
Market-wide trades
</h4>
<button onclick="refresh();" title="Refresh" style="margin-left: 1rem;">
<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="M17.65 6.35C16.2 4.9 14.21 4 12 4c-4.42 0-7.99 3.58-7.99 8s3.57 8 7.99 8c3.73 0 6.84-2.55 7.73-6h-2.08c-.82 2.33-3.04 4-5.65 4-3.31 0-6-2.69-6-6s2.69-6 6-6c1.66 0 3.14.69 4.22 1.78L13 11h7V4l-2.35 2.35z" />
</svg>
</button>
<strip-select id="market_orders_category_selector" class="tab justify-right">
<strip-option value="open" selected>Live</strip-option>
<strip-option value="completed">Trades</strip-option>
</strip-select>
</div>
<div id="market_orders_wrapper">
<div class="grid gap-1">
<p>Order placement denotes priority at which orders will get executed.</p>
<div class="flex text-center">
<b class="flex-1" style="color: var(--green);">Buy</b>
<b class="flex-1" style="color: var(--danger-color);">Sell</b>
</div>
<div id="market_open_orders_wrapper" class="flex gap-0-5">
<div class="flex-1">
<ul id="market_buy_orders" class="observe-empty-state"></ul>
<p class="empty-state">
No buy orders placed
</p>
</div>
<div class="flex-1">
<ul id="market_sell_orders" class="observe-empty-state"></ul>
<p class="empty-state">
No sell orders placed
</p>
</div>
</div>
</div>
<div>
<ul id="market_trades" class="observe-empty-state"></ul>
<p class="empty-state">
No trades happened
</p>
</div>
</div>
</div>
</section>
<section id="wallet" class="grid mobile-page hide">
<h4 id="wallet__header" class="flex align-center">
<svg xmlns="http://www.w3.org/2000/svg" class="icon margin-right-0-5" height="24px"
viewBox="0 0 24 24" width="24px">
<path d="M0 0h24v24H0V0z" fill="none" />
<path
d="M21 7.28V5c0-1.1-.9-2-2-2H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2v-2.28c.59-.35 1-.98 1-1.72V9c0-.74-.41-1.37-1-1.72zM20 9v6h-7V9h7zM5 19V5h14v2h-6c-1.1 0-2 .9-2 2v6c0 1.1.9 2 2 2h6v2H5z" />
<circle cx="16" cy="12" r="1.5" />
</svg>
My wallet
</h4>
<div id="wallet_actions">
<p class="label">Select asset</p>
<sm-select id="wallet_asset_selector"></sm-select>
<div class="flex wallet_actions__wrapper">
<button class="button" value="deposit">
Deposit
</button>
<button class="button" value="withdraw">
Withdraw
</button>
<button class="button" value="transfer">
Transfer
</button>
</div>
</div>
<div class="grid gap-0-5">
<div class="flex align-center space-between">
<h4>Balance</h4>
<div class="multi-state-button">
<button id="wallet_balance_refresh_button" class="button" onclick="refresh(false,this);"
title="Refresh">
Refresh
</button>
</div>
</div>
<ul id="my_assets" class="grid"></ul>
</div>
</section>
<div id="help" class="mobile-page hide grid gap-2">
<h1>Hey there! How can we help you today?</h1>
<div class="grid gap-0-5">
<h5>F.A.Qs</h5>
<div class="grid gap-0-5">
<details>
<summary class="interact">
<h4>
What are rupee tokens?
</h4>
<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="M7.41 8.59L12 13.17l4.59-4.58L18 10l-6 6-6-6 1.41-1.41z" />
</svg>
</summary>
<p>
Rupee tokens are a digital asset which has value equal to 1 INR. Which can be used with
RanchiMall exchange and other RanchiMall products.
</p>
</details>
<details>
<summary class="interact">
<h4>
Where can I get rupee tokens?
</h4>
<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="M7.41 8.59L12 13.17l4.59-4.58L18 10l-6 6-6-6 1.41-1.41z" />
</svg>
</summary>
<p>
Rupee tokens can be acquired by paying equivalent amount of rupees using our <strong>
<a href="https://ranchimall.github.io/flopay/" target="_blank">FLO Pay</a>
</strong>
app.
</p>
</details>
<details>
<summary class="interact">
<h4>
Why is there a difference between current asset prices and prices shown as
buying/selling price?
</h4>
<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="M7.41 8.59L12 13.17l4.59-4.58L18 10l-6 6-6-6 1.41-1.41z" />
</svg>
</summary>
<p>
Contrary to other exchanges, the price you see as buying/selling price works as a upper
bound for buying and lower bound for selling. you order will bne executed at
best price determined by the exchange algorithm.
</p>
</details>
<details>
<summary class="interact">
<h4>
Why my order hasn't been filled yet?
</h4>
<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="M7.41 8.59L12 13.17l4.59-4.58L18 10l-6 6-6-6 1.41-1.41z" />
</svg>
</summary>
<p>
Our Exchange works a little differently than other exchanges. You can only buy or
sell at
the
market price.
If you have placed an order at lower/higher price than current price, your order will
not be
executed until the market price matches your order price.
</p>
</details>
<details>
<summary class="interact">
<h4>
Why am I not able to sell my assets?
</h4>
<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="M7.41 8.59L12 13.17l4.59-4.58L18 10l-6 6-6-6 1.41-1.41z" />
</svg>
</summary>
<p>
We only allows selling of assets that were bought in this exchange.
Assets bought in other exchanges can not be sold here.
</p>
</details>
<details>
<summary class="interact">
<h4>
I have rupee tokens in FLO ID, so why can't I see them in my wallet?
</h4>
<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="M7.41 8.59L12 13.17l4.59-4.58L18 10l-6 6-6-6 1.41-1.41z" />
</svg>
</summary>
<p>
In order to user your rupee tokens in exchange, you have to deposit them in exchange
first.
Assets owned by a FLO ID are different than assets you own in exchange.
</p>
</details>
<details>
<summary class="interact">
<h4>
Why don't prices fluctuate often?
</h4>
<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="M7.41 8.59L12 13.17l4.59-4.58L18 10l-6 6-6-6 1.41-1.41z" />
</svg>
</summary>
<p>
Our exchange has a different pricing model than other exchanges. We have an algorithm
based
pricing model which updates prices every hour
based on predefined rules. This prevents rapid fluctuations in price and ensures that
you
can always buy or sell at the best price.
</p>
</details>
</div>
</div>
</div>
</section>
<nav id="main_navbar" class="flex align-center">
<a href="#/exchange" class="main_navbar__item main_navbar__item--active interact">
<svg class="icon" xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px"
fill="#000000">
<path d="M0 0h24v24H0z" fill="none" />
<path d="M16 17.01V10h-2v7.01h-3L15 21l4-3.99h-3zM9 3L5 6.99h3V14h2V6.99h3L9 3z" />
</svg>
<div class="item__title">Exchange</div>
</a>
<a href="#/my_orders" class="main_navbar__item user-content hide interact">
<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">
<path d="M0,0h24v24H0V0z" fill="none" />
<g>
<path
d="M19.5,3.5L18,2l-1.5,1.5L15,2l-1.5,1.5L12,2l-1.5,1.5L9,2L7.5,3.5L6,2v14H3v3c0,1.66,1.34,3,3,3h12c1.66,0,3-1.34,3-3V2 L19.5,3.5z M15,20H6c-0.55,0-1-0.45-1-1v-1h10V20z M19,19c0,0.55-0.45,1-1,1s-1-0.45-1-1v-3H8V5h11V19z" />
<rect height="2" width="6" x="9" y="7" />
<rect height="2" width="2" x="16" y="7" />
<rect height="2" width="6" x="9" y="10" />
<rect height="2" width="2" x="16" y="10" />
</g>
</svg>
<div class="item__title">My orders</div>
</a>
<a href="#/market" class="main_navbar__item interact">
<svg class="icon" xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 24 24" height="24px"
viewBox="0 0 24 24" width="24px" fill="#000000">
<g>
<rect fill="none" height="24" width="24" />
</g>
<g>
<g />
<g>
<path
d="M21.9,8.89l-1.05-4.37c-0.22-0.9-1-1.52-1.91-1.52H5.05C4.15,3,3.36,3.63,3.15,4.52L2.1,8.89 c-0.24,1.02-0.02,2.06,0.62,2.88C2.8,11.88,2.91,11.96,3,12.06V19c0,1.1,0.9,2,2,2h14c1.1,0,2-0.9,2-2v-6.94 c0.09-0.09,0.2-0.18,0.28-0.28C21.92,10.96,22.15,9.91,21.9,8.89z M18.91,4.99l1.05,4.37c0.1,0.42,0.01,0.84-0.25,1.17 C19.57,10.71,19.27,11,18.77,11c-0.61,0-1.14-0.49-1.21-1.14L16.98,5L18.91,4.99z M13,5h1.96l0.54,4.52 c0.05,0.39-0.07,0.78-0.33,1.07C14.95,10.85,14.63,11,14.22,11C13.55,11,13,10.41,13,9.69V5z M8.49,9.52L9.04,5H11v4.69 C11,10.41,10.45,11,9.71,11c-0.34,0-0.65-0.15-0.89-0.41C8.57,10.3,8.45,9.91,8.49,9.52z M4.04,9.36L5.05,5h1.97L6.44,9.86 C6.36,10.51,5.84,11,5.23,11c-0.49,0-0.8-0.29-0.93-0.47C4.03,10.21,3.94,9.78,4.04,9.36z M5,19v-6.03C5.08,12.98,5.15,13,5.23,13 c0.87,0,1.66-0.36,2.24-0.95c0.6,0.6,1.4,0.95,2.31,0.95c0.87,0,1.65-0.36,2.23-0.93c0.59,0.57,1.39,0.93,2.29,0.93 c0.84,0,1.64-0.35,2.24-0.95c0.58,0.59,1.37,0.95,2.24,0.95c0.08,0,0.15-0.02,0.23-0.03V19H5z" />
</g>
</g>
</svg>
<div class="item__title">Market</div>
</a>
<a href="#/wallet" class="main_navbar__item user-content hide interact">
<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="M21 7.28V5c0-1.1-.9-2-2-2H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2v-2.28c.59-.35 1-.98 1-1.72V9c0-.74-.41-1.37-1-1.72zM20 9v6h-7V9h7zM5 19V5h14v2h-6c-1.1 0-2 .9-2 2v6c0 1.1.9 2 2 2h6v2H5z" />
<circle cx="16" cy="12" r="1.5" />
</svg>
<div class="item__title">Wallet</div>
</a>
<a href="#/help" class="main_navbar__item interact">
<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="M11 18h2v-2h-2v2zm1-16C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8zm0-14c-2.21 0-4 1.79-4 4h2c0-1.1.9-2 2-2s2 .9 2 2c0 2-3 1.75-3 5h2c0-2.25 3-2.5 3-5 0-2.21-1.79-4-4-4z" />
</svg>
<div class="item__title">Help</div>
</a>
</nav>
</article>
<!--
* add warning to show if an order is not considered
-->
<sm-popup id="confirm_trade_popup">
<header slot="header" class="popup__header">
<button class="popup__header__close" onclick="hidePopup()">
<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="M12 10.586l4.95-4.95 1.414 1.414-4.95 4.95 4.95 4.95-1.414 1.414-4.95-4.95-4.95 4.95-1.414-1.414 4.95-4.95-4.95-4.95L7.05 5.636z" />
</svg>
</button>
<h3 id="confirm_trade__title" class="uppercase">BUY</h3>
</header>
<section class="grid gap-1-5">
<div id="confirm_trade__details" class="grid gap-1-5"></div>
<sm-button variant="primary" onclick="tradeAsset()" autofocus>Confirm</sm-button>
</section>
</sm-popup>
<sm-popup id="user_popup">
<header slot="header" class="popup__header">
<button class="popup__header__close" onclick="hidePopup()">
<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="M12 10.586l4.95-4.95 1.414 1.414-4.95 4.95 4.95 4.95-1.414 1.414-4.95-4.95-4.95 4.95-1.414-1.414 4.95-4.95-4.95-4.95L7.05 5.636z" />
</svg>
</button>
<h3>Profile</h3>
</header>
<section class="grid gap-2">
<div class="grid gap-0-5">
<div class="label">My FLO ID</div>
<sm-copy id="user_id"></sm-copy>
</div>
<div class="grid gap-1">
<div class="grid gap-0-5">
<h4>Add password lock</h4>
<p>
Adding a password lock allows to authenticate transactions with a custom password instead of
private key.
</p>
</div>
<sm-button onclick="proxy.lock();">Add password</sm-button>
</div>
<sm-button class="danger" onclick="UI_evt.logout();">Log out</sm-button>
</section>
</sm-popup>
<sm-popup id="sign_up_popup">
<header slot="header" class="popup__header">
<button class="popup__header__close" onclick="hidePopup()">
<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="M12 10.586l4.95-4.95 1.414 1.414-4.95 4.95 4.95 4.95-1.414 1.414-4.95-4.95-4.95 4.95-1.414-1.414 4.95-4.95-4.95-4.95L7.05 5.636z" />
</svg>
</button>
<h4>Get credentials</h4>
</header>
<section id="sign_up_section" class="grid gap-1-5">
<div class="grid gap-1-5">
<div class="grid gap-0-5">
<h5>FLO ID</h5>
<sm-copy id="generated_flo_id"></sm-copy>
</div>
<div class="grid gap-0-5">
<h5>Private key</h5>
<sm-copy id="generated_private_key"></sm-copy>
</div>
</div>
<strong class="warning">
Keep your private key secure and don't share with anyone.
Once lost there is no way to recover private key.
</strong>
</section>
</sm-popup>
<sm-popup id="wallet_popup">
<header slot="header" class="popup__header">
<button class="popup__header__close" onclick="hidePopup()">
<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="M12 10.586l4.95-4.95 1.414 1.414-4.95 4.95 4.95 4.95-1.414 1.414-4.95-4.95-4.95 4.95-1.414-1.414 4.95-4.95-4.95-4.95L7.05 5.636z" />
</svg>
</button>
<h4 id="wallet_popup__title" class="capitalize"></h4>
</header>
<sm-form id="wallet_form">
<input type="text" id="sink_id" style="display: none;" hidden />
<sm-input id="get_receiver_id" placeholder="Receiver FLO ID" error-text="Invalid FLO ID" data-flo-id
required animate></sm-input>
<sm-input id="get_user_amount" placeholder="Quantity" type="number" min="0.00000001" step="0.00000001"
required animate>
</sm-input>
<div id="wallet_quantity_selector" class="flex align-center quantity-selector">
<span id="wallet_quantity_type">Rupee</span>
<button class="button" value="0.25">25%</button>
<button class="button" value="0.5">50%</button>
<button class="button" value="0.75">75%</button>
<button class="button" value="1">100%</button>
</div>
<p id="withdraw_flo_tip" class="hide">*While withdrawing 100% of balance FLO, <b>0.1 FLO</b> is reserved for
transactions
on blockchain.
</p>
<sm-input id="get_private_key" placeholder="FLO private key" type="password" required
error-text="Invalid private key" data-private-key="" animate>
</sm-input>
<div id="wallet_popup__cta_wrapper" class="stateful-button-wrapper">
<sm-button id="wallet_popup__cta" class="uppercase" variant="primary"></sm-button>
</div>
</sm-form>
<div id="wallet_result" class="grid gap-2 hide">
<div id="wallet_result__icon"></div>
<div class="grid gap-0-5">
<h4 id="wallet_result__title"></h4>
<p id="wallet_result__description"></p>
</div>
<div id="wallet_result__cta" class="hide grid gap-1-5">
<div class="grid gap-0-5">
<h4>Low on rupee balance?</h4>
<p>Visit RanchiMall Pay to deposit rupee in your FLO ID.</p>
</div>
<a href="https://ranchimall.github.io/upi/" target="_blank" rel="noopener noreferrer"
class="button button--primary">Open RanchiMall Pay</a>
</div>
</div>
</sm-popup>
<sm-popup id="transaction_info_popup">
<header slot="header" class="popup__header">
<button class="popup__header__close" onclick="hidePopup()">
<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="M12 10.586l4.95-4.95 1.414 1.414-4.95 4.95 4.95 4.95-1.414 1.414-4.95-4.95-4.95 4.95-1.414-1.414 4.95-4.95-4.95-4.95L7.05 5.636z" />
</svg>
</button>
<h4>Transaction details</h4>
</header>
<div class="grid gap-1-5">
<div id="transaction__buyer_wrapper" class="grid">
<h5 class="label capitalize">Buyer</h5>
<sm-copy id="transaction__buyer"></sm-copy>
</div>
<div id="transaction__seller_wrapper" class="grid">
<h5 class="label capitalize">Seller</h5>
<sm-copy id="transaction__seller"></sm-copy>
</div>
<div class="grid">
<h5 id="transaction_time__label" class="label">Completed</h5>
<time style="font-size: 0.9rem;" id="transaction_time"></time>
</div>
</div>
</sm-popup>
<!-- templates -->
<template id="listed_asset_template">
<li>
<a class="listed-asset interact grid align-center">
<div class="listed-asset__icon"></div>
<h4 class="listed-asset__name"></h4>
<b class="listed-asset__rate"></b>
<div class="listed-asset__countdown"></div>
</a>
</li>
</template>
<template id="asset_balance_card_template">
<li class="balance-card">
<div class="balance-card__icon"></div>
<h4 class="balance-card__token"></h4>
</li>
</template>
<template id="net_balance_template">
<span class="available-balance"></span>
</template>
<template id="locked_balance_template">
<div class="grid balance-card__amount-wrapper">
<div class="grid">
<span class="label">Locked</span>
<span class="locked-balance"></span>
</div>
<div class="grid">
<span class="label">Available</span>
<span class="available-balance"></span>
</div>
</div>
</template>
<template id="order_template">
<li class="list__item order-card">
<sm-checkbox></sm-checkbox>
<div class="grid">
<div class="order-card__type capitalize"></div>
<div class="order-card__quantity"></div>
</div>
<div class="grid">
<span class="label order-card__price-type"></span>
<div class="order-card__price"></div>
</div>
<time class="order-card__time"></time>
<button class="cancel-order" title="Cancel this order">
<svg xmlns="http://www.w3.org/2000/svg" class="icon" height="24px" viewBox="0 0 24 24" width="24px">
<path d="M0 0h24v24H0V0z" fill="none" />
<path
d="M16 9v10H8V9h8m-1.5-6h-5l-1 1H5v2h14V4h-3.5l-1-1zM18 7H6v12c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7z" />
</svg>
<span>Cancel</span>
</button>
</li>
</template>
<template id="market_order_template">
<li class="live-order align-center">
<div class="flex gap-1 space-between align-start">
<b class="transaction-card__quantity"></b>
<button class="more-info" title="View order details">
<svg xmlns="http://www.w3.org/2000/svg" class="icon" height="24px" viewBox="0 0 24 24" width="24px">
<path d="M0 0h24v24H0V0z" fill="none" />
<path
d="M11 7h2v2h-2zm0 4h2v6h-2zm1-9C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8z" />
</svg>
</button>
</div>
<div class="flex gap-0-5">
<div class="grid flex-1">
<span class="label">Valid upto</span>
<b class="transaction-card__price wrap-around"></b>
</div>
<div class="grid flex-1">
<span class="label">Amount</span>
<div class="transaction-card__total wrap-around"></div>
</div>
</div>
</li>
</template>
<template id="transaction_template">
<li class="list__item transaction-card align-center">
<div class="grid">
<div class="transaction-card__type capitalize"></div>
<div class="transaction-card__quantity"></div>
</div>
<div class="grid">
<span class="label transaction-card__price-type">Unit price</span>
<div class="transaction-card__price"></div>
</div>
<div class="grid">
<span class="label transaction-card__price-type">Amount</span>
<div class="transaction-card__total"></div>
</div>
<button class="more-info" title="View transaction details">
<svg xmlns="http://www.w3.org/2000/svg" class="icon" height="24px" viewBox="0 0 24 24" width="24px">
<path d="M0 0h24v24H0V0z" fill="none" />
<path
d="M11 7h2v2h-2zm0 4h2v6h-2zm1-9C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8z" />
</svg>
</button>
</li>
</template>
<template id="market_transaction_template">
<li class="list__item transaction-card align-center">
<div class="transaction-card__quantity"></div>
<div class="transaction-card__price"></div>
<div class="transaction-card__total"></div>
<button class="more-info" title="View transaction details">
<svg xmlns="http://www.w3.org/2000/svg" class="icon" height="24px" viewBox="0 0 24 24" width="24px">
<path d="M0 0h24v24H0V0z" fill="none" />
<path
d="M11 7h2v2h-2zm0 4h2v6h-2zm1-9C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8z" />
</svg>
</button>
</li>
</template>
<template id="market_order_list_template">
<h4 class="grid list__header">
<div>Quantity</div>
<div>Buy price</div>
<div>Sell price</div>
<div>Quantity</div>
</h4>
<section id="buyers_list"></section>
<section id="sellers_list"></section>
</template>
<template id="market_transaction_list_template">
<h4 class="grid list__header">
<div>Quantity</div>
<div>Traded at</div>
<div>Amount</div>
<div></div>
</h4>
</template>
<template id="success_template">
<div class="stateful-result stateful-result--success">
<div class="result__background result__background--success"></div>
<div class="icon-wrapper flex align-center">
<svg xmlns="http://www.w3.org/2000/svg" class="icon margin-right-0-5" height="24px" viewBox="0 0 24 24"
width="24px" fill="#000000">
<path d="M0 0h24v24H0V0z" fill="none" />
<path d="M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4L9 16.2z" />
</svg>
<span>Success</span>
</div>
</div>
</template>
<template id="failure_template">
<div class="stateful-result stateful-result--failure">
<div class="result__background"></div>
<div class="icon-wrapper flex align-center">
<svg xmlns="http://www.w3.org/2000/svg" class="icon margin-right-0-5" height="24px" viewBox="0 0 24 24"
width="24px" fill="#000000">
<path
d="M11 15h2v2h-2v-2zm0-8h2v6h-2V7zm.99-5C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2zM12 20c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8z" />
</svg>
<span>Failed</span>
</div>
</div>
</template>
<script>
/**
* @yaireo/relative-time - javascript function to transform timestamp or date to local relative-time
*
* @version v1.0.0
* @homepage https://github.com/yairEO/relative-time
*/
!function (e, t) { var o = o || {}; "function" == typeof o && o.amd ? o([], t) : "object" == typeof exports && "object" == typeof module ? module.exports = t() : "object" == typeof exports ? exports.RelativeTime = t() : e.RelativeTime = t() }(this, (function () { const e = { year: 31536e6, month: 2628e6, day: 864e5, hour: 36e5, minute: 6e4, second: 1e3 }, t = "en", o = { numeric: "auto" }; function n(e) { e = { locale: (e = e || {}).locale || t, options: { ...o, ...e.options } }, this.rtf = new Intl.RelativeTimeFormat(e.locale, e.options) } return n.prototype = { from(t, o) { const n = t - (o || new Date); for (let t in e) if (Math.abs(n) > e[t] || "second" == t) return this.rtf.format(Math.round(n / e[t]), t) } }, n }));
</script>
<script id="ui_utils">
// Global variables
const domRefs = {};
let timerId;
const currentYear = new Date().getFullYear();
const relativeTime = new RelativeTime({ style: 'narrow' });
//Checks for internet connection status
if (!navigator.onLine) {
notify(
"There seems to be a problem connecting to the internet. Please check your internet connection.",
"error",
{ pinned: true }
);
}
window.addEventListener("offline", () => {
notify(
"There seems to be a problem connecting to the internet. Please check your internet connection.",
"error",
{ pinned: true }
);
location.reload()
});
window.addEventListener("online", () => {
getRef("notification_drawer").clearAll();
notify("We are back online.", "success");
});
// Use instead of document.getElementById
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;
}
}
}
// returns dom with specified element
function createElement(tagName, options = {}) {
const { className, textContent, innerHTML, attributes = {} } = options
const elem = document.createElement(tagName)
for (let attribute in attributes) {
elem.setAttribute(attribute, attributes[attribute])
}
if (className)
elem.className = className
if (textContent)
elem.textContent = textContent
if (innerHTML)
elem.innerHTML = innerHTML
return elem
}
// Use when a function needs to be executed after user finishes changes
const debounce = (callback, wait) => {
let timeoutId = null;
return (...args) => {
window.clearTimeout(timeoutId);
timeoutId = window.setTimeout(() => {
callback.apply(null, args);
}, wait);
};
}
let zIndex = 10
// function required for popups or modals to appear
function showPopup(popupId, pinned) {
zIndex++
getRef(popupId).setAttribute('style', `z-index: ${zIndex}`)
getRef(popupId).show({ pinned })
return getRef(popupId);
}
// hides the popup or modal
function hidePopup() {
if (popupStack.peek() === undefined)
return;
popupStack.peek().popup.hide()
}
// displays a popup for asking permission. Use this instead of JS confirm
const getConfirmation = (title, options = {}) => {
return new Promise(resolve => {
const { message, cancelText = 'Cancel', confirmText = 'OK' } = options
showPopup('confirmation_popup', true)
getRef('confirm_title').textContent = title;
getRef('confirm_message').textContent = message;
let cancelButton = getRef('confirmation_popup').children[2].children[0],
submitButton = getRef('confirmation_popup').children[2].children[1]
submitButton.textContent = confirmText
cancelButton.textContent = cancelText
submitButton.onclick = () => {
hidePopup()
resolve(true);
}
cancelButton.onclick = () => {
hidePopup()
resolve(false);
}
})
}
// displays a popup for asking user input. Use this instead of JS prompt
function getPromptInput(title, message = '', options = {}) {
const { isPassword = true, cancelText = 'Cancel', confirmText = 'OK' } = options
showPopup('prompt_popup', true)
getRef('prompt_title').textContent = title;
getRef('prompt_message').textContent = message;
let buttons = getRef('prompt_popup').querySelectorAll("sm-button");
if (isPassword)
getRef('prompt_input').setAttribute("type", "password")
getRef('prompt_input').focusIn()
buttons[0].textContent = cancelText;
buttons[1].textContent = confirmText;
return new Promise((resolve, reject) => {
buttons[0].onclick = () => {
hidePopup()
return (null);
}
buttons[1].onclick = () => {
const value = getRef('prompt_input').value;
hidePopup()
resolve(value)
}
})
}
//Function for displaying toast notifications. pass in error for mode param if you want to show an error.
function notify(message, mode, options = {}) {
const { pinned = false, sound = false } = 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>`
break;
}
getRef("notification_drawer").push(message, { pinned, icon });
if (mode === 'error') {
console.error(message)
}
}
function getFormattedTime(time, format) {
try {
let [day, month, date, year] = new Date(time).toString().split(' '),
minutes = new Date(time).getMinutes(),
hours = new Date(time).getHours(),
currentTime = new Date().toString().split(' ')
minutes = minutes < 10 ? `0${minutes}` : minutes
let finalHours = ``;
if (hours > 12)
finalHours = `${hours - 12}:${minutes}`
else if (hours === 0)
finalHours = `12:${minutes}`
else
finalHours = `${hours}:${minutes}`
finalHours = hours >= 12 ? `${finalHours} PM` : `${finalHours} AM`
switch (format) {
case 'date-only':
return `${month} ${date}, ${year}`;
break;
default:
return `${month} ${date} ${year}, ${finalHours}`;
}
} catch (e) {
console.error(e);
return time;
}
}
window.addEventListener('hashchange', e => showPage(window.location.hash))
window.addEventListener("load", () => {
showPage(window.location.hash, { firstLoad: true });
document.body.classList.remove('hide')
document.querySelectorAll('sm-input[data-flo-id]').forEach(input => input.customValidation = floCrypto.validateAddr)
document.querySelectorAll('sm-input[data-private-key]').forEach(input => input.customValidation = floCrypto.getPubKeyHex)
document.addEventListener('keyup', (e) => {
if (e.key === 'Escape') {
hidePopup()
}
})
document.addEventListener('copy', () => {
notify('copied', 'success')
})
document.addEventListener("pointerdown", (e) => {
if (e.target.closest("button:not([disabled]), sm-button:not([disabled]), .interact")) {
createRipple(e, e.target.closest("button, sm-button, .interact"));
}
});
});
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(4)",
opacity: 0,
},
],
{
duration: 600,
fill: "forwards",
easing: "ease-out",
}
);
target.append(circle);
rippleAnimation.onfinish = () => {
circle.remove();
};
}
const pagesData = {
lastPage: '',
currentPage: '',
params: {}
}
async function showPage(targetPage, options = {}) {
const { firstLoad, hashChange } = options
let pageId
let subPageId
let params = {}
let searchParams
if (targetPage === '') {
pageId = 'exchange'
} else {
if (targetPage.includes('/')) {
if (targetPage.includes('?')) {
const splitAddress = targetPage.split('?')
searchParams = splitAddress.pop()
const pages = splitAddress.pop().split('/')
pageId = pages[1]
subPageId = pages[2]
} else {
const pages = targetPage.split('/')
pageId = pages[1]
subPageId = pages[2]
}
} else {
pageId = targetPage
}
}
if (searchParams) {
const urlSearchParams = new URLSearchParams('?' + searchParams);
params = Object.fromEntries(urlSearchParams.entries());
}
if (typeof proxy.userID === "undefined" && !['exchange', 'market', 'help'].includes(pageId)) {
pageId = 'exchange'
history.replaceState(null, null, '#/exchange')
}
pagesData.currentPage = pageId
if (!firstLoad)
switch (pageId) {
case 'exchange':
if (!document.body.classList.contains('is-signed-in')) break;
if (!isMobileView && !params.hasOwnProperty('asset') || params.asset === '') {
params.asset = 'FLO'
}
if (params.hasOwnProperty('asset') && params.asset !== '') {
if (getRef('listed_assets').querySelector('.listed-asset--active'))
getRef('listed_assets').querySelector('.listed-asset--active').classList.remove('listed-asset--active')
getRef('listed_assets').querySelector(`[href="#/exchange?asset=${params.asset}"]`).classList.add('listed-asset--active')
getRef('chart_asset').textContent = `${params.asset}/INR`
showSuggestedPrice(params.asset)
getRef('traded_asset').textContent = `Trade ${params.asset}`
getRef('trade_button').textContent = `${tradeType} ${params.asset}`
getRef('quantity_type').textContent = tradeType === 'buy' ? formatAmount(allTokens.rupee.net, true) : `${parseFloat(allTokens[params.asset].net.toFixed(4))} ${params.asset}`
updateTooltip(params.asset, tradeType)
}
const animOptions = {
duration: 150,
easing: 'ease',
fill: 'forwards',
}
if (params.hasOwnProperty('asset') && params.asset !== '') {
if (isMobileView) {
if (!getRef('asset_list_wrapper').classList.contains('hide-on-mobile')) {
animateTo(getRef('main_header'), slideOutLeft, animOptions)
animateTo(getRef('main_navbar'), slideOutLeft, animOptions)
animateTo(getRef('asset_list_wrapper'), slideOutLeft, animOptions).onfinish = () => {
getRef('main_header').classList.add('hide-on-mobile')
getRef('main_navbar').classList.add('hide-on-mobile')
getRef('asset_list_wrapper').classList.add('hide-on-mobile')
getRef('asset_page').classList.remove('hide-on-mobile')
animateTo(getRef('asset_page'), slideInLeft, animOptions)
}
}
} else {
getRef('main_header').classList.add('hide-on-mobile')
getRef('main_navbar').classList.add('hide-on-mobile')
getRef('asset_list_wrapper').classList.add('hide-on-mobile')
getRef('asset_page').classList.remove('hide-on-mobile')
}
if (!chart) {
chart = LightweightCharts.createChart(getRef('price_history_chart'), {
width: 800, height: 600,
timeScale: {
timeVisible: true,
},
});
lineSeries = chart.addLineSeries();
setChartTheme()
chartObserver.observe(getRef('price_chart_wrapper'))
}
render.chart(params.asset)
} else {
if (isMobileView) {
if (!getRef('asset_page').classList.contains('hide-on-mobile')) {
animateTo(getRef('asset_page'), slideOutRight, animOptions).onfinish = () => {
getRef('asset_page').classList.add('hide-on-mobile')
getRef('asset_list_wrapper').classList.remove('hide-on-mobile')
animateTo(getRef('asset_list_wrapper'), slideInRight, animOptions)
getRef('main_header').classList.remove('hide-on-mobile')
getRef('main_navbar').classList.remove('hide-on-mobile')
animateTo(getRef('main_header'), slideInRight, animOptions)
animateTo(getRef('main_navbar'), slideInRight, animOptions)
}
}
} else {
getRef('asset_page').classList.add('hide-on-mobile')
getRef('asset_list_wrapper').classList.remove('hide-on-mobile')
}
}
break;
case 'my_orders':
break;
case 'market':
break;
case 'wallet':
break;
}
if (pagesData.lastPage !== pageId) {
document.querySelectorAll('.mobile-page').forEach(elem => elem.classList.add('hide'))
getRef(pageId).classList.remove('hide')
document.querySelectorAll('.main_navbar__item').forEach(elem => elem.classList.remove('main_navbar__item--active'))
document.querySelector(`.main_navbar__item[href="#/${pageId}"]`).classList.add('main_navbar__item--active')
getRef('pages_container').style.overflowY = "hidden";
getRef(pageId).animate([
{
opacity: 0,
transform: 'translateY(1rem)'
},
{
opacity: 1,
transform: 'translateY(0)'
},
],
{
duration: 300,
easing: 'cubic-bezier(0.175, 0.885, 0.32, 1.275)'
}).onfinish = () => {
getRef('pages_container').style.overflowY = "";
}
pagesData.lastPage = pageId
}
pagesData.params = params
}
// class based lazy loading
class LazyLoader {
constructor(container, elementsToRender, renderFn, options = {}) {
const { batchSize = 10 } = options
this.elementsToRender = elementsToRender
this.arrayOfElements = (typeof elementsToRender === 'function') ? this.elementsToRender() : elementsToRender || []
this.renderFn = renderFn
this.intersectionObserver
this.batchSize = batchSize
this.lazyContainer = document.querySelector(container)
this.update = this.update.bind(this)
this.render = this.render.bind(this)
this.init = this.init.bind(this)
this.clear = this.clear.bind(this)
}
init() {
this.intersectionObserver = new IntersectionObserver((entries, observer) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
observer.disconnect()
this.render({ lazyLoad: true })
}
})
}, {
threshold: 0.3
})
this.mutationObserver = new MutationObserver(mutationList => {
mutationList.forEach(mutation => {
if (mutation.type === 'childList') {
if (mutation.addedNodes.length) {
this.intersectionObserver.observe(this.lazyContainer.lastElementChild)
}
}
})
})
this.mutationObserver.observe(this.lazyContainer, {
childList: true,
})
this.render()
}
update(elementsToRender) {
this.arrayOfElements = (typeof elementsToRender === 'function') ? this.elementsToRender() : elementsToRender || []
this.render()
}
render(options = {}) {
let { lazyLoad = false } = options
const frag = document.createDocumentFragment();
if (lazyLoad) {
this.updateStartIndex = this.updateEndIndex
this.updateEndIndex = this.arrayOfElements.length > this.updateEndIndex + this.batchSize ? this.updateEndIndex + this.batchSize : this.arrayOfElements.length
} else {
this.intersectionObserver.disconnect()
this.lazyContainer.innerHTML = ``;
this.updateStartIndex = 0
this.updateEndIndex = this.arrayOfElements.length > this.batchSize ? this.batchSize : this.arrayOfElements.length
}
for (let index = this.updateStartIndex; index < this.updateEndIndex; index++) {
frag.append(this.renderFn(this.arrayOfElements[index]))
}
this.lazyContainer.append(frag)
}
clear() {
this.intersectionObserver.disconnect()
this.mutationObserver.disconnect()
this.lazyContainer.innerHTML = ``;
}
reset() {
this.arrayOfElements = (typeof this.elementsToRender === 'function') ? this.elementsToRender() : this.elementsToRender || []
this.render()
}
}
function animateTo(element, keyframes, options) {
const anime = element.animate(keyframes, { ...options, fill: 'both' })
anime.finished.then(() => {
anime.commitStyles()
anime.cancel()
})
return anime
}
let isMobileView = false
const mobileQuery = window.matchMedia('(max-width: 40rem)')
function handleMobileChange(e) {
isMobileView = e.matches
if (!isMobileView) {
getRef('main_header').style = ''
getRef('asset_list_wrapper').style = ''
getRef('asset_page').style = ''
getRef('main_navbar').style = ''
}
}
mobileQuery.addEventListener('change', handleMobileChange)
handleMobileChange(mobileQuery)
function showChild(id, index) {
[...getRef(id).children].forEach((child, i) => {
if (i === index)
child.classList.remove('hide')
else
child.classList.add('hide')
})
}
function handleVisibilityChange() {
if (document.visibilityState === "hidden") {
// code if page is hidden
} else {
updateRate();
}
}
document.addEventListener("visibilitychange", handleVisibilityChange, false);
</script>
<script>
function buttonLoader(id, show = false) {
getRef(id).disabled = show;
const animOptions = {
duration: 200,
fill: 'forwards',
easing: 'ease'
}
if (show) {
getRef(id).parentNode.append(createElement('sm-spinner'))
getRef(id).animate([
{
clipPath: 'circle(100%)',
},
{
clipPath: 'circle(0)',
},
], animOptions).onfinish = e => {
e.target.commitStyles()
e.target.cancel()
}
} else {
getRef(id).animate([
{
clipPath: 'circle(0)',
},
{
clipPath: 'circle(100%)',
},
], animOptions).onfinish = e => {
e.target.commitStyles()
e.target.cancel()
}
getRef(id).style = ''
const potentialTarget = getRef(id).parentNode.querySelector('sm-spinner')
if (potentialTarget) potentialTarget.remove();
}
}
const listedAssets = {
rupee: {
icon: `<svg class="icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<path
d="M15.3,4.91a4.78,4.78,0,0,0-.39-.5l3.14,0L18.75,2H6L5.25,4.6H9a4.22,4.22,0,0,1,3.06,1,3.16,3.16,0,0,1,.75,1.24H5.93L5.25,9.22h7.62a3.15,3.15,0,0,1-.34.82,3,3,0,0,1-1.37,1.17,5.34,5.34,0,0,1-2.2.4H5.5l0,1.9,7,8.49h3.56v-.17L9.68,14l.09,0a8.07,8.07,0,0,0,3.65-1,5,5,0,0,0,2-2.09A6.29,6.29,0,0,0,16,9.22h2.1l.69-2.42H15.93A5.93,5.93,0,0,0,15.3,4.91Z" />
</svg>`},
FLO: {
icon: `<svg class="icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<path
d="M16.36,15.39c1.83,0,4.26-2.49,4.36-4.74-5.65-.19-4.91.47-7.28,2.39,2.19-2.4,1.42-7.79-1.43-10V6.17c2.33,1.49,2.21,5.14,0,7.15-2.23-2-2.27-5.69,0-7.15V3c-2.83,2.26-3.62,7.66-1.44,10-2.36-1.93-1.63-2.58-7.28-2.39.1,2.26,2.55,4.73,4.36,4.74,0,0-1.93.22-2.74-2.62,2.38-.37,4.29-.14,6.28,2-.79-.11-4.89,1.13-4.38,3.26.53.06,3,.3,3.58-.83-.17.18-1.25.5-1.53.05.38-1.39,2.32-2,2.32-2-1,1.82-.48,4.63.82,5.72,1.31-1.08,1.8-3.95.82-5.72,0,0,1.95.6,2.32,2-.29.46-1.36.12-1.53-.05.58,1.14,3.06.88,3.58.83.49-2.17-3.58-3.36-4.38-3.26,2-2.17,3.92-2.39,6.28-2C18.3,15.62,16.36,15.39,16.36,15.39ZM12,19.46c-.91-.79-.5-3,0-3.59C12.5,16.45,12.91,18.66,12,19.46Z" />
</svg>`
},
flobnb: {
icon: `
<svg class="icon" width="64" height="56" viewBox="0 0 64 56" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M37.3261 19.7091C37.2823 19.3891 37.2604 19.0614 37.2604 18.7261C37.2604 17.4352 37.4871 16.2887 37.9405 15.2866C38.4101 14.2675 39.0416 13.4777 39.835 12.9172C40.6284 12.3397 41.519 12.051 42.5067 12.051C43.462 12.051 44.2797 12.3057 44.9598 12.8153C45.6399 13.3079 46.1499 13.9618 46.4899 14.7771C46.83 15.5924 47 16.4671 47 17.4013C47 18.6921 46.7652 19.8471 46.2956 20.8662C45.8261 21.8684 45.1865 22.6582 44.3769 23.2357C43.5835 23.7962 42.701 24.0764 41.7295 24.0764C40.7741 24.0764 39.9564 23.8302 39.2763 23.3376C38.8283 22.9937 38.454 22.5802 38.1535 22.0971C37.7343 22.518 37.2952 22.8891 36.8359 23.2102C36.0263 23.7877 35.1034 24.0764 34.0671 24.0764C32.966 24.0764 32.0835 23.6603 31.4197 22.828C30.7558 21.9788 30.3024 20.8323 30.0595 19.3885C29.509 19.5414 28.9261 19.6178 28.3108 19.6178C27.7764 19.6178 27.1854 19.5754 26.5377 19.4904C26.7644 20.5605 26.9506 21.758 27.0963 23.0828C27.2421 24.4076 27.3149 25.4947 27.3149 26.344C27.3149 28.1783 27.0316 29.5796 26.4649 30.5478C25.8981 31.5159 25.1533 32 24.2303 32C23.0645 32 22.2306 31.1338 21.7286 29.4013C21.2429 27.6688 21 25.0531 21 21.5541C21 18.293 21.3319 14.9894 21.9958 11.6433C22.6759 8.28026 23.5988 5.50318 24.7647 3.3121C25.9467 1.10403 27.2421 0 28.6508 0C29.4118 0 30.0028 0.356688 30.4238 1.07006C30.861 1.78344 31.0796 2.7431 31.0796 3.94905C31.0796 7.94055 28.8046 12.2887 24.2546 16.9936C24.0927 18.6582 24.0117 20.1189 24.0117 21.3758C24.0117 23.1253 24.0684 24.9172 24.1818 26.7516C24.2951 28.603 24.4813 29.5287 24.7404 29.5287C25.2262 29.5287 25.469 28.6454 25.469 26.879C25.469 25.5541 25.38 24.2718 25.2019 23.0318C25.0399 21.7919 24.8133 20.4841 24.5218 19.1083C24.5056 18.8875 24.5704 18.6072 24.7161 18.2675C24.878 17.9278 25.0723 17.6306 25.299 17.3758C25.5257 17.121 25.7281 16.9936 25.9062 16.9936C26.1167 16.9936 26.4487 17.0106 26.902 17.0446C27.4202 17.0786 27.8088 17.0955 28.0679 17.0955C28.6508 17.0955 29.2499 17.0106 29.8652 16.8408V16.7643C29.8652 14.6921 30.1162 12.3312 30.6181 9.68153C31.1363 7.03185 31.8892 4.75584 32.877 2.8535C33.8809 0.951168 35.071 0 36.4473 0C37.2246 0 37.8318 0.382166 38.2689 1.1465C38.7223 1.89384 38.949 2.9724 38.949 4.38217C38.949 5.75796 38.7061 7.3206 38.2204 9.07006C37.7346 10.8195 37.0302 12.5011 36.1073 14.1147C35.1843 15.7113 34.0995 16.9936 32.8527 17.9618C32.9174 19.1677 33.0875 20.0255 33.3627 20.535C33.638 21.0276 34.0428 21.2739 34.5771 21.2739C35.241 21.2739 35.8239 21.0786 36.3259 20.6879C36.614 20.4539 36.9474 20.1277 37.3261 19.7091ZM27.0478 4.07643C27.485 3.04034 27.8493 2.52229 28.1407 2.52229C28.5455 2.52229 28.748 3.04034 28.748 4.07643C28.7318 5.53716 28.3755 7.10828 27.6793 8.78981C26.983 10.4544 25.9872 12.0594 24.6918 13.6051C24.9995 11.7028 25.3638 9.90234 25.7848 8.20382C26.2058 6.48832 26.6268 5.11253 27.0478 4.07643ZM34.7229 4.43312C35.1762 3.15924 35.573 2.52229 35.913 2.52229C36.3664 2.52229 36.5931 3.16773 36.5931 4.4586C36.5931 5.49469 36.4554 6.65817 36.1802 7.94905C35.9211 9.22293 35.5082 10.4883 34.9415 11.7452C34.3747 12.9851 33.6866 14.0382 32.877 14.9045C32.9579 13.0531 33.1765 11.1592 33.5327 9.22293C33.889 7.28663 34.2857 5.69002 34.7229 4.43312ZM43.3811 20.3822C43.0086 21.0106 42.5472 21.3248 41.9966 21.3248C41.5109 21.3248 41.1061 21.0955 40.7822 20.6369C40.4584 20.1783 40.2964 19.465 40.2964 18.4968C40.2964 17.2739 40.4827 16.3567 40.8551 15.7452C41.2437 15.1168 41.7295 14.8025 42.3124 14.8025C42.7658 14.8025 43.1544 15.0403 43.4782 15.5159C43.802 15.9915 43.964 16.6964 43.964 17.6306C43.964 18.8365 43.7697 19.7537 43.3811 20.3822ZM23.5795 37.5556C23.0372 39.1867 22.6225 40.8605 22.3354 42.5769C20.9523 42.8675 19.7215 43.0456 18.6428 43.1111C18.3936 40.9185 17.6149 39.0815 16.3066 37.6C14.9984 36.0889 13.3007 35.2593 11.2137 35.1111C13.4565 32.4741 15.0607 29.9556 16.0263 27.5556C16.9919 25.1556 17.4747 22.7407 17.4747 20.3111C17.4747 18.4444 17.0386 16.9333 16.1665 15.7778C15.2943 14.5926 14.1418 14 12.7089 14C10.0612 14 7.77173 15.5852 5.84048 18.7556C3.94038 21.8963 2.49194 25.7185 1.49516 30.2222C0.498388 34.6963 0 38.8444 0 42.6667C0 46.9926 0.716432 50.2963 2.1493 52.5778C3.58216 54.8593 5.87163 56 9.0177 56C11.1047 56 13.0048 55.2444 14.718 53.7333C16.4624 52.2222 17.646 50.237 18.269 47.7778C19.5276 47.7279 20.7273 47.594 21.8682 47.3762C21.8565 47.76 21.8507 48.1457 21.8507 48.5333C21.8507 51.1407 22.0843 53.037 22.5516 54.2222C23.0499 55.4074 23.891 56 25.0746 56C26.0403 56 26.7411 55.763 27.1772 55.2889C27.6445 54.7852 28.0494 53.837 28.392 52.4444C28.8593 50.637 29.4667 48.9185 30.2143 47.2889C30.993 45.6593 31.7406 44.3556 32.457 43.3778C33.2046 42.3704 33.7809 41.8667 34.1858 41.8667C34.5284 41.8667 34.6998 42.1037 34.6998 42.5778C34.6998 43.2889 34.4973 44.5778 34.0924 46.4444C33.6563 48.5778 33.4382 50.0593 33.4382 50.8889C33.4382 52.5481 33.8432 53.8222 34.653 54.7111C35.4629 55.5704 36.6622 56 38.2508 56C40.2132 56 41.9575 55.4963 43.4838 54.4889C44.678 53.7165 45.808 52.7786 46.874 51.6753C47.0272 51.9921 47.1913 52.2929 47.3663 52.5778C48.7992 54.8593 51.0731 56 54.188 56C55.9012 56 57.5054 55.5111 59.0005 54.5333C60.4957 53.5259 61.695 52.1333 62.5983 50.3556C63.5328 48.5778 64 46.5778 64 44.3556C64 42.7556 63.6885 41.2741 63.0655 39.9111C62.4737 38.5481 61.6015 37.437 60.449 36.5778C59.3276 35.7185 58.0038 35.2296 56.4775 35.1111C58.7202 32.4741 60.3244 29.9556 61.29 27.5556C62.2556 25.1556 62.7385 22.7407 62.7385 20.3111C62.7385 18.4444 62.3024 16.9333 61.4302 15.7778C60.558 14.5926 59.4055 14 57.9726 14C55.3249 14 53.0355 15.5852 51.1042 18.7556C49.2041 21.8963 47.7557 25.7185 46.7589 30.2222C45.7621 34.6963 45.2637 38.8444 45.2637 42.6667C45.2637 44.3055 45.3643 45.7977 45.5655 47.1431C44.3991 48.4396 43.4404 49.4067 42.6895 50.0444C41.8485 50.7556 41.1165 51.1111 40.4935 51.1111C39.5902 51.1111 39.1385 50.5185 39.1385 49.3333C39.1385 48.5037 39.4344 46.8 40.0263 44.2222C40.7116 41.2 41.0542 39.1111 41.0542 37.9556C41.0542 36.0296 40.0419 35.0667 38.0172 35.0667C36.9892 35.0667 35.8523 35.4074 34.6063 36.0889C33.3915 36.7704 32.1455 37.9111 30.8684 39.5111C29.5913 41.1111 28.4388 43.1852 27.4108 45.7333C27.5354 44.4296 27.6912 43.3333 27.8781 42.4444C28.065 41.5556 28.3142 40.5185 28.6257 39.3333C29.0929 37.6741 29.3265 36.6074 29.3265 36.1333C29.3265 35.7185 29.2019 35.437 28.9527 35.2889C28.7035 35.1407 28.2674 35.0667 27.6445 35.0667C26.4919 35.0667 25.5886 35.2741 24.9345 35.6889C24.3115 36.0741 23.8598 36.6963 23.5795 37.5556ZM11.6342 18.4C11.0113 18.4 10.326 19.2889 9.57839 21.0667C8.86196 22.8148 8.19225 25.2 7.56926 28.2222C6.94628 31.2444 6.47904 34.5481 6.16755 38.1333C8.2234 34.5481 9.85873 31.3926 11.0736 28.6667C12.3195 25.9111 12.9425 23.4667 12.9425 21.3333C12.9425 20.3852 12.8179 19.6593 12.5687 19.1556C12.3507 18.6519 12.0392 18.4 11.6342 18.4ZM9.2046 51.2889C10.1702 51.2889 11.0268 50.9037 11.7744 50.1333C12.522 49.363 13.0204 48.2519 13.2696 46.8C12.3039 46.1778 11.5564 45.363 11.0268 44.3556C10.5284 43.3481 10.2792 42.2815 10.2792 41.1556C10.2792 40.7407 10.3415 40.1778 10.4661 39.4667H10.326C9.04885 39.4667 7.97421 40.0741 7.10203 41.2889C6.261 42.4741 5.84048 44.0741 5.84048 46.0889C5.84048 47.7778 6.16755 49.0667 6.82168 49.9556C7.50697 50.8444 8.30127 51.2889 9.2046 51.2889ZM56.3373 28.6667C55.1225 31.3926 53.4871 34.5481 51.4313 38.1333C51.7428 34.5481 52.21 31.2444 52.833 28.2222C53.456 25.2 54.1257 22.8148 54.8421 21.0667C55.5897 19.2889 56.275 18.4 56.898 18.4C57.3029 18.4 57.6144 18.6519 57.8325 19.1556C58.0816 19.6593 58.2062 20.3852 58.2062 21.3333C58.2062 23.4667 57.5833 25.9111 56.3373 28.6667ZM57.0381 49.5556C56.3217 50.6519 55.434 51.2 54.3749 51.2C53.4404 51.2 52.6617 50.8 52.0387 50C51.4157 49.1704 51.1042 47.8667 51.1042 46.0889C51.1042 44.0444 51.478 42.4889 52.2256 41.4222C52.9732 40.3556 53.8921 39.8222 54.9823 39.8222C55.8545 39.8222 56.6021 40.237 57.225 41.0667C57.848 41.8963 58.1595 43.1259 58.1595 44.7556C58.1595 46.8593 57.7857 48.4593 57.0381 49.5556Z"/>
</svg>
`
},
mining: {
icon: `<svg class="icon" width="64" height="64" viewBox="0 0 64 64" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M22.0861 14.6534C22.3924 14.3472 22.7898 14.1486 23.2186 14.0876L44.6946 11.0319C45.2676 10.9504 45.8455 11.1432 46.2547 11.5524C47.2381 12.5358 46.8168 14.2128 45.4853 14.6146L28.6869 19.6843C28.3711 19.7796 28.0838 19.9515 27.8505 20.1848L27.0092 21.0261L28.3236 22.3404C29.0306 23.0475 29.0976 24.1522 28.5245 24.9346L52.2562 48.6662C53.0372 49.4473 53.0372 50.7136 52.2562 51.4946L51.4947 52.2561C50.7137 53.0372 49.4473 53.0372 48.6663 52.2561L24.9346 28.5245C24.1522 29.0976 23.0475 29.0306 22.3404 28.3236L21.0261 27.0092L20.1848 27.8505C19.9515 28.0838 19.7796 28.3711 19.6843 28.6869L14.6146 45.4853C14.2128 46.8168 12.5358 47.2381 11.5524 46.2547C11.1432 45.8455 10.9504 45.2675 11.0319 44.6946L14.0876 23.2186C14.1486 22.7898 14.3472 22.3924 14.6534 22.0861L15.3949 21.3447C14.8777 20.6386 14.8818 19.67 15.4072 18.9681C14.8209 18.1848 14.8837 17.0693 15.5958 16.3572L16.3573 15.5958C17.0694 14.8837 18.1848 14.8208 18.9681 15.4072C19.6701 14.8818 20.6386 14.8777 21.3447 15.3949L22.0861 14.6534Z"/>
</svg>`
},
default: {
icon: `<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="M15 4c-4.42 0-8 3.58-8 8s3.58 8 8 8 8-3.58 8-8-3.58-8-8-8zm0 14c-3.31 0-6-2.69-6-6s2.69-6 6-6 6 2.69 6 6-2.69 6-6 6zM3 12c0-2.61 1.67-4.83 4-5.65V4.26C3.55 5.15 1 8.27 1 12s2.55 6.85 6 7.74v-2.09c-2.33-.82-4-3.04-4-5.65z"/></svg>`
}
}
function getIcon(asset) {
return listedAssets.hasOwnProperty(asset) ? listedAssets[asset].icon : listedAssets.default.icon;
}
function formatAmount(amount, shorten = false) {
return amount.toLocaleString(`en-IN`, { style: 'currency', currency: 'INR', maximumFractionDigits: shorten ? 2 : 8 })
}
// Convert milliseconds to time left in HH:MM:SS format
function getTimeLeft(milliseconds) {
const diff = milliseconds - Date.now()
const hours = Math.floor(diff / 3600000)
const minutes = Math.floor((diff % 3600000) / 60000)
const seconds = Math.floor(((diff % 3600000) % 60000) / 1000)
return `${hours}:${minutes < 10 ? '0' : ''}${minutes}:${seconds < 10 ? '0' : ''}${seconds}`
}
function getSuggestedPrice(asset = pagesData.params.asset || 'FLO') {
return parseFloat((parseFloat(floGlobals.exchangeRates[asset]) * deviation[tradeType]).toFixed(8))
}
function showSuggestedPrice(asset = pagesData.params.asset || 'FLO') {
getRef('get_price').innerHTML = `
<div class="grid">
<div style="font-size: 0.8rem; font-weight: 500; margin-bottom: 0.3rem;">Current price</div>
<h3>${formatAmount(floGlobals.exchangeRates[asset])}</h3>
</div>
<div class="grid">
<div style="font-size: 0.8rem; font-weight: 500; margin-bottom: 0.3rem;">${tradeType === 'buy' ? 'Highest' : 'Lowest'} price</div>
<h3>${formatAmount(getSuggestedPrice(asset))}</h3>
</div>
<div class="tooltip">
<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="M11 7h2v2h-2zm0 4h2v6h-2zm1-9C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8z"/></svg>
<p class="banner">
${tradeType === 'buy' ?
`<b>Highest price</b> is the max price upto which your order can be executed, which is <b>${DEFAULT_TRADE_PRICE_DEVIATION * 100}%</b> higher than current price.` :
`<b>Lowest price</b> is the min price until which your order can be executed, which is <b>${DEFAULT_TRADE_PRICE_DEVIATION * 100}%</b> lower than current price.`
} System will always try to execute your order at the <b>nearest price possible to current price</b>.
</p>
</div>
`
}
const chartDimensions = {
height: 0,
width: 0
}
floGlobals.countDowns = {
intervals: {},
timeouts: {}
}
// convert GMT to IST
function getIST(originalTime) {
const d = new Date(originalTime);
return Date.UTC(d.getFullYear(), d.getMonth(), d.getDate(), d.getHours(), d.getMinutes(), d.getSeconds(), d.getMilliseconds()) / 1000;
}
const render = {
listedAsset(asset, rate, countDown) {
const clone = getRef('listed_asset_template').content.cloneNode(true).firstElementChild
clone.firstElementChild.href = `#/exchange?asset=${asset}`
clone.firstElementChild.dataset.listedAsset = asset
clone.querySelector('.listed-asset__icon').innerHTML = getIcon(asset)
clone.querySelector('.listed-asset__rate').textContent = formatAmount(rate)
clone.querySelector('.listed-asset__name').textContent = asset
floGlobals.countDowns.intervals[asset] = setInterval(() => {
clone.querySelector('.listed-asset__countdown').textContent = `Est. time left: ${getTimeLeft(countDown)}`;
}, 1000);
floGlobals.countDowns.timeouts[asset] = setTimeout(() => {
updateRate()
delete floGlobals.countDowns.timeouts[asset]
}, countDown - Date.now());
return clone
},
orderCard(orderDetails = {}) {
const { id, asset, quantity, price, time, type } = orderDetails
const card = getRef('order_template').content.cloneNode(true).firstElementChild
card.dataset.id = id
card.dataset.type = type
card.querySelector('.order-card__type').textContent = type
card.querySelector('.order-card__quantity').textContent = `${quantity} ${asset}`
card.querySelector('.order-card__price-type').textContent = type === 'buy' ? 'Valid upto' : 'Valid until'
card.querySelector('.order-card__price').textContent = formatAmount(price)
card.querySelector('.order-card__time').textContent = relativeTime.from(new Date(time).getTime())
return card
},
transactionCard(transactionDetails = {}) {
const { buyer, seller, type, other, asset, quantity, unitValue, time } = transactionDetails
const card = getRef('transaction_template').content.cloneNode(true).firstElementChild
card.dataset.type = type
card.querySelector('.transaction-card__type').textContent = type
card.querySelector('.transaction-card__quantity').textContent = `${quantity} ${asset}`
card.querySelector('.transaction-card__price').textContent = formatAmount(unitValue)
card.querySelector('.transaction-card__total').textContent = formatAmount(parseFloat(unitValue * quantity))
card.querySelector('.more-info').dataset.buyer = buyer
card.querySelector('.more-info').dataset.seller = seller
card.querySelector('.more-info').dataset.other = other
card.querySelector('.more-info').dataset.time = time
return card
},
marketOrderCard(orderDetails = {}) {
const { floID, asset, quantity, minPrice, maxPrice, time_placed, type } = orderDetails
const card = getRef('market_order_template').content.cloneNode(true).firstElementChild
const unitValue = minPrice || maxPrice;
card.dataset.type = type
card.classList.add(`transaction-card--${type}`)
card.querySelector('.transaction-card__quantity').textContent = `${quantity} ${asset}`
card.querySelector('.transaction-card__price').textContent = formatAmount(unitValue)
card.querySelector('.transaction-card__total').textContent = formatAmount(parseFloat(unitValue * quantity))
card.querySelector('.more-info').dataset.time = time_placed
card.querySelector('.more-info').dataset.buyer = type === 'buy' ? floID : undefined
card.querySelector('.more-info').dataset.seller = type === 'sell' ? floID : undefined
card.querySelector('.more-info').dataset.pending = true
return card
},
marketTransactionCard(transactionDetails = {}) {
const { buyer, seller, asset, quantity, unitValue, time } = transactionDetails
const card = getRef('market_transaction_template').content.cloneNode(true).firstElementChild
card.querySelector('.transaction-card__quantity').textContent = `${quantity} ${asset}`
card.querySelector('.transaction-card__price').textContent = `${unitValue}`
card.querySelector('.transaction-card__total').textContent = formatAmount(parseFloat(unitValue * quantity))
card.querySelector('.more-info').dataset.time = time
card.querySelector('.more-info').dataset.buyer = buyer
card.querySelector('.more-info').dataset.seller = seller
return card
},
assetBalanceCard(asset) {
const { net, locked } = allTokens[asset]
const card = getRef('asset_balance_card_template').content.cloneNode(true).firstElementChild
card.className = `balance-card ${locked ? 'is-locked' : ''}`
card.querySelector('.balance-card__token').textContent = asset
card.querySelector('.balance-card__icon').innerHTML = getIcon(asset)
const templateToClone = locked ? 'locked_balance_template' : 'net_balance_template';
const assetBalance = getRef(templateToClone).content.cloneNode(true)
assetBalance.querySelector('.available-balance').textContent = asset === 'rupee' ? formatAmount(net) : parseFloat(net.toFixed(4))
if (locked) {
assetBalance.querySelector('.locked-balance').textContent = asset === 'rupee' ? formatAmount(locked) : parseFloat(locked.toFixed(4))
}
card.appendChild(assetBalance)
return card
},
chart(asset = 'FLO', duration = '48 weeks') {
if (pagesData.currentPage !== 'exchange') return
floExchangeAPI.getRateHistory(asset, duration).then(data => {
data = data.map(({ time, rate }) => {
return {
time: getIST(time),
value: rate
}
})
lineSeries.setData(data);
new ResizeObserver(entries => {
chartDimensions.height = entries[0].contentRect.height - 10;
chartDimensions.width = entries[0].contentRect.width;
chart.applyOptions({ width: chartDimensions.width, height: chartDimensions.height });
}).observe(getRef('price_chart_wrapper'));
})
},
userOrders() {
let { buyOrders, sellOrders, transactions } = accountDetails
getRef('orders_list').innerHTML = '';
const frag = document.createDocumentFragment()
const ordersType = getRef('my_orders_category_selector').value
if (ordersType === 'open') {
getRef('my_orders__title').textContent = 'My orders'
const allOpenOrders = [...buyOrders, ...sellOrders].sort((a, b) => new Date(b.time_placed).getTime() - new Date(a.time_placed).getTime())
allOpenOrders.forEach(order => {
const { id, asset, quantity, minPrice = undefined, maxPrice = undefined, time_placed } = order
const orderDetails = {
id,
asset,
quantity,
type: minPrice ? 'sell' : 'buy',
price: minPrice || maxPrice,
time: time_placed
}
frag.append(render.orderCard(orderDetails))
})
} else {
getRef('my_orders__title').textContent = 'My trades'
transactions.forEach(transaction => {
const { asset, quantity, unitValue, tx_time, buyer, seller } = transaction
let type, other;
if (seller === proxy.userID) {
type = 'Sold';
other = buyer === proxy.userID ? 'MySelf' : buyer;
} else if (buyer === proxy.userID) {
type = 'Bought';
other = seller;
} else
return;
const transactionDetails = {
buyer,
seller,
type,
other,
asset,
quantity,
unitValue,
time: tx_time
}
frag.append(render.transactionCard(transactionDetails))
});
}
getRef('orders_list').append(frag)
},
marketOrders() {
const frag = document.createDocumentFragment()
const ordersType = getRef('market_orders_category_selector').value
if (ordersType === 'open') {
getRef('market_orders__title').textContent = 'Market-wide orders';
showChild('market_orders_wrapper', 0)
getRef('market_buy_orders').innerHTML = '<sm-spinner></sm-spinner>';
floExchangeAPI.getBuyList().then(buyOrders => {
getRef('market_buy_orders').innerHTML = '';
buyOrders.forEach(order => {
frag.append(render.marketOrderCard({
...order,
type: 'buy'
}))
})
getRef('market_buy_orders').append(frag)
}).catch(err => {
console.log(err)
})
getRef('market_sell_orders').innerHTML = '<sm-spinner></sm-spinner>';
floExchangeAPI.getSellList().then(sellOrders => {
getRef('market_sell_orders').innerHTML = '';
sellOrders.forEach(order => {
frag.append(render.marketOrderCard({
...order,
type: 'sell'
}))
})
getRef('market_sell_orders').append(frag)
}).catch(err => {
console.log(err)
})
} else {
getRef('market_orders__title').textContent = 'Market-wide trades';
showChild('market_orders_wrapper', 1)
getRef('market_trades').innerHTML = '<sm-spinner></sm-spinner>';
floExchangeAPI.getTradeList().then(trades => {
trades.forEach(transaction => {
const { seller, buyer, asset, quantity, unitValue, tx_time } = transaction
const transactionDetails = {
buyer,
seller,
asset,
quantity,
unitValue,
time: tx_time
}
frag.append(render.marketTransactionCard(transactionDetails))
})
getRef('market_trades').innerHTML = '';
const marketTransactionList = getRef('market_transaction_list_template').content.cloneNode(true)
getRef('market_trades').append(marketTransactionList)
getRef('market_trades').append(frag)
}).catch(err => {
console.log(err)
})
}
}
}
function showProcess(id) {
getRef(id).children[0].classList.add('clip')
getRef(id).children[0].disabled = true
getRef(id).append(document.createElement('sm-spinner'))
}
function hideProcess(id) {
getRef(id).children[0].classList.remove('clip')
getRef(id).children[0].disabled = false
getRef(id).querySelector('sm-spinner')?.remove()
}
const chartObserver = new IntersectionObserver(entries => {
if (entries[0].isIntersecting && chart) {
const { width, height } = entries[0].target.getBoundingClientRect()
chartDimensions.height = height - 10;
chartDimensions.width = width;
chart.applyOptions({ width: chartDimensions.width, height: chartDimensions.height });
}
})
let chart
let lineSeries
function getChartTheme() {
const theme = getRef('theme_toggle').value
const textColor = window.getComputedStyle(document.body).getPropertyValue('--text-color')
const accentColor = theme === 'dark' ? '#a3a1ff' : '#504dff'
return {
chart: {
layout: {
backgroundColor: `rgba(${textColor}, 0.01)`,
lineColor: `rgba(${textColor}, 0.1)`,
textColor: `rgba(${textColor}, 0.8)`,
},
watermark: {
color: 'rgba(0, 0, 0, 0)',
},
crosshair: {
color: '#758696',
},
grid: {
vertLines: {
color: `rgba(${textColor}, 0.2)`,
},
horzLines: {
color: `rgba(${textColor}, 0.2)`,
},
},
},
series: {
color: accentColor
}
}
}
function setChartTheme(e) {
if (chart) {
const themeToApply = getChartTheme()
chart.applyOptions(themeToApply.chart);
lineSeries.applyOptions(themeToApply.series);
}
}
document.addEventListener('themechange', setChartTheme)
getRef('trading_view_switcher').addEventListener('change', e => {
if (e.target.value === 'trade') {
getRef('price_chart_container').classList.add('hide-on-mobile')
getRef('trade_form').classList.remove('hide-on-mobile')
} else {
getRef('trade_form').classList.add('hide-on-mobile')
getRef('price_chart_container').classList.remove('hide-on-mobile')
}
})
function updateTooltip(asset, tradeType) {
getRef('quantity_selector').querySelectorAll('.button').forEach(button => {
if (tradeType === 'buy') {
button.title = `Buy ${asset} worth ${button.textContent} of total rupee`
} else {
button.title = `Sell ${button.textContent} of total ${asset}`
}
})
getRef('quantity_selector_tip').textContent = `${tradeType} ${asset} worth of the above percentage`
}
let tradeType = 'buy'
getRef('trade_type_selector').addEventListener('change', e => {
tradeType = e.detail.value
const selectedAsset = pagesData.params.asset
showSuggestedPrice()
getRef('get_total').setAttribute('placeholder', tradeType === 'buy' ? `Locked amount (₹)` : `Min amount received (₹)`)
getRef('trade_button').textContent = `${tradeType} ${selectedAsset}`
getRef('quantity_type').textContent = tradeType === 'buy' ? formatAmount(allTokens.rupee.net, true) : `${parseFloat(allTokens[selectedAsset].net.toFixed(4))} ${selectedAsset}`
updateTooltip(selectedAsset, tradeType)
})
getRef('price_duration_selector').addEventListener('change', e => {
render.chart(pagesData.params.asset, e.detail.value === 'hour' ? '48 weeks' : 'all-time')
})
async function tradeAsset() {
hidePopup()
const asset = pagesData.params.asset;
const quantity = parseFloat(getRef('get_quantity').value)
const price = getSuggestedPrice()
showProcess('trade_button_wrapper')
try {
if (tradeType === 'buy') {
await floExchangeAPI.buy(asset, quantity, price, proxy.userID, await proxy.secret)
} else {
await floExchangeAPI.sell(asset, quantity, price, proxy.userID, await proxy.secret)
}
getRef('trade_button_wrapper').append(getRef('success_template').content.cloneNode(true))
notify(`Placed ${tradeType} order`, 'success')
refresh()
}
catch (err) {
getRef('trade_button_wrapper').append(getRef('failure_template').content.cloneNode(true))
if (err.message === 'Insufficient rupee') {
notify(`Insufficient balance to ${tradeType} ${asset}. Please deposit rupee to wallet first.`, 'error', { pinned: true })
} else {
notify(err.message, 'error')
}
}
finally {
updateRate()
getRef('get_quantity').value = 0
getRef('get_total').value = 0
setTimeout(() => {
hideProcess('trade_button_wrapper')
getRef('trade_button').disabled = true
setTimeout(() => {
getRef('trade_button_wrapper').querySelector('.stateful-result').remove()
}, 100);
}, 4000);
}
}
getRef('quantity_selector').addEventListener('click', e => {
if (e.target.closest('button')) {
const selectedAsset = pagesData.params.asset
const target = e.target.closest('button')
const unitValue = getSuggestedPrice()
const fraction = parseFloat(target.value)
if (tradeType === 'buy') {
getRef('get_total').value = parseFloat((fraction * allTokens['rupee'].net).toFixed(8))
getRef('get_quantity').value = parseFloat(((allTokens['rupee'].net * fraction) / getSuggestedPrice()).toFixed(8))
} else {
getRef('get_total').value = parseFloat((fraction * allTokens[selectedAsset].net * getSuggestedPrice()).toFixed(8))
getRef('get_quantity').value = parseFloat((allTokens[selectedAsset].net * fraction).toFixed(8))
}
}
})
getRef('get_quantity').addEventListener('focusin', e => {
if (tradeType === 'buy') {
getRef('quantity_selector_tip').innerHTML = `<b>Locked amount</b> is highest total amount you'll be charged for buying specified quantity, most likely you'll charged less than locked amount.`
} else {
getRef('quantity_selector_tip').innerHTML = `<b>Min amount</b> received is lowest total amount you'll get by selling specified quantity, most likely you will get more than this amount. `
}
})
getRef('get_total').addEventListener('focusin', e => {
if (tradeType === 'buy') {
getRef('quantity_selector_tip').innerHTML = `<b>Locked amount</b> is highest total amount you'll be charged for buying specified quantity, most likely you'll charged less than locked amount.`
} else {
getRef('quantity_selector_tip').innerHTML = `<b>Min amount</b> received is lowest total amount you'll get by selling specified quantity, most likely you will get more than this amount. `
}
})
getRef('get_quantity').addEventListener('keyup', e => {
const unitValue = getSuggestedPrice()
getRef('get_total').value = parseFloat((parseFloat(e.target.value) * unitValue).toFixed(8)) || 0
})
getRef('get_total').addEventListener('keyup', e => {
const unitValue = getSuggestedPrice()
getRef('get_quantity').value = parseFloat((parseFloat(e.target.value) / unitValue).toFixed(8)) || 0
})
getRef('wallet_actions').addEventListener('click', e => {
if (e.target.closest('.button')) {
const target = e.target.closest('.button')
const type = target.value
const asset = getRef('wallet_asset_selector').value
getRef('wallet_quantity_type').textContent = getRef('quantity_type').textContent = asset === 'rupee' ? formatAmount(allTokens.rupee.net, true) : `${parseFloat(allTokens[asset].net.toFixed(8))} ${asset}`
getRef('wallet_popup__cta').textContent = `${type} ${asset}`
getRef('wallet_popup__cta').setAttribute('value', type)
getRef('wallet_popup__title').textContent = `${type} ${asset}`
// default form element state
getRef('get_receiver_id').removeAttribute('required')
getRef('get_receiver_id').classList.add('hide')
getRef('get_private_key').removeAttribute('required')
getRef('get_private_key').classList.add('hide')
getRef('wallet_quantity_selector').classList.remove('hide')
switch (type) {
case 'withdraw':
if (asset === 'FLO') {
getRef('withdraw_flo_tip').classList.remove('hide')
}
break;
case 'deposit':
getRef('get_private_key').setAttribute('required', '')
getRef('get_private_key').classList.remove('hide')
getRef('wallet_quantity_selector').classList.add('hide')
break;
case 'transfer':
getRef('get_receiver_id').setAttribute('required', '')
getRef('get_receiver_id').classList.remove('hide')
break;
}
getRef('wallet_form').elementsChanged()
showPopup('wallet_popup')
}
})
function showWalletResult(status, title, description, cta = '') {
const animOptions = {
duration: 150,
easing: 'ease',
fill: 'forwards'
}
let icon
if (status === 'success') {
icon = `<svg xmlns="http://www.w3.org/2000/svg" class="icon icon--success" height="24px" viewBox="0 0 24 24" width="24px"
fill="#000000">
<path d="M0 0h24v24H0V0z" fill="none" />
<path d="M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4L9 16.2z" />
</svg>`
} else {
icon = `<svg xmlns="http://www.w3.org/2000/svg" class="icon icon--failure" height="24px"
viewBox="0 0 24 24" width="24px" fill="#000000">
<path
d="M11 15h2v2h-2v-2zm0-8h2v6h-2V7zm.99-5C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2zM12 20c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8z" />
</svg>`
}
getRef('wallet_result__icon').innerHTML = icon
getRef('wallet_result__title').textContent = title
getRef('wallet_result__description').textContent = description
getRef('wallet_form').animate(slideOutLeft, animOptions)
.onfinish = () => {
getRef('wallet_form').classList.add('hide')
getRef('wallet_result').classList.remove('hide')
getRef('wallet_result').animate(slideInLeft, animOptions)
}
getRef('wallet_result__cta').classList.add('hide')
switch (cta) {
case 'open-upi':
getRef('wallet_result__cta').classList.remove('hide')
break;
default:
break;
}
}
function hideWalletResult() {
const animOptions = {
duration: 150,
easing: 'ease',
fill: 'forwards'
}
getRef('wallet_result').animate(slideOutRight, animOptions)
.onfinish = () => {
getRef('wallet_result').classList.add('hide')
getRef('wallet_form').classList.remove('hide')
getRef('wallet_form').animate(slideInRight, animOptions)
}
}
getRef('wallet_quantity_selector').addEventListener('click', e => {
// Get latest balance and exchange rate
if (e.target.closest('button')) {
const target = e.target.closest('button')
const asset = getRef('wallet_asset_selector').value
const fraction = parseFloat(target.value)
let total = parseFloat((allTokens[asset].net * fraction).toFixed(8));
if (asset == 'FLO' && fraction === 1 & total > 0.1) {
total -= 0.1;
}
getRef('get_user_amount').value = total
}
})
getRef('wallet_popup__cta').addEventListener('click', async e => {
const asset = getRef('wallet_asset_selector').value
const type = e.target.getAttribute('value')
const quantity = parseFloat(getRef('get_user_amount').value)
try {
showProcess('wallet_popup__cta_wrapper')
const proxySecret = await proxy.secret;
switch (type) {
case 'deposit':
const privKey = getRef('get_private_key').value;
if (asset === 'FLO') {
await floExchangeAPI.depositFLO(quantity, proxy.userID, proxy.sinkID, privKey, proxySecret)
} else {
await floExchangeAPI.depositToken(asset, quantity, proxy.userID, proxy.sinkID, privKey, proxySecret)
}
showWalletResult('success', `Sent ${asset} deposit request`, 'This may take upto 30 mins to reflect in your wallet.')
break;
case 'withdraw':
if (asset === 'FLO') {
await floExchangeAPI.withdrawFLO(quantity, proxy.userID, proxySecret)
} else {
await floExchangeAPI.withdrawToken(asset, quantity, proxy.userID, proxySecret)
}
showWalletResult('success', `Sent ${asset} withdraw request`, 'This may take upto 30 mins to reflect in your wallet.')
break;
case 'transfer':
const receiverID = getRef('get_receiver_id').value.trim();
const receiver = {
[receiverID]: quantity
}
await floExchangeAPI.transferToken(receiver, asset, proxy.userID, proxySecret)
showWalletResult('success', `Sent ${quantity} ${asset} to ${receiverID}`, `This may take upto 30 mins to reflect in receiver's wallet.`)
break;
}
}
catch (err) {
if ((err.message || err) === 'Insufficient rupee balance') {
showWalletResult('error', `Failed`, err.message || err, 'open-upi')
} else {
showWalletResult('error', `Failed`, err.message || err)
}
}
finally {
hideProcess('wallet_popup__cta_wrapper')
refresh()
}
})
const slideInLeft = [
{
opacity: 0,
transform: 'translateX(1rem)'
},
{
opacity: 1,
transform: 'translateX(0)'
}
]
const slideOutLeft = [
{
opacity: 1,
transform: 'translateX(0)'
},
{
opacity: 0,
transform: 'translateX(-1rem)'
},
]
const slideInRight = [
{
opacity: 0,
transform: 'translateX(-1rem)'
},
{
opacity: 1,
transform: 'translateX(0)'
}
]
const slideOutRight = [
{
opacity: 1,
transform: 'translateX(0)'
},
{
opacity: 0,
transform: 'translateX(1rem)'
},
]
const slideInDown = [
{
opacity: 0,
transform: 'translateY(-1rem)'
},
{
opacity: 1,
transform: 'translateY(0)'
},
]
const slideOutUp = [
{
opacity: 1,
transform: 'translateY(0)'
},
{
opacity: 0,
transform: 'translateY(-1rem)'
},
]
const selectedOrders = new Map()
getRef('orders_list').addEventListener('change', e => {
const animOptions = {
duration: 150,
easing: 'ease',
fill: 'forwards'
}
const target = e.target.parentNode;
target.classList.toggle('order-card--selected')
if (e.target.checked) {
selectedOrders.set(target.dataset.id, target.dataset.type)
} else {
selectedOrders.delete(target.dataset.id)
}
getRef('selected_orders').textContent = `${selectedOrders.size} selected`
if (selectedOrders.size === 1 && !getRef('my_orders_section__header').children[0].classList.contains('hide')) {
getRef('my_orders_section__header').children[0].animate(slideOutLeft, animOptions)
.onfinish = () => {
getRef('my_orders_section__header').children[0].classList.add('hide')
getRef('my_orders_section__header').children[1].classList.remove('hide')
getRef('my_orders_section__header').children[1].animate(slideInLeft, animOptions)
}
} else if (selectedOrders.size === 0 && getRef('my_orders_section__header').children[0].classList.contains('hide')) {
hideMyOrdersOptions()
}
})
function hideMyOrdersOptions() {
const animOptions = {
duration: 150,
easing: 'ease',
fill: 'forwards'
}
getRef('my_orders_section__header').children[1].animate(slideOutRight, animOptions)
.onfinish = () => {
getRef('my_orders_section__header').children[1].classList.add('hide')
getRef('my_orders_section__header').children[0].classList.remove('hide')
getRef('my_orders_section__header').children[0].animate(slideInRight, animOptions)
}
}
function clearSelection() {
getRef('orders_list').querySelectorAll('sm-checkbox[checked]').forEach(elem => elem.checked = false)
}
function showMoreDetails(e) {
const target = e.target.closest('.more-info')
showPopup('transaction_info_popup')
if (target.dataset.buyer !== 'undefined') {
getRef('transaction__buyer_wrapper').classList.remove('hide')
getRef('transaction__buyer').value = target.dataset.buyer
} else {
getRef('transaction__buyer_wrapper').classList.add('hide')
}
if (target.dataset.seller !== 'undefined') {
getRef('transaction__seller_wrapper').classList.remove('hide')
getRef('transaction__seller').value = target.dataset.seller
} else {
getRef('transaction__seller_wrapper').classList.add('hide')
}
getRef('transaction_time__label').textContent = target.dataset.pending === 'true' ? 'Placed on' : 'Completed on'
getRef('transaction_time').textContent = getFormattedTime(target.dataset.time)
}
getRef('orders_list').addEventListener('click', e => {
if (e.target.closest('.cancel-order')) {
getConfirmation('Cancel this order?').then(async res => {
if (res) {
const target = e.target.closest('.order-card')
const id = target.dataset.id
const type = target.dataset.type
floExchangeAPI.cancelOrder(type, id, proxy.userID, await proxy.secret)
.then(() => {
notify('Order cancelled', 'success')
target.animate([
{
opacity: 1
},
{
opacity: 0
},
], {
duration: 100,
fill: 'forwards'
})
.onfinish = () => {
if (!target.parentNode) return
const height = target.getBoundingClientRect().height
const siblings = Array.from(target.parentNode.children)
const nextSiblings = siblings.slice(siblings.indexOf(target) + 1)
nextSiblings.forEach(elem => {
elem.animate([
{
transform: 'translateY(0)'
},
{
transform: `translateY(-${height}px)`
},
], {
duration: 200,
fill: 'forwards'
})
.onfinish = (e) => {
e.target.cancel()
}
})
setTimeout(() => {
target.remove()
refresh()
}, 200);
}
})
.catch(err => notify(err.message, 'error'))
}
})
} else if (e.target.closest('.more-info')) {
showMoreDetails(e)
}
})
function cancelAll() {
getConfirmation('Cancel all selected orders?').then(async res => {
if (res) {
try {
const proxy_secret = await proxy.secret;
const promises = [...selectedOrders].map(([id, type]) => floExchangeAPI.cancelOrder(type, id, proxy.userID, proxy_secret))
await Promise.all(promises)
selectedOrders.clear()
hideMyOrdersOptions()
}
catch (err) {
notify(err.message, 'error')
}
finally {
refresh()
}
}
})
}
getRef('my_orders_category_selector').addEventListener('change', render.userOrders)
getRef('market_orders_category_selector').addEventListener('change', render.marketOrders)
getRef('market').addEventListener('click', e => {
if (e.target.closest('.more-info')) {
showMoreDetails(e)
}
})
document.addEventListener('popupopened', e => {
switch (e.target.id) {
case 'registration_popup':
getRef('get_registration_key').focusIn()
break;
case 'sign_up_popup':
const { floID, privKey } = floCrypto.generateNewID()
getRef('generated_flo_id').value = floID
getRef('generated_private_key').value = privKey
break;
case 'confirm_trade_popup':
const asset = pagesData.params.asset;
const quantity = parseFloat(getRef('get_quantity').value)
const currentPrice = parseFloat(floGlobals.exchangeRates[asset].toFixed(8));
const price = parseFloat(getSuggestedPrice().toFixed(8));
const total = formatAmount(parseFloat(getRef('get_total').value))
const minTotal = formatAmount(parseFloat((currentPrice * quantity).toFixed(8)))
getRef('confirm_trade__title').textContent = `${tradeType} ${asset}`
getRef('confirm_trade__details').innerHTML = `
<div class="grid">
<p>Quantity</p>
<b>${quantity} ${asset}</b>
</div>
<div class="grid">
<p>${tradeType === 'buy' ? 'Min cost' : 'Max earned'}</p>
<div>
<b>${minTotal}</b><span> @ ${currentPrice}/${asset}</span>
</div>
</div>
<div class="grid gap-0-3">
<p>${tradeType === 'buy' ? 'Max cost (Amount locked)' : 'Min earned'}</p>
<div>
<b>${total}</b><span> @ ${price}/${asset}</span>
</div>
</div>
<p>
<strong>All trades will be executed at current price.</strong>
</p>
`;
break;
}
})
document.addEventListener('popupclosed', e => {
switch (e.target.id) {
case 'wallet_popup':
hideWalletResult()
getRef('withdraw_flo_tip').classList.add('hide')
break;
}
})
</script>
<script>
//container for user ID and proxy private-key
const proxy = {
user: null,
private: null,
public: null,
async lock() {
if (!this.private)
return notify("No proxy key found!", 'error');
getPromptInput("Add password", 'This password applies to this browser only!', {
isPassword: true,
confirmText: "Add password"
}).then(pwd => {
if (!pwd)
notify("Password cannot be empty", 'error');
else if (pwd.length < 4)
notify("Password minimum length is 4", 'error');
else {
let tmp = Crypto.AES.encrypt(this.private, pwd);
localStorage.setItem("exchange-proxy_secret", "?" + tmp);
notify("Successfully locked with Password", 'success');
}
}).catch(_ => null);
},
clear() {
localStorage.removeItem("exchange-proxy_secret");
localStorage.removeItem("exchange-user_ID");
this.user = null;
this.private = null;
this.public = null;
},
get sinkID() {
return getRef("sink_id").value;
},
set userID(id) {
localStorage.setItem("exchange-user_ID", id);
this.user = id;
},
get userID() {
if (this.user)
return this.user;
else {
let id = localStorage.getItem('exchange-user_ID');
return id ? this.user = id : undefined;
}
},
set secret(key) {
localStorage.setItem("exchange-proxy_secret", key);
this.private = key;
this.public = floCrypto.getPubKeyHex(key);
},
get secret() {
const self = this;
return new Promise((resolve, reject) => {
if (self.private)
return resolve(self.private);
const Reject = reason => {
notify(reason, 'error');
reject(reason);
}
const setValues = priv => {
try {
self.private = priv;
self.public = floCrypto.getPubKeyHex(priv);
resolve(self.private);
} catch (error) {
Reject("Unable to fetch Proxy secret");
}
};
let tmp = localStorage.getItem("exchange-proxy_secret");
if (typeof tmp !== "string")
Reject("Unable to fetch Proxy secret");
else if (tmp.startsWith("?")) {
getPromptInput("Enter password", '', {
isPassword: true
}).then(pwd => {
if (!pwd)
return Reject("Password Required for making transactions");
try {
tmp = Crypto.AES.decrypt(tmp.substring(1), pwd);
setValues(tmp);
} catch (error) {
Reject("Incorrect Password! Password Required for making transactions");
}
}).catch(_ => Reject("Password Required for making transactions"));
} else
setValues(tmp);
})
}
}
function updateRate(init = false) {
floExchangeAPI.getRates().then(({ rates, countDown }) => {
console.debug(rates);
if (init) {
floGlobals.exchangeRates = rates
getRef('wallet_asset_selector').append(
createElement('sm-option', {
textContent: floGlobals.currency,
attributes: { value: floGlobals.currency },
})
);
Object.entries(rates).sort((a, b) => a[1] < b[1] ? 1 : -1).forEach(([asset, rate]) => {
if (!allTokens.hasOwnProperty(asset)) {
allTokens[asset] = {
total: 0,
locked: 0,
net: 0
}
}
// dynamically render listed assets if not already rendered
getRef('listed_assets').append(render.listedAsset(asset, formatAmount(parseFloat(rate)), countDown[asset]));
getRef('wallet_asset_selector').append(createElement('sm-option', {
textContent: asset,
attributes: { value: asset },
}));
getRef('market_asset_rates').append(createElement('li', {
className: 'listed-asset grid align-center',
innerHTML: `
<div class="listed-asset__icon">${getIcon(asset)}</div>
<h4 class="listed-asset__name">${asset}</h4>
<b class="listed-asset__rate">${formatAmount(rate)}</b>
`
}))
})
} else {
// update rates in UI
for (const asset in rates) {
const rate = rates[asset]
const listedAsset = getRef(`listed_assets`).querySelector(`[data-listed-asset="${asset}"]`)
if (listedAsset) {
listedAsset.querySelector('.listed-asset__rate').textContent = formatAmount(parseFloat(rate))
if (floGlobals.countDowns.intervals.hasOwnProperty(asset)) {
clearInterval(floGlobals.countDowns.intervals[asset]);
}
floGlobals.countDowns.intervals[asset] = setInterval(() => {
listedAsset.querySelector('.listed-asset__countdown').textContent = `Est. time left: ${getTimeLeft(countDown[asset])}`
}, 1000)
if (floGlobals.countDowns.timeouts.hasOwnProperty(asset)) {
clearTimeout(floGlobals.countDowns.timeouts[asset]);
delete floGlobals.countDowns.timeouts[asset]
}
floGlobals.countDowns.timeouts[asset] = setTimeout(() => {
updateRate()
}, countDown[asset] - Date.now());
}
}
}
render.chart(pagesData.params.asset)
showSuggestedPrice()
}).catch(error => console.error(error.message))
}
async function refresh(init = false, refreshButton) {
if (refreshButton)
buttonLoader('wallet_balance_refresh_button', true);
if (init) {
console.info("init");
if (!proxy.userID) {
floExchangeAPI.getLoginCode().then(response => {
getRef("login_form").classList.remove('hide');
document.querySelectorAll(".user-content").forEach(elem => elem.classList.add('hide'))
getRef('sign_in_code').value = response.code;
getRef('sign_in_hash').value = response.hash;
proxy.clear();
setTimeout(() => {
getRef('login_form__priv_key').focusIn()
}, 0);
}).catch(error => console.error(error))
.finally(() => {
getRef('loading').classList.add('hide')
getRef('home').classList.remove('hide')
})
}
} else
console.info("refresh");
render.marketOrders();
updateRate(init)
if (proxy.userID) {
await account();
if (refreshButton)
buttonLoader('wallet_balance_refresh_button', false);
}
}
let accountDetails = {}
let allTokens = {}
async function account() {
floExchangeAPI.getAccount(proxy.userID, await proxy.secret).then(async acc => {
document.body.classList.add('is-signed-in');
getRef('market_asset_rates').parentNode.remove()
// save login time
localStorage.setItem(`${acc.floID}_last_login`, Date.now());
getRef("login_form").classList.add('hide')
getRef('user_popup_button').classList.remove('hide')
accountDetails = acc
console.debug(acc);
//Element display
document.querySelectorAll(".user-content").forEach(elem => elem.classList.remove('hide'))
getRef("user_id").value = acc.floID;
getRef("sink_id").value = acc.sinkID;
if (acc.subAdmin)
console.info("logged in as subAdmin");
// rupee balance init
allTokens[floGlobals.currency] = {
total: 0,
locked: 0,
net: 0
}
// token balance
acc.tokenBalance.forEach(({ token, quantity }) => {
allTokens[token] = {
total: quantity,
locked: 0,
net: 0
}
})
acc.sellOrders.forEach(({ asset, quantity }) => {
allTokens[asset].locked += quantity
})
allTokens[floGlobals.currency].locked = acc.buyOrders.reduce((a, x) => a + x.quantity * x.maxPrice, 0)
for (const token in allTokens) {
allTokens[token].net = allTokens[token].total - allTokens[token].locked
}
console.debug("FLO", allTokens['FLO']);
console.log(await floExchangeAPI.getBalance(acc.floID))
console.debug("RUPEE", allTokens['rupee']);
// render all assets in wallet
const frag = document.createDocumentFragment();
Object.entries(allTokens).sort((a, b) => b[1].net - a[1].net).forEach(([asset]) => {
frag.append(render.assetBalanceCard(asset))
})
getRef('my_assets').innerHTML = ''
getRef('my_assets').append(frag)
//My orders
render.userOrders();
proxy.secret.then(_ => null).catch(_ => null);
showPage(window.location.hash);
}).catch(error => {
console.debug(error)
if (error.message === 'Invalid request signature! Re-login if this error occurs frequently') {
proxy.clear()
location.reload()
}
else
notify(error.message, 'error')
})
.finally(() => {
hideProcess('login_button_wrapper')
getRef('loading').classList.add('hide')
getRef('home').classList.remove('hide')
})
};
const UI_evt = {
logout() {
getConfirmation('Log out?', { cancelText: 'Stay', confirmText: 'Log out' }).then(async res => {
if (res) {
floExchangeAPI.logout(proxy.userID, await proxy.secret).then(result => {
console.warn(result);
proxy.clear();
location.reload();
}).catch(error => console.error(error));
}
})
},
login() {
showProcess('login_button_wrapper')
let privKey = getRef('login_form__priv_key').value;
let code = getRef('sign_in_code').value,
hash = getRef('sign_in_hash').value;
let rememberMe = getRef('remember_me').checked;
let tmpKey = floCrypto.generateNewID();
floExchangeAPI.login(privKey, tmpKey.pubKey, code, hash).then(result => {
console.log(result);
proxy.secret = tmpKey.privKey;
proxy.userID = floCrypto.getFloID(privKey);
getRef('sign_in_code').value = null;
getRef('sign_in_hash').value = null;
account();
}).catch(error => {
notify(error.message, 'error')
hideProcess('login_button_wrapper')
})
}
};
window.addEventListener('load', e => {
floExchangeAPI.init().then(nodes => {
console.log(nodes);
refresh(true);
}).catch(error => console.error(error))
})
</script>
</body>
</html>