Skip to content

Commit

Permalink
Merge pull request #14 from tadeubas/develop_rc
Browse files Browse the repository at this point in the history
Removed code duplicates
  • Loading branch information
odudex authored Aug 24, 2023
2 parents d350667 + fb7afcb commit 5879807
Show file tree
Hide file tree
Showing 13 changed files with 1,200 additions and 1,289 deletions.
1 change: 0 additions & 1 deletion i18n/translations/de-DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@
"Failed to store mnemonic": "Mnemonic konnte nicht gespeichert werden",
"Fee: ": "Gebühr: ",
"Feed Rate": "Vorschubgeschwindigkeit",
"File selected:\n\n%s": "Ausgewählte Datei:\n\n%s",
"Filename": "Dateiname",
"Filename %s exists on SD card, overwrite?": "Dateiname %s existiert auf SD-Karte, überschreiben?",
"Fingerprint: %s": "Fingerabdruck: %s",
Expand Down
1 change: 0 additions & 1 deletion i18n/translations/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@
"Failed to store mnemonic": "Failed to store mnemonic",
"Fee: ": "Fee: ",
"Feed Rate": "Feed Rate",
"File selected:\n\n%s": "File selected:\n\n%s",
"Filename": "Filename",
"Filename %s exists on SD card, overwrite?": "Filename %s exists on SD card, overwrite?",
"Fingerprint: %s": "Fingerprint: %s",
Expand Down
1 change: 0 additions & 1 deletion i18n/translations/es-MX.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@
"Failed to store mnemonic": "No pudo almacenar mnemonic",
"Fee: ": "Comisión: ",
"Feed Rate": "Tasa de alimentación",
"File selected:\n\n%s": "Archivo seleccionado:\n\n%s",
"Filename": "Nombre del archivo",
"Filename %s exists on SD card, overwrite?": "El nombre de archivo %s existe en la tarjeta SD, ¿sobrescribir?",
"Fingerprint: %s": "Huella Dactilar: %s",
Expand Down
1 change: 0 additions & 1 deletion i18n/translations/fr-FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@
"Failed to store mnemonic": "Échec de stocker mnémonique",
"Fee: ": "Frais: ",
"Feed Rate": "Taux d'alimentation",
"File selected:\n\n%s": "Fichier sélectionné :\n\n%s",
"Filename": "Nom de fichier",
"Filename %s exists on SD card, overwrite?": "Le nom de fichier %s existe sur la carte SD, écraser ?",
"Fingerprint: %s": "Empreinte Digitale: %s",
Expand Down
1 change: 0 additions & 1 deletion i18n/translations/nl-NL.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@
"Failed to store mnemonic": "Geheugensteun opslaan is niet gelukt",
"Fee: ": "Tarief: ",
"Feed Rate": "Voedingssnelheid",
"File selected:\n\n%s": "Bestand geselecteerd:\n\n%s",
"Filename": "Bestandsnaam",
"Filename %s exists on SD card, overwrite?": "Bestandsnaam %s OVERSCHRIJVEN op SD kaart?",
"Fingerprint: %s": "Vingerafdruk: %s",
Expand Down
1 change: 0 additions & 1 deletion i18n/translations/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@
"Failed to store mnemonic": "Falhou ao armazenar mnemônico",
"Fee: ": "Taxa: ",
"Feed Rate": "Taxa de Alimentação",
"File selected:\n\n%s": "Arquivo selecionado:\n\n%s",
"Filename": "Nome do arquivo",
"Filename %s exists on SD card, overwrite?": "O nome do arquivo %s existe no cartão SD, substituir?",
"Fingerprint: %s": "Impressão digital: %s",
Expand Down
1 change: 0 additions & 1 deletion i18n/translations/vi-VN.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@
"Failed to store mnemonic": "Không lưu trữ MNemonic",
"Fee: ": "Phí: ",
"Feed Rate": "Tỷ lệ thức ăn",
"File selected:\n\n%s": "Tệp được chọn:\n\n%s",
"Filename": "Tên tệp",
"Filename %s exists on SD card, overwrite?": "Tên tệp %s tồn tại trên thẻ SD, ghi đè lên?",
"Fingerprint: %s": "Dấu vân tay: %s",
Expand Down
22 changes: 18 additions & 4 deletions src/krux/pages/encryption_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def __init__(self, ctx):
super().__init__(ctx, None)
self.ctx = ctx

