fix labels plugin
This commit is contained in:
parent
2b0d92e767
commit
ec141ebb67
|
@ -288,7 +288,7 @@ class ElectrumWindow(QMainWindow):
|
||||||
self.update_buttons_on_seed()
|
self.update_buttons_on_seed()
|
||||||
self.update_console()
|
self.update_console()
|
||||||
|
|
||||||
run_hook('load_wallet')
|
run_hook('load_wallet', wallet)
|
||||||
|
|
||||||
|
|
||||||
def select_wallet_file(self):
|
def select_wallet_file(self):
|
||||||
|
|
|
@ -48,9 +48,9 @@ class Plugin(BasePlugin):
|
||||||
def init(self):
|
def init(self):
|
||||||
self.target_host = 'labelectrum.herokuapp.com'
|
self.target_host = 'labelectrum.herokuapp.com'
|
||||||
self.window = self.gui.main_window
|
self.window = self.gui.main_window
|
||||||
self.wallet = self.window.wallet
|
|
||||||
self.labels = self.wallet.labels
|
def load_wallet(self, wallet):
|
||||||
self.transactions = self.wallet.transactions
|
self.wallet = wallet
|
||||||
mpk = self.wallet.master_public_keys["m/0'/"][1]
|
mpk = self.wallet.master_public_keys["m/0'/"][1]
|
||||||
self.encode_password = hashlib.sha1(mpk).digest().encode('hex')[:32]
|
self.encode_password = hashlib.sha1(mpk).digest().encode('hex')[:32]
|
||||||
self.wallet_id = hashlib.sha256(mpk).digest().encode('hex')
|
self.wallet_id = hashlib.sha256(mpk).digest().encode('hex')
|
||||||
|
@ -170,7 +170,7 @@ class Plugin(BasePlugin):
|
||||||
def do_full_push(self):
|
def do_full_push(self):
|
||||||
try:
|
try:
|
||||||
bundle = {"labels": {}}
|
bundle = {"labels": {}}
|
||||||
for key, value in self.labels.iteritems():
|
for key, value in self.wallet.labels.iteritems():
|
||||||
encoded = self.encode(key)
|
encoded = self.encode(key)
|
||||||
bundle["labels"][encoded] = self.encode(value)
|
bundle["labels"][encoded] = self.encode(value)
|
||||||
|
|
||||||
|
@ -214,8 +214,8 @@ class Plugin(BasePlugin):
|
||||||
for label in response:
|
for label in response:
|
||||||
decoded_key = self.decode(label["external_id"])
|
decoded_key = self.decode(label["external_id"])
|
||||||
decoded_label = self.decode(label["text"])
|
decoded_label = self.decode(label["text"])
|
||||||
if force or not self.labels.get(decoded_key):
|
if force or not self.wallet.labels.get(decoded_key):
|
||||||
self.labels[decoded_key] = decoded_label
|
self.wallet.labels[decoded_key] = decoded_label
|
||||||
return True
|
return True
|
||||||
except socket.gaierror as e:
|
except socket.gaierror as e:
|
||||||
print_error('Error connecting to service: %s ' % e)
|
print_error('Error connecting to service: %s ' % e)
|
||||||
|
|
|
@ -102,6 +102,7 @@ class Plugin(BasePlugin):
|
||||||
|
|
||||||
def init(self):
|
def init(self):
|
||||||
self.window = self.gui.main_window
|
self.window = self.gui.main_window
|
||||||
|
self.wallet = self.window.wallet
|
||||||
|
|
||||||
self.qr_window = None
|
self.qr_window = None
|
||||||
self.merchant_name = self.config.get('merchant_name', 'Invoice')
|
self.merchant_name = self.config.get('merchant_name', 'Invoice')
|
||||||
|
@ -111,8 +112,9 @@ class Plugin(BasePlugin):
|
||||||
self.requested_amounts = {}
|
self.requested_amounts = {}
|
||||||
self.toggle_QR_window(True)
|
self.toggle_QR_window(True)
|
||||||
|
|
||||||
def load_wallet(self):
|
def load_wallet(self, wallet):
|
||||||
self.requested_amounts = self.window.wallet.storage.get('requested_amounts',{})
|
self.wallet = wallet
|
||||||
|
self.requested_amounts = self.wallet.storage.get('requested_amounts',{})
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
self.window.receive_list.setHeaderLabels([ _('Address'), _('Label'), _('Balance'), _('Tx')])
|
self.window.receive_list.setHeaderLabels([ _('Address'), _('Label'), _('Balance'), _('Tx')])
|
||||||
|
@ -138,7 +140,7 @@ class Plugin(BasePlugin):
|
||||||
item = self.window.receive_list.currentItem()
|
item = self.window.receive_list.currentItem()
|
||||||
if item:
|
if item:
|
||||||
address = str(item.text(1))
|
address = str(item.text(1))
|
||||||
label = self.window.wallet.labels.get(address)
|
label = self.wallet.labels.get(address)
|
||||||
amount, currency = self.requested_amounts.get(address, (None, None))
|
amount, currency = self.requested_amounts.get(address, (None, None))
|
||||||
self.qr_window.set_content( address, label, amount, currency )
|
self.qr_window.set_content( address, label, amount, currency )
|
||||||
|
|
||||||
|
@ -166,9 +168,11 @@ class Plugin(BasePlugin):
|
||||||
|
|
||||||
|
|
||||||
def current_item_changed(self, a):
|
def current_item_changed(self, a):
|
||||||
|
if not self.wallet:
|
||||||
|
return
|
||||||
if a is not None and self.qr_window and self.qr_window.isVisible():
|
if a is not None and self.qr_window and self.qr_window.isVisible():
|
||||||
address = str(a.text(0))
|
address = str(a.text(0))
|
||||||
label = self.window.wallet.labels.get(address)
|
label = self.wallet.labels.get(address)
|
||||||
try:
|
try:
|
||||||
amount, currency = self.requested_amounts.get(address, (None, None))
|
amount, currency = self.requested_amounts.get(address, (None, None))
|
||||||
except:
|
except:
|
||||||
|
@ -183,7 +187,7 @@ class Plugin(BasePlugin):
|
||||||
address = str( item.text(0) )
|
address = str( item.text(0) )
|
||||||
text = str( item.text(column) )
|
text = str( item.text(column) )
|
||||||
try:
|
try:
|
||||||
seq = self.window.wallet.get_address_index(address)
|
seq = self.wallet.get_address_index(address)
|
||||||
index = seq[1][1]
|
index = seq[1][1]
|
||||||
except:
|
except:
|
||||||
print "cannot get index"
|
print "cannot get index"
|
||||||
|
@ -201,12 +205,12 @@ class Plugin(BasePlugin):
|
||||||
currency = currency.upper()
|
currency = currency.upper()
|
||||||
|
|
||||||
self.requested_amounts[address] = (amount, currency)
|
self.requested_amounts[address] = (amount, currency)
|
||||||
self.window.wallet.storage.put('requested_amounts', self.requested_amounts, True)
|
self.wallet.storage.put('requested_amounts', self.requested_amounts, True)
|
||||||
|
|
||||||
label = self.window.wallet.labels.get(address)
|
label = self.wallet.labels.get(address)
|
||||||
if label is None:
|
if label is None:
|
||||||
label = self.merchant_name + ' - %04d'%(index+1)
|
label = self.merchant_name + ' - %04d'%(index+1)
|
||||||
self.window.wallet.labels[address] = label
|
self.wallet.labels[address] = label
|
||||||
|
|
||||||
if self.qr_window:
|
if self.qr_window:
|
||||||
self.qr_window.set_content( address, label, amount, currency )
|
self.qr_window.set_content( address, label, amount, currency )
|
||||||
|
|
Loading…
Reference in New Issue