예제 #1
0
def start(cli, m):
    tg_id = m.from_user.id

    # Делает проверку зарегестрирован ли юзер
    response = WalletAPI.check_user(tg_id)

    if response.status_code == 200:
        wallets = cache.get_user_wallets(tg_id)

        if len(wallets) == 0:
            profile = cache.get_user_profile(tg_id)
            if profile["master_mnemonic"] == "none":
                return new_msg(cli, m, tg_id,
                               'Do you want to create a wallet or add an existing one',
                               kb.after_delete_wallet(tg_id), "wallet_menu_id", "wallet_menu_id",
                        "on_message")
            else:
                return new_msg(cli, m, tg_id,
                               'Do you want to add an existing one wallet',
                               kb.after_delete_wallet(tg_id), "wallet_menu_id", "wallet_menu_id",
                               "on_message")

        new_msg(cli, m, tg_id, texts.wallet_menu(tg_id), kb.wallet_menu(), "wallet_menu_id", "wallet_menu_id",
                "on_message")
    if response.status_code == 404:
        if len(m.command) > 1:
            refcode = m.command[1]
            refcodes = cache.get_refcodes()
            if refcode in refcodes:
                WalletAPI.registration_user(m.from_user)
                m.reply('Do you want to create a wallet or add an existing one', reply_markup=kb.first_start())
                cache.del_refcode(refcode)
                return

        m.reply("Sorry, but the entrance is by invitation only")
예제 #2
0
def open_repl_wallet(cli, cb):
    tg_id = cb.from_user.id
    wallet_id = cb.data.split('-')[1]
    WalletAPI.activate_wallet(wallet_id)
    cb.message.edit(cb.message.text)
    # 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_message")
예제 #3
0
def confirm_tx(cli, cb):
    tg_id = cb.from_user.id
    action = cb.data.split('-')[1]
    address_to = cache.read_user_cache(tg_id, "address_to")
    if action == "send":
        amount = int(cb.data.split('-')[2])
        WalletAPI.send_tx(tg_id, address_to, amount)
        cb.message.edit(texts.success_tx(amount, address_to))
        delete_inline_kb(cli, tg_id, cache.read_user_cache(tg_id, "wallet_menu_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)
    elif action == "cancel":
        back_wallet(cli, cb)
예제 #4
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)
예제 #5
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")
예제 #6
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")
예제 #7
0
def my_w(cli, m):
    tg_id = m.from_user.id
    new_msg(cli, m, tg_id, texts.wallet_menu(tg_id), kb.wallet_menu(), "wallet_menu_id", "wallet_menu_id", "on_message")
예제 #8
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")