From bc05e2b7f256fc0227322e4fac6a270d6877c97c Mon Sep 17 00:00:00 2001 From: Michael Flaxman Date: Thu, 17 Sep 2015 17:02:45 -0700 Subject: [PATCH] working new rounding --- addresses/templatetags/btc_formats.py | 12 +----------- templates/address_overview.html | 10 +++++----- templates/balance_widget.html | 3 ++- templates/block_overview.html | 4 ++-- templates/received_widget.html | 2 +- transactions/models.py | 24 +++++++++++++++++++++--- 6 files changed, 32 insertions(+), 23 deletions(-) diff --git a/addresses/templatetags/btc_formats.py b/addresses/templatetags/btc_formats.py index dc8e6d24..abb837bc 100644 --- a/addresses/templatetags/btc_formats.py +++ b/addresses/templatetags/btc_formats.py @@ -1,6 +1,6 @@ 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 @@ -8,16 +8,6 @@ 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( diff --git a/templates/address_overview.html b/templates/address_overview.html index c710f95c..f6f84589 100644 --- a/templates/address_overview.html +++ b/templates/address_overview.html @@ -64,19 +64,19 @@

diff --git a/templates/received_widget.html b/templates/received_widget.html index 1a1c34e3..cd149c65 100644 --- a/templates/received_widget.html +++ b/templates/received_widget.html @@ -17,7 +17,7 @@ {{ b58_address }}

- {{ 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

diff --git a/transactions/models.py b/transactions/models.py index 574d2972..9a250a29 100644 --- a/transactions/models.py +++ b/transactions/models.py @@ -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 @@ -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,