Beispiel #1
0
 def btnSellClicked(self):
     valid = True
     if not self.edtSellQuantity.text().toDouble()[1]:
         self.edtSellQuantity.setStyleSheet('background:#FF8080')
         valid = False
     if not self.edtSellPrice.text().toDouble()[1]:
         self.edtSellPrice.setStyleSheet('background:#FF8080')
         valid = False
     if not valid:
         return
     moniker = str(self.cbMoniker.currentText())
     asset = wallet.get_asset_definition(moniker)
     value = self.edtSellQuantity.text().toDouble()[0]
     bitcoin = wallet.get_asset_definition('bitcoin')
     price = self.edtSellPrice.text().toDouble()[0]
     delta = wallet.get_balance(asset) - asset.parse_value(value)
     if delta < 0:
         message = 'The transaction amount exceeds the balance by %s %s' % \
             (asset.format_value(-delta), moniker)
         QtGui.QMessageBox.critical(self, '', message, QtGui.QMessageBox.Ok)
         return
     offer = wallet.p2ptrade_make_offer(True, {
         'moniker': moniker,
         'value': value,
         'price': price,
     })
     wallet.p2p_agent.register_my_offer(offer)
     self.update_offers()
     self.edtSellQuantity.setText('')
     self.edtSellPrice.setText('')
Beispiel #2
0
 def btnSellClicked(self):
     valid = True
     if not self.edtSellQuantity.text().toDouble()[1]:
         self.edtSellQuantity.setStyleSheet('background:#FF8080')
         valid = False
     if not self.edtSellPrice.text().toDouble()[1]:
         self.edtSellPrice.setStyleSheet('background:#FF8080')
         valid = False
     if not valid:
         return
     moniker = str(self.cbMoniker.currentText())
     asset = wallet.get_asset_definition(moniker)
     value = self.edtSellQuantity.text().toDouble()[0]
     bitcoin = wallet.get_asset_definition('bitcoin')
     price = self.edtSellPrice.text().toDouble()[0]
     delta = wallet.get_available_balance(asset) - asset.parse_value(value)
     if delta < 0:
         message = 'The transaction amount exceeds available balance by %s %s' % \
             (asset.format_value(-delta), moniker)
         QtGui.QMessageBox.critical(self, '', message, QtGui.QMessageBox.Ok)
         return
     offer = wallet.p2ptrade_make_offer(True, {
         'moniker': moniker,
         'value': value,
         'price': price,
     })
     wallet.p2p_agent.register_my_offer(offer)
     self.update_offers()
     self.edtSellQuantity.setText('')
     self.edtSellPrice.setText('')
Beispiel #3
0
    def update_offers(self):
        moniker = str(self.cbMoniker.currentText())
        if moniker == '':
            return
        bitcoin = wallet.get_asset_definition('bitcoin')
        asset = wallet.get_asset_definition(moniker)
        color_desc = asset.get_color_set().color_desc_list[0]

        wallet.p2p_agent.update()

        selected_oids = [None, None]
        viewsList = [
            [0, self.tvBuy,  self.proxyModelBuy],
            [1, self.tvSell, self.proxyModelSell],
        ]
        for i, view, proxy in viewsList:
            selected = view.selectedIndexes()
            if selected:
                index = proxy.index(selected[0].row(), 3)
                selected_oids[i] = str(proxy.data(index).toString())

        self.modelBuy.removeRows(0, self.modelBuy.rowCount())
        self.modelSell.removeRows(0, self.modelSell.rowCount())
        offers = wallet.p2p_agent.their_offers.items() + wallet.p2p_agent.my_offers.items()
        for i, item in enumerate(offers):
            oid, offer = item
            data = offer.get_data()
            if data['A'].get('color_spec') == color_desc:
                value = data['A']['value']
                total = data['B']['value']
                price = int(total*asset.unit/float(value))
                self.modelSell.addRow([
                    bitcoin.format_value(price),
                    asset.format_value(value),
                    bitcoin.format_value(total),
                    oid,
                ])
            if data['B'].get('color_spec') == color_desc:
                value = data['B']['value']
                total = data['A']['value']
                price = int(total*asset.unit/float(value))
                self.modelBuy.addRow([
                    bitcoin.format_value(price),
                    asset.format_value(value),
                    bitcoin.format_value(total),
                    oid,
                ])

        for i, view, proxy in viewsList:
            for row in xrange(proxy.rowCount()):
                oid = str(proxy.data(proxy.index(row, 3)).toString())
                if oid == selected_oids[i]:
                    view.selectRow(row)
