예제 #1
0
def await_amount_to(cli, m):
    tg_id = m.from_user.id
    wallet = cache.get_active_wallet(tg_id)
    delete_inline_kb(cli, tg_id, cache.read_user_cache(tg_id, "last_msg_id"))
    fee = cache.get_fee()
    try:
        amount = int(m.text)
        if amount + fee > wallet["balance"]:
            raise Exception
    except:
        m.reply("Invalid amount")
        new_msg(cli, m, tg_id,
                "Invalid amount",
                kb.back_wallet(tg_id),
                "wallet_menu_id",
                "wallet_menu_id",
                "on_message")
        return
    cache.change_user_flag(tg_id, "await_to_amount", False)

    new_msg(cli, m, tg_id,
            texts.confirm_transaction(cache.read_user_cache(tg_id, "address_to"), amount),
            kb.confirm_tx(tg_id, amount),
            "wallet_menu_id",
            "wallet_menu_id",
            "on_message")
예제 #2
0
def wallet_menu(cli, cb):
    tg_id = cb.from_user.id
    btn = cb.data.split("-")[1]
    wallet = cache.get_active_wallet(tg_id)
    if btn == "send":

        if wallet["balance"] > 1:
            cache.change_user_flag(tg_id, "await_to_address", True)

            new_msg(cli, cb, tg_id, "Send me an address to send UAX:", kb.back_wallet(), "wallet_menu_id", "wallet_menu_id",
                    "on_callback")
        else:
            new_msg(cli, cb, tg_id, "Insufficient funds", kb.back_wallet(), "wallet_menu_id",
                    "wallet_menu_id",
                    "on_callback")

    elif btn == "recive":
        new_msg(cli, cb, tg_id,
                wallet["address"],
                kb.back_wallet(),
                "wallet_menu_id",
                "wallet_menu_id",
                "on_callback")

    elif btn == "settings":
        new_msg(cli, cb, tg_id,
                texts.wallet_settings(tg_id),
                kb.settings(tg_id),
                "wallet_menu_id",
                "wallet_menu_id",
                "on_callback")
예제 #3
0
def send_max(cli, cb):
    tg_id = cb.from_user.id
    wallet = cache.get_active_wallet(tg_id)
    fee = cache.get_fee()
    amount = wallet["balance"] - fee
    cache.change_user_flag(tg_id, "await_to_amount", False)
    new_msg(cli, cb, tg_id,
            texts.confirm_transaction(cache.read_user_cache(tg_id, "address_to"), amount),
            kb.confirm_tx(tg_id, amount),
            "wallet_menu_id",
            "wallet_menu_id",
            "on_callback")
예제 #4
0
def wallet_title(cli, m):
    tg_id = m.from_user.id
    title = m.text
    cache.change_user_flag(tg_id, "await_wallet_title", False)
    wallet_id = cache.read_user_cache(tg_id, "last_wallet_id")
    WalletAPI.edit_title(wallet_id, title)

    new_msg(cli, m, tg_id,
            texts.settings_wallet(tg_id, wallet_id),
            kb.settings_wallet(tg_id, wallet_id),
            "wallet_menu_id",
            "wallet_menu_id",
            "on_message")
예제 #5
0
def new_wallet(cli, cb):
    tg_id = cb.from_user.id
    cache.change_user_flag(tg_id, "create_wallet", True)

    cb.message.edit(cb.message.text)
    try:
        cli.answer_callback_query(cb.id, "Wait a moment. I'm creating a wallet for you.", show_alert=True)
    except:
        cb.message.reply("Wait a moment. I'm creating a wallet for you.")
        
    wallet = WalletAPI.create_wallet(tg_id)

    cb.message.reply("Welcome to UAX Wallet", reply_markup=kb.reply(tg_id))
    msg = cb.message.reply(texts.wallet_menu(tg_id), reply_markup=kb.wallet_menu())
    cache.write_user_cache(tg_id, "wallet_menu_id", msg.message_id)
    cache.change_user_flag(tg_id, "create_wallet", False)
예제 #6
0
def back_add_wallet(cli, cb):
    tg_id = cb.from_user.id
    wallets = cache.get_user_wallets(tg_id)
    cache.change_user_flag(tg_id, "await_mnemonic", False)
    if len(wallets) == 0:
        return new_msg(cli, cb, tg_id,
                "Do you want to create a wallet or add an existing one",
                kb.none_wallet_start(),
                "wallet_menu_id",
                "wallet_menu_id",
                "on_callback")

    new_msg(cli, cb, tg_id,
            texts.add_wallet(tg_id),
            kb.add_wallet(tg_id),
            "wallet_menu_id",
            "wallet_menu_id",
            "on_callback")
예제 #7
0
def await_address_to(cli, m):
    tg_id = m.from_user.id
    valid_address = WalletAPI.check_wallet(m.text)

    delete_inline_kb(cli, tg_id, cache.read_user_cache(tg_id, "last_msg_id"))
    if valid_address:
        cache.change_user_flag(tg_id, "await_to_address", False)
        cache.change_user_flag(tg_id, "await_to_amount", True)
        cache.write_user_cache(tg_id, "address_to", m.text)
        txt = "Enter amount in UAX"
        kbq = kb.max_amount(tg_id)
    else:
        txt = "invalid address"
        kbq = kb.back_wallet()

    new_msg(cli, m, tg_id,
            txt,
            kbq,
            "wallet_menu_id",
            "wallet_menu_id",
            "on_message")
