diff --git a/wowstash/blueprints/wallet/routes.py b/wowstash/blueprints/wallet/routes.py index c2593e2..e23912c 100644 --- a/wowstash/blueprints/wallet/routes.py +++ b/wowstash/blueprints/wallet/routes.py @@ -9,13 +9,21 @@ from wowstash.models import User @wallet_bp.route("/wallet/dashboard") @login_required def dashboard(): + all_transfers = list() user = User.query.get(current_user.id) wallet_height = wallet.height()['height'] daemon_height = daemon.height()['height'] - subaddress = wallet.get_address(0, user.subaddress_index)['addresses'][0]['address'] + subaddress = wallet.get_address(0, user.subaddress_index) + balances = wallet.get_balance(0, user.subaddress_index) + transfers = wallet.get_transfers(0, user.subaddress_index) + for type in transfers: + for tx in transfers[type]: + all_transfers.append(tx) return render_template( "wallet/dashboard.html", wallet_height=wallet_height, - daemon=daemon_height, - subaddress=subaddress + daemon_height=daemon_height, + subaddress=subaddress, + balances=balances, + all_transfers=all_transfers ) diff --git a/wowstash/factory.py b/wowstash/factory.py index f4ea17f..9de6276 100644 --- a/wowstash/factory.py +++ b/wowstash/factory.py @@ -4,6 +4,7 @@ from flask_session import Session from flask_bcrypt import Bcrypt from flask_login import LoginManager from redis import Redis +from datetime import datetime from wowstash import config @@ -61,6 +62,12 @@ def create_app(): from wowstash.models import User return User.query.get(user_id) + # template filters + @app.template_filter('datestamp') + def datestamp(s): + d = datetime.fromtimestamp(s) + return d.strftime('%Y-%m-%d %H:%M:%S') + # Routes from wowstash.blueprints.auth import auth_bp from wowstash.blueprints.wallet import wallet_bp diff --git a/wowstash/library/jsonrpc.py b/wowstash/library/jsonrpc.py index d2b1a17..2fc0957 100644 --- a/wowstash/library/jsonrpc.py +++ b/wowstash/library/jsonrpc.py @@ -1,9 +1,12 @@ import json import requests -import operator +from six import integer_types +from decimal import Decimal from wowstash import config +PICOWOW = Decimal('0.00000000001') + class JSONRPC(object): def __init__(self, proto, host, port, username='', password=''): self.endpoint = '{}://{}:{}/'.format( @@ -53,7 +56,27 @@ class Wallet(JSONRPC): def get_address(self, account_index, subaddress_index): data = {'account_index': account_index, 'address_index': [subaddress_index]} - return self.make_rpc('get_address', data) + subaddress = self.make_rpc('get_address', data)['addresses'][0]['address'] + return subaddress + + def get_balance(self, account_index, subaddress_index): + data = {'account_index': account_index, 'address_indices': [subaddress_index]} + _balance = self.make_rpc('get_balance', data) + locked = from_atomic(_balance['per_subaddress'][0]['balance']) + unlocked = from_atomic(_balance['per_subaddress'][0]['unlocked_balance']) + return (float(locked), float(unlocked)) + + def get_transfers(self, account_index, subaddress_index): + data = { + 'account_index': account_index, + 'subaddr_indices': [subaddress_index], + 'in': True, + 'out': True, + 'pending': True, + 'failed': True, + 'pool': True + } + return self.make_rpc('get_transfers', data) class Daemon(JSONRPC): @@ -67,6 +90,19 @@ class Daemon(JSONRPC): return self.make_rpc('get_height', {}, json_rpc=False) +def to_atomic(amount): + if not isinstance(amount, (Decimal, float) + integer_types): + raise ValueError("Amount '{}' doesn't have numeric type. Only Decimal, int, long and " + "float (not recommended) are accepted as amounts.") + return int(amount * 10**11) + +def from_atomic(amount): + return (Decimal(amount) * PICOWOW).quantize(PICOWOW) + +def as_wownero(amount): + return Decimal(amount).quantize(PICOWOW) + + daemon = Daemon( proto=config.DAEMON_PROTO, host=config.DAEMON_HOST, diff --git a/wowstash/static/css/new-age.css b/wowstash/static/css/main.css similarity index 98% rename from wowstash/static/css/new-age.css rename to wowstash/static/css/main.css index be854eb..04b6785 100644 --- a/wowstash/static/css/new-age.css +++ b/wowstash/static/css/main.css @@ -501,3 +501,16 @@ footer ul li a:hover, footer ul li a:focus, footer ul li a:active, footer ul li header.masthead .header-content-lg { max-width: 70%; } + +@media (min-width: 992px) { + .tx-table { + display: inline-table; + margin: 0 auto + } +} + +.slim { + width: 75%; + line-break: anywhere; + margin: auto; +} diff --git a/wowstash/static/js/new-age.js b/wowstash/static/js/main.js similarity index 100% rename from wowstash/static/js/new-age.js rename to wowstash/static/js/main.js diff --git a/wowstash/templates/auth/register.html b/wowstash/templates/auth/register.html index 0d738f7..a91470c 100644 --- a/wowstash/templates/auth/register.html +++ b/wowstash/templates/auth/register.html @@ -58,46 +58,6 @@ - - {% include 'footer.html' %} {% include 'scripts.html' %} diff --git a/wowstash/templates/footer.html b/wowstash/templates/footer.html index 4911616..b4f69f2 100644 --- a/wowstash/templates/footer.html +++ b/wowstash/templates/footer.html @@ -3,13 +3,13 @@
© {{ config.SITE_NAME }} 2020. All Rights Reserved.
diff --git a/wowstash/templates/head.html b/wowstash/templates/head.html index cd365da..4ed6c31 100644 --- a/wowstash/templates/head.html +++ b/wowstash/templates/head.html @@ -5,7 +5,7 @@ - +Address: {{ subaddress }}
+Balance: {{ balances.1 }} WOW (locked {{ balances.0 }} WOW)
+Height ({{ wallet_height }} / {{ daemon_height }})
+Your address: {{ subaddress }}
-