Beispiel #4
0
    def update_offers(self):
        self.need_update_offers = False
        moniker = str(self.cbMoniker.currentText())
        if moniker == '':
            return
        bitcoin = wallet.get_asset_definition('bitcoin')
        asset = wallet.get_asset_definition(moniker)
        color_desc = asset.get_color_set().color_desc_list[0]

        selected_oids = [None, None]
        viewsList = [
            [0, self.tvBuy, self.proxyModelBuy],
            [1, self.tvSell, self.proxyModelSell],
        ]
        for i, view, proxy in viewsList:
            selected = view.selectedIndexes()
            if selected:
                index = proxy.index(selected[0].row(), 3)
                selected_oids[i] = str(proxy.data(index).toString())

        self.modelBuy.removeRows(0, self.modelBuy.rowCount())
        self.modelSell.removeRows(0, self.modelSell.rowCount())
        offers = wallet.p2p_agent.their_offers.items(
        ) + wallet.p2p_agent.my_offers.items()
        for i, item in enumerate(offers):
            oid, offer = item
            data = offer.get_data()
            if data['A'].get('color_spec') == color_desc:
                value = data['A']['value']
                total = data['B']['value']
                price = int(total * asset.unit / float(value))
                self.modelSell.addRow([
                    bitcoin.format_value(price),
                    asset.format_value(value),
                    bitcoin.format_value(total),
                    oid,
                ])
            if data['B'].get('color_spec') == color_desc:
                value = data['B']['value']
                total = data['A']['value']
                price = int(total * asset.unit / float(value))
                self.modelBuy.addRow([
                    bitcoin.format_value(price),
                    asset.format_value(value),
                    bitcoin.format_value(total),
                    oid,
                ])

        for i, view, proxy in viewsList:
            for row in xrange(proxy.rowCount()):
                oid = str(proxy.data(proxy.index(row, 3)).toString())
                if oid == selected_oids[i]:
                    view.selectRow(row)
Beispiel #5
0
    def tvSellDoubleClicked(self):
        selected = self.tvSell.selectedIndexes()
        if not selected:
            return
        index = self.proxyModelSell.index(selected[0].row(), 3)
        oid = str(self.proxyModelSell.data(index).toString())
        if oid in wallet.p2p_agent.their_offers:
            offer = wallet.p2p_agent.their_offers[oid]
            moniker = str(self.cbMoniker.currentText())
            asset = wallet.get_asset_definition(moniker)
            if wallet.get_balance(asset) < offer.get_data()['A']['value']:
                QtGui.QMessageBox.warning(self, '', "Not enough money...",
                                          QtGui.QMessageBox.Cancel)
                return
            message = "Buy <b>{value}</b> {moniker} for <b>{course}</b> \
bitcoin (Total: <b>{total}</b> bitcoin)".format(
                **{
                    'value': self.proxyModelSell.data(selected[1]).toString(),
                    'moniker': moniker,
                    'course': self.proxyModelSell.data(selected[0]).toString(),
                    'total': self.proxyModelSell.data(selected[2]).toString(),
                })
            retval = QtGui.QMessageBox.question(
                self, "Confirm buy coins", message,
                QtGui.QMessageBox.Yes | QtGui.QMessageBox.Cancel,
                QtGui.QMessageBox.Cancel)
            if retval != QtGui.QMessageBox.Yes:
                return
            new_offer = wallet.p2ptrade_make_mirror_offer(offer)
            wallet.p2p_agent.register_my_offer(new_offer)
        else:
            offer = wallet.p2p_agent.my_offers[oid]
            wallet.p2p_agent.cancel_my_offer(offer)
        self.update_offers()
Beispiel #6
0
 def updateAvailableBalance(self):
     moniker = str(self.cbMoniker.currentText())
     if moniker:
         asset = wallet.get_asset_definition(moniker)
         balance = wallet.get_available_balance(moniker)
         self.edtAmount.setMaximum(balance)
         self.lblAvailaleBalance.setText("%s %s" % (asset.format_value(balance), moniker))
Beispiel #7
0
    def tvSellDoubleClicked(self):
        selected = self.tvSell.selectedIndexes()
        if not selected:
            return
        index = self.proxyModelSell.index(selected[0].row(), 3)
        oid = str(self.proxyModelSell.data(index).toString())
        if oid in wallet.p2p_agent.their_offers:
            offer = wallet.p2p_agent.their_offers[oid]
            moniker = str(self.cbMoniker.currentText())
            asset = wallet.get_asset_definition(moniker)
            if wallet.get_available_balance(asset) < offer.get_data()['A']['value']:
                QtGui.QMessageBox.warning(self, '', "Not enough money...",
                    QtGui.QMessageBox.Cancel)
                return
            message = "Buy <b>{value}</b> {moniker} for <b>{course}</b> \
bitcoin (Total: <b>{total}</b> bitcoin)".format(**{
                'value': self.proxyModelSell.data(selected[1]).toString(),
                'moniker': moniker,
                'course': self.proxyModelSell.data(selected[0]).toString(),
                'total': self.proxyModelSell.data(selected[2]).toString(),
            })
            retval = QtGui.QMessageBox.question(
                self, "Confirm buy coins", message,
                QtGui.QMessageBox.Yes | QtGui.QMessageBox.Cancel,
                QtGui.QMessageBox.Cancel)
            if retval != QtGui.QMessageBox.Yes:
                return
            new_offer = wallet.p2ptrade_make_mirror_offer(offer)
            wallet.p2p_agent.register_my_offer(new_offer)
        else:
            offer = wallet.p2p_agent.my_offers[oid]
            wallet.p2p_agent.cancel_my_offer(offer)
        self.update_offers()
Beispiel #8
0
    def update_balance(self):
        moniker = str(self.cbMoniker.currentText())
        if moniker == '':
            return

        asset = wallet.get_asset_definition('bitcoin')
        value = asset.format_value(wallet.get_available_balance(asset))
        self.lblBuy.setText('<b>Buy</b> %s' % moniker)
        self.lblBuyAvail.setText('(Available: %s bitcoin)' % value)

        asset = wallet.get_asset_definition(moniker)
        value = asset.format_value(wallet.get_available_balance(asset))
        self.lblSell.setText('<b>Sell</b> %s' % moniker)
        self.lblSellAvail.setText('(Available: %s %s)' % (value, moniker))

        self.update_offers()
