Exemplo n.º 1
0
class TransactionPage(Page):

    def __init__(self, *args, **kwargs):
        Page.__init__(self, *args, **kwargs)

        self.configuration = Configuration().load_configuration()
        self.api = WalletAPI()
        self.tokens = self.api.list_tokens(self.configuration)
        self.eth_balance, _ = self.api.get_balance(self.configuration)

        def change_token(token):
            if token == 'ETH':
                self.eth_balance, _ = self.api.get_balance(self.configuration)
            else:
                self.eth_balance, _ = self.api.get_balance(self.configuration, token)

            balance.set(str(self.eth_balance) + ' ' + token)

        token_symbol = StringVar()
        token_symbol.set('ETH')
        balance = StringVar()
        balance.set(str(self.eth_balance) + ' ' + token_symbol.get())

        mb = Menubutton(self,
                        width=60,
                        textvariable=token_symbol,
                        relief=RAISED)
        mb.grid()
        mb.menu = Menu(mb, tearoff=0)
        mb["menu"] = mb.menu
        mb.menu.add_radiobutton(label="ETH",
                                variable=token_symbol,
                                value='ETH',
                                command=lambda: change_token(token_symbol.get()))
        for token in self.tokens:
            mb.menu.add_radiobutton(label=token,
                                    variable=token_symbol,
                                    value=token,
                                    command=lambda: change_token(token_symbol.get()))
        mb.pack()

        label = Label(self,
                      textvariable=balance,
                      width=60,
                      font=(None, 30))
        label.pack()

        lbl_address = Label(self,
                            text="To address:",
                            width=60,
                            font=(None, 20))
        lbl_address.pack()

        entry_address = Entry(self,
                              font=(None, 20),
                              width=60,
                              justify=CENTER)
        entry_address.pack()

        lbl_amount = Label(self,
                           text="Amount:",
                           width=60,
                           font=(None, 20))
        lbl_amount.pack()

        entry_amount = Entry(self,
                             font=(None, 20),
                             width=60,
                             justify=CENTER)
        entry_amount.pack()

        lbl_passphrase = Label(self,
                               text="Passphrase:",
                               width=60,
                               font=(None, 20))
        lbl_passphrase.pack()

        entry_passphrase = Entry(self,
                                 font=(None, 20),
                                 width=60,
                                 justify=CENTER)
        entry_passphrase.pack()

        btn_send = Button(self,
                          text="Send",
                          width=60,
                          font=(None, 16),
                          command=lambda: self.send_transaction(entry_address.get(),
                                                                entry_amount.get(),
                                                                entry_passphrase.get(),
                                                                token_symbol.get()))
        btn_send.pack()

        btn_back = Button(self,
                          text="Back",
                          width=60,
                          font=(None, 16),
                          command=self.navigate_home_page)
        btn_back.pack()

    def navigate_home_page(self):
        """
        Navigate to home page
        :return:
        """
        info_page = HomePage(self)
        info_page.place(in_=self, x=0, y=0, relwidth=1, relheight=1)
        info_page.show()

    def send_transaction(self, to, value, password, token):
        """
        Send transaction
        :return:
        """
        if token == 'ETH':
            tx_thread = TransactionThread(configuration=self.configuration,
                                          password=password,
                                          to=to,
                                          value=value,
                                          token=None)
        else:
            tx_thread = TransactionThread(configuration=self.configuration,
                                          password=password,
                                          to=to,
                                          value=value,
                                          token=token)
        tx_thread.start()
Exemplo n.º 2
0
class HomePage(Page):

    def __init__(self, *args, **kwargs):
        Page.__init__(self, *args, **kwargs)

        self.configuration = Configuration().load_configuration()
        self.api = WalletAPI()
        self.tokens = self.api.list_tokens(self.configuration)
        self.eth_balance, self.address = self.api.get_balance(self.configuration)

        def refresh():
            change_token(token_symbol.get())

        def change_token(token):
            if token == 'ETH':
                self.eth_balance, self.address = self.api.get_balance(self.configuration)
            else:
                self.eth_balance, self.address = self.api.get_balance(self.configuration, token)
            balance.set(str(self.eth_balance) + ' ' + token)

        token_symbol = StringVar()
        token_symbol.set('ETH')
        balance = StringVar()
        balance.set(str(self.eth_balance) + ' ' + token_symbol.get())

        mb = Menubutton(self,
                        width=60,
                        textvariable=token_symbol,
                        relief=RAISED)
        mb.grid()
        mb.menu = Menu(mb, tearoff=0)
        mb["menu"] = mb.menu
        mb.menu.add_radiobutton(label="ETH",
                                variable=token_symbol,
                                value='ETH',
                                command=lambda: change_token(token_symbol.get()))
        for token in self.tokens:
            mb.menu.add_radiobutton(label=token,
                                    variable=token_symbol,
                                    value=token,
                                    command=lambda: change_token(token_symbol.get()))
        mb.menu.add_radiobutton(label="Add new token ...",
                                command=self.navigate_add_token_page)
        mb.pack()

        label_address_lbl = Label(self,
                                  text='Address:',
                                  width=60,
                                  font=(None, 10, "bold"))
        label_address_lbl.pack()
        label_address = Label(self,
                              text=self.address,
                              width=60,
                              font=(None, 10))
        label_address.pack()

        label_balance = Label(self,
                              textvariable=balance,
                              width=60,
                              font=(None, 30))
        label_balance.pack()

        btn_refresh = Button(self,
                             text="Refresh",
                             command=refresh,
                             width=60,
                             font=(None, 16))
        btn_refresh.pack()

        btn_copy_address = Button(self,
                                  text="Copy address",
                                  command=self.copy_address,
                                  width=60,
                                  font=(None, 16))
        btn_copy_address.pack()

        btn_send_transaction = Button(self,
                                      text="Send Transaction",
                                      command=self.navigate_transaction_page,
                                      width=60,
                                      font=(None, 16))
        btn_send_transaction.pack()

    def navigate_transaction_page(self):
        """
        Navigate to transaction page
        :return:
        """
        transaction_page = TransactionPage(self)
        transaction_page.place(in_=self, x=0, y=0, relwidth=1, relheight=1)
        transaction_page.show()

    def navigate_add_token_page(self):
        """
        Navigate to transaction page
        :return:
        """
        add_token_page = AddTokenPage(self)
        add_token_page.place(in_=self, x=0, y=0, relwidth=1, relheight=1)
        add_token_page.show()

    def copy_address(self):
        """Add address to the clipboard"""
        self.clipboard_clear()  # clear clipboard contents
        self.clipboard_append(self.address)  # append new value to clipbao