From cb27fb6c4c524e50273bc833dffa8cade80dd132 Mon Sep 17 00:00:00 2001
From: tecnovert <tecnovert@tecnovert.net>
Date: Fri, 11 Dec 2020 14:08:32 +0200
Subject: [PATCH] Lower min locktime to 1 hour for easier testing.

Fix blocks confirmed count.
---
 basicswap/basicswap.py             | 6 ++++--
 basicswap/interface_btc.py         | 2 +-
 basicswap/templates/bid.html       | 1 -
 basicswap/templates/bid_xmr.html   | 7 ++++++-
 basicswap/templates/offer_new.html | 2 +-
 basicswap/ui.py                    | 4 ++--
 6 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/basicswap/basicswap.py b/basicswap/basicswap.py
index 9cccfd9..729174c 100644
--- a/basicswap/basicswap.py
+++ b/basicswap/basicswap.py
@@ -236,6 +236,8 @@ def strBidState(state):
         return 'Sent'
     if state == BidStates.BID_RECEIVING:
         return 'Receiving'
+    if state == BidStates.BID_RECEIVING_ACC:
+        return 'Receiving accept'
     if state == BidStates.BID_RECEIVED:
         return 'Received'
     if state == BidStates.BID_ACCEPTED:
@@ -2624,16 +2626,16 @@ class BasicSwap(BaseApp):
                     self.logBidEvent(bid, EventLogTypes.LOCK_TX_A_CONFIRMED, '', session)
                     bid.xmr_a_lock_tx.setState(TxStates.TX_CONFIRMED)
                     bid.setState(BidStates.XMR_SWAP_SCRIPT_COIN_LOCKED)
-                    self.saveBidInSession(bid_id, bid, session, xmr_swap)
+                    bid_changed = True
 
                     if bid.was_sent:
                         delay = random.randrange(self.min_delay_event, self.max_delay_event)
                         self.log.info('Sending xmr swap chain B lock tx for bid %s in %d seconds', bid_id.hex(), delay)
                         self.createEventInSession(delay, EventTypes.SEND_XMR_SWAP_LOCK_TX_B, bid_id, session)
                         # bid.setState(BidStates.SWAP_DELAYING)
-                    bid_changed = True
 
                 if bid_changed:
+                    self.saveBidInSession(bid_id, bid, session, xmr_swap)
                     session.commit()
 
             elif state == BidStates.XMR_SWAP_SCRIPT_COIN_LOCKED:
diff --git a/basicswap/interface_btc.py b/basicswap/interface_btc.py
index 5bbfeda..231c14c 100644
--- a/basicswap/interface_btc.py
+++ b/basicswap/interface_btc.py
@@ -824,7 +824,7 @@ class BTCInterface(CoinInterface):
                 continue
 
             rv.append({
-                'depth': 0 if 'height' not in utxo else chain_height - utxo['height'],
+                'depth': 0 if 'height' not in utxo else (chain_height - utxo['height']) + 1,
                 'height': 0 if 'height' not in utxo else utxo['height'],
                 'amount': utxo['amount'] * COIN,
                 'txid': utxo['txid'],
diff --git a/basicswap/templates/bid.html b/basicswap/templates/bid.html
index 7d1a775..b1a90ac 100644
--- a/basicswap/templates/bid.html
+++ b/basicswap/templates/bid.html
@@ -74,7 +74,6 @@
 </table>
 
 <p><a href="/">home</a></p>
-
 <script>
 function confirmPopup() {
     confirm("Are you sure?");
diff --git a/basicswap/templates/bid_xmr.html b/basicswap/templates/bid_xmr.html
index afa08dc..e361f38 100644
--- a/basicswap/templates/bid_xmr.html
+++ b/basicswap/templates/bid_xmr.html
@@ -48,7 +48,7 @@
 {% if data.was_received == 'True' %}
 <input name="accept_bid" type="submit" value="Accept Bid"><br/>
 {% endif %}
-<input name="abandon_bid" type="submit" value="Abandon Bid">
+<input name="abandon_bid" type="submit" value="Abandon Bid" onclick="confirmPopup()">
 {% if data.show_txns %}
 <input name="hide_txns" type="submit" value="Hide Info">
 {% else %}
@@ -77,4 +77,9 @@
 </table>
 
 <p><a href="/">home</a></p>
+<script>
+function confirmPopup() {
+    confirm("Are you sure?");
+}
+</script>
 </body></html>
diff --git a/basicswap/templates/offer_new.html b/basicswap/templates/offer_new.html
index ef98ccd..09dff2e 100644
--- a/basicswap/templates/offer_new.html
+++ b/basicswap/templates/offer_new.html
@@ -31,7 +31,7 @@
 </select>
 </td><td>Amount To</td><td><input type="text" name="amt_to"></td></tr>
 
-<tr><td>Contract locked (hrs)</td><td><input type="number" name="lockhrs" min="2" max="96" value="48"></td><td colspan=2>Participate txn will be locked for half the time.</td></tr>
+<tr><td>Contract locked (hrs)</td><td><input type="number" name="lockhrs" min="1" max="64" value="32"></td><td colspan=2>Participate txn will be locked for half the time.</td></tr>
 <tr><td>Auto Accept Bids</td><td colspan=3><input type="checkbox" name="autoaccept" value="aa" checked></td></tr>
 </table>
 
diff --git a/basicswap/ui.py b/basicswap/ui.py
index c9bbd38..ea72a34 100644
--- a/basicswap/ui.py
+++ b/basicswap/ui.py
@@ -154,14 +154,14 @@ def describeBid(swap_client, bid, offer, edit_bid, show_txns):
             if bid.xmr_a_lock_tx:
                 confirms = None
                 if swap_client.coin_clients[ci_from.coin_type()]['last_height'] and bid.xmr_a_lock_tx.chain_height:
-                    confirms = swap_client.coin_clients[ci_from.coin_type()]['last_height'] - bid.xmr_a_lock_tx.chain_height
+                    confirms = (swap_client.coin_clients[ci_from.coin_type()]['last_height'] - bid.xmr_a_lock_tx.chain_height) + 1
                 txns.append({'type': 'Chain A Lock', 'txid': bid.xmr_a_lock_tx.txid.hex(), 'confirms': confirms})
             if bid.xmr_a_lock_spend_tx:
                 txns.append({'type': 'Chain A Lock Spend', 'txid': bid.xmr_a_lock_spend_tx.txid.hex()})
             if bid.xmr_b_lock_tx:
                 confirms = None
                 if swap_client.coin_clients[ci_to.coin_type()]['last_height'] and bid.xmr_b_lock_tx.chain_height:
-                    confirms = swap_client.coin_clients[ci_to.coin_type()]['last_height'] - bid.xmr_b_lock_tx.chain_height
+                    confirms = (swap_client.coin_clients[ci_to.coin_type()]['last_height'] - bid.xmr_b_lock_tx.chain_height) + 1
                 txns.append({'type': 'Chain B Lock', 'txid': bid.xmr_b_lock_tx.txid.hex(), 'confirms': confirms})
             if bid.xmr_b_lock_tx and bid.xmr_b_lock_tx.spend_txid:
                 txns.append({'type': 'Chain B Lock Spend', 'txid': bid.xmr_b_lock_tx.spend_txid.hex()})