Beispiel #9
0
 def contextMenuEvent(self, event):
     selected = self.tableView.selectedIndexes()
     if not selected:
         return
     actions = [
         self.actionCopyMoniker,
         self.actionCopyColorSet,
         self.actionCopyUnit,
         self.actionCopyAsJSON,
         self.actionShowAddresses,
     ]
     menu = QtGui.QMenu()
     for action in actions:
         menu.addAction(action)
     result = menu.exec_(event.globalPos())
     if result is None or result not in actions:
         return
     if actions.index(result) in [0, 1, 2]:
         index = selected[actions.index(result)]
         QtGui.QApplication.clipboard().setText(
             self.proxyModel.data(index).toString())
     elif actions.index(result) == 3:
         moniker = str(self.proxyModel.data(selected[0]).toString())
         asset = wallet.get_asset_definition(moniker)
         QtGui.QApplication.clipboard().setText(
             json.dumps(asset.get_data()))
     elif actions.index(result) == 4:
         window = self.parentWidget().parentWidget().parentWidget()
         window.gotoReceivePage()
         window.receivepage.setMonikerFilter(
             self.proxyModel.data(selected[0]).toString())
Beispiel #10
0
    def cbMonikerIndexChanged(self):
        moniker = str(self.cbMoniker.currentText())
        if moniker == '':
            return

        asset = wallet.get_asset_definition('bitcoin')
        value = asset.format_value(wallet.get_balance(asset))
        text = '<b>Buy</b> {0} (Available: {1} bitcoin)'.format(moniker, value)
        self.lblBuy.setText(text)

        asset = wallet.get_asset_definition(moniker)
        value = asset.format_value(wallet.get_balance(asset))
        text = '<b>Sell</b> {0} (Available: {1} {0})'.format(moniker, value)
        self.lblSell.setText(text)

        self.update_offers()
Beispiel #11
0
 def contextMenuEvent(self, event):
     selected = self.tableView.selectedIndexes()
     if not selected:
         return
     actions = [
         self.actionCopyMoniker,
         self.actionCopyColorSet,
         self.actionCopyUnit,
         self.actionCopyAsJSON,
         self.actionShowAddresses,
     ]
     menu = QtGui.QMenu()
     for action in actions:
         menu.addAction(action)
     result = menu.exec_(event.globalPos())
     if result is None or result not in actions:
         return
     if actions.index(result) in [0, 1, 2]:
         index = selected[actions.index(result)]
         QtGui.QApplication.clipboard().setText(
             self.proxyModel.data(index).toString())
     elif actions.index(result) == 3:
         moniker = str(self.proxyModel.data(selected[0]).toString())
         asset = wallet.get_asset_definition(moniker)
         QtGui.QApplication.clipboard().setText(
             json.dumps(asset.get_data()))
     elif actions.index(result) == 4:
         window = self.parentWidget().parentWidget().parentWidget()
         window.gotoReceivePage()
         window.receivepage.setMonikerFilter(
             self.proxyModel.data(selected[0]).toString())
Beispiel #12
0
    def cbMonikerIndexChanged(self):
        moniker = str(self.cbMoniker.currentText())
        if moniker == '':
            return

        asset = wallet.get_asset_definition('bitcoin')
        value = asset.format_value(wallet.get_available_balance(asset))
        text = '<b>Buy</b> {0} (Available: {1} bitcoin)'.format(moniker, value)
        self.lblBuy.setText(text)

        asset = wallet.get_asset_definition(moniker)
        value = asset.format_value(wallet.get_available_balance(asset))
        text = '<b>Sell</b> {0} (Available: {1} {0})'.format(moniker, value)
        self.lblSell.setText(text)

        self.update_offers()
Beispiel #13
0
 def updateAvailableBalance(self):
     moniker = str(self.cbMoniker.currentText())
     if moniker:
         asset = wallet.get_asset_definition(moniker)
         balance = wallet.get_available_balance(moniker)
         self.edtAmount.setMaximum(balance)
         self.lblAvailaleBalance.setText(
             '%s %s' % (asset.format_value(balance), moniker))
Beispiel #14
0
 def updateAvailableBalance(self):
     moniker = str(self.cb_monikers.currentText())
     if moniker:
         balance = wallet.get_balance(moniker)
         asset = wallet.get_asset_definition(moniker)
         self.edt_amount.setMaximum(balance)
         self.lbl_availaleBalance.setText(
             '%s %s' % (asset.format_value(balance), moniker))
Beispiel #15
0
 def lblSellTotalChange(self):
     bitcoin = wallet.get_asset_definition('bitcoin')
     quantity = self._to_decimal(self.edtSellQuantity)
     price = bitcoin.parse_value(self._to_decimal(self.edtSellPrice))
     total = quantity * price
     if total:
         self.lblSellTotal.setText('%sBTC' % bitcoin.format_value(total))
     else:
         self.lblSellTotal.setText('')
Beispiel #16
0
 def changeTotalBTC(self):
     amount = self.edtUnits.text().toInt()
     units = self.edtAtoms.text().toInt()
     if amount[1] and units[1]:
         need = amount[0] * units[0]
         text = "%s bitcoin" % wallet.get_asset_definition("bitcoin").format_value(need)
         if need > self.availableBTC:
             text = '<font color="#FF3838">%s</font>' % text
         self.lblTotalBTC.setText(text)
