From fe83736ec715369385db1a5685fefc8e9362ee93 Mon Sep 17 00:00:00 2001
From: Gerlof van Ek <info@gerlofvanek.com>
Date: Mon, 14 Oct 2024 18:11:03 +0200
Subject: [PATCH] ui: Added custom order price tiles + Fixes

---
 basicswap/static/js/pricechart.js | 12 ++--
 basicswap/templates/offers.html   | 92 ++++++++++++++++++-------------
 2 files changed, 61 insertions(+), 43 deletions(-)

diff --git a/basicswap/static/js/pricechart.js b/basicswap/static/js/pricechart.js
index 9e6b811..00a92c2 100644
--- a/basicswap/static/js/pricechart.js
+++ b/basicswap/static/js/pricechart.js
@@ -5,6 +5,7 @@ const config = {
     { symbol: 'BTC', usesCryptoCompare: true, usesCoinGecko: false, historicalDays: 30 },
     { symbol: 'XMR', usesCryptoCompare: true, usesCoinGecko: false, historicalDays: 30 },
     { symbol: 'PART', usesCryptoCompare: true, usesCoinGecko: false, historicalDays: 30 },
+    { symbol: 'BCH', usesCryptoCompare: true, usesCoinGecko: false, historicalDays: 30 },
     { symbol: 'PIVX', usesCryptoCompare: true, usesCoinGecko: false, historicalDays: 30 },
     { symbol: 'FIRO', usesCryptoCompare: true, usesCoinGecko: false, historicalDays: 30 },
     { symbol: 'DASH', usesCryptoCompare: true, usesCoinGecko: false, historicalDays: 30 },
@@ -13,8 +14,7 @@ const config = {
     { symbol: 'ETH', usesCryptoCompare: true, usesCoinGecko: false, historicalDays: 30 },
     { symbol: 'DCR', usesCryptoCompare: true, usesCoinGecko: false, historicalDays: 30 },
     { symbol: 'ZANO', usesCryptoCompare: true, usesCoinGecko: false, historicalDays: 30 },
-    { symbol: 'WOW', usesCryptoCompare: false, usesCoinGecko: true, historicalDays: 30 },
-    { symbol: 'BCH', usesCryptoCompare: true, usesCoinGecko: false, historicalDays: 30 }
+    { symbol: 'WOW', usesCryptoCompare: false, usesCoinGecko: true, historicalDays: 30 }
   ],
   apiEndpoints: {
     cryptoCompare: 'https://min-api.cryptocompare.com/data/pricemultifull',
@@ -1172,7 +1172,7 @@ const app = {
   
 sortTable: (columnIndex) => {
   console.log(`Sorting column: ${columnIndex}`);
-  const sortableColumns = [1, 5, 6, 7]; // 1: Time, 5: Rate, 6: Market +/-, 7: Trade
+  const sortableColumns = [0, 5, 6, 7]; // 0: Time, 5: Rate, 6: Market +/-, 7: Trade
   if (!sortableColumns.includes(columnIndex)) {
     console.log(`Column ${columnIndex} is not sortable`);
     return;
@@ -1200,7 +1200,7 @@ sortTable: (columnIndex) => {
       case 1: // Time column
         aValue = getSafeTextContent(a.querySelector('td:first-child .text-xs:first-child'));
         bValue = getSafeTextContent(b.querySelector('td:first-child .text-xs:first-child'));
-        // console.log(`Comparing times: "${aValue}" vs "${bValue}"`);
+        console.log(`Comparing times: "${aValue}" vs "${bValue}"`);
 
         const parseTime = (timeStr) => {
           const [value, unit] = timeStr.split(' ');
@@ -1263,9 +1263,9 @@ sortTable: (columnIndex) => {
   if (tbody) {
     rows.forEach(row => tbody.appendChild(row));
   } else {
-    // console.error("Table body not found.");
+    console.error("Table body not found.");
   }
-  // console.log('Sorting completed');
+  console.log('Sorting completed');
 },
   
   initializeSelectImages: () => {
diff --git a/basicswap/templates/offers.html b/basicswap/templates/offers.html
index 3fc4a73..0d24aeb 100644
--- a/basicswap/templates/offers.html
+++ b/basicswap/templates/offers.html
@@ -35,7 +35,7 @@ function getAPIKeys() {
       </div>
     </div>
   </section>
-{% else %}
+</div>
 {% endif %}
  
 {% if sent_offers %}
@@ -59,7 +59,6 @@ function getAPIKeys() {
       </div>
     </div>
   </section>
-</div> 
 
 {% include 'inc_messages.html' %}
 
@@ -153,12 +152,13 @@ function getAPIKeys() {
 
 <section class="py-4 flex flex-wrap justify-center overflow-hidden container-to-blur">
  <div class="container px-4 mx-auto">
-  <div class="flex flex-wrap justify-center -m-3">
-  {% set coin_data = {
+  <div class="flex flex-wrap justify-center -m-3" id="coin-container">
+{% set coin_data = {
     'BTC': {'name': 'Bitcoin', 'symbol': 'BTC', 'image': 'Bitcoin.png', 'show': true},
     'XMR': {'name': 'Monero', 'symbol': 'XMR', 'image': 'Monero.png', 'show': true},
     'PART': {'name': 'Particl', 'symbol': 'PART', 'image': 'Particl.png', 'show': true},
     'LTC': {'name': 'Litecoin', 'symbol': 'LTC', 'image': 'Litecoin.png', 'show': true},
+    'BCH': {'name': 'Bitcoin Cash', 'symbol': 'BCH', 'image': 'Bitcoin-Cash.png', 'show': true},
     'FIRO': {'name': 'Firo', 'symbol': 'FIRO', 'image': 'Firo.png', 'show': true},
     'PIVX': {'name': 'PIVX', 'symbol': 'PIVX', 'image': 'PIVX.png', 'show': true},
     'DASH': {'name': 'Dash', 'symbol': 'DASH', 'image': 'Dash.png', 'show': true},
@@ -166,47 +166,65 @@ function getAPIKeys() {
     'DOGE': {'name': 'Dogecoin', 'symbol': 'DOGE', 'image': 'Doge.png', 'show': false},
     'DCR': {'name': 'Decred', 'symbol': 'DCR', 'image': 'Decred.png', 'show': true},
     'ZANO': {'name': 'Zano', 'symbol': 'ZANO', 'image': 'Zano.png', 'show': false},
-    'BCH': {'name': 'BCH', 'symbol': 'BCH', 'image': 'Bitcoin-cash.png', 'show': true},
     'WOW': {'name': 'Wownero', 'symbol': 'WOW', 'image': 'Wownero.png', 'show': true}
     }
   %}
-{% for coin_symbol, coin in coin_data.items() if coin_symbol in enabled_chart_coins and coin.show %}
-<div class="w-full sm:w-1/2 lg:w-1/5 p-3" id="{{ coin_symbol.lower() }}-container">
-    <div class="px-5 py-3 h-full bg-coolGray-100 dark:bg-gray-500 rounded-2xl dark:text-white {% if coin_symbol == 'BTC' %}active-container{% endif %}" style="min-height: 180px;">
-     <div class="flex items-center">
-      <img src="/static/images/coins/{{ coin.image }}" class="rounded-xl" style="width: 28px; height: 28px; object-fit: contain;" alt="{{ coin.name }}">
-      <p class="ml-1 text-black text-sm dark:text-white">
-     {{ coin.name }} {% if coin.symbol != coin.name %}({{ coin.symbol }})
-      {% endif %}
-      </p>
-     </div>
-     <div class="flex flex-col justify-start relative">
-      <div id="{{ coin_symbol.lower() }}-loader" class="absolute inset-0 flex items-center justify-center bg-coolGray-100 dark:bg-gray-500 z-10 hidden">
-       <div class="w-16 h-1 bg-blue-500 rounded-full animate-pulse"></div>
-      </div>
-      <p class="my-2 text-xl font-bold text-left monospace text-gray-700 dark:text-gray-100" id="{{ coin_symbol.lower() }}-price-usd"> <span id="{{ coin_symbol.lower() }}-price-usd-value" {% if coin_symbol in ['DCR', 'ZANO', 'WOW'] %}style="min-width: 80px;" {% endif %}></span>
-      </p>
-      <div class="flex items-center text-sm">
-       <div class="w-auto">
-        <div id="{{ coin_symbol.lower() }}-price-change-container" class="w-auto p-1"></div>
-       </div>
-      </div>
-      {% if coin_symbol != 'BTC' %}
-      <div id="{{ coin_symbol.lower() }}-btc-price-div" class="flex items-center text-xs text-gray-600 dark:text-gray-300 mt-2 {% if coin_symbol == 'WOW' %}hidden{% endif %}">
-       <span class="bold mr-2">BTC:</span> <span id="{{ coin_symbol.lower() }}-price-btc"></span> </div> {% endif %} <div id="{{ coin_symbol.lower() }}-volume-div" class="flex items-center text-xs text-gray-600 dark:text-gray-300 mt-2">
-       <span class="bold mr-2">VOL:</span>
-       <div id="{{ coin_symbol.lower() }}-volume-24h"></div>
-      </div>
-     </div>
+  {% set custom_order = ['BTC', 'ETH', 'XMR', 'PART', 'LTC', 'BCH', 'FIRO', 'PIVX', 'DASH', 'DOGE', 'DCR', 'ZANO', 'WOW'] %}
+  
+  {% if enabled_chart_coins is string %}
+    {% if enabled_chart_coins == "" %}
+      {% set display_coins = coin_data.keys()|list %}
+    {% elif enabled_chart_coins == "all" %}
+      {% set display_coins = custom_order %}
+    {% else %}
+      {% set display_coins = enabled_chart_coins.split(',') %}
+    {% endif %}
+  {% else %}
+    {% set display_coins = enabled_chart_coins %}
+  {% endif %}
+
+  {% for coin_symbol in custom_order %}
+    {% if coin_symbol in display_coins and coin_data[coin_symbol]['show'] %}
+    <div class="w-full sm:w-1/2 lg:w-1/5 p-3" id="{{ coin_symbol.lower() }}-container">
+        <div class="px-5 py-3 h-full bg-coolGray-100 dark:bg-gray-500 rounded-2xl dark:text-white {% if coin_symbol == 'BTC' %}active-container{% endif %}" style="min-height: 180px;">
+         <div class="flex items-center">
+          <img src="/static/images/coins/{{ coin_data[coin_symbol]['image'] }}" class="rounded-xl" style="width: 28px; height: 28px; object-fit: contain;" alt="{{ coin_data[coin_symbol]['name'] }}">
+          <p class="ml-1 text-black text-sm dark:text-white">
+         {{ coin_data[coin_symbol]['name'] }} {% if coin_data[coin_symbol]['symbol'] != coin_data[coin_symbol]['name'] %}({{ coin_data[coin_symbol]['symbol'] }}){% endif %}
+          </p>
+         </div>
+         <div class="flex flex-col justify-start relative">
+          <div id="{{ coin_symbol.lower() }}-loader" class="absolute inset-0 flex items-center justify-center bg-coolGray-100 dark:bg-gray-500 z-10 hidden">
+           <div class="w-16 h-1 bg-blue-500 rounded-full animate-pulse"></div>
+          </div>
+          <p class="my-2 text-xl font-bold text-left monospace text-gray-700 dark:text-gray-100" id="{{ coin_symbol.lower() }}-price-usd"> <span id="{{ coin_symbol.lower() }}-price-usd-value" {% if coin_symbol in ['DCR', 'ZANO', 'WOW'] %}style="min-width: 80px;"{% endif %}></span>
+          </p>
+          <div class="flex items-center text-sm">
+           <div class="w-auto">
+            <div id="{{ coin_symbol.lower() }}-price-change-container" class="w-auto p-1"></div>
+           </div>
+          </div>
+          {% if coin_symbol != 'BTC' %}
+          <div id="{{ coin_symbol.lower() }}-btc-price-div" class="flex items-center text-xs text-gray-600 dark:text-gray-300 mt-2 {% if coin_symbol == 'WOW' %}hidden{% endif %}">
+           <span class="bold mr-2">BTC:</span> <span id="{{ coin_symbol.lower() }}-price-btc"></span>
+          </div>
+          {% endif %}
+          <div id="{{ coin_symbol.lower() }}-volume-div" class="flex items-center text-xs text-gray-600 dark:text-gray-300 mt-2">
+           <span class="bold mr-2">VOL:</span>
+           <div id="{{ coin_symbol.lower() }}-volume-24h"></div>
+          </div>
+         </div>
+        </div>
     </div>
-   </div>
-   {% endfor %}
-   </div>
+    {% endif %}
+  {% endfor %}
+  </div>
  </div>
 </section>
-{% endif %}
 
+{% endif %}
 <script src="/static/js/pricechart.js"></script>
+
 <section>
   <div class="pl-6 pr-6 pt-0 pb-0 mt-5 h-full overflow-hidden">
     <div class="border-coolGray-100">