def update_address(self): self.show_loader(title="Deriving address...") if self.idx > 0: self.prv.set_state(lv.btn.STATE.REL) else: self.prv.set_state(lv.btn.STATE.INA) addr, gap = self.wallet.get_address(self.idx, network=self.network, change=self.change) prefix = "Change" if self.change else "Receiving" note = "%s address #%d" % (prefix, self.idx) self.note.set_text(note) self.message.set_text(format_addr(addr, words=4)) self.qr.set_text("bitcoin:" + addr) if self.idx > gap: self.warning.set_text("This address exceeds the gap limit.\n" "Your watching wallet may not track balance " "received to it!") elif self.idx < self.wallet.unused_recv: self.warning.set_text("This address may have been used before.\n" "Reusing it would diminish your privacy!") else: self.warning.set_text("") self.hide_loader()
async def check_unknown_assets(self, meta, show_screen): unknown_assets = {sc["raw_asset"] for sc in (meta["inputs"]+meta["outputs"]) if "raw_asset" in sc} if len(unknown_assets) == 0: return scr = Prompt( "Warning!", "\nUnknown assets in the transaction!\n\n\n" "Number of unknown assets: %d\n\n" "Do you want to label them?\n" "Otherwise they will be rendered\nwith partial hex id." % len(unknown_assets), ) if await show_screen(scr): for asset in unknown_assets: # return False if the user cancelled scr = InputScreen("Asset\n\n"+format_addr(hexlify(bytes(reversed(asset))).decode(), letters=8, words=2), note="\nChoose a label for unknown asset.\nBetter to keep it short, like LBTC or LDIY") scr.ta.set_pos(190, 350) scr.ta.set_width(100) lbl = await show_screen(scr) # if user didn't label the asset - go to the next one if not lbl: continue else: self.assets[asset] = lbl self.save_assets() # replace labels we just saved for sc in meta["inputs"] + meta["outputs"]: if sc.get("raw_asset"): sc["asset"] = self.asset_label(sc["raw_asset"])
def __init__(self, wallet, network, idx=None, branch_index=0): self.wallet = wallet self.network = network self.idx = wallet.unused_recv addr, gap = wallet.get_address(self.idx, network=network, branch_index=branch_index) super().__init__( " " + wallet.name + " #708092 " + lv.SYMBOL.EDIT, format_addr(addr, words=4), "bitcoin:" + addr, qr_width=350, ) self.title.set_recolor(True) self.title.set_click(True) self.title.set_event_cb(on_release(self.rename)) self.policy = add_label(wallet.policy, y=55, style="hint", scr=self) style = lv.style_t() lv.style_copy(style, self.message.get_style(0)) style.text.font = lv.font_roboto_mono_22 self.message.set_style(0, style) # index self.branch_index = branch_index self.note = add_label("%s address #%d" % (self.prefix, self.idx), y=80, style="hint", scr=self) self.qr.align(self.note, lv.ALIGN.OUT_BOTTOM_MID, 0, 15) self.message.align(self.qr, lv.ALIGN.OUT_BOTTOM_MID, 0, 15) # warning label for address gap limit self.warning = add_label("", scr=self) self.warning.align(self.message, lv.ALIGN.OUT_BOTTOM_MID, 0, 15) style = lv.style_t() lv.style_copy(style, self.note.get_style(0)) style.text.color = lv.color_hex(0xFF9A00) self.warning.set_style(0, style) # delbtn = add_button("Delete wallet", on_release(cb_del), y=610) self.prv = add_button(lv.SYMBOL.LEFT, on_release(self.prev), scr=self) self.nxt = add_button(lv.SYMBOL.RIGHT, on_release(self.next), scr=self) if self.idx <= 0: self.prv.set_state(lv.btn.STATE.INA) self.prv.set_width(70) self.prv.align(self.qr, lv.ALIGN.OUT_LEFT_MID, -20, 0) self.prv.set_x(0) self.nxt.set_width(70) self.nxt.align(self.qr, lv.ALIGN.OUT_RIGHT_MID, 20, 0) self.nxt.set_x(HOR_RES - 70) self.menubtn = add_button(lv.SYMBOL.SETTINGS + " Settings", on_release(self.show_menu), scr=self) self.menubtn.align(self.close_button, lv.ALIGN.OUT_TOP_MID, 0, -20) if idx is not None: self.idx = idx self.update_address()
async def process_host_command(self, stream, show_screen): platform.delete_recursively(self.tempdir) cmd, stream = self.parse_stream(stream) if cmd == ADD_ASSET: arr = stream.read().decode().split(" ") if len(arr) != 2: raise WalletError("Invalid number of arguments. Usage: addasset <hex_asset> asset_lbl") hexasset, assetlbl = arr if await show_screen(Prompt("Import asset?", "Asset:\n\n"+format_addr(hexasset, letters=8, words=2)+"\n\nLabel: "+assetlbl)): asset = bytes(reversed(unhexlify(hexasset))) self.assets[asset] = assetlbl self.save_assets() return BytesIO(b"success"), {} elif cmd == DUMP_ASSETS: return BytesIO(self.assets_json()), {} else: stream.seek(0) return await super().process_host_command(stream, show_screen)