Beispiel #17
0
    def update(self):
        allowTextSelection = (
            QtCore.Qt.LinksAccessibleByMouse |
            QtCore.Qt.TextSelectableByKeyboard |
            QtCore.Qt.TextSelectableByMouse)

        self.scrollAreaContents = QtGui.QWidget()
        self.scrollArea.setWidget(self.scrollAreaContents)
        self.scrollAreaLayout = QtGui.QVBoxLayout(self.scrollAreaContents)

        hbox = QtGui.QHBoxLayout()
        hbox.addItem(QtGui.QSpacerItem(20, 0))
        hbox.setStretch(0, 1)
        updateButton = QtGui.QPushButton('Update', self.scrollAreaContents)
        updateButton.clicked.connect(self.updateButtonClicked)
        hbox.addWidget(updateButton)
        self.scrollAreaLayout.addLayout(hbox)

        for moniker in wallet.get_all_monikers():
            asset = wallet.get_asset_definition(moniker)
            address = wallet.get_some_address(asset)
            total_balance = wallet.get_total_balance(asset)
            unconfirmed_balance = wallet.get_unconfirmed_balance(asset)

            groupBox = QtGui.QGroupBox(moniker, self.scrollAreaContents)
            layout = QtGui.QFormLayout(groupBox)

            label = QtGui.QLabel(groupBox)
            label.setText('Balance:')
            layout.setWidget(0, QtGui.QFormLayout.LabelRole, label)

            balance_text = asset.format_value(total_balance)
            if not (unconfirmed_balance == 0):
                balance_text += " (%s unconfirmed, %s available)" % \
                    (asset.format_value(unconfirmed_balance),
                     asset.format_value(wallet.get_available_balance(asset)))

            label = QtGui.QLabel(groupBox)
            label.setTextInteractionFlags(allowTextSelection)
            label.setCursor(QtGui.QCursor(QtCore.Qt.IBeamCursor))
            label.setText(balance_text)
            layout.setWidget(0, QtGui.QFormLayout.FieldRole, label)

            label = QtGui.QLabel(groupBox)
            label.setText('Address:')
            layout.setWidget(1, QtGui.QFormLayout.LabelRole, label)

            label = QtGui.QLabel(groupBox)
            label.setTextInteractionFlags(allowTextSelection)
            label.setCursor(QtGui.QCursor(QtCore.Qt.IBeamCursor))
            label.setText(address)
            layout.setWidget(1, QtGui.QFormLayout.FieldRole, label)

            self.scrollAreaLayout.addWidget(groupBox)

        self.scrollAreaLayout.addItem(QtGui.QSpacerItem(20, 0))
        self.scrollAreaLayout.setStretch(self.scrollAreaLayout.count()-1, 1)
Beispiel #18
0
 def getData(self):
     moniker = str(self.cbMoniker.currentText())
     asset = wallet.get_asset_definition(moniker)
     value = asset.parse_value(str(self.edtAmount.value()))
     return {
         'address': str(self.edtAddress.text()),
         'value': value,
         'moniker': moniker,
     }
Beispiel #19
0
 def getData(self):
     moniker = str(self.cbMoniker.currentText())
     asset = wallet.get_asset_definition(moniker)
     value = asset.parse_value(str(self.edtAmount.value()))
     return {
         'address': str(self.edtAddress.text()),
         'value':  value,
         'moniker': moniker,
     }
Beispiel #20
0
    def validate_sell_input(self, quantity, price):
        moniker = str(self.cbMoniker.currentText())
        asset = wallet.get_asset_definition(moniker)
        bitcoin = wallet.get_asset_definition('bitcoin')

        # check if quantity was given
        if quantity <= Decimal("0"): # no quantity
            self.edtSellQuantity.setStyleSheet('background:#FF8080')
            return False

        # check if price was given
        if price <= Decimal("0"): # no price
            self.edtSellPrice.setStyleSheet('background:#FF8080')
            return False

        # quantity must be multiple of atom
        if not asset.validate_value(quantity):
            atom = asset.format_value(1)
            message = "Quantity must be a multiple of %s!" % atom
            QtGui.QMessageBox.critical(self, '', message, QtGui.QMessageBox.Ok)
            self.edtSellQuantity.setStyleSheet('background:#FF8080')
            return False

        # price must be multiple of atom
        if not bitcoin.validate_value(price):
            atom = bitcoin.format_value(1)
            message = "Price must be a multiple of %s!" % atom
            QtGui.QMessageBox.critical(self, '', message, QtGui.QMessageBox.Ok)
            self.edtSellPrice.setStyleSheet('background:#FF8080')
            return False

        # check if amount exceeds available balance
        needed = asset.parse_value(quantity)
        delta = wallet.get_available_balance(asset) - needed
        if delta < 0:
            args = (asset.format_value(-delta), moniker)
            msg_str = 'The amount exceeds available balance by %s %s'
            message = msg_str % args
            QtGui.QMessageBox.critical(self, '', message, QtGui.QMessageBox.Ok)
            self.edtSellQuantity.setStyleSheet('background:#FF8080')
            self.edtSellPrice.setStyleSheet('background:#FF8080')
            return False

        return True
