def get_current_balance(request, credential_id): credential = get_object_or_404(BaseCredential, id=credential_id) user = request.user merchant = user.get_merchant() assert credential.merchant == merchant, 'potential hacker alert!' satoshis = credential.get_balance() if satoshis is False: pass dict_response = { 'satoshis': satoshis, 'fswu': format_satoshis_with_units(satoshis), 'fswur': format_satoshis_with_units_rounded(satoshis), } return HttpResponse(json.dumps(dict_response), content_type='application/json')
def satoshis_formatted(self, instance): return format_satoshis_with_units(instance.satoshis)
def format_satoshis_amount(self): return format_satoshis_with_units(self.satoshis)
def get_btc_transactions_total_formatted(self): return format_satoshis_with_units( self.get_satoshis_transactions_total())
def get_txn_group_payload(self): """ Get forwarding transactions and summary data for returning to AJAX call Handle edge case of multiple transactions coming through """ txn_list = [] all_confirmed = True # loop through forwarding txns for fwd_txn in self.get_all_forwarding_transactions(): is_confirmed = fwd_txn.is_confirmed() txn_dict = { 'satoshis': fwd_txn.satoshis, 'satoshis_fwu': format_satoshis_with_units(fwd_txn.satoshis), 'txn_hash': fwd_txn.txn_hash, 'is_confirmed': is_confirmed, 'confirmed_by': fwd_txn.txn_confirmed_by(), 'bc_pref': fwd_txn.blockcypher_preference, 'conf_num': fwd_txn.conf_num, 'fiat_amount': fwd_txn.fiat_amount, 'currency_code': fwd_txn.currency_code_when_created, 'confs_needed': fwd_txn.get_confs_needed(), 'fiat_amount_formatted': fwd_txn.get_fiat_amount_formatted(), 'fiat_amount': fwd_txn.fiat_amount, # DISGUSTING HACK: 'conf_str': unicode(fwd_txn.get_status()), 'conf_delay_str': unicode(fwd_txn.get_conf_delay_str()), } txn_list.append(txn_dict) if not is_confirmed: all_confirmed = False total_satoshis = sum([x['satoshis'] for x in txn_list]) if len(txn_list) == 0: conf_str = '' conf_delay_str = '' confs_needed = self.merchant.minimum_confirmations total_fiat_amount_formatted = '' confirmed_by = '' elif len(txn_list) == 1: conf_str = txn_list[0]['conf_str'] conf_delay_str = txn_list[0]['conf_delay_str'] confs_needed = txn_list[0]['confs_needed'] total_fiat_amount_formatted = txn_list[0]['fiat_amount_formatted'] confirmed_by = txn_list[0]['confirmed_by'] else: confs_needed = self.merchant.minimum_confirmations if all_confirmed: conf_str = _('Confirmed (Multiple Transactions Detected)') confirmed_by = 'CoinSafe' else: conf_str = _('Not Confirmed (Multiple Transactions Detected)') confirmed_by = '' conf_delay_str = _( '10-20 Minutes (Multiple Transactions Detected)') total_fiat_amount = [x['fiat_amount'] for x in txn_list] total_fiat_amount_formatted = format_fiat_amount( fiat_amount=total_fiat_amount, currency_code=txn_list[0]['currency_code']) return { 'txn_list': txn_list, 'txn_list_cnt': len(txn_list), 'total_satoshis': total_satoshis, 'total_sfwu': format_satoshis_with_units(total_satoshis), 'conf_str': conf_str, 'conf_delay_str': conf_delay_str, 'all_confirmed': all_confirmed, 'confs_needed': confs_needed, 'total_fiat_amount_formatted': total_fiat_amount_formatted, 'all_txns_confirmed_by': confirmed_by, }
def get_max_mbtc_purchase_formatted(self): return format_satoshis_with_units( mbtc_to_satoshis(self.max_mbtc_shopper_purchase))