def load_from_storage(self):
def load_from_storage(self, delete_opt=False):
"""Lists all encrypted mnemonics stored is flash and SD card"""
from ..encryption import MnemonicStorage

Expand All @@ -247,17 +247,21 @@ def load_from_storage(self):
mnemonic_ids_menu.append(
(
mnemonic_id + "(flash)",
lambda m_id=mnemonic_id: self._load_encrypted_mnemonic(m_id),
lambda m_id=mnemonic_id: self._delete_encrypted_mnemonic(m_id)
if delete_opt
else self._load_encrypted_mnemonic(m_id),
)
)
if has_sd:
for mnemonic_id in sd_mnemonics:
mnemonic_ids_menu.append(
(
mnemonic_id + "(SD card)",
lambda m_id=mnemonic_id: self._load_encrypted_mnemonic(
lambda m_id=mnemonic_id: self._delete_encrypted_mnemonic(
m_id, sd_card=True
),
)
if delete_opt
else self._load_encrypted_mnemonic(m_id, sd_card=True),
)
)
mnemonic_ids_menu.append((t("Back"), lambda: MENU_EXIT))
Expand Down Expand Up @@ -289,3 +293,13 @@ def _load_encrypted_mnemonic(self, mnemonic_id, sd_card=False):
raise ValueError(t("Failed to decrypt"))
del mnemonic_storage
return words

def _delete_encrypted_mnemonic(self, mnemonic_id, sd_card=False):
"""Deletes a mnemonic"""
from ..encryption import MnemonicStorage

mnemonic_storage = MnemonicStorage()
self.ctx.display.clear()
if self.prompt(t("Delete %s?" % mnemonic_id), self.ctx.display.height() // 2):
mnemonic_storage.del_mnemonic(mnemonic_id, sd_card)
del mnemonic_storage
23 changes: 15 additions & 8 deletions src/krux/pages/files_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

import time
import uos
import board
import gc
from . import Page, Menu, MENU_EXIT, MENU_CONTINUE
Expand Down Expand Up @@ -121,6 +119,19 @@ def show_file_details(self, file):
if SDHandler.dir_exists(file):
return MENU_EXIT

self.display_file(file)
self.ctx.input.wait_for_button()
# if self.prompt(t("Delete File?"), self.ctx.display.bottom_prompt_line):
# with SDHandler() as sd:
# sd.delete(file)
# return MENU_EXIT
return MENU_CONTINUE

def display_file(self, file):
"""Display the file details on the device's screen"""
import uos
import time

stats = uos.stat(file)
size = stats[6] / 1024
size_deximal_places = str(int(size * 100))[-2:]
Expand All @@ -145,9 +156,5 @@ def show_file_details(self, file):
+ "%s-%s-%s %s:%s"
% (modified[0], modified[1], modified[2], modified[3], modified[4])
)
self.ctx.input.wait_for_button()
# if self.prompt(t("Delete File?"), self.ctx.display.bottom_prompt_line):
# with SDHandler() as sd:
# sd.delete(file)
# return MENU_EXIT
return MENU_CONTINUE

return file
56 changes: 4 additions & 52 deletions src/krux/pages/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,6 @@
)
from ..sd_card import SDHandler


STANDARD_MODE = 0
LINE_MODE = 1
ZOOMED_R_MODE = 2
REGION_MODE = 3
TRANSCRIBE_MODE = 4

# to start xpub value without the xpub/zpub/ypub prefix
WALLET_XPUB_START = 4
# len of the xpub to show
Expand Down Expand Up @@ -304,8 +297,6 @@ def sign_psbt(self):
if self.prompt(
t("Load PSBT from SD card?"), self.ctx.display.height() // 2
):
import uos
import time
from .files_manager import FileManager

file_manager = FileManager(self.ctx)
Expand All @@ -314,43 +305,7 @@ def sign_psbt(self):
)

if psbt_filename:
stats = uos.stat(psbt_filename)
size = stats[6] / 1024
size_deximal_places = str(int(size * 100))[-2:]
created = time.localtime(stats[9])
modified = time.localtime(stats[8])

