Skip to content

Commit

Permalink
working new rounding
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Flaxman committed Sep 18, 2015
1 parent ae4b5fe commit bc05e2b
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 23 deletions.
12 changes: 1 addition & 11 deletions addresses/templatetags/btc_formats.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
from django import template

from blockcypher.utils import satoshis_to_btc, satoshis_to_btc_rounded, format_crypto_units
from blockcypher.utils import format_crypto_units
from blockcypher.api import _get_websocket_url
from blockcypher.constants import COIN_SYMBOL_MAPPINGS


register = template.Library()


@register.filter(name='satoshis_to_btc_rounding')
def satoshis_to_btc_rounding(satoshis):
return satoshis_to_btc_rounded(satoshis=satoshis, decimals=4)


@register.filter(name='satoshis_to_btc_full')
def satoshis_to_btc_full(satoshis):
return satoshis_to_btc(satoshis=satoshis)


@register.simple_tag(name='satoshis_to_user_units_trimmed')
def satoshis_to_user_units_trimmed(input_satoshis, user_unit='btc', coin_symbol='btc', print_cs=True, round_digits=0):
return format_crypto_units(
Expand Down
10 changes: 5 additions & 5 deletions templates/address_overview.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,19 @@ <h4 class="tagline wrapit semi">
<ul>
<li>
<span class="dash-label">Received</span><br>
{% satoshis_to_user_units_trimmed total_received_satoshis tcp__user_units coin_symbol %}
{% satoshis_to_user_units_trimmed total_received_satoshis tcp__user_units coin_symbol True 4 %}
</li>
<li>
<span class="dash-label">Sent</span><br>
{% satoshis_to_user_units_trimmed total_sent_satoshis tcp__user_units coin_symbol %}
{% satoshis_to_user_units_trimmed total_sent_satoshis tcp__user_units coin_symbol True 4 %}
</li>
<li>
<span class="dash-label">Balance</span><br>
{% satoshis_to_user_units_trimmed total_balance_satoshis tcp__user_units coin_symbol %}
{% satoshis_to_user_units_trimmed total_balance_satoshis tcp__user_units coin_symbol True 4 %}
{% if unconfirmed_balance_satoshis %}
<br>
<span class="dash-label">
({% satoshis_to_user_units_trimmed unconfirmed_balance_satoshis tcp__user_units coin_symbol %} unconfirmed)
({% satoshis_to_user_units_trimmed unconfirmed_balance_satoshis tcp__user_units coin_symbol True %} unconfirmed)
</span>
{% endif %}
</li>
Expand Down Expand Up @@ -214,7 +214,7 @@ <h2>
</td>
<td>
{% if transaction.tx_input_n >= 0 %}-{% else %}+{% endif %}
{% satoshis_to_user_units_trimmed transaction.value tcp__user_units coin_symbol %}
{% satoshis_to_user_units_trimmed transaction.value tcp__user_units coin_symbol True 0 %}
</td>
<td>
{% if transaction.confirmations >= 6 %}
Expand Down
3 changes: 2 additions & 1 deletion templates/balance_widget.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@

</head>
<body>

<a target="_blank" href="{{ BASE_URL }}{% url 'address_overview' coin_symbol b58_address %}" class="btn btn-default">

<i class="fa fa-qrcode"></i>
{{ b58_address }}

<h4>
{{ address_overview.final_balance|satoshis_to_btc_rounding }} {{ coin_symbol|coin_symbol_to_currency_name }}
{% satoshis_to_user_units_trimmed address_overview.final_balance 'btc' coin_symbol True 0 %}
</h4>

<i>
Expand Down
4 changes: 2 additions & 2 deletions templates/block_overview.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ <h2 class="tagline wrapit semi">{{ block_details.hash }}</h2>
</li>
<li>
<span class="dash-label">Total Transacted</span><br>
{% satoshis_to_user_units_trimmed block_details.total tcp__user_units coin_symbol %}
{% satoshis_to_user_units_trimmed block_details.total tcp__user_units coin_symbol True 4 %}
</li>
<li>
<span class="dash-label">Total Fees</span><br>
{% satoshis_to_user_units_trimmed block_details.fees tcp__user_units coin_symbol %}
{% satoshis_to_user_units_trimmed block_details.fees tcp__user_units coin_symbol True 4 %}
</li>
</ul>
<div class="clearfix"></div>
Expand Down
2 changes: 1 addition & 1 deletion templates/received_widget.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
{{ b58_address }}

<h4>
{{ address_overview.total_received|satoshis_to_btc_rounding }} {{ coin_symbol|coin_symbol_to_currency_name }}
{% satoshis_to_user_units_trimmed address_overview.total_received 'btc' coin_symbol True 0 %}
Received
</h4>

Expand Down
24 changes: 21 additions & 3 deletions transactions/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.db import models

from blockcypher.utils import satoshis_to_btc_rounded
from blockcypher.utils import format_crypto_units

from emails.trigger import send_and_log

Expand Down Expand Up @@ -28,11 +28,29 @@ def send_double_spend_tx_notification(self):

def send_unconfirmed_tx_email(self):
b58_address = self.address_subscription.b58_address
sent_in_btc = format_crypto_units(
input_quantity=self.satoshis_sent,
input_type='satoshi',
output_type='btc',
coin_symbol=self.address_subscription.coin_symbol,
print_cs=False,
safe_trimming=False,
round_digits=4,
)
fee_in_btc = format_crypto_units(
input_quantity=self.fee_in_satoshis,
input_type='satoshi',
output_type='btc',
coin_symbol=self.address_subscription.coin_symbol,
print_cs=False,
safe_trimming=False,
round_digits=4,
)
context_dict = {
'b58_address': b58_address,
'coin_symbol': self.address_subscription.coin_symbol,
'sent_in_btc': satoshis_to_btc_rounded(self.satoshis_sent),
'fee_in_btc': satoshis_to_btc_rounded(self.fee_in_satoshis),
'sent_in_btc': sent_in_btc,
'fee_in_btc': fee_in_btc,
'currency_display_name': self.address_subscription.get_currency_display_name(),
'currency_abbrev': self.address_subscription.get_currency_abbrev(),
'tx_hash': self.tx_hash,
Expand Down

0 comments on commit bc05e2b

Please sign in to comment.