def balance(self): wallet = faircoin_utils.is_connected() if wallet: is_wallet_address = faircoin_utils.is_mine(self.address) if is_wallet_address: try: balances = faircoin_utils.get_address_balance(self.address) unconfirmed_balance = Decimal(balances[1]) / FAIRCOIN_DIVISOR unconfirmed_balance += self.resource.balance_in_tx_state_new() confirmed_balance = Decimal(balances[0]) / FAIRCOIN_DIVISOR if unconfirmed_balance < 0: confirmed_balance += unconfirmed_balance elif unconfirmed_balance == 0: unconfirmed_balance = confirmed_balance return confirmed_balance except: pass return None
def manage_faircoin_account(request, resource_id): resource = get_object_or_404(EconomicResource, id=resource_id) user_agent = get_agent(request) if not user_agent or not (resource.owner() == user_agent or resource.owner() in user_agent.managed_projects()): raise Http404 send_coins_form = None is_wallet_address = None limit = 0 confirmed_balance = None unconfirmed_balance = None faircoin_account = False payment_due = False share_price = False number_of_shares = False can_pay = False candidate_membership = None wallet = faircoin_utils.is_connected() if wallet: is_wallet_address = faircoin_utils.is_mine( resource.faircoin_address.address) if is_wallet_address: send_coins_form = SendFairCoinsForm(agent=resource.owner()) try: balances = faircoin_utils.get_address_balance( resource.faircoin_address.address) unconfirmed_balance = Decimal(balances[1]) / FAIRCOIN_DIVISOR unconfirmed_balance += resource.balance_in_tx_state_new() confirmed_balance = Decimal(balances[0]) / FAIRCOIN_DIVISOR if unconfirmed_balance < 0: confirmed_balance += unconfirmed_balance elif unconfirmed_balance == 0: unconfirmed_balance = confirmed_balance except: confirmed_balance = "Not accessible now" unconfirmed_balance = "Not accessible now" else: #wallet = False if resource.is_address_requested(): is_wallet_address = True netfee = faircoin_utils.network_fee_fairs() project = jn_req = None pending_amount = 0 for req in resource.owner().project_join_requests.all(): #candidate_membership = resource.owner().candidate_membership(req.project.agent) if req.pending_shares() and req.project.agent.need_faircoins( ): #candidate_membership: obj = req.payment_option() faircoin_account = resource.owner().faircoin_resource() shacct = req.project.shares_account_type() if faircoin_account and wallet and obj and obj[ 'key'] == 'faircoin' and shacct: share = req.project.shares_type( ) #EconomicResourceType.objects.membership_share() #share_price = faircoin_utils.share_price_in_fairs(req) number_of_shares = req.pending_shares( ) #resource.owner().number_of_shares() share_price = Decimal(req.payment_pending_amount() ) #share_price * number_of_shares pending_amount = share_price project = req.project jn_req = req payment_due = True if resource.owner().owns_resource_of_type( shacct) and share_price == 0: payment_due = False if confirmed_balance and confirmed_balance != "Not accessible now": can_pay = round(confirmed_balance, 8) >= round( share_price, 8) if not can_pay: pending_amount = round(share_price - confirmed_balance, 8) break elif request.user.is_superuser and req.project.agent.need_faircoins( ): logger.warning("(debug) pro:" + str(req.project.agent) + " fair_account:" + str(faircoin_account) + " wallet:" + str(wallet) + " obj:" + str(obj) + " shares_account_type:" + str(shacct)) messages.warning( request, "(debug) pro:" + str(req.project.agent) + " fair_account:" + str(faircoin_account) + " wallet:" + str(wallet) + " obj:" + str(obj) + " shares_account_type:" + str(shacct)) return render( request, "faircoin/faircoin_account.html", { "resource": resource, "photo_size": (128, 128), "agent": resource.owner(), "wallet": wallet, "send_coins_form": send_coins_form, "is_wallet_address": is_wallet_address, "confirmed_balance": confirmed_balance, "unconfirmed_balance": unconfirmed_balance, "faircoin_account": faircoin_account, "candidate_membership": candidate_membership, "payment_due": payment_due, "share_price": round(share_price, 8), "pending_amount": round(pending_amount, 8), "number_of_shares": number_of_shares, "can_pay": can_pay, "project": project, "jn_req": jn_req, "help": get_help("faircoin account"), })
def is_mine(self): is_wallet_address = False if WALLET: is_wallet_address = faircoin_utils.is_mine(self.address) return is_wallet_address
def manage_faircoin_account(request, resource_id): resource = get_object_or_404(EconomicResource, id=resource_id) user_agent = get_agent(request) if not user_agent or not (resource.owner() == user_agent or resource.owner() in user_agent.managed_projects()): raise Http404 send_coins_form = None is_wallet_address = None limit = 0 confirmed_balance = None unconfirmed_balance = None faircoin_account = False payment_due = False share_price = False number_of_shares = False can_pay = False wallet = faircoin_utils.is_connected() if wallet: is_wallet_address = faircoin_utils.is_mine( resource.faircoin_address.address) if not is_wallet_address: if resource.is_address_requested(): is_wallet_address = True if is_wallet_address: send_coins_form = SendFairCoinsForm(agent=resource.owner()) try: balances = faircoin_utils.get_address_balance( resource.faircoin_address.address) confirmed_balance = Decimal(balances[0]) / FAIRCOIN_DIVISOR unconfirmed_balance = Decimal(balances[0] + balances[1]) / FAIRCOIN_DIVISOR unconfirmed_balance += resource.balance_in_tx_state_new() fee = Decimal(faircoin_utils.network_fee()) / FAIRCOIN_DIVISOR limit = min(confirmed_balance, unconfirmed_balance) - fee except: confirmed_balance = "Not accessible now" unconfirmed_balance = "Not accessible now" limit = Decimal("0.0") else: wallet = False candidate_membership = resource.owner().candidate_membership() if candidate_membership: faircoin_account = resource.owner().faircoin_resource() if faircoin_account and wallet: share = EconomicResourceType.objects.membership_share() share_price = share.price_per_unit number_of_shares = resource.owner().number_of_shares() share_price = share_price * number_of_shares payment_due = True if resource.owner().owns_resource_of_type(share): payment_due = False if confirmed_balance and confirmed_balance != "Not accessible now": can_pay = confirmed_balance >= share_price return render( request, "faircoin/faircoin_account.html", { "resource": resource, "photo_size": (128, 128), "agent": resource.owner(), "wallet": wallet, "send_coins_form": send_coins_form, "is_wallet_address": is_wallet_address, "confirmed_balance": confirmed_balance, "unconfirmed_balance": unconfirmed_balance, "limit": limit, "faircoin_account": faircoin_account, "candidate_membership": candidate_membership, "payment_due": payment_due, "share_price": share_price, "number_of_shares": number_of_shares, "can_pay": can_pay, "help": get_help("faircoin account"), })
def manage_faircoin_account(request, resource_id): resource = get_object_or_404(EconomicResource, id=resource_id) user_agent = get_agent(request) if not user_agent or not (resource.owner() == user_agent or resource.owner() in user_agent.managed_projects()): raise Http404 send_coins_form = None is_wallet_address = None limit = 0 confirmed_balance = None unconfirmed_balance = None faircoin_account = False payment_due = False share_price = False number_of_shares = False can_pay = False wallet = faircoin_utils.is_connected() if wallet: is_wallet_address = faircoin_utils.is_mine(resource.faircoin_address.address) if is_wallet_address: send_coins_form = SendFairCoinsForm(agent=resource.owner()) try: balances = faircoin_utils.get_address_balance(resource.faircoin_address.address) unconfirmed_balance = Decimal(balances[1]) / FAIRCOIN_DIVISOR unconfirmed_balance += resource.balance_in_tx_state_new() confirmed_balance = Decimal(balances[0]) / FAIRCOIN_DIVISOR if unconfirmed_balance < 0: confirmed_balance += unconfirmed_balance elif unconfirmed_balance == 0: unconfirmed_balance = confirmed_balance except: confirmed_balance = "Not accessible now" unconfirmed_balance = "Not accessible now" else: wallet = False if resource.is_address_requested(): is_wallet_address = True candidate_membership = resource.owner().candidate_membership() if candidate_membership: faircoin_account = resource.owner().faircoin_resource() if faircoin_account and wallet: share = EconomicResourceType.objects.membership_share() share_price = share.price_per_unit number_of_shares = resource.owner().number_of_shares() share_price = share_price * number_of_shares payment_due = True if resource.owner().owns_resource_of_type(share): payment_due = False if confirmed_balance and confirmed_balance != "Not accessible now": can_pay = confirmed_balance >= share_price return render(request, "faircoin/faircoin_account.html", { "resource": resource, "photo_size": (128, 128), "agent": resource.owner(), "wallet": wallet, "send_coins_form": send_coins_form, "is_wallet_address": is_wallet_address, "confirmed_balance": confirmed_balance, "unconfirmed_balance": unconfirmed_balance, "faircoin_account": faircoin_account, "candidate_membership": candidate_membership, "payment_due": payment_due, "share_price": share_price, "number_of_shares": number_of_shares, "can_pay": can_pay, "help": get_help("faircoin account"), })