Exemplo n.º 1
0
def manage_coin(stdscr, coin: str, wallet: Wallet):
    """
    Display a manage screen for a specific coin

    :param coin: the coin to manage
    :param wallet: wallet object
    """
    c = 0
    option = 0
    tracked_coin = wallet.get_coin_info(coin)
    addresses_list = list(tracked_coin.addresses)
    balances = lookup_addresses(coin, addresses_list)
    manual_balance = tracked_coin.manual_balance
    base_x = SUB_MENU_START[X]
    base_y = SUB_MENU_START[Y]
    
    while True:
        should_render = True
        while c != ENTER and c != ESCAPE:
            if should_render:
                main_header(stdscr)
                stdscr.addstr(base_y, base_x, coin + " in wallet:")
                if balances is None:
                    balances = [-1] * len(addresses_list)
                display_addresses_list(stdscr, addresses_list, balances, base_y + 2, base_x)
                y = base_y + 2 + len(addresses_list) + 2  # the next line to write to
                if manual_balance != 0:
                    stdscr.addstr(y, base_x, "Manual balance: " + ('%.8f' % manual_balance))
                    y += 2
                display_options_bar(stdscr, y, base_x, MANAGE_COIN_OPTIONS,
                                    highlight=option, layout='horizontal')
                should_render = False
            
            c, new_option = read_option(stdscr, option, len(MANAGE_COIN_OPTIONS), 'horizontal')
            if new_option != option:
                option = new_option
                should_render = True
        
        if c == ESCAPE or option == RETURN:
            return
        
        if option == REMOVE_ADDRESSES:
            remove_addresses_scr(stdscr, coin, addresses_list, balances, wallet)
            # addresses may have changed. get updated info
            tracked_coin = wallet.get_coin_info(coin)
            balances = lookup_addresses(coin, list(tracked_coin.addresses))
        elif option == REMOVE_MANUAL_BALANCE:
            wallet.remove_manual_balance(coin)
            manual_balance = 0
        elif option == DELETE_COIN:
            wallet.remove_coin(coin)
            return
        c = 0
Exemplo n.º 2
0
 def test_ltc_lookup_single(self):
     addresses = [
         "LgYj5bghguAf4kdSh8erb3bTnjpuZtYUti",  # balance 0.05587024
     ]
     expected_balances = [0.05587024]
     balances = lookup_addresses(coin="LTC", addresses=addresses)
     self.assertListEqual(balances, expected_balances)
Exemplo n.º 3
0
 def test_btc_lookup_single(self):
     addresses = [
         "1FDMwEo8qNa9icVcooBUoGvA6NriePtJJ3",  # balance 50
     ]
     expected_balances = [50]
     balances = lookup_addresses(coin="BTC", addresses=addresses)
     self.assertListEqual(balances, expected_balances)
Exemplo n.º 4
0
 def test_eth_lookup_single(self):
     addresses = [
         "0x2C3C1dF3c25FE3875cE559FC68c6E9068bD952ED",  # balance 0.000518161526620852
     ]
     expected_balances = [0.000518161526620852]
     balances = lookup_addresses(coin="ETH", addresses=addresses)
     self.assertListEqual(balances, expected_balances)
Exemplo n.º 5
0
 def test_ltc_lookup_multiple(self):
     addresses = [
         "LgYj5bghguAf4kdSh8erb3bTnjpuZtYUti",  # balance 0.05587024
         "LhKxXU6QtxoGNxeU9uUTrLjA1X5wPtbiep",  # balance 0.00000960
     ]
     expected_balances = [0.05587024, 0.00000960]
     balances = lookup_addresses(coin="LTC", addresses=addresses)
     self.assertListEqual(balances, expected_balances)
Exemplo n.º 6
0
 def test_bch_lookup_multiple(self):
     addresses = [
         "15NUwyBYrZcnUgTagsm1A7M2yL2GntpuaZ",  # balance 0
         "1FDMwEo8qNa9icVcooBUoGvA6NriePtJJ3",  # balance 50
     ]
     expected_balances = [0, 50]
     balances = lookup_addresses(coin="BCH", addresses=addresses)
     self.assertListEqual(balances, expected_balances)
Exemplo n.º 7
0
 def test_eth_lookup_multiple(self):
     addresses = [
         "0xDf190dC7190dfba737d7777a163445b7Fff16133",  # balance 0
         "0x2C3C1dF3c25FE3875cE559FC68c6E9068bD952ED",  # balance 0.000518161526620852
         "0xGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG",  # invalid address format
     ]
     expected_balances = [0, 0.000518161526620852, NOT_FOUND]
     balances = lookup_addresses(coin="ETH", addresses=addresses)
     self.assertListEqual(balances, expected_balances)
Exemplo n.º 8
0
 def test_btc_lookup_multiple(self):
     # both addresses were last used in 2009. probably wouldn't change.
     # worst case, test will fail and we'll figure it out
     addresses = [
         "15NUwyBYrZcnUgTagsm1A7M2yL2GntpuaZ",  # balance 0
         "1FDMwEo8qNa9icVcooBUoGvA6NriePtJJ3",  # balance 50
     ]
     expected_balances = [0, 50]
     balances = lookup_addresses(coin="BTC", addresses=addresses)
     self.assertListEqual(balances, expected_balances)
Exemplo n.º 9
0
    def get_balances(self):
        """
        :return: List of lists. each inner list has the following elements:
                      [coin_code, amount, value_in_usd, value_in_btc]
                 coins for which finding the value was failed, the values will be 'N/A'
        """
        res = []
        coin_symbols_list = list(self.wallet.keys())
        coins_values = lookup_value(coin_symbols_list)
        for coin_idx, coin_code in enumerate(coin_symbols_list):
            addresses_amounts = lookup_addresses(
                coin_code, list(self.wallet[coin_code].addresses))
            total_coin_amount = 0
            if addresses_amounts is not None:
                # addresses whose balance was failed to retrieve is -1. sum everything except
                # failures
                for addr_amount in addresses_amounts:
                    if addr_amount > 0:
                        total_coin_amount += addr_amount

            total_coin_amount += self.wallet[coin_code].manual_balance
            total_coin_amount = round(
                total_coin_amount,
                8)  # truncate to maximum 8 digits after decimal point

            if coins_values[coin_idx] is None:
                value_usd = 'N/A'
                value_btc = 'N/A'
            else:
                value_usd = round(
                    (total_coin_amount * coins_values[coin_idx][0]), 3)
                value_btc = round(
                    (total_coin_amount * coins_values[coin_idx][1]), 8)

            res.append([coin_code, total_coin_amount, value_usd, value_btc])

        return res