Removed price input and UI improvements

This commit is contained in:
sairaj mote 2022-05-03 18:02:48 +05:30
parent c1dcf7916a
commit 79a23399db
4 changed files with 118 additions and 38 deletions

View File

@ -143,6 +143,10 @@ sm-form {
--gap: 1rem; --gap: 1rem;
} }
sm-copy {
font-size: 0.9rem;
}
ul { ul {
list-style: none; list-style: none;
} }
@ -461,6 +465,9 @@ details summary {
cursor: pointer; cursor: pointer;
padding: 1rem 0; padding: 1rem 0;
} }
details .icon {
flex-shrink: 0;
}
details[open] { details[open] {
padding-bottom: 1rem; padding-bottom: 1rem;
} }
@ -518,6 +525,27 @@ sm-checkbox {
flex-shrink: 0; flex-shrink: 0;
} }
.tooltip {
position: relative;
z-index: 1;
cursor: pointer;
}
.tooltip .banner {
position: absolute;
right: 0;
width: min(20rem, 100vw - 1rem);
display: none;
font-size: 0.9rem;
background-color: rgba(var(--foreground-color), 1);
padding: 1rem;
border-radius: 0.5rem;
box-shadow: 0 0.2rem 0.5rem rgba(0, 0, 0, 0.1);
border: solid thin rgba(var(--text-color), 0.2);
}
.tooltip:hover .banner {
display: flex;
}
.page-layout { .page-layout {
display: grid; display: grid;
grid-template-columns: 1.5rem minmax(0, 1fr) 1.5rem; grid-template-columns: 1.5rem minmax(0, 1fr) 1.5rem;
@ -558,10 +586,6 @@ sm-checkbox {
#sign_up header { #sign_up header {
padding: 1.5rem 0; padding: 1.5rem 0;
} }
#sign_up sm-copy {
font-size: 0.9rem;
--button-border-radius: 0.5rem;
}
#sign_up .h2 { #sign_up .h2 {
margin-bottom: 0.5rem; margin-bottom: 0.5rem;
} }

File diff suppressed because one or more lines are too long

View File