Beispiel #21
0
    def update(self):
        allowTextSelection = (QtCore.Qt.LinksAccessibleByMouse
                              | QtCore.Qt.TextSelectableByKeyboard
                              | QtCore.Qt.TextSelectableByMouse)

        self.scrollAreaContents = QtGui.QWidget()
        self.scrollArea.setWidget(self.scrollAreaContents)
        self.scrollAreaLayout = QtGui.QVBoxLayout(self.scrollAreaContents)

        hbox = QtGui.QHBoxLayout()
        hbox.addItem(QtGui.QSpacerItem(20, 0))
        hbox.setStretch(0, 1)
        updateButton = QtGui.QPushButton('Update', self.scrollAreaContents)
        updateButton.clicked.connect(self.updateButtonClicked)
        hbox.addWidget(updateButton)
        self.scrollAreaLayout.addLayout(hbox)

        for moniker in wallet.get_all_monikers():
            asset = wallet.get_asset_definition(moniker)
            address = wallet.get_some_address(asset)
            total_balance = wallet.get_total_balance(asset)
            unconfirmed_balance = wallet.get_unconfirmed_balance(asset)

            groupBox = QtGui.QGroupBox(moniker, self.scrollAreaContents)
            layout = QtGui.QFormLayout(groupBox)

            label = QtGui.QLabel(groupBox)
            label.setText('Balance:')
            layout.setWidget(0, QtGui.QFormLayout.LabelRole, label)

            balance_text = asset.format_value(total_balance)
            if not (unconfirmed_balance == 0):
                balance_text += " (%s unconfirmed, %s available)" % \
                    (asset.format_value(unconfirmed_balance),
                     asset.format_value(wallet.get_available_balance(asset)))

            label = QtGui.QLabel(groupBox)
            label.setTextInteractionFlags(allowTextSelection)
            label.setCursor(QtGui.QCursor(QtCore.Qt.IBeamCursor))
            label.setText(balance_text)
            layout.setWidget(0, QtGui.QFormLayout.FieldRole, label)

            label = QtGui.QLabel(groupBox)
            label.setText('Address:')
            layout.setWidget(1, QtGui.QFormLayout.LabelRole, label)

            label = QtGui.QLabel(groupBox)
            label.setTextInteractionFlags(allowTextSelection)
            label.setCursor(QtGui.QCursor(QtCore.Qt.IBeamCursor))
            label.setText(address)
            layout.setWidget(1, QtGui.QFormLayout.FieldRole, label)

            self.scrollAreaLayout.addWidget(groupBox)

        self.scrollAreaLayout.addItem(QtGui.QSpacerItem(20, 0))
        self.scrollAreaLayout.setStretch(self.scrollAreaLayout.count() - 1, 1)
Beispiel #22
0
    def validate_buy_input(self, quantity, price):
        moniker = str(self.cbMoniker.currentText())
        asset = wallet.get_asset_definition(moniker)
        bitcoin = wallet.get_asset_definition('bitcoin')

        # check if quantity was given
        if quantity <= Decimal("0"): # no quantity
            self.edtBuyQuantity.setStyleSheet('background:#FF8080')
            return False

        # check if price was given
        if price <= Decimal("0"): # no price
            self.edtBuyPrice.setStyleSheet('background:#FF8080')
            return False

        # quantity must be multiple of atom
        if not asset.validate_value(quantity):
            message = "Quantity must be a multiple of %s!" % asset.get_atom()
            QtGui.QMessageBox.critical(self, '', message, QtGui.QMessageBox.Ok)
            self.edtBuyQuantity.setStyleSheet('background:#FF8080')
            return False

        # price must be multiple of atom
        if not bitcoin.validate_value(price):
            message = "Price must be a multiple of %s!" % asset.get_atom()
            QtGui.QMessageBox.critical(self, '', message, QtGui.QMessageBox.Ok)
            self.edtBuyPrice.setStyleSheet('background:#FF8080')
            return False

        # check if amount exceeds available balance
        needed = quantity * bitcoin.parse_value(price)
        available = wallet.get_available_balance(bitcoin)
        delta = available - needed
        if delta < 0:
            neg_delta = bitcoin.format_value(-delta)
            msg_str = 'The amount exceeds available balance by %s bitcoin!'
            message = msg_str % neg_delta
            QtGui.QMessageBox.critical(self, '', message, QtGui.QMessageBox.Ok)
            self.edtBuyQuantity.setStyleSheet('background:#FF8080')
            self.edtBuyPrice.setStyleSheet('background:#FF8080')
            return False

        return True
Beispiel #23
0
 def changeTotalBTC(self):
     amount = self.edtUnits.text().toInt()
     units = self.edtAtoms.text().toInt()
     if amount[1] and units[1]:
         need = amount[0] * units[0]
         text = '%s bitcoin' % \
             wallet.get_asset_definition('bitcoin').format_value(need)
         if need > self.availableBTC:
             text = '<font color="#FF3838">%s</font>' % text
         self.lblTotalBTC.setText(text)
Beispiel #24
0
 def lblSellTotalChange(self):
     self.lblSellTotal.setText('')
     if self.edtSellQuantity.text().toDouble()[1] \
             and self.edtSellPrice.text().toDouble()[1]:
         value = self.edtSellQuantity.text().toDouble()[0]
         bitcoin = wallet.get_asset_definition('bitcoin')
         price = bitcoin.parse_value(self.edtSellPrice.text().toDouble()[0])
         total = value * price
         self.lblSellTotal.setText('%s bitcoin' %
                                   bitcoin.format_value(total))
Beispiel #25
0
 def lblSellTotalChange(self):
     self.lblSellTotal.setText('')
     if self.edtSellQuantity.text().toDouble()[1] \
             and self.edtSellPrice.text().toDouble()[1]:
         value = self.edtSellQuantity.text().toDouble()[0]
         bitcoin = wallet.get_asset_definition('bitcoin')
         price = bitcoin.parse_value(
             self.edtSellPrice.text().toDouble()[0])
         total = value*price
         self.lblSellTotal.setText('%s bitcoin' % bitcoin.format_value(total))
