ui/update: Bug fixes, Added Coin Price Lookup Table (Offer new page) + Update github readme header GFX.

This commit is contained in:
gerlofvanek 2023-04-07 14:26:59 +02:00
parent 5536c82ded
commit e67ca94dfb
9 changed files with 272 additions and 179 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 204 KiB

After

Width:  |  Height:  |  Size: 230 KiB

View file

@ -14,7 +14,7 @@ function updateSelectCache(select) {
function setSelectData(select) {
const selectedOption = select.options[select.selectedIndex];
const image = selectedOption.getAttribute('data-image') || 'https://dummyimage.com/20x20/000/fff'; // set a default image URL
const image = selectedOption.getAttribute('data-image') || '/static/images/other/coin.png'; // set a default image URL
const name = selectedOption.textContent.trim();
if (image) {
select.style.backgroundImage = `url(${image})`;

View file

@ -111,7 +111,7 @@
<td class="py-3 px-6 monospace">
<a href=/offer/{{ s[1] }}>{{ s[1] }}</a>
</td>
<td class="py-3 px-6">{{ s[2] }}</td>
<td class="py-3 px-6 w-52 whitespace-normal break-words">{{ s[2] }}</td>
<td class="py-3 px-6">{{ s[3] }}</td>
<td class="py-3 px-6">{{ s[4] }}</td>
</tr>

View file

@ -412,7 +412,7 @@
<button data-tooltip-target="tooltip-darkmode" id="theme-toggle" type="button" class="text-gray-500 dark:text-gray-400 focus:outline-none rounded-lg text-sm ml-5">
<svg id="theme-toggle-dark-icon" class="hidden w-5 h-5" fill="#F59E0B" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="M17.293 13.293A8 8 0 016.707 2.707a8.001 8.001 0 1010.586 10.586z"></path></svg>
<svg id="theme-toggle-light-icon" class="hidden w-5 h-5" fill="#F59E0B" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="M10 2a1 1 0 011 1v1a1 1 0 11-2 0V3a1 1 0 011-1zm4 8a4 4 0 11-8 0 4 4 0 018 0zm-.464 4.95l.707.707a1 1 0 001.414-1.414l-.707-.707a1 1 0 00-1.414 1.414zm2.12-10.607a1 1 0 010 1.414l-.706.707a1 1 0 11-1.414-1.414l.707-.707a1 1 0 011.414 0zM17 11a1 1 0 100-2h-1a1 1 0 100 2h1zm-7 4a1 1 0 011 1v1a1 1 0 11-2 0v-1a1 1 0 011-1zM5.05 6.464A1 1 0 106.465 5.05l-.708-.707a1 1 0 00-1.414 1.414l.707.707zm1.414 8.486l-.707.707a1 1 0 01-1.414-1.414l.707-.707a1 1 0 011.414 1.414zM4 11a1 1 0 100-2H3a1 1 0 000 2h1z" fill-rule="evenodd" clip-rule="evenodd"></path></svg>
<span data-tooltip-target="tooltip-TOR"></span>
<span data-tooltip-target="tooltip-darkmode"></span>
<div class="tooltip-arrow" data-popper-arrow></div>
<div id="tooltip-darkmode" role="tooltip" class="inline-block absolute invisible z-10 py-2 px-3 text-sm font-medium text-white bg-blue-500 rounded-lg shadow-sm opacity-0 transition-opacity duration-300 tooltip">Dark mode</div>
</button>

View file

@ -668,12 +668,6 @@
<div class="flex flex-wrap justify-end">
<div class="w-full md:w-auto p-1.5">
<button name="step2" type="submit" value="Back" class="flex flex-wrap justify-center w-full px-4 py-2.5 font-medium text-sm text-coolGray-500 hover:text-coolGray-600 border border-coolGray-200 hover:border-coolGray-300 bg-white rounded-md focus:ring-0 focus:outline-none dark:text-white dark:hover:text-white dark:bg-gray-600 dark:hover:bg-gray-700 dark:border-gray-600 dark:hover:border-gray-600">
<svg class="mr-2" xmlns="http://www.w3.org/2000/svg" height="20" width="20" viewBox="0 0 24 24">
<g stroke-linecap="round" stroke-width="2" fill="none" stroke="#ffffff" stroke-linejoin="round">
<circle cx="12" cy="12" r="11"></circle>
<polyline points="13 16 9 12 13 8" stroke="#ffffff"></polyline>
</g>
</svg>
</svg>
<span>Back</span>
</button>

View file

@ -252,9 +252,10 @@
<path d="M11.3333 6.1133C11.2084 5.98913 11.0395 5.91943 10.8633 5.91943C10.6872 5.91943 10.5182 5.98913 10.3933 6.1133L8.00001 8.47329L5.64001 6.1133C5.5151 5.98913 5.34613 5.91943 5.17001 5.91943C4.99388 5.91943 4.82491 5.98913 4.70001 6.1133C4.63752 6.17527 4.58792 6.249 4.55408 6.33024C4.52023 6.41148 4.50281 6.49862 4.50281 6.58663C4.50281 6.67464 4.52023 6.76177 4.55408 6.84301C4.58792 6.92425 4.63752 6.99799 4.70001 7.05996L7.52667 9.88663C7.58865 9.94911 7.66238 9.99871 7.74362 10.0326C7.82486 10.0664 7.912 10.0838 8.00001 10.0838C8.08801 10.0838 8.17515 10.0664 8.25639 10.0326C8.33763 9.99871 8.41136 9.94911 8.47334 9.88663L11.3333 7.05996C11.3958 6.99799 11.4454 6.92425 11.4793 6.84301C11.5131 6.76177 11.5305 6.67464 11.5305 6.58663C11.5305 6.49862 11.5131 6.41148 11.4793 6.33024C11.4454 6.249 11.3958 6.17527 11.3333 6.1133Z" fill="#8896AB"></path>
</svg>
<select class="select hover:border-blue-500 pl-10 bg-gray-50 text-gray-900 appearance-none pr-10 dark:bg-gray-500 dark:text-white border border-gray-300 dark:border-gray-400 dark:text-gray-50 dark:placeholder-gray-400 text-sm rounded-lg outline-none focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 focus:ring-0"" id="coin_to" name="coin_to" onchange="set_rate('coin_to');">
<option class="no-space" value="-1">Select coin you get</option>
<option value="-1">Select coin you get</option>
{% for c in coins %}
<option{% if data.coin_to==c[0] %} selected{% endif %} value="{{ c[0] }}" data-image="/static/images/coins/{{ c[1]|replace(" ", "-") }}-20.png">{{ c[1] }}</option>{% endfor %}
<option{% if data.coin_to==c[0] %} selected{% endif %} value="{{ c[0] }}" data-image="/static/images/coins/{{ c[1]|replace(" ", "-") }}-20.png">{{ c[1] }}</option>
{% endfor %}
</select>
<div class="select-dropdown">
<img class="select-icon" src="" alt="">
@ -354,15 +355,48 @@
</div>
</div>
</div>
<div class="py-3 border-b items-center justify-between -mx-4 mb-6 pb-6 border-gray-400 border-opacity-20">
<div class="pricejsonhidden hidden py-3 border-b items-center justify-between -mx-4 mb-6 pb-6 border-gray-400 border-opacity-20">
<div class="w-full md:w-10/12">
<div class="flex flex-wrap -m-3 w-full sm:w-auto px-4 mb-6 sm:mb-0">
<div class="w-full md:w-1/3 p-3">
<p class="text-sm text-coolGray-800 dark:text-white font-semibold">Rates</p>
<p class="text-sm text-coolGray-800 dark:text-white font-semibold">Coin Prices/Rates (JSON)</p>
</div>
<div class="w-full md:flex-1 p-3 dark:text-white text-sm monospace">
<p id="rates_display"></p>
<!-- todo adjust font-size -->
</div>
</div>
</div>
</div>
<div class="pricetablehidden hidden py-3 border-b items-center justify-between -mx-4 mb-6 pb-6 border-gray-400 border-opacity-20">
<div class="w-full md:w-10/12">
<div class="flex flex-wrap -m-3 w-full sm:w-auto px-4 mb-6 sm:mb-0">
<div class="w-full md:w-1/3 p-3">
<p class="text-sm text-coolGray-800 dark:text-white font-semibold">Coin Prices/Rates (Table)</p>
</div>
<div class="w-full md:flex-1 p-3 dark:text-white text-sm">
<table id="priceTable" class="hidden w-full min-w-max text-sm">
<thead class="uppercase">
<tr class="text-left">
<th class="p-0">
<div class="py-3 px-6 rounded-tl-xl bg-coolGray-200 dark:bg-gray-600">
<span class="text-xs text-gray-600 dark:text-gray-300 font-semibold">Coin</span>
</div>
</th>
<th class="p-0">
<div class="py-3 bg-coolGray-200 dark:bg-gray-600">
<span class="text-xs text-gray-600 dark:text-gray-300 font-semibold">Price in USD</span>
</div>
</th>
<th class="p-0">
<div class="py-3 rounded-tr-xl bg-coolGray-200 dark:bg-gray-600">
<span class="text-xs text-gray-600 dark:text-gray-300 font-semibold">Price in BTC (Rate)</span>
</div>
</th>
</tr>
</thead>
<tbody id="priceTableBody" class="text-gray-700">
</tbody>
</table>
</div>
</div>
</div>
@ -381,8 +415,15 @@
<div class="flex flex-wrap justify-end">
<!--<div class="w-full md:w-auto p-1.5"><button name="show_rates_table" type="button" value="Show Rates Table" onclick='lookup_rates_table();' class="flex flex-wrap justify-center w-full px-4 py-2.5 font-medium text-sm text-coolGray-500 hover:text-coolGray-600 border border-coolGray-200 hover:border-coolGray-300 bg-white rounded-md shadow-button focus:ring-0 focus:outline-none"><svg class="mr-2"
xmlns="http://www.w3.org/2000/svg" height="20" width="20" viewBox="0 0 24 24"><g fill="#556987"><path fill="#556987" d="M12,3c1.989,0,3.873,0.65,5.43,1.833l-3.604,3.393l9.167,0.983L22.562,0l-3.655,3.442 C16.957,1.862,14.545,1,12,1C5.935,1,1,5.935,1,12h2C3,7.037,7.037,3,12,3z"></path><path data-color="#556987" d="M12,21c-1.989,0-3.873-0.65-5.43-1.833l3.604-3.393l-9.167-0.983L1.438,24l3.655-3.442 C7.043,22.138,9.455,23,12,23c6.065,0,11-4.935,11-11h-2C21,16.963,16.963,21,12,21z"></path></g></svg><span>Show Rates Table</span></button></div>-->
{% if show_chart %}
<div class="w-full md:w-auto p-1.5">
<button name="check_rates" type="button" value="Lookup Rates (RAW)" onclick='lookup_rates();' class="flex flex-wrap justify-center w-full px-4 py-2.5 font-medium text-sm text-coolGray-500 hover:text-coolGray-600 border border-coolGray-200 hover:border-coolGray-300 bg-white rounded-md focus:ring-0 focus:outline-none dark:text-white dark:hover:text-white dark:bg-gray-600 dark:hover:bg-gray-700 dark:border-gray-600 dark:hover:border-gray-600"><span>Check Current Rates</span>
<button name="loadPrices" type="button" value="Lookup Rates (RAW)" onclick="loadPrices();" class="flex flex-wrap justify-center w-full px-4 py-2.5 font-medium text-sm text-coolGray-500 hover:text-coolGray-600 border border-coolGray-200 hover:border-coolGray-300 bg-white rounded-md focus:ring-0 focus:outline-none dark:text-white dark:hover:text-white dark:bg-gray-600 dark:hover:bg-gray-700 dark:border-gray-600 dark:hover:border-gray-600">
<span>Check Current Coin Prices/Rates (TABLE)</span>
</button>
</div>
{% endif %}
<div class="w-full md:w-auto p-1.5">
<button name="check_rates" type="button" value="Lookup Rates (RAW)" onclick='lookup_rates();' class="flex flex-wrap justify-center w-full px-4 py-2.5 font-medium text-sm text-coolGray-500 hover:text-coolGray-600 border border-coolGray-200 hover:border-coolGray-300 bg-white rounded-md focus:ring-0 focus:outline-none dark:text-white dark:hover:text-white dark:bg-gray-600 dark:hover:bg-gray-700 dark:border-gray-600 dark:hover:border-gray-600"><span>Check Current Price/Rates (JSON)</span>
</button>
</div>
<div class="w-full md:w-auto p-1.5">
@ -413,6 +454,7 @@ select.select-disabled {
opacity: 0.50 !important;
}
</style>
<script>
const xhr_rates = new XMLHttpRequest();
xhr_rates.onload = () => {
@ -428,12 +470,10 @@ opacity: 0.50 !important;
const obj = JSON.parse(xhr_rate.response);
if (obj.hasOwnProperty('rate')) {
document.getElementById('rate').value = obj['rate'];
}
else
} else
if (obj.hasOwnProperty('amount_to')) {
document.getElementById('amt_to').value = obj['amount_to'];
}
else
} else
if (obj.hasOwnProperty('amount_from')) {
document.getElementById('amt_from').value = obj['amount_from'];
}
@ -485,11 +525,16 @@ opacity: 0.50 !important;
}
inner_html = '<p>Updating...</p>';
document.getElementById('rates_display').innerHTML = inner_html;
// Remove the 'hidden' class
document.querySelector(".pricejsonhidden").classList.remove("hidden");
xhr_rates.open('POST', '/json/rates');
xhr_rates.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xhr_rates.send('coin_from=' + coin_from + '&coin_to=' + coin_to);
}
function lookup_rates_table() {
const coin_from = document.getElementById('coin_from').value;
const coin_to = document.getElementById('coin_to').value;
@ -499,10 +544,15 @@ opacity: 0.50 !important;
}
inner_html = 'Updating...</p>';
document.getElementById('rates_display').innerHTML = inner_html;
// Remove the 'hidden' class
document.querySelector(".hidden.py-3.border-b").classList.remove("hidden");
xhr_rates_table.open('GET', '/json/rateslist?from=' + coin_from + '&to=' + coin_to);
xhr_rates_table.send();
}
function set_swap_type_enabled(coin_from, coin_to, swap_type) {
let make_hidden = false;
if (coin_to == '6' /* XMR */ || coin_to == '8' /* PART_ANON */ || coin_to == '7' /* PART_BLIND */ || coin_from == '7' /* PART_BLIND */ ) {
@ -586,5 +636,60 @@ opacity: 0.50 !important;
</div>
{% include 'footer.html' %}
</div>
{% if show_chart %}
<script>
document.addEventListener('DOMContentLoaded', function() {
document.querySelector("button[name='loadPrices']").addEventListener("click", loadPrices);
function loadPrices() {
const api_key = '{{chart_api_key}}';
const coins = ['BTC', 'PART', 'XMR', 'LTC', 'FIRO', 'DASH', 'PIVX'];
document.getElementById("priceTable").classList.remove("hidden");
coins.forEach(coin => {
fetch(`https://min-api.cryptocompare.com/data/pricemultifull?fsyms=${coin}&tsyms=USD,BTC&api_key=${api_key}`)
.then(response => response.json())
.then(data => {
const priceUSD = data.RAW[coin].USD.PRICE;
const priceBTC = data.RAW[coin].BTC.PRICE;
const tableRow = document.createElement("tr");
tableRow.classList.add("opacity-100", "text-gray-500", "dark:text-gray-100", "dark:text-gray-100", "hover:bg-coolGray-200", "dark:hover:bg-gray-600");
const coinCell = document.createElement("td", "py-3", "px-6");
coinCell.textContent = coin;
coinCell.classList.add("py-3", "px-6", "bold");
tableRow.appendChild(coinCell);
const usdPriceCell = document.createElement("td", "py-3", "px-6");
usdPriceCell.textContent = priceUSD.toFixed(2) + ' USD';
coinCell.classList.add("py-3", "px-6");
tableRow.appendChild(usdPriceCell);
const btcPriceCell = document.createElement("td");
if (coin !== 'BTC') {
btcPriceCell.textContent = priceBTC.toFixed(8) + ' BTC';
} else {
btcPriceCell.textContent = '-';
}
coinCell.classList.add("py-3", "px-6");
tableRow.appendChild(btcPriceCell);
document.getElementById("priceTableBody").appendChild(tableRow);
})
.catch(error => console.error(`Error fetching ${coin} data:`, error));
});
// Remove the 'hidden' class from the section when the button is clicked
document.querySelector(".pricetablehidden").classList.remove("hidden");
// Disable the button to prevent multiple clicks
const button = document.querySelector("button[name='loadPrices']");
button.disabled = true;
}
});
</script>
{% endif %}
</body>
</html>

View file

@ -571,13 +571,6 @@
<div class="flex flex-wrap justify-end">
<div class="w-full md:w-auto p-1.5">
<button name="step1" type="submit" value="Back" class="flex flex-wrap justify-center w-full px-4 py-2.5 font-medium text-sm text-coolGray-500 hover:text-coolGray-600 border border-coolGray-200 hover:border-coolGray-300 bg-white rounded-md focus:ring-0 focus:outline-none dark:text-white dark:hover:text-white dark:bg-gray-600 dark:hover:bg-gray-700 dark:border-gray-600 dark:hover:border-gray-600">
<svg class="mr-2" xmlns="http://www.w3.org/2000/svg" height="20" width="20" viewBox="0 0 24 24">
<g stroke-linecap="round" stroke-width="2" fill="none" stroke="#ffffff" stroke-linejoin="round">
<circle cx="12" cy="12" r="11"></circle>
<polyline points="13 16 9 12 13 8" stroke="#ffffff"></polyline>
</g>
</svg>
</svg>
<span>Back</span>
</button>
</div>

View file

@ -264,7 +264,7 @@
<script>
window.addEventListener('load', function() {
const api_key = 'price-chart';
const api_key = '{{chart_api_key}}';
const coins = ['BTC', 'PART', 'XMR', 'LTC', 'FIRO', 'DASH', 'PIVX'];
@ -309,13 +309,8 @@ if (priceChange1h >= 0) {
});
});
</script>
{% endif %}
<section>
<div class="pl-6 pr-6 pt-0 pb-0 mt-5 h-full overflow-hidden">
<div class="pb-6 border-coolGray-100">
@ -550,7 +545,7 @@ if (priceChange1h >= 0) {
</td>
<td class="py-3 px-6 text-xs">{{ o[13] }}</td>
<td class="py-3 px-6 text-xs">
<span class="inline-flex align-middle items-center justify-center w-9 h-10 bg-white-50 rounded">
<span class="inline-flex align-middle items-center justify-center w-9 h-10 rounded">
{% if o[9]==true %} <img class="h-7" src="/static/images/coins/{{ o[3]|replace(" ", "-") }}.png" alt="">
</span>{{ o[3] }}
</td>
@ -562,7 +557,7 @@ if (priceChange1h >= 0) {
<td class="py-3 px-6 text-xs">{{ o[4]|truncate(8,true,'',0) }}</td>
{% endif %}
<td class="py-4 px-6 text-xs">
<span class="inline-flex align-middle items-center justify-center w-9 h-10 bg-white-50 rounded"> {% if o[9]==true %} <img class="h-7" src="/static/images/coins/{{ o[2]|replace(" ", "-") }}.png" alt="">
<span class="inline-flex align-middle items-center justify-center w-9 h-10 rounded"> {% if o[9]==true %} <img class="h-7" src="/static/images/coins/{{ o[2]|replace(" ", "-") }}.png" alt="">
</span>{{ o[2] }}
</td>
<td class="py-3 px-6 text-xs">{{ o[4] }}</td>

View file

@ -431,6 +431,11 @@ def page_newoffer(self, url_split, post_string):
automation_filters = {'type_ind': Concepts.OFFER, 'sort_by': 'label'}
automation_strategies = swap_client.listAutomationStrategies(automation_filters)
chart_api_key = swap_client.settings.get('chart_api_key', '')
if chart_api_key == '':
chart_api_key_enc = swap_client.settings.get('chart_api_key_enc', '')
chart_api_key = 'cd7600e7b5fdd99c6f900673ff0ee8f64d6d4219a4bb87191ad4a2e3fc65d7f4' if chart_api_key_enc == '' else bytes.fromhex(chart_api_key_enc).decode('utf-8')
return self.render_template(template, {
'messages': messages,
'err_messages': err_messages,
@ -442,9 +447,10 @@ def page_newoffer(self, url_split, post_string):
'automation_strategies': automation_strategies,
'summary': summary,
'swap_types': [(strSwapType(x), strSwapDesc(x)) for x in SwapTypes if strSwapType(x)],
'show_chart': swap_client.settings.get('show_chart', True),
'chart_api_key': chart_api_key,
})
def page_offer(self, url_split, post_string):
ensure(len(url_split) > 2, 'Offer ID not specified')
offer_id = decode_offer_id(url_split[2])