@ -133,6 +133,9 @@ sm-button {
sm-form { sm-form {
--gap: 1rem; --gap: 1rem;
} }
sm-copy {
font-size: 0.9rem;
}
ul { ul {
list-style: none; list-style: none;
} }
@ -442,7 +445,9 @@ details {
cursor: pointer; cursor: pointer;
padding: 1rem 0; padding: 1rem 0;
} }
.icon {
flex-shrink: 0;
}
&[open] { &[open] {
padding-bottom: 1rem; padding-bottom: 1rem;
summary { summary {
@ -496,6 +501,26 @@ sm-checkbox {
flex-shrink: 0; flex-shrink: 0;
} }
} }
.tooltip {
position: relative;
z-index: 1;
cursor: pointer;
.banner {
position: absolute;
right: 0;
width: min(20rem, calc(100vw - 1rem));
display: none;
font-size: 0.9rem;
background-color: rgba(var(--foreground-color), 1);
padding: 1rem;
border-radius: 0.5rem;
box-shadow: 0 0.2rem 0.5rem rgba(0, 0, 0, 0.1);
border: solid thin rgba(var(--text-color), 0.2);
}
&:hover .banner {
display: flex;
}
}
.page-layout { .page-layout {
display: grid; display: grid;
grid-template-columns: 1.5rem minmax(0, 1fr) 1.5rem; grid-template-columns: 1.5rem minmax(0, 1fr) 1.5rem;
@ -532,10 +557,6 @@ sm-checkbox {
header { header {
padding: 1.5rem 0; padding: 1.5rem 0;
} }
sm-copy {
font-size: 0.9rem;
--button-border-radius: 0.5rem;
}
.h2 { .h2 {
margin-bottom: 0.5rem; margin-bottom: 0.5rem;
} }

View File

@ -112,7 +112,10 @@
</sm-form> </sm-form>
<section id="exchange_wrapper" class="hide user-content"> <section id="exchange_wrapper" class="hide user-content">
<div id="asset_list_wrapper" class="grid gap-1 align-start"> <div id="asset_list_wrapper" class="grid gap-1 align-start">
<h5>ASSETS</h5> <div class="flex align-center space-between">
<h5>ASSETS</h5>
<h5>PRICE</h5>
</div>
<ul id="listed_assets" class="user-content hide"></ul> <ul id="listed_assets" class="user-content hide"></ul>
</div> </div>
<div id="asset_page" class="hide-on-mobile"> <div id="asset_page" class="hide-on-mobile">
@ -150,10 +153,8 @@
<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" placeholder="Max price (₹)" type="number" step="0.0001" required <div id="get_price" class="flex align-center space-between"></div>
animate> <sm-input id="get_quantity" placeholder="Quantity" type="number" step="0.00000001" required
</sm-input>
<sm-input id="get_quantity" placeholder="Quantity" type="number" step="0.0001" required
animate> animate>
</sm-input> </sm-input>
</sm-input> </sm-input>
@ -338,6 +339,24 @@
app. app.
</p> </p>
</details> </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> <details>
<summary class="interact"> <summary class="interact">
<h4> <h4>
@ -1097,7 +1116,7 @@
getRef('listed_assets').querySelector('.listed-asset--active').classList.remove('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('listed_assets').querySelector(`[href="#/exchange?asset=${params.asset}"]`).classList.add('listed-asset--active')
getRef('chart_asset').innerHTML = `<h4> ${params.asset}/INR</h4><p>${formatAmount(floGlobals.exchangeRates[params.asset])}</p>` getRef('chart_asset').innerHTML = `<h4> ${params.asset}/INR</h4><p>${formatAmount(floGlobals.exchangeRates[params.asset])}</p>`
getRef('get_price').value = (parseFloat(floGlobals.exchangeRates[params.asset]) * deviation[tradeType]).toFixed(6) ; showSuggestedPrice(params.asset)
getRef('traded_asset').textContent = `Trade ${params.asset}` getRef('traded_asset').textContent = `Trade ${params.asset}`
getRef('trade_button').textContent = `${tradeType} ${params.asset}` getRef('trade_button').textContent = `${tradeType} ${params.asset}`
getRef('quantity_type').textContent = tradeType === 'buy' ? formatAmount(allTokens.rupee.net) : `${parseFloat(allTokens[params.asset].net.toFixed(4))} ${params.asset}` getRef('quantity_type').textContent = tradeType === 'buy' ? formatAmount(allTokens.rupee.net) : `${parseFloat(allTokens[params.asset].net.toFixed(4))} ${params.asset}`
@ -1357,6 +1376,27 @@
return amount.toLocaleString(`en-IN`, { style: 'currency', currency: 'INR', maximumFractionDigits: 5 }) return amount.toLocaleString(`en-IN`, { style: 'currency', currency: 'INR', maximumFractionDigits: 5 })
} }
function getSuggestedPrice(asset = pagesData.params.asset || 'FLO') {
const tradeType = getRef('trade_type_selector').value
return parseFloat((parseFloat(floGlobals.exchangeRates[asset]) * deviation[tradeType]).toFixed(8))
}
function showSuggestedPrice(asset) {
const tradeType = getRef('trade_type_selector').value
getRef('get_price').innerHTML = `
<div class="grid">
<div style="font-size: 0.8rem; font-weight: 500; margin-bottom: 0.3rem;">${tradeType === 'buy' ? 'Buy upto' : 'Sell till'}</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">
This is the ${tradeType === 'buy' ? 'Highest price upto' : 'Lowest price until'} which your order will be considered valid. System will always try to match your order with the best price.
</p>
</div>
`
}
const chartDimensions = { const chartDimensions = {
height: 0, height: 0,
width: 0 width: 0
@ -1378,7 +1418,7 @@
card.dataset.type = type card.dataset.type = type
card.querySelector('.order-card__type').textContent = type card.querySelector('.order-card__type').textContent = type
card.querySelector('.order-card__quantity').textContent = `${quantity} ${asset}` card.querySelector('.order-card__quantity').textContent = `${quantity} ${asset}`
card.querySelector('.order-card__price-type').textContent = type === 'buy' ? 'Max price' : 'Min price' 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__price').textContent = formatAmount(price)
card.querySelector('.order-card__time').textContent = relativeTime.from(new Date(time).getTime()) card.querySelector('.order-card__time').textContent = relativeTime.from(new Date(time).getTime())
return card return card
@ -1650,8 +1690,7 @@
getRef('trade_type_selector').addEventListener('change', e => { getRef('trade_type_selector').addEventListener('change', e => {
tradeType = e.detail.value tradeType = e.detail.value
const selectedAsset = pagesData.params.asset const selectedAsset = pagesData.params.asset
getRef('get_price').setAttribute('placeholder', tradeType === 'buy' ? 'Max price' : 'Min price') showSuggestedPrice()
getRef('get_price').value = (parseFloat(floGlobals.exchangeRates[selectedAsset]) * deviation[tradeType]).toFixed(6) ;
getRef('trade_button').textContent = `${tradeType} ${selectedAsset}` getRef('trade_button').textContent = `${tradeType} ${selectedAsset}`
getRef('quantity_type').textContent = tradeType === 'buy' ? formatAmount(allTokens.rupee.net) : `${parseFloat(allTokens[selectedAsset].net.toFixed(4))} ${selectedAsset}` getRef('quantity_type').textContent = tradeType === 'buy' ? formatAmount(allTokens.rupee.net) : `${parseFloat(allTokens[selectedAsset].net.toFixed(4))} ${selectedAsset}`
updateTooltip(selectedAsset, tradeType) updateTooltip(selectedAsset, tradeType)
@ -1663,7 +1702,7 @@
hidePopup() hidePopup()
const asset = pagesData.params.asset; const asset = pagesData.params.asset;
const quantity = parseFloat(getRef('get_quantity').value) const quantity = parseFloat(getRef('get_quantity').value)
const price = parseFloat(getRef('get_price').value) const price = getSuggestedPrice()
showProcess('trade_button_wrapper') showProcess('trade_button_wrapper')
try { try {
if (tradeType === 'buy') { if (tradeType === 'buy') {
@ -1698,10 +1737,10 @@
} }
getRef('quantity_selector').addEventListener('click', e => { getRef('quantity_selector').addEventListener('click', e => {
if (e.target.closest('button')) { if (e.target.closest('button')) {
const target = e.target.closest('button')
const unitValue = parseFloat(getRef('get_price').value)
const fraction = parseFloat(target.value)
const selectedAsset = pagesData.params.asset const selectedAsset = pagesData.params.asset
const target = e.target.closest('button')
const unitValue = getSuggestedPrice()
const fraction = parseFloat(target.value)
if (tradeType === 'buy') { if (tradeType === 'buy') {
console.log(parseFloat((fraction * allTokens['rupee'].net).toFixed(4)), parseFloat(((allTokens['rupee'].net * fraction) / unitValue).toFixed(4))) console.log(parseFloat((fraction * allTokens['rupee'].net).toFixed(4)), parseFloat(((allTokens['rupee'].net * fraction) / unitValue).toFixed(4)))
getRef('get_total').value = parseFloat((fraction * allTokens['rupee'].net).toFixed(2)) getRef('get_total').value = parseFloat((fraction * allTokens['rupee'].net).toFixed(2))
@ -1713,19 +1752,13 @@
} }
} }
}) })
getRef('get_price').addEventListener('keyup', e => {
const unitValue = parseFloat(getRef('get_price').value) || floGlobals.exchangeRates[pagesData.params.asset]
const quantity = parseFloat(getRef('get_quantity').value) || 0
getRef('get_total').value = parseFloat((quantity * unitValue).toFixed(2)) || 0
})
getRef('get_quantity').addEventListener('keyup', e => { getRef('get_quantity').addEventListener('keyup', e => {
const unitValue = parseFloat(getRef('get_price').value) const unitValue = getSuggestedPrice()
getRef('get_total').value = parseFloat((parseFloat(e.target.value) * unitValue).toFixed(2)) || 0 getRef('get_total').value = parseFloat((parseFloat(e.target.value) * unitValue).toFixed(2)) || 0
}) })
getRef('get_total').addEventListener('keyup', e => { getRef('get_total').addEventListener('keyup', e => {
const unitValue = parseFloat(getRef('get_price').value) const unitValue = getSuggestedPrice()
getRef('get_quantity').value = parseFloat((parseFloat(e.target.value) / unitValue).toFixed(6)) || 0 getRef('get_quantity').value = parseFloat((parseFloat(e.target.value) / unitValue).toFixed(8)) || 0
}) })
getRef('wallet_actions').addEventListener('click', e => { getRef('wallet_actions').addEventListener('click', e => {
@ -2091,10 +2124,10 @@
const asset = pagesData.params.asset; const asset = pagesData.params.asset;
const tradeType = getRef('trade_type_selector').value const tradeType = getRef('trade_type_selector').value
const quantity = parseFloat(getRef('get_quantity').value) const quantity = parseFloat(getRef('get_quantity').value)
const price = parseFloat(getRef('get_price').value) const price = getSuggestedPrice()
const total = parseFloat(getRef('get_total').value) const total = parseFloat(getRef('get_total').value)
getRef('confirm_trade__title').textContent = `${tradeType} ${asset}` getRef('confirm_trade__title').textContent = `${tradeType} ${asset}`
getRef('confirm_trade__price_type').textContent = tradeType === 'buy' ? 'Max price' : 'Min price' getRef('confirm_trade__price_type').textContent = tradeType === 'buy' ? 'Valid upto' : 'Valid until'
getRef('confirm_trade__price').textContent = formatAmount(price) getRef('confirm_trade__price').textContent = formatAmount(price)
getRef('confirm_trade__quantity').textContent = quantity getRef('confirm_trade__quantity').textContent = quantity
getRef('confirm_trade__total').textContent = formatAmount(total) getRef('confirm_trade__total').textContent = formatAmount(total)
@ -2247,8 +2280,10 @@
} }
} }
} }
if (pagesData.params.hasOwnProperty('asset' && pagesData.params.asset !== '')) if (pagesData.params.hasOwnProperty('asset' && pagesData.params.asset !== '')) {
getRef('get_price').value = (parseFloat(rates[pagesData.params.asset]) * deviation[tradeType]).toFixed(6) ; const tradeType = getRef('trade_type_selector').value
showSuggestedPrice()
}
if (refreshButton) if (refreshButton)
buttonLoader('wallet_balance_refresh_button', false); buttonLoader('wallet_balance_refresh_button', false);
}).catch(error => console.error(error.message)) }).catch(error => console.error(error.message))
@ -2296,9 +2331,9 @@
document.querySelectorAll(".user-content").forEach(elem => elem.classList.remove('hide')) document.querySelectorAll(".user-content").forEach(elem => elem.classList.remove('hide'))
getRef("user_id").value = acc.floID; getRef("user_id").value = acc.floID;
getRef("sink_id").value = acc.sinkID; getRef("sink_id").value = acc.sinkID;
if(acc.subAdmin) if (acc.subAdmin)
console.info("logged in as subAdmin"); console.info("logged in as subAdmin");
// rupee balance init // rupee balance init
allTokens[floGlobals.currency] = { allTokens[floGlobals.currency] = {
total: 0, total: 0,