Beispiel #26
0
 def updateWallet(self):
     moniker = str(self.cb_monikers.currentText())
     if moniker == '':
         return
     asset = wallet.get_asset_definition(moniker)
     balance = wallet.get_balance(asset)
     self.lbl_balance.setText(
         '%s %s' % (asset.format_value(balance), moniker))
     wam = wallet.model.get_address_manager()
     addr = wam.get_some_address(asset.get_color_set()).get_address()
     self.lbl_address.setText(addr)
Beispiel #27
0
    def update(self):
        self.model.removeRows(0, self.model.rowCount())
        for moniker in wallet.get_all_monikers():
            asset = wallet.get_asset_definition(moniker)
            for row in wallet.get_address_balance(asset):
                self.model.addRow([moniker, row['color_address'], asset.format_value(row['value'])])

        moniker = self.cbMoniker.currentText()
        monikers = [''] + wallet.get_all_monikers()
        self.cbMoniker.clear()
        self.cbMoniker.addItems(monikers)
        if moniker in monikers:
            self.cbMoniker.setCurrentIndex(monikers.index(moniker))
        self.setMonikerFilter(self.cbMoniker.currentText())
Beispiel #28
0
    def update(self):
        self.model.removeRows(0, self.model.rowCount())
        for moniker in wallet.get_all_monikers():
            asset = wallet.get_asset_definition(moniker)
            for row in wallet.get_received_by_address(asset):
                self.model.addRow([moniker, row['color_address'], asset.format_value(row['value'])])

        moniker = self.cbMoniker.currentText()
        monikers = [''] + wallet.get_all_monikers()
        self.cbMoniker.clear()
        self.cbMoniker.addItems(monikers)
        if moniker in monikers:
            self.cbMoniker.setCurrentIndex(monikers.index(moniker))
        self.setMonikerFilter(self.cbMoniker.currentText())
Beispiel #29
0
    def __init__(self, parent):
        QtGui.QDialog.__init__(self, parent)
        uic.loadUi(uic.getUiPath('issuedialog.ui'), self)

        self.cbScheme.addItem('obc')

        for wname in ['edtMoniker', 'edtUnits', 'edtAtoms']:
            getattr(self, wname).focusInEvent = \
                lambda e, name=wname: getattr(self, name).setStyleSheet('')

        self.edtUnits.textChanged.connect(self.changeTotalBTC)
        self.edtAtoms.textChanged.connect(self.changeTotalBTC)

        self.availableBTC = wallet.get_balance('bitcoin')
        self.lblTotalBTC.setToolTip('Available: %s bitcoin' % \
            wallet.get_asset_definition('bitcoin').format_value(self.availableBTC))
Beispiel #30
0
 def information_about_offer(offer, action, buysell_text):
     A, B = offer.get_data()['A'], offer.get_data()['B']
     bitcoin = wallet.get_asset_definition('bitcoin')
     sell_offer = B['color_spec'] == ''
     asset = wallet.get_asset_definition_by_color_set(
         (A if sell_offer else B)['color_spec'])
     value = (A if sell_offer else B)['value']
     total = (B if sell_offer else A)['value']
     text = '{action} {type} {value} {moniker} @{price} btc ea. (Total: {total} btc)'.format(**{
         'action': action,
         'type': buysell_text[sell_offer],
         'value': asset.format_value(value),
         'moniker': asset.get_monikers()[0],
         'price': bitcoin.format_value(total*asset.unit/value),
         'total': bitcoin.format_value(total),
     })
     self.add_log_entry(text)
Beispiel #31
0
 def information_about_offer(offer, action='Create'):
     A, B = offer.get_data()['A'], offer.get_data()['B']
     bitcoin = wallet.get_asset_definition('bitcoin')
     sell_offer = B['color_spec'] == ''
     asset = wallet.get_asset_definition_by_color_set(
         (A if sell_offer else B)['color_spec'])
     value = (A if sell_offer else B)['value']
     total = (B if sell_offer else A)['value']
     text = '{action} {type} offer {value} {moniker} for {price} btc. (Total: {total} btc)'.format(**{
         'action': action,
         'type': 'sell' if sell_offer else 'buy',
         'value': asset.format_value(value),
         'moniker': asset.get_monikers()[0],
         'price': bitcoin.format_value(total*asset.unit/value),
         'total': bitcoin.format_value(total),
     })
     QtGui.QMessageBox.information(self,
         '{action} offer'.format(action=action), text, QtGui.QMessageBox.Yes)
Beispiel #32
0
    def __init__(self, parent):
        QtGui.QDialog.__init__(self, parent)
        uic.loadUi(uic.getUiPath('issuedialog.ui'), self)

        self.cbScheme.addItem('obc')

        for wname in ['edtMoniker', 'edtUnits', 'edtAtoms']:
            def clearBackground(event, wname=wname):
                getattr(self, wname).setStyleSheet('')
                QtGui.QLineEdit.focusInEvent(getattr(self, wname), event)
            getattr(self, wname).focusInEvent = clearBackground

        self.edtUnits.textChanged.connect(self.changeTotalBTC)
        self.edtAtoms.textChanged.connect(self.changeTotalBTC)

        self.availableBTC = wallet.get_balance('bitcoin')
        self.lblTotalBTC.setToolTip('Available: %s bitcoin' % \
            wallet.get_asset_definition('bitcoin').format_value(self.availableBTC))
