Skip to content

Commit

Permalink
Minor fixes for BTC wallet and GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
devos50 committed Mar 15, 2018
1 parent 1610407 commit 1c92591
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Tribler/Core/Modules/restapi/wallets_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def render_POST(self, request):
.. sourcecode:: none
curl -X GET http://localhost:8085/wallets/BTC/transfer
curl -X POST http://localhost:8085/wallets/BTC/transfer
--data "amount=0.3&destination=mpC1DDgSP4PKc5HxJzQ5w9q6CGLBEQuLsN"
**Example response**:
Expand Down
4 changes: 2 additions & 2 deletions Tribler/community/market/community.py
Original file line number Diff line number Diff line change
Expand Up @@ -1033,10 +1033,10 @@ def received_proposed_trade(self, _, data):
declined_trade = Trade.decline(self.message_repository.next_identity(),
Timestamp.now(), proposed_trade, decline_reason)
self.logger.debug("Declined trade made with id: %s for proposed trade with id: %s "
"(valid? %s, available quantity of order: %s, reserved: %s, traded: %s)",
"(valid? %s, available quantity of order: %s, reserved: %s, traded: %s), reason: %s",
str(declined_trade.message_id), str(proposed_trade.message_id),
order.is_valid(), order.available_quantity, order.reserved_quantity,
order.traded_quantity)
order.traded_quantity, decline_reason)
self.send_declined_trade(declined_trade)
else:
self.logger.debug("Proposed trade received with id: %s for order with id: %s",
Expand Down
8 changes: 7 additions & 1 deletion Tribler/community/market/core/trade.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,13 @@ def has_acceptable_price(self, is_ask, order_price):
Return whether this trade proposal has an acceptable price.
:rtype: bool
"""
return (is_ask and self.price >= order_price) or (not is_ask and self.price <= order_price)
def isclose(price_a, price_b):
price_a = float(price_a)
price_b = float(price_b)
return abs(price_a - price_b) <= 1e-06

return (is_ask and (self.price >= order_price or isclose(self.price, order_price))) or \
(not is_ask and (self.price <= order_price or isclose(self.price, order_price)))

def to_network(self):
"""
Expand Down
27 changes: 17 additions & 10 deletions Tribler/community/market/wallet/btc_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,23 @@ def get_balance(self):
"""
Return the balance of the wallet.
"""
divider = 100000000
if self.created:
confirmed, unconfirmed, unmatured = self.wallet.get_balance()
options = {'nolnet': False, 'password': None, 'verbose': False, 'cmd': 'getbalance',
'wallet_path': self.wallet_file, 'testnet': self.testnet, 'segwit': False,
'cwd': self.wallet_dir,
'portable': False}
config = SimpleConfig(options)

server = self.get_daemon().get_server(config)
result = server.run_cmdline(options)

confirmed = float(result['confirmed'])
unconfirmed = float(result['unconfirmed']) if 'unconfirmed' in result else 0
unconfirmed += (float(result['unmatured']) if 'unmatured' in result else 0)

return succeed({
"available": float(confirmed) / divider,
"pending": float(unconfirmed + unmatured) / divider,
"available": confirmed,
"pending": unconfirmed,
"currency": 'BTC'
})
else:
Expand Down Expand Up @@ -231,12 +242,8 @@ def get_transactions(self):
transactions = []
for transaction in result:
outgoing = transaction['value'] < 0
if outgoing:
from_address = self.get_address()
to_address = ''
else:
from_address = ''
to_address = self.get_address()
from_address = ','.join(transaction['input_addresses'])
to_address = ','.join(transaction['output_addresses'])

transactions.append({
'id': transaction['txid'],
Expand Down
13 changes: 8 additions & 5 deletions TriblerGUI/qt_resources/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>875</width>
<height>768</height>
<height>777</height>
</rect>
</property>
<property name="sizePolicy">
Expand Down Expand Up @@ -7982,8 +7982,8 @@ QTabBar::tab:selected {
<rect>
<x>0</x>
<y>0</y>
<width>673</width>
<height>341</height>
<width>131</width>
<height>260</height>
</rect>
</property>
<layout class="QFormLayout" name="formLayout_4">
Expand Down Expand Up @@ -11196,7 +11196,7 @@ QTabBar::tab:selected {
}</string>
</property>
<property name="currentIndex">
<number>0</number>
<number>1</number>
</property>
<widget class="QWidget" name="tab_4">
<attribute name="title">
Expand Down Expand Up @@ -11273,8 +11273,11 @@ QTabBar::tab:selected {
</property>
<item>
<widget class="QTreeWidget" name="wallet_transactions_list">
<property name="selectionMode">
<enum>QAbstractItemView::NoSelection</enum>
</property>
<property name="indentation">
<number>8</number>
<number>0</number>
</property>
<column>
<property name="text">
Expand Down
2 changes: 1 addition & 1 deletion TriblerGUI/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def timestamp_to_time(timestamp):

diff = today - discovered
if diff.days > 0 or today.day != discovered.day:
return discovered.strftime('%d-%m-%Y')
return discovered.strftime('%d-%m-%Y %H:%M')
return discovered.strftime('Today %H:%M')


Expand Down
1 change: 1 addition & 0 deletions TriblerGUI/widgets/marketpage.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ def on_bid(self, bid):

def on_transaction_complete(self, transaction):
if transaction["mine"]:
transaction = transaction["tx"]
main_text = "Transaction with price %f %s and quantity %f %s completed." \
% (transaction["price"], transaction["price_type"],
transaction["quantity"], transaction["quantity_type"])
Expand Down
5 changes: 3 additions & 2 deletions TriblerGUI/widgets/marketwalletspage.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from TriblerGUI.dialogs.confirmationdialog import ConfirmationDialog
from TriblerGUI.tribler_action_menu import TriblerActionMenu
from TriblerGUI.tribler_request_manager import TriblerRequestManager
from TriblerGUI.utilities import get_image_path
from TriblerGUI.utilities import get_image_path, timestamp_to_time


class MarketWalletsPage(QWidget):
Expand Down Expand Up @@ -139,7 +139,8 @@ def on_transactions(self, transactions):
item.setText(3, "%g %s" % (transaction["amount"], transaction["currency"]))
item.setText(4, "%g %s" % (transaction["fee_amount"], transaction["currency"]))
item.setText(5, transaction["id"])
item.setText(6, transaction["timestamp"])
timestamp = timestamp_to_time(float(transaction["timestamp"])) if transaction["timestamp"] != "False" else "-"
item.setText(6, timestamp)
self.window().wallet_transactions_list.addTopLevelItem(item)

def on_add_wallet_clicked(self):
Expand Down

0 comments on commit 1c92591

Please sign in to comment.