psbt_filename = psbt_filename[4:] # remove "/sd/" prefix
self.ctx.display.clear()
self.ctx.display.draw_hcentered_text(
psbt_filename
+ "\n\n"
+ t("Size: ")
+ "{:,}".format(int(size))
+ "."
+ size_deximal_places
+ " KB"
+ "\n\n"
+ t("Created: ")
+ "%s-%s-%s %s:%s"
% (
created[0],
created[1],
created[2],
created[3],
created[4],
)
+ "\n\n"
+ t("Modified: ")
+ "%s-%s-%s %s:%s"
% (
modified[0],
modified[1],
modified[2],
modified[3],
modified[4],
)
)
psbt_filename = file_manager.display_file(psbt_filename)

if self.prompt(
t("Load?"), self.ctx.display.bottom_prompt_line
Expand Down Expand Up @@ -467,13 +422,10 @@ def sign_message(self):
message_filename = file_manager.select_file()

if message_filename:
self.ctx.display.clear()
self.ctx.display.draw_hcentered_text(
t("File selected:\n\n%s") % message_filename
message_filename = file_manager.display_file(
message_filename
)
message_filename = message_filename[
4:
] # remove "/sd/" prefix

if self.prompt(
t("Load?"), self.ctx.display.bottom_prompt_line
):
Expand Down
14 changes: 0 additions & 14 deletions src/krux/pages/keypads.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,8 @@
)
from ..display import DEFAULT_PADDING

MENU_CONTINUE = 0
MENU_EXIT = 1
MENU_SHUTDOWN = 2

ESC_KEY = 1
FIXED_KEYS = 3 # 'More' key only appears when there are multiple keysets

ANTI_GLARE_WAIT_TIME = 500
QR_CODE_STEP_TIME = 100
CAMERA_INIT_TIME = 1000

LETTERS = "abcdefghijklmnopqrstuvwxyz"
UPPERCASE_LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
NUM_SPECIAL_1 = "0123456789 !#$%&'()*"
NUM_SPECIAL_2 = '+,-./:;<=>?@[\\]^_"{|}~'


class Keypad:
"""Controls keypad creation and management"""
Expand Down
46 changes: 6 additions & 40 deletions src/krux/pages/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,48 +101,14 @@ def sd_check(self):

def del_stored_mnemonic(self):
"""Lists and allow deletion of stored mnemonics"""
from ..encryption import MnemonicStorage
from .encryption_ui import LoadEncryptedMnemonic

encrypted_mnemonics = LoadEncryptedMnemonic(self.ctx)
while True:
mnemonic_storage = MnemonicStorage()
mnemonic_ids_menu = []
has_sd = mnemonic_storage.has_sd_card
mnemonics = mnemonic_storage.list_mnemonics()
sd_mnemonics = mnemonic_storage.list_mnemonics(sd_card=True)
del mnemonic_storage

for mnemonic_id in mnemonics:
mnemonic_ids_menu.append(
(
mnemonic_id + "(flash)",
lambda m_id=mnemonic_id: self._delete_encrypted_mnemonic(m_id),
)
)
if has_sd:
for mnemonic_id in sd_mnemonics:
mnemonic_ids_menu.append(
(
mnemonic_id + "(SD card)",
lambda m_id=mnemonic_id: self._delete_encrypted_mnemonic(
m_id, sd_card=True
),
)
)
mnemonic_ids_menu.append((t("Back"), lambda: MENU_EXIT))
submenu = Menu(self.ctx, mnemonic_ids_menu)
index, _ = submenu.run_loop()
if index == len(submenu.menu) - 1:
return MENU_CONTINUE

def _delete_encrypted_mnemonic(self, mnemonic_id, sd_card=False):
"""Deletes a mnemonic"""
from ..encryption import MnemonicStorage

mnemonic_storage = MnemonicStorage()
self.ctx.display.clear()
if self.prompt(t("Delete %s?" % mnemonic_id), self.ctx.display.height() // 2):
mnemonic_storage.del_mnemonic(mnemonic_id, sd_card)
del mnemonic_storage
ret = encrypted_mnemonics.load_from_storage(delete_opt=True)
if ret == MENU_CONTINUE:
del encrypted_mnemonics
return ret

def print_test(self):
"""Handler for the 'Print Test QR' menu item"""
Expand Down
Loading

0 comments on commit 5879807

Please sign in to comment.