예제 #8
0
def wallet_settings(cli, cb):
    tg_id = cb.from_user.id
    action = cb.data.split('-')[1]
    if action == "show_phrase":
        new_msg(cli, cb, tg_id,
                texts.show_phrase(tg_id),
                kb.back_wallet_settings(tg_id),
                "wallet_menu_id",
                "wallet_menu_id",
                "on_callback")

    elif action == "edit_title":
        cache.change_user_flag(tg_id, "await_wallet_title", True)
        #cache.write_user_cache(tg_id, "last_wallet_id", wallet_id)
        new_msg(cli, cb, tg_id,
                texts.edit_title(tg_id),
                kb.back_wallet_settings(tg_id),
                "wallet_menu_id",
                "wallet_menu_id",
                "on_callback")

    elif action == "delete_wallet":
        wallet_id = cache.get_active_wallet(tg_id)["id"]
        new_msg(cli, cb, tg_id,
                texts.delete_wallet(tg_id),
                kb.delete_wallet_1(tg_id),
                "wallet_menu_id",
                "wallet_menu_id",
                "on_callback")

    elif action == "back_wallet":
        cache.change_user_flag(tg_id, "await_wallet_title", False)
        new_msg(cli, cb, tg_id,
                texts.settings_wallet(tg_id),
                kb.settings_wallet(tg_id),
                "wallet_menu_id",
                "wallet_menu_id",
                "on_callback")
예제 #9
0
def await_mnemonic(cli, m):
    tg_id = m.from_user.id
    check_ = cache.get_user_wallets(tg_id)

    mnemonic = m.text
    if not WalletAPI.add_from_mnemonic(tg_id, mnemonic):
        return new_msg(cli, m, tg_id,
                "Bad phrase",
                kb.back_add_menu(tg_id),
                "wallet_menu_id",
                "wallet_menu_id",
                "on_message")

    if len(check_) == 0:
        m.reply("Welcome to UAX Wallet", reply_markup=kb.reply(tg_id))

    cache.change_user_flag(tg_id, "await_mnemonic", False)
    new_msg(cli, m, tg_id,
            texts.wallet_menu(tg_id),
            kb.wallet_menu(),
            "wallet_menu_id",
            "wallet_menu_id",
            "on_message")
예제 #10
0
def back_wallet(cli, cb):
    tg_id = cb.from_user.id
    cache.change_user_flag(tg_id, "await_to_address", False)
    cache.change_user_flag(tg_id, "await_to_amount", False)
    cache.change_user_flag(tg_id, "await_wallet_title", False)
    wallets = cache.get_user_wallets(tg_id)

    if len(wallets) == 0:
        return new_msg(cli, cb, tg_id,
                       'Do you want to create a wallet or add an existing one',
                       kb.none_wallet_start(), "wallet_menu_id", "wallet_menu_id",
                       "on_callback")

    new_msg(cli, cb, tg_id,
            texts.wallet_menu(tg_id),
            kb.wallet_menu(),
            "wallet_menu_id",
            "wallet_menu_id",
            "on_callback")
예제 #11
0
def settings(cli, cb):
    tg_id = cb.from_user.id
    action = cb.data.split('-')[1]

    if action == "current_wallet":
        wallets = cache.get_user_wallets(tg_id)
        if len(wallets) == 0:
            return cli.answer_callback_query(cb.id, "You don't have wallets to switch between them")
        new_msg(cli, cb, tg_id,
                texts.current_wallet(tg_id),
                kb.current_wallet(tg_id),
                "wallet_menu_id",
                "wallet_menu_id",
                "on_callback")

    # elif action == "manage_wallet":
    #     new_msg(cli, cb, tg_id,
    #             texts.manage_wallets(tg_id),
    #             kb.manage_wallets(tg_id),
    #             "wallet_menu_id",
    #             "wallet_menu_id",
    #             "on_callback")

    elif action == "select_wallet":
        wallet_id = cb.data.split('-')[2]
        WalletAPI.activate_wallet(wallet_id)
        #delete_inline_kb(cli, tg_id, cb.message.message_id)
        new_msg(cli, cb, tg_id,
                texts.wallet_menu(tg_id),
                kb.wallet_menu(),
                "wallet_menu_id",
                "wallet_menu_id",
                "on_callback")

    elif action == "add_wallet":
        cache.change_user_flag(tg_id, "await_mnemonic", False)
        new_msg(cli, cb, tg_id,
                texts.add_wallet(tg_id),
                kb.add_wallet(tg_id),
                "wallet_menu_id",
                "wallet_menu_id",
                "on_callback")

    elif action == "create_wallet":
        new_wallet(cli, cb)
    elif action == "seed_phrase":
        cache.change_user_flag(tg_id, "await_mnemonic", True)

        new_msg(cli, cb, tg_id,
                texts.enter_mnemonic(tg_id),
                kb.back_add_wallet(tg_id),
                "wallet_menu_id",
                "wallet_menu_id",
                "on_callback")

    elif action == "manage_wallet":
        new_msg(cli, cb, tg_id,
                texts.settings_wallet(tg_id),
                kb.settings_wallet(tg_id),
                "wallet_menu_id",
                "wallet_menu_id",
                "on_callback")
    elif action == "chat_mode":
        current_mode = cb.data.split("-")[2]
        if current_mode == "Historical":
            cache.write_user_cache(tg_id, "chat_mode", "Modern")
        else:
            cache.write_user_cache(tg_id, "chat_mode", "Historical")

        new_msg(cli, cb, tg_id,
                texts.wallet_settings(tg_id),
                kb.settings(tg_id),
                "wallet_menu_id",
                "wallet_menu_id",
                "on_callback")

    elif action == "back_settings":
        new_msg(cli, cb, tg_id,
                texts.wallet_settings(tg_id),
                kb.settings(tg_id),
                "wallet_menu_id",
                "wallet_menu_id",
                "on_callback")