Beispiel #33
0
 def information_about_offer(offer, action='Create'):
     A, B = offer.get_data()['A'], offer.get_data()['B']
     bitcoin = wallet.get_asset_definition('bitcoin')
     sell_offer = B['color_spec'] == ''
     asset = wallet.get_asset_definition_by_color_set(
         (A if sell_offer else B)['color_spec'])
     value = (A if sell_offer else B)['value']
     total = (B if sell_offer else A)['value']
     text = '{action} {type} offer {value} {moniker} for {price} btc. (Total: {total} btc)'.format(
         **{
             'action': action,
             'type': 'sell' if sell_offer else 'buy',
             'value': asset.format_value(value),
             'moniker': asset.get_monikers()[0],
             'price': bitcoin.format_value(total * asset.unit / value),
             'total': bitcoin.format_value(total),
         })
     QtGui.QMessageBox.information(
         self, '{action} offer'.format(action=action), text,
         QtGui.QMessageBox.Yes)
Beispiel #34
0
    def tvBuyDoubleClicked(self):
        """click on bids, colored coins will be sold"""
        selected = self.tvBuy.selectedIndexes()
        if not selected:
            return
        index = self.proxyModelBuy.index(selected[0].row(), 3)
        oid = str(self.proxyModelBuy.data(index).toString())
        if oid in wallet.p2p_agent.their_offers:
            offer = wallet.p2p_agent.their_offers[oid]
            moniker = str(self.cbMoniker.currentText())
            asset = wallet.get_asset_definition(moniker)
            if wallet.get_available_balance(asset) < offer.get_data()['B']['value']:
                self.logger.warn("%s avail <  %s required",
                                 wallet.get_available_balance(asset),
                                 offer.get_data()['A']['value'])
                msg = "Not enough coins: %s %s needed, %s available" % \
                    (str(self.proxyModelBuy.data(selected[2]).toString()),
                     moniker,
                     asset.format_value(wallet.get_available_balance(asset)))
                QtGui.QMessageBox.warning(self, '', msg,
                    QtGui.QMessageBox.Ok)
                return
            message = "About to <u>sell</u> <b>{value}</b> {moniker} @ <b>{course}</b> \
bitcoin each. <br> (Total: <b>{total}</b> bitcoin)".format(**{
                'value': self.proxyModelBuy.data(selected[1]).toString(),
                'moniker': str(self.cbMoniker.currentText()),
                'course': self.proxyModelBuy.data(selected[0]).toString(),
                'total': self.proxyModelBuy.data(selected[2]).toString(),
            })
            retval = QtGui.QMessageBox.question(
                self, "Confirm buying asset", message,
                QtGui.QMessageBox.Ok | QtGui.QMessageBox.Cancel,
                QtGui.QMessageBox.Cancel)
            if retval != QtGui.QMessageBox.Ok:
                return
            new_offer = wallet.p2ptrade_make_mirror_offer(offer)
            wallet.p2p_agent.register_my_offer(new_offer)
        else:
            offer = wallet.p2p_agent.my_offers[oid]
            wallet.p2p_agent.cancel_my_offer(offer)
        self.update_offers()
Beispiel #35
0
 def btnSendClicked(self):
     entries = [self.entries.itemAt(i).widget() for i in xrange(self.entries.count())]
     if not all([entry.isValid() for entry in entries]):
         return
     data = [entry.getData() for entry in entries]
     message = "Are you sure you want to send"
     for recipient in data:
         asset = wallet.get_asset_definition(recipient["moniker"])
         value = asset.format_value(recipient["value"])
         message += "<br><b>{value} {moniker}</b> to {address}".format(
             **{
                 "value": value,
                 "moniker": "BTC" if recipient["moniker"] == "bitcoin" else recipient["moniker"],
                 "address": recipient["address"],
             }
         )
     message += "?"
     retval = QtGui.QMessageBox.question(
         self,
         "Confirm send coins",
         message,
         QtGui.QMessageBox.Yes | QtGui.QMessageBox.Cancel,
         QtGui.QMessageBox.Cancel,
     )
     if retval != QtGui.QMessageBox.Yes:
         return
     # check value exceeds balance
     currency = collections.defaultdict(Decimal)
     for recipient in data:
         currency[recipient["moniker"]] += recipient["value"]
     for moniker, value in currency.items():
         if value > wallet.get_available_balance(moniker):
             QtGui.QMessageBox.warning(
                 self,
                 "Send coins",
                 "The amount for <b>%s</b> exceeds your available balance." % moniker,
                 QtGui.QMessageBox.Ok,
             )
             return
     wallet.send_coins(data)
     self.parent().parent().parent().update()
Beispiel #36
0
    def __init__(self, parent):
        QtGui.QDialog.__init__(self, parent)
        uic.loadUi(uic.getUiPath("issuedialog.ui"), self)

        self.cbScheme.addItem("obc")

        for wname in ["edtMoniker", "edtUnits", "edtAtoms"]:

            def clearBackground(event, wname=wname):
                getattr(self, wname).setStyleSheet("")
                QtGui.QLineEdit.focusInEvent(getattr(self, wname), event)

            getattr(self, wname).focusInEvent = clearBackground

        self.edtUnits.textChanged.connect(self.changeTotalBTC)
        self.edtAtoms.textChanged.connect(self.changeTotalBTC)

        self.availableBTC = wallet.get_balance("bitcoin")
        self.lblTotalBTC.setToolTip(
            "Available: %s bitcoin" % wallet.get_asset_definition("bitcoin").format_value(self.availableBTC)
        )
