commit
f5b7c5cb61
@ -137,12 +137,12 @@ customElements.define('sm-button',
|
|||||||
}
|
}
|
||||||
attributeChangedCallback(name) {
|
attributeChangedCallback(name) {
|
||||||
if (name === 'disabled') {
|
if (name === 'disabled') {
|
||||||
this.removeAttribute('tabindex');
|
if (this.hasAttribute('disabled')) {
|
||||||
this.setAttribute('aria-disabled', 'true');
|
this.removeAttribute('tabindex');
|
||||||
}
|
} else {
|
||||||
else {
|
this.setAttribute('tabindex', '0');
|
||||||
this.setAttribute('tabindex', '0');
|
}
|
||||||
this.setAttribute('aria-disabled', 'false');
|
this.setAttribute('aria-disabled', this.hasAttribute('disabled'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@ -639,7 +639,7 @@ sm-checkbox {
|
|||||||
padding: 1rem 1.5rem 1.5rem 1.5rem;
|
padding: 1rem 1.5rem 1.5rem 1.5rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
#quantity_selector .button {
|
.quantity-selector .button {
|
||||||
-webkit-box-flex: 1;
|
-webkit-box-flex: 1;
|
||||||
-ms-flex: 1;
|
-ms-flex: 1;
|
||||||
flex: 1;
|
flex: 1;
|
||||||
@ -647,7 +647,8 @@ sm-checkbox {
|
|||||||
margin-left: 0.5rem;
|
margin-left: 0.5rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
#quantity_type {
|
#quantity_type,
|
||||||
|
#wallet_quantity_type {
|
||||||
font-size: 0.8rem;
|
font-size: 0.8rem;
|
||||||
padding-right: 0.5rem;
|
padding-right: 0.5rem;
|
||||||
border-right: thin solid rgba(var(--text-color), 0.3);
|
border-right: thin solid rgba(var(--text-color), 0.3);
|
||||||
|
|||||||
2
public/css/main.min.css
vendored
2
public/css/main.min.css
vendored
File diff suppressed because one or more lines are too long
@ -560,14 +560,15 @@ sm-checkbox {
|
|||||||
align-self: flex-start;
|
align-self: flex-start;
|
||||||
padding: 1rem 1.5rem 1.5rem 1.5rem;
|
padding: 1rem 1.5rem 1.5rem 1.5rem;
|
||||||
}
|
}
|
||||||
#quantity_selector {
|
.quantity-selector {
|
||||||
.button {
|
.button {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
padding: 0.5rem 0.6rem;
|
padding: 0.5rem 0.6rem;
|
||||||
margin-left: 0.5rem;
|
margin-left: 0.5rem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#quantity_type {
|
#quantity_type,
|
||||||
|
#wallet_quantity_type {
|
||||||
font-size: 0.8rem;
|
font-size: 0.8rem;
|
||||||
padding-right: 0.5rem;
|
padding-right: 0.5rem;
|
||||||
border-right: thin solid rgba(var(--text-color), 0.3);
|
border-right: thin solid rgba(var(--text-color), 0.3);
|
||||||
|
|||||||
223
public/home.html
223
public/home.html
@ -116,20 +116,20 @@
|
|||||||
<strip-option value="sell">Sell</strip-option>
|
<strip-option value="sell">Sell</strip-option>
|
||||||
</strip-select>
|
</strip-select>
|
||||||
</div>
|
</div>
|
||||||
<sm-input id="get_price" variant="outlined" placeholder="Max price (₹)" type="number" step="0.00001"
|
<sm-input id="get_price" variant="outlined" placeholder="Max price (₹)" type="number" step="0.01"
|
||||||
required hiderequired animate>
|
required hiderequired animate>
|
||||||
</sm-input>
|
</sm-input>
|
||||||
<sm-input id="get_quantity" variant="outlined" placeholder="Quantity (FLO)" type="number"
|
<sm-input id="get_quantity" variant="outlined" placeholder="Quantity (FLO)" type="number" step="0.0001"
|
||||||
step="0.00000001" required hiderequired animate></sm-input>
|
required hiderequired animate></sm-input>
|
||||||
<sm-input id="get_total" variant="outlined" placeholder="Total (₹)" type="number" min="0.01" step="0.01"
|
<sm-input id="get_total" variant="outlined" placeholder="Total (₹)" type="number" min="0.01" step="0.01"
|
||||||
required hiderequired animate>
|
required hiderequired animate>
|
||||||
</sm-input>
|
</sm-input>
|
||||||
<div id="quantity_selector" class="flex align-center">
|
<div id="quantity_selector" class="flex align-center quantity-selector">
|
||||||
<span id="quantity_type">Rupee</span>
|
<span id="quantity_type">Rupee</span>
|
||||||
<button class="button" value="25">25%</button>
|
<button class="button" value="0.25">25%</button>
|
||||||
<button class="button" value="50">50%</button>
|
<button class="button" value="0.5">50%</button>
|
||||||
<button class="button" value="75">75%</button>
|
<button class="button" value="0.75">75%</button>
|
||||||
<button class="button" value="100">100%</button>
|
<button class="button" value="1">100%</button>
|
||||||
</div>
|
</div>
|
||||||
<div id="trade_button_wrapper" class="stateful-button-wrapper flex align-center justify-center">
|
<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="tradeFlo()">BUY FLO
|
<sm-button id="trade_button" class="uppercase w-100" variant="primary" onclick="tradeFlo()">BUY FLO
|
||||||
@ -224,25 +224,27 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="grid gap-0-5">
|
<div class="grid gap-0-5">
|
||||||
<h4>Balance</h4>
|
<h4>Balance</h4>
|
||||||
<div class="balance-card">
|
<div class="grid gap-1">
|
||||||
<div class="balance-card__icon">
|
<div class="balance-card">
|
||||||
<svg class="icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
|
<div class="balance-card__icon">
|
||||||
<path
|
<svg class="icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
|
||||||
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" />
|
<path
|
||||||
</svg>
|
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>
|
||||||
|
</div>
|
||||||
|
<div class="balance-card__token">FLO</div>
|
||||||
|
<div id="flo_balance"></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="balance-card__token">FLO</div>
|
<div class="balance-card">
|
||||||
<div id="flo_balance"></div>
|
<div class="balance-card__icon">
|
||||||
</div>
|
<svg class="icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
|
||||||
<div class="balance-card">
|
<path
|
||||||
<div class="balance-card__icon">
|
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 class="icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
|
</svg>
|
||||||
<path
|
</div>
|
||||||
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" />
|
<div class="balance-card__token">Rupee</div>
|
||||||
</svg>
|
<div id="rupee_balance"></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="balance-card__token">Rupee</div>
|
|
||||||
<div id="rupee_balance"></div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
@ -397,6 +399,13 @@
|
|||||||
<sm-input id="get_user_amount" variant="outlined" placeholder="Quantity" type="number" min="0.01"
|
<sm-input id="get_user_amount" variant="outlined" placeholder="Quantity" type="number" min="0.01"
|
||||||
step="0.00001" required hiderequired animate>
|
step="0.00001" required hiderequired animate>
|
||||||
</sm-input>
|
</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>
|
||||||
<sm-input id="get_private_key" variant="outlined" placeholder="FLO private key" type="password" required
|
<sm-input id="get_private_key" variant="outlined" placeholder="FLO private key" type="password" required
|
||||||
error-text="Invalid private key" hiderequired animate>
|
error-text="Invalid private key" hiderequired animate>
|
||||||
</sm-input>
|
</sm-input>
|
||||||
@ -443,11 +452,11 @@
|
|||||||
<span class="available-balance"></span>
|
<span class="available-balance"></span>
|
||||||
</template>
|
</template>
|
||||||
<template id="locked_balance_template">
|
<template id="locked_balance_template">
|
||||||
<div>
|
<div class="grid">
|
||||||
<span class="label">Locked</span>
|
<span class="label">Locked</span>
|
||||||
<span class="locked-balance"></span>
|
<span class="locked-balance"></span>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div class="grid">
|
||||||
<span class="label">Available</span>
|
<span class="label">Available</span>
|
||||||
<span class="available-balance"></span>
|
<span class="available-balance"></span>
|
||||||
</div>
|
</div>
|
||||||
@ -737,7 +746,7 @@
|
|||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
buttons[0].onclick = () => {
|
buttons[0].onclick = () => {
|
||||||
hidePopup()
|
hidePopup()
|
||||||
reject(null);
|
return (null);
|
||||||
}
|
}
|
||||||
buttons[1].onclick = () => {
|
buttons[1].onclick = () => {
|
||||||
const value = getRef('prompt_input').value;
|
const value = getRef('prompt_input').value;
|
||||||
@ -769,21 +778,17 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getFormattedTime(time, relative) {
|
function getFormattedTime(timeString, relative) {
|
||||||
try {
|
try {
|
||||||
if (String(time).indexOf('_'))
|
const [date, time] = timeString.split('T')
|
||||||
time = String(time).split('_')[0]
|
const [year, month, day] = date.split('-').map(v => parseInt(v))
|
||||||
const intTime = parseInt(time)
|
let [hours, minutes] = time.split(':').map(v => parseInt(v))
|
||||||
if (String(intTime).length < 13)
|
const currentTime = new Date()
|
||||||
time *= 1000
|
const currentTimeFrag = currentTime.toString().split(' ')
|
||||||
let timeFrag = new Date(intTime).toString().split(' '),
|
const monthNames = ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
||||||
day = timeFrag[0],
|
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
|
||||||
month = timeFrag[1],
|
];
|
||||||
date = timeFrag[2],
|
const monthName = monthNames[month]
|
||||||
year = timeFrag[3],
|
|
||||||
minutes = new Date(intTime).getMinutes(),
|
|
||||||
hours = new Date(intTime).getHours(),
|
|
||||||
currentTime = new Date().toString().split(' ')
|
|
||||||
|
|
||||||
minutes = minutes < 10 ? `0${minutes}` : minutes
|
minutes = minutes < 10 ? `0${minutes}` : minutes
|
||||||
let finalHours = ``;
|
let finalHours = ``;
|
||||||
@ -797,25 +802,25 @@
|
|||||||
finalHours = hours >= 12 ? `${finalHours} PM` : `${finalHours} AM`
|
finalHours = hours >= 12 ? `${finalHours} PM` : `${finalHours} AM`
|
||||||
if (relative) {
|
if (relative) {
|
||||||
if (year == currentYear) {
|
if (year == currentYear) {
|
||||||
if (currentTime[1] === month) {
|
if ((currentTime.getMonth() + 1) === month) {
|
||||||
const dateDiff = (parseInt(currentTime[2]) - parseInt(date))
|
const dateDiff = (parseInt(currentTimeFrag[2]) - parseInt(day))
|
||||||
if (dateDiff === 0)
|
if (dateDiff === 0)
|
||||||
return `${finalHours}`;
|
return `${finalHours}`;
|
||||||
else if (dateDiff === 1)
|
else if (dateDiff === 1)
|
||||||
return `Yesterday`;
|
return `Yesterday`;
|
||||||
else if (dateDiff > 1 && dateDiff < 8)
|
else if (dateDiff > 1 && dateDiff < 8)
|
||||||
return currentTime[0];
|
return currentTimeFrag[0];
|
||||||
else
|
else
|
||||||
return ` ${date} ${month}`;
|
return ` ${day} ${monthName}`;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return ` ${date} ${month}`;
|
return ` ${day} ${monthName}`;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return `${month} ${year}`;
|
return `${monthName} ${year}`;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return `${finalHours}, ${month} ${date} ${year}`;
|
return `${finalHours}, ${monthName} ${day} ${year}`;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
return time;
|
return time;
|
||||||
@ -1039,10 +1044,12 @@
|
|||||||
|
|
||||||
function showProcess(id) {
|
function showProcess(id) {
|
||||||
getRef(id).children[0].classList.add('clip')
|
getRef(id).children[0].classList.add('clip')
|
||||||
|
getRef(id).children[0].disabled = true
|
||||||
getRef(id).append(document.createElement('sm-spinner'))
|
getRef(id).append(document.createElement('sm-spinner'))
|
||||||
}
|
}
|
||||||
function hideProcess(id) {
|
function hideProcess(id) {
|
||||||
getRef(id).children[0].classList.remove('clip')
|
getRef(id).children[0].classList.remove('clip')
|
||||||
|
getRef(id).children[0].disabled = false
|
||||||
getRef(id).querySelector('sm-spinner')?.remove()
|
getRef(id).querySelector('sm-spinner')?.remove()
|
||||||
}
|
}
|
||||||
let tradeType = 'buy'
|
let tradeType = 'buy'
|
||||||
@ -1064,6 +1071,7 @@
|
|||||||
}
|
}
|
||||||
getRef('trade_button_wrapper').append(getRef('success_template').content.cloneNode(true))
|
getRef('trade_button_wrapper').append(getRef('success_template').content.cloneNode(true))
|
||||||
notify(`Placed ${tradeType} order`, 'success')
|
notify(`Placed ${tradeType} order`, 'success')
|
||||||
|
refresh()
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
getRef('trade_button_wrapper').append(getRef('failure_template').content.cloneNode(true))
|
getRef('trade_button_wrapper').append(getRef('failure_template').content.cloneNode(true))
|
||||||
@ -1086,18 +1094,19 @@
|
|||||||
if (e.target.closest('button')) {
|
if (e.target.closest('button')) {
|
||||||
const target = e.target.closest('button')
|
const target = e.target.closest('button')
|
||||||
const unitValue = parseFloat(getRef('get_price').value)
|
const unitValue = parseFloat(getRef('get_price').value)
|
||||||
const fraction = parseInt(target.value) / 100
|
const fraction = parseFloat(target.value)
|
||||||
if (tradeType === 'buy') {
|
if (tradeType === 'buy') {
|
||||||
getRef('get_total').value = parseFloat((fraction * balance.rupee).toFixed(2))
|
getRef('get_total').value = parseFloat((fraction * balance.rupee).toFixed(2))
|
||||||
getRef('get_quantity').value = parseFloat(((balance.rupee * fraction) / unitValue).toFixed(5))
|
getRef('get_quantity').value = parseFloat(((balance.rupee * fraction) / unitValue).toFixed(4))
|
||||||
} else {
|
} else {
|
||||||
getRef('get_total').value = parseFloat(((fraction * balance.flo) * rate.flo).toFixed(2))
|
console.log(fraction, balance.flo, floExchangeRate)
|
||||||
getRef('get_quantity').value = parseFloat((balance.flo * fraction).toFixed(5))
|
getRef('get_total').value = parseFloat((fraction * balance.flo * floExchangeRate).toFixed(2))
|
||||||
|
getRef('get_quantity').value = parseFloat((balance.flo * fraction).toFixed(4))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
getRef('get_price').addEventListener('keyup', e => {
|
getRef('get_price').addEventListener('keyup', e => {
|
||||||
const unitValue = parseFloat(getRef('get_price').value) || rate.flo
|
const unitValue = parseFloat(getRef('get_price').value) || floExchangeRate
|
||||||
const quantity = parseFloat(getRef('get_quantity').value) || 0
|
const quantity = parseFloat(getRef('get_quantity').value) || 0
|
||||||
getRef('get_total').value = parseFloat((quantity * unitValue).toFixed(2)) || 0
|
getRef('get_total').value = parseFloat((quantity * unitValue).toFixed(2)) || 0
|
||||||
})
|
})
|
||||||
@ -1107,23 +1116,30 @@
|
|||||||
})
|
})
|
||||||
getRef('get_total').addEventListener('keyup', e => {
|
getRef('get_total').addEventListener('keyup', e => {
|
||||||
const unitValue = parseFloat(getRef('get_price').value)
|
const unitValue = parseFloat(getRef('get_price').value)
|
||||||
getRef('get_quantity').value = parseFloat((parseFloat(e.target.value) / unitValue).toFixed(5)) || 0
|
getRef('get_quantity').value = parseFloat((parseFloat(e.target.value) / unitValue).toFixed(4)) || 0
|
||||||
})
|
})
|
||||||
|
|
||||||
getRef('wallet_actions').addEventListener('click', e => {
|
getRef('wallet_actions').addEventListener('click', e => {
|
||||||
if (e.target.closest('.button')) {
|
if (e.target.closest('.button')) {
|
||||||
const target = e.target.closest('.button')
|
const target = e.target.closest('.button')
|
||||||
showPopup('wallet_popup')
|
showPopup('wallet_popup')
|
||||||
const type = target.value
|
const type = target.value
|
||||||
const asset = getRef('wallet_asset_selector').value
|
const asset = getRef('wallet_asset_selector').value
|
||||||
|
getRef('wallet_quantity_type').textContent = asset
|
||||||
getRef('wallet_popup__cta').textContent = `${type} ${asset}`
|
getRef('wallet_popup__cta').textContent = `${type} ${asset}`
|
||||||
getRef('wallet_popup__cta').setAttribute('value', type)
|
getRef('wallet_popup__cta').setAttribute('value', type)
|
||||||
getRef('wallet_popup__title').textContent = `${type} ${asset}`
|
getRef('wallet_popup__title').textContent = `${type} ${asset}`
|
||||||
|
getRef('get_user_amount').setAttribute('step', asset === 'FLO' ? '0.0001' : '0.01')
|
||||||
|
getRef('get_user_amount').setAttribute('min', asset === 'FLO' ? '0.0001' : '0.01')
|
||||||
if (type === 'withdraw') {
|
if (type === 'withdraw') {
|
||||||
getRef('get_private_key').classList.add('hide-completely')
|
getRef('get_private_key').classList.add('hide-completely')
|
||||||
|
getRef('wallet_quantity_selector').classList.remove('hide-completely')
|
||||||
getRef('get_private_key').removeAttribute('required')
|
getRef('get_private_key').removeAttribute('required')
|
||||||
getRef('get_private_key').removeAttribute('hiderequired')
|
getRef('get_private_key').removeAttribute('hiderequired')
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
getRef('get_private_key').setAttribute('required', '')
|
getRef('get_private_key').setAttribute('required', '')
|
||||||
|
getRef('wallet_quantity_selector').classList.add('hide-completely')
|
||||||
getRef('get_private_key').setAttribute('hiderequired', '')
|
getRef('get_private_key').setAttribute('hiderequired', '')
|
||||||
getRef('get_private_key').classList.remove('hide-completely')
|
getRef('get_private_key').classList.remove('hide-completely')
|
||||||
}
|
}
|
||||||
@ -1173,6 +1189,15 @@
|
|||||||
getRef('wallet_form').animate(slideInRight, animOptions)
|
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.toLowerCase()
|
||||||
|
const fraction = parseFloat(target.value)
|
||||||
|
getRef('get_user_amount').value = parseFloat((balance[asset] * fraction).toFixed(asset === "flo" ? 4 : 2))
|
||||||
|
}
|
||||||
|
})
|
||||||
getRef('wallet_popup__cta').addEventListener('click', async e => {
|
getRef('wallet_popup__cta').addEventListener('click', async e => {
|
||||||
const asset = getRef('wallet_asset_selector').value
|
const asset = getRef('wallet_asset_selector').value
|
||||||
const type = e.target.getAttribute('value')
|
const type = e.target.getAttribute('value')
|
||||||
@ -1189,9 +1214,9 @@
|
|||||||
showWalletResult('success', `Sent ${asset} deposit request`, 'This may take upto 30 mins to reflect in your wallet.')
|
showWalletResult('success', `Sent ${asset} deposit request`, 'This may take upto 30 mins to reflect in your wallet.')
|
||||||
} else {
|
} else {
|
||||||
if (asset === 'FLO') {
|
if (asset === 'FLO') {
|
||||||
await withdrawFLO(quantity, await proxy.secret)
|
await withdrawFLO(quantity, proxy.secret)
|
||||||
} else {
|
} else {
|
||||||
await withdrawRupee(quantity, await proxy.secret)
|
await withdrawRupee(quantity, proxy.secret)
|
||||||
}
|
}
|
||||||
showWalletResult('success', `Sent ${asset} withdraw request`, 'This may take upto 30 mins to reflect in your wallet.')
|
showWalletResult('success', `Sent ${asset} withdraw request`, 'This may take upto 30 mins to reflect in your wallet.')
|
||||||
}
|
}
|
||||||
@ -1204,7 +1229,6 @@
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const selectedOrders = new Map()
|
|
||||||
const slideInLeft = [
|
const slideInLeft = [
|
||||||
{
|
{
|
||||||
opacity: 0,
|
opacity: 0,
|
||||||
@ -1265,6 +1289,8 @@
|
|||||||
transform: 'translateY(-1rem)'
|
transform: 'translateY(-1rem)'
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
const selectedOrders = new Map()
|
||||||
getRef('orders_list').addEventListener('change', e => {
|
getRef('orders_list').addEventListener('change', e => {
|
||||||
const animOptions = {
|
const animOptions = {
|
||||||
duration: 150,
|
duration: 150,
|
||||||
@ -1287,14 +1313,22 @@
|
|||||||
getRef('my_orders_section__header').children[1].animate(slideInLeft, animOptions)
|
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-completely')) {
|
} else if (selectedOrders.size === 0 && getRef('my_orders_section__header').children[0].classList.contains('hide-completely')) {
|
||||||
getRef('my_orders_section__header').children[1].animate(slideOutRight, animOptions)
|
hideMyOrdersOptions()
|
||||||
.onfinish = () => {
|
|
||||||
getRef('my_orders_section__header').children[1].classList.add('hide-completely')
|
|
||||||
getRef('my_orders_section__header').children[0].classList.remove('hide-completely')
|
|
||||||
getRef('my_orders_section__header').children[0].animate(slideInRight, animOptions)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
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-completely')
|
||||||
|
getRef('my_orders_section__header').children[0].classList.remove('hide-completely')
|
||||||
|
getRef('my_orders_section__header').children[0].animate(slideInRight, animOptions)
|
||||||
|
}
|
||||||
|
}
|
||||||
function clearSelection() {
|
function clearSelection() {
|
||||||
getRef('orders_list').querySelectorAll('sm-checkbox[checked]').forEach(elem => elem.checked = false)
|
getRef('orders_list').querySelectorAll('sm-checkbox[checked]').forEach(elem => elem.checked = false)
|
||||||
}
|
}
|
||||||
@ -1361,6 +1395,7 @@
|
|||||||
})
|
})
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
target.remove()
|
target.remove()
|
||||||
|
refresh()
|
||||||
}, 200);
|
}, 200);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -1375,30 +1410,29 @@
|
|||||||
getConfirmation('Cancel all selected orders?').then(async res => {
|
getConfirmation('Cancel all selected orders?').then(async res => {
|
||||||
if (res) {
|
if (res) {
|
||||||
try {
|
try {
|
||||||
let proxy_secret = await proxy.secret;
|
const proxy_secret = await proxy.secret;
|
||||||
await Promise.all(
|
const promises = [...selectedOrders].map(([id, type]) => cancelOrder(type, id, proxy_secret))
|
||||||
selectedOrders.map((type, id) => cancelOrder(type, id, proxy_secret))
|
await Promise.all(promises)
|
||||||
)
|
|
||||||
selectedOrders.forEach((type, id) => {
|
|
||||||
getRef('orders_list').querySelector(`[data-id="${id}"]`).remove()
|
|
||||||
})
|
|
||||||
notify('All selected orders cancelled', 'success')
|
|
||||||
selectedOrders.clear()
|
selectedOrders.clear()
|
||||||
|
hideMyOrdersOptions()
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
notify(err.data, 'error')
|
notify(err.data, 'error')
|
||||||
}
|
}
|
||||||
|
finally {
|
||||||
|
refresh()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderUserOrders() {
|
function renderUserOrders() {
|
||||||
const { buyOrders, sellOrders, transactions } = accountDetails
|
let { buyOrders, sellOrders, transactions } = accountDetails
|
||||||
getRef('orders_list').innerHTML = '';
|
getRef('orders_list').innerHTML = '';
|
||||||
const frag = document.createDocumentFragment()
|
const frag = document.createDocumentFragment()
|
||||||
const ordersType = getRef('my_orders_category_selector').value
|
const ordersType = getRef('my_orders_category_selector').value
|
||||||
if (ordersType === 'open') {
|
if (ordersType === 'open') {
|
||||||
const allOpenOrders = [...(buyOrders || myBuyOrders), ...(sellOrders || mySellOrders)].sort((a, b) => b.time_placed - a.time_placed)
|
const allOpenOrders = [...buyOrders, ...sellOrders].sort((a, b) => new Date(b.time_placed).getTime() - new Date(a.time_placed).getTime())
|
||||||
allOpenOrders.forEach(order => {
|
allOpenOrders.forEach(order => {
|
||||||
const { id, quantity, minPrice = undefined, maxPrice = undefined, time_placed } = order
|
const { id, quantity, minPrice = undefined, maxPrice = undefined, time_placed } = order
|
||||||
const orderDetails = {
|
const orderDetails = {
|
||||||
@ -1411,13 +1445,13 @@
|
|||||||
frag.append(render.orderCard(orderDetails))
|
frag.append(render.orderCard(orderDetails))
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
(transactions || myTransactions).forEach(transaction => {
|
transactions.forEach(transaction => {
|
||||||
const { floID, quantity, unitValue, tx_time, buyer, seller } = transaction
|
const { quantity, unitValue, tx_time, buyer, seller } = transaction
|
||||||
let type, other;
|
let type, other;
|
||||||
if (seller === floID) {
|
if (seller === userID) {
|
||||||
type = 'Sold';
|
type = 'Sold';
|
||||||
other = buyer === floID ? 'MySelf' : buyer;
|
other = buyer === userID ? 'MySelf' : buyer;
|
||||||
} else if (buyer === floID) {
|
} else if (buyer === userID) {
|
||||||
type = 'Bought';
|
type = 'Bought';
|
||||||
other = seller;
|
other = seller;
|
||||||
} else
|
} else
|
||||||
@ -1446,7 +1480,7 @@
|
|||||||
if (ordersType === 'open') {
|
if (ordersType === 'open') {
|
||||||
try {
|
try {
|
||||||
const [buyOrders, sellOrders] = await Promise.all([getBuyList(), getSellList()])
|
const [buyOrders, sellOrders] = await Promise.all([getBuyList(), getSellList()])
|
||||||
const allOpenOrders = [...(buyOrders), ...(sellOrders)].sort((a, b) => b.time_placed - a.time_placed)
|
const allOpenOrders = [...(buyOrders), ...(sellOrders)].sort((a, b) => new Date(b.time_placed).getTime() - new Date(a.time_placed).getTime())
|
||||||
allOpenOrders.forEach(order => {
|
allOpenOrders.forEach(order => {
|
||||||
const { floID, quantity, minPrice = undefined, maxPrice = undefined, time_placed } = order
|
const { floID, quantity, minPrice = undefined, maxPrice = undefined, time_placed } = order
|
||||||
const orderDetails = {
|
const orderDetails = {
|
||||||
@ -1565,7 +1599,6 @@
|
|||||||
Reject("Unable to fetch Proxy secret");
|
Reject("Unable to fetch Proxy secret");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let tmp = localStorage.getItem("proxy_secret");
|
let tmp = localStorage.getItem("proxy_secret");
|
||||||
if (typeof tmp !== "string")
|
if (typeof tmp !== "string")
|
||||||
Reject("Unable to fetch Proxy secret");
|
Reject("Unable to fetch Proxy secret");
|
||||||
@ -1580,6 +1613,7 @@
|
|||||||
setValues(tmp);
|
setValues(tmp);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
Reject("Incorrect Password! Password Required for making transactions");
|
Reject("Incorrect Password! Password Required for making transactions");
|
||||||
|
|
||||||
}
|
}
|
||||||
}).catch(_ => Reject("Password Required for making transactions"));
|
}).catch(_ => Reject("Password Required for making transactions"));
|
||||||
} else
|
} else
|
||||||
@ -1588,9 +1622,10 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let floExchangeRate = 0
|
||||||
function updateRate() {
|
function updateRate() {
|
||||||
getRate().then(rate => {
|
getRate().then(rate => {
|
||||||
rate.flo = rate
|
floExchangeRate = parseFloat(rate)
|
||||||
getRef('flo_rate').textContent = formatAmount(parseFloat(rate))
|
getRef('flo_rate').textContent = formatAmount(parseFloat(rate))
|
||||||
getRef('get_price').value = parseFloat(parseFloat(rate).toFixed(2))
|
getRef('get_price').value = parseFloat(parseFloat(rate).toFixed(2))
|
||||||
}).catch(error => console.error(error))
|
}).catch(error => console.error(error))
|
||||||
@ -1606,23 +1641,22 @@
|
|||||||
account();
|
account();
|
||||||
}
|
}
|
||||||
|
|
||||||
function showBalance(containerId, availableBalance = 0, lockedBalance = 0) {
|
function showBalance(type, availableBalance = 0, lockedBalance = 0) {
|
||||||
getRef(containerId).innerHTML = ''
|
getRef(`${type}_balance`).innerHTML = ''
|
||||||
const templateToClone = lockedBalance ? 'locked_balance_template' : 'net_balance_template';
|
const templateToClone = lockedBalance ? 'locked_balance_template' : 'net_balance_template';
|
||||||
const card = getRef(templateToClone).content.cloneNode(true)
|
const card = getRef(templateToClone).content.cloneNode(true)
|
||||||
card.querySelector('.available-balance').textContent = availableBalance
|
card.querySelector('.available-balance').textContent = type === 'flo' ? parseFloat(availableBalance.toFixed(4)) : formatAmount(availableBalance)
|
||||||
if (lockedBalance) {
|
if (lockedBalance) {
|
||||||
card.querySelector('.locked-balance').textContent = lockedBalance
|
card.querySelector('.locked-balance').textContent = type === 'flo' ? parseFloat(lockedBalance.toFixed(4)) : formatAmount(lockedBalance)
|
||||||
}
|
}
|
||||||
getRef(containerId).className = lockedBalance ? 'grid balance-card__amount-wrapper' : ''
|
getRef(`${type}_balance`).className = lockedBalance ? 'grid balance-card__amount-wrapper' : ''
|
||||||
getRef(containerId).parentNode.className = `balance-card ${lockedBalance ? 'is-locked' : ''}`
|
getRef(`${type}_balance`).parentNode.className = `balance-card ${lockedBalance ? 'is-locked' : ''}`
|
||||||
getRef(containerId).append(card)
|
getRef(`${type}_balance`).append(card)
|
||||||
}
|
}
|
||||||
|
|
||||||
const balance = {}
|
const balance = {}
|
||||||
|
|
||||||
let accountDetails = {}
|
let accountDetails = {}
|
||||||
|
|
||||||
function account() {
|
function account() {
|
||||||
getAccount().then(acc => {
|
getAccount().then(acc => {
|
||||||
getRef("login_form").classList.add('hide-completely')
|
getRef("login_form").classList.add('hide-completely')
|
||||||
@ -1641,14 +1675,14 @@
|
|||||||
console.debug("FLO", flo_total, flo_locked, flo_net);
|
console.debug("FLO", flo_total, flo_locked, flo_net);
|
||||||
balance.flo = flo_net
|
balance.flo = flo_net
|
||||||
|
|
||||||
showBalance("flo_balance", flo_net, flo_locked)
|
showBalance("flo", flo_net, flo_locked,)
|
||||||
//Rupee Balance
|
//Rupee Balance
|
||||||
let rupee_total = acc.rupee_total;
|
let rupee_total = acc.rupee_total;
|
||||||
let rupee_locked = acc.buyOrders.reduce((a, x) => a + x.quantity * x.maxPrice, 0);
|
let rupee_locked = acc.buyOrders.reduce((a, x) => a + x.quantity * x.maxPrice, 0);
|
||||||
let rupee_net = rupee_total - rupee_locked;
|
let rupee_net = rupee_total - rupee_locked;
|
||||||
console.debug("RUPEE", rupee_total, rupee_locked, rupee_net);
|
console.debug("RUPEE", rupee_total, rupee_locked, rupee_net);
|
||||||
balance.rupee = rupee_net
|
balance.rupee = rupee_net
|
||||||
showBalance("rupee_balance", rupee_net, rupee_locked)
|
showBalance("rupee", rupee_net, rupee_locked)
|
||||||
//My orders
|
//My orders
|
||||||
renderUserOrders();
|
renderUserOrders();
|
||||||
proxy.secret.then(_ => null).catch(_ => null);
|
proxy.secret.then(_ => null).catch(_ => null);
|
||||||
@ -1684,10 +1718,7 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
logout() {
|
logout() {
|
||||||
getConfirmation('Log out?', {
|
getConfirmation('Log out?', { cancelText: 'Stay', confirmText: 'Log out' }).then(res => {
|
||||||
cancelText: 'Stay',
|
|
||||||
confirmText: 'Log out'
|
|
||||||
}).then(res => {
|
|
||||||
if (res) {
|
if (res) {
|
||||||
logout().then(result => {
|
logout().then(result => {
|
||||||
console.warn(result);
|
console.warn(result);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user