Exemple #1
0
def display_add_scr(stdscr, wallet: Wallet):
    """
    Display the 'add coin' screen to the user and handles adding new coin

    :param wallet: Wallet object to which coins should be added
    :param y_base the first row to draw from
    :param x_base the first column to draw from
    """
    c = 0  # last character read
    option = 0
    
    while c != ESCAPE and c != ENTER:
        add_menu_header(stdscr)
        display_options_bar(stdscr, SUB_MENU_START[Y], SUB_MENU_START[X],
                            ["Add addresses to watch", "Add balance manually"], option, 'vertical')
        c, option = read_option(stdscr, option, 2, 'vertical')
    
    if c == ESCAPE:
        return
    
    last_line = SUB_MENU_START[Y]  # the last line we wrote to
    try:
        curses.echo()  # so the user sees what he types
        curses.curs_set(1)
        
        add_menu_header(stdscr)
        stdscr.addstr(last_line + 2, SUB_MENU_START[X],
                      "Enter coin code/symbol (e.g. BTC): ")
        last_line += 2
        coin_code = stdscr.getstr().decode("utf-8").upper()
        
        if option == 0:
            stdscr.addstr(last_line + 2, SUB_MENU_START[X],
                          "Enter addresses to watch (comma separated, e.g. addr1,addr2,addr3):")
            last_line += 2
            stdscr.move(last_line + 1, SUB_MENU_START[X])
            last_line += 1
            addresses = read_address_from_user(stdscr)
            wallet.add_addresses(coin_code, addresses)
        else:
            # manually add balance
            stdscr.addstr(last_line + 2, SUB_MENU_START[X], "Enter amount to add: ")
            last_line += 2
            amount = float(stdscr.getstr().decode("utf-8"))
            wallet.add_manual_balance(coin_code, amount)
        
        curses.curs_set(0)
        curses.noecho()
    except Exception:
        curses.curs_set(0)
        curses.noecho()
        return None