Beispiel #37
0
    def tvSellDoubleClicked(self):
        """"Click on asks, colored coins are going to be bought"""
        selected = self.tvSell.selectedIndexes()
        if not selected:
            return
        index = self.proxyModelSell.index(selected[0].row(), 3)
        oid = str(self.proxyModelSell.data(index).toString())
        if oid in wallet.p2p_agent.their_offers:
            offer = wallet.p2p_agent.their_offers[oid]
            moniker = str(self.cbMoniker.currentText())
            bitcoin = wallet.get_asset_definition('bitcoin')
            if wallet.get_available_balance(bitcoin) < offer.get_data()['B']['value']:
                self.logger.warn("Not enough money: %s <  %s",
                                 wallet.get_available_balance(bitcoin),
                                 offer.get_data()['B']['value'])
                msg = "Not enough money: %s bitcoins needed, %s available" % \
                    (self.proxyModelSell.data(selected[2]).toString(),
                     bitcoin.format_value(wallet.get_available_balance(bitcoin)))
                QtGui.QMessageBox.warning(self, '', msg,
                                          QtGui.QMessageBox.Ok)
                return
            message = "About to <u>buy</u> <b>{value}</b> {moniker} @ <b>{course}</b> \
bitcoin each. <br> (Total: <b>{total}</b> bitcoin)".format(**{
                'value': self.proxyModelSell.data(selected[1]).toString(),
                'moniker': moniker,
                'course': self.proxyModelSell.data(selected[0]).toString(),
                'total': self.proxyModelSell.data(selected[2]).toString(),
            })
            retval = QtGui.QMessageBox.question(
                self, "Confirm buy coins", message,
                QtGui.QMessageBox.Ok | QtGui.QMessageBox.Cancel,
                QtGui.QMessageBox.Cancel)
            if retval != QtGui.QMessageBox.Ok:
                return
            new_offer = wallet.p2ptrade_make_mirror_offer(offer)
            wallet.p2p_agent.register_my_offer(new_offer)
        else:
            offer = wallet.p2p_agent.my_offers[oid]
            wallet.p2p_agent.cancel_my_offer(offer)
        self.update_offers()
Beispiel #38
0
 def btnSendClicked(self):
     entries = [
         self.entries.itemAt(i).widget()
         for i in xrange(self.entries.count())
     ]
     if not all([entry.isValid() for entry in entries]):
         return
     data = [entry.getData() for entry in entries]
     message = 'Are you sure you want to send'
     for recipient in data:
         asset = wallet.get_asset_definition(recipient['moniker'])
         value = asset.format_value(recipient['value'])
         message += '<br><b>{value} {moniker}</b> to {address}'.format(**{
             'value': value,
             'moniker': 'BTC' if recipient['moniker'] == 'bitcoin' \
                 else recipient['moniker'],
             'address': recipient['address'],
         })
     message += '?'
     retval = QtGui.QMessageBox.question(
         self, 'Confirm send coins', message,
         QtGui.QMessageBox.Yes | QtGui.QMessageBox.Cancel,
         QtGui.QMessageBox.Cancel)
     if retval != QtGui.QMessageBox.Yes:
         return
     # check value exceeds balance
     currency = collections.defaultdict(Decimal)
     for recipient in data:
         currency[recipient['moniker']] += recipient['value']
     for moniker, value in currency.items():
         if value > wallet.get_available_balance(moniker):
             QtGui.QMessageBox.warning(
                 self, 'Send coins',
                 'The amount for <b>%s</b> exceeds your available balance.'
                 % moniker, QtGui.QMessageBox.Ok)
             return
     wallet.send_coins(data)
     self.parent().parent().parent().update()
Beispiel #39
0
 def btnSendClicked(self):
     entries = [self.entries.itemAt(i).widget()
                 for i in xrange(self.entries.count())]
     if not all([entry.isValid() for entry in entries]):
         return
     data = [entry.getData() for entry in entries]
     message = 'Are you sure you want to send'
     for recipient in data:
         asset = wallet.get_asset_definition(recipient['moniker'])
         value = asset.format_value(recipient['value'])
         message += '<br><b>{value} {moniker}</b> to {address}'.format(**{
             'value': value,
             'moniker': 'BTC' if recipient['moniker'] == 'bitcoin' \
                 else recipient['moniker'],
             'address': recipient['address'],
         })
     message += '?'
     retval = QtGui.QMessageBox.question(
         self, 'Confirm send coins',
         message,
         QtGui.QMessageBox.Yes | QtGui.QMessageBox.Cancel,
         QtGui.QMessageBox.Cancel)
     if retval != QtGui.QMessageBox.Yes:
         return
     # check value exceeds balance
     currency = collections.defaultdict(float)
     for recipient in data:
         currency[recipient['moniker']] += recipient['value']
     for moniker, value in currency.items():
         if value > wallet.get_balance(moniker):
             QtGui.QMessageBox.warning(
                 self, 'Send coins',
                 'The amount for <b>%s</b> exceeds your balance.' % moniker,
                 QtGui.QMessageBox.Ok)
             return
     wallet.send_coins(data)
     self.parent().parent().parent().update()
Beispiel #40
0
 def getData(self):
     moniker = str(self.cbMoniker.currentText())
     asset = wallet.get_asset_definition(moniker)
     value = asset.parse_value(str(self.edtAmount.value()))
     return {"address": str(self.edtAddress.text()), "value": value, "moniker": moniker}