Skip to content

Commit

Permalink
code refactor and msg changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tadeubas committed May 14, 2024
1 parent dea4c1c commit 8cde85e
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 21 deletions.
2 changes: 1 addition & 1 deletion i18n/translations/de-DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@
"Wallet output descriptor loaded!": "Wallet Ausgabedeskriptor geladen!",
"Wallet output descriptor not found.": "Wallet Ausgabedeskriptor nicht gefunden.",
"Warning:": "Warnung:",
"Warning: Path mismatch": "Warnung: Pfad stimmt nicht überein",
"Path mismatch": "Pfad stimmt nicht überein",
"Wipe Device": "Gerät löschen",
"Wiping Device..": "Gerät wird gewischt..",
"Word %d": "Wort %d",
Expand Down
2 changes: 1 addition & 1 deletion i18n/translations/es-MX.json
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@
"Wallet output descriptor loaded!": "¡Se ha cargado el descriptor de salida de la cartera!",
"Wallet output descriptor not found.": "No se encontró el descriptor de salida de la cartera.",
"Warning:": "Advertencia:",
"Warning: Path mismatch": "Advertencia: La ruta no coincide",
"Path mismatch": "La ruta no coincide",
"Wipe Device": "Borrar Dispositivo",
"Wiping Device..": "Borrando dispositivo..",
"Word %d": "Palabra %d",
Expand Down
2 changes: 1 addition & 1 deletion i18n/translations/fr-FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@
"Wallet output descriptor loaded!": "Descripteur de sortie du portefeuille chargé!",
"Wallet output descriptor not found.": "Descripteur de sortie du portefeuille introuvable.",
"Warning:": "Avertissement:",
"Warning: Path mismatch": "Avertissement : non-concordance de chemin",
"Path mismatch": "non-concordance de chemin",
"Wipe Device": "Effacer l'appareil",
"Wiping Device..": "Effacement de l'appareil en cours...",
"Word %d": "Mot %d",
Expand Down
2 changes: 1 addition & 1 deletion i18n/translations/nl-NL.json
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@
"Wallet output descriptor loaded!": "Portemonnee descriptor geladen!",
"Wallet output descriptor not found.": "Portemonnee descriptor niet gevonden.",
"Warning:": "Waarschuwing:",
"Warning: Path mismatch": "Waarschuwing: pad komt niet overeen",
"Path mismatch": "pad komt niet overeen",
"Wipe Device": "Apparaat wissen",
"Wiping Device..": "Apparaat wissen...",
"Word %d": "Woord %d",
Expand Down
2 changes: 1 addition & 1 deletion i18n/translations/pl-PL.json
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@
"Wallet output descriptor loaded!": "Załadowany deskryptor wyjściowy portfela!",
"Wallet output descriptor not found.": "Nie znaleziono deskryptora wyjściowego portfela.",
"Warning:": "Ostrzeżenie:",
"Warning: Path mismatch": "Ostrzeżenie: Niezgodność ścieżki",
"Path mismatch": "Niezgodność ścieżki",
"Wipe Device": "Wyczyść urządzenie",
"Wiping Device..": "Czyszczenie urządzenia...",
"Word %d": "Słowo %d",
Expand Down
2 changes: 1 addition & 1 deletion i18n/translations/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@
"Wallet output descriptor loaded!": "Descritor de saída da carteira carregado!",
"Wallet output descriptor not found.": "O descritor de saída da carteira não foi encontrado.",
"Warning:": "Aviso:",
"Warning: Path mismatch": "Aviso: Incompatibilidade de caminho",
"Path mismatch": "Incompatibilidade de caminho",
"Wipe Device": "Limpar Dispositivo",
"Wiping Device..": "Limpando Dispositivo..",
"Word %d": "Palavra %d",
Expand Down
2 changes: 1 addition & 1 deletion i18n/translations/ru-RU.json
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@
"Wallet output descriptor loaded!": "Выходной дескриптор кошелька загружен!",
"Wallet output descriptor not found.": "Выходной дескриптор кошелька не найден.",
"Warning:": "Предупреждение:",
"Warning: Path mismatch": "Предупреждение: Несоответствие пути",
"Path mismatch": "Несоответствие пути",
"Wipe Device": "Очистка Устройства",
"Wiping Device..": "Очистка Устройства..",
"Word %d": "Слово %d",
Expand Down
2 changes: 1 addition & 1 deletion i18n/translations/tr-TR.json
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@
"Wallet output descriptor loaded!": "Cüzdan çıktı tanımlayıcısı yüklendi!",
"Wallet output descriptor not found.": "Cüzdan çıktı tanımlayıcısı bulunamadı.",
"Warning:": "Uyarı:",
"Warning: Path mismatch": "Uyarı: Yol uyuşmazlığı",
"Path mismatch": "Yol uyuşmazlığı",
"Wipe Device": "Cihazı Sil",
"Wiping Device..": "Cihaz Siliniyor..",
"Word %d": "Kelime %d",
Expand Down
2 changes: 1 addition & 1 deletion i18n/translations/vi-VN.json
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@
"Wallet output descriptor loaded!": "Đã tải bộ mô tả đầu ra của ví!",
"Wallet output descriptor not found.": "Không tìm thấy bộ mô tả đầu ra ví.",
"Warning:": "Cảnh báo:",
"Warning: Path mismatch": "Cảnh báo: Đường dẫn không khớp",
"Path mismatch": "Đường dẫn không khớp",
"Wipe Device": "Xóa dữ liệu trên thiết bị",
"Wiping Device..": "Đang xóa dữ liệu trên thiết bị..",
"Word %d": "Kí tự %d",
Expand Down
9 changes: 7 additions & 2 deletions src/krux/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def format_btc(amount):

return (
"{:,}".format(btc_without_decimal).replace(",", THOUSANDS_SEPARATOR)
+ get_decimal_separator()
+ render_decimal_separator()
+ btc_decimal_8char[:2]
+ THOUSANDS_SEPARATOR
+ btc_decimal_8char[2:5]
Expand All @@ -47,10 +47,15 @@ def format_btc(amount):
)


def get_decimal_separator():
def render_decimal_separator():
"""Return decimal separator depending on locale"""
decimal_separator = ","
if Settings().i18n.locale == "en-US":
decimal_separator = "."

return decimal_separator


def replace_decimal_separator(text):
"""Replace decimal separator in text depending on locale"""
return text.replace(".", render_decimal_separator())
15 changes: 13 additions & 2 deletions src/krux/pages/home_pages/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from ...display import BOTTOM_PROMPT_LINE
from ...qr import FORMAT_NONE, FORMAT_PMOFN
from ...krux_settings import t, Settings
from ...format import replace_decimal_separator
from .. import (
Page,
Menu,
Expand Down Expand Up @@ -279,7 +280,9 @@ def sign_psbt(self):
if path_mismatch:
self.ctx.display.clear()
self.ctx.display.draw_centered_text(
t("Warning: Path mismatch")
t("Warning:")
+ " "
+ t("Path mismatch")
+ "\n"
+ "Wallet: "
+ self.ctx.wallet.key.derivation_str()
Expand Down Expand Up @@ -332,7 +335,15 @@ def sign_psbt(self):
# Warn if fees greater than 30% of what is spent
if fee_percent >= 30.0:
self.ctx.display.clear()
self.ctx.display.draw_centered_text(t("Warning: Fees are greater than 30%"))
self.ctx.display.draw_centered_text(
t("Warning:")
+ " "
+ t("High fees!")
+ "\n"
+ replace_decimal_separator(("%.1f" % fee_percent))
+ t("% of the amount spent")
)

if not self.prompt(t("Proceed?"), BOTTOM_PROMPT_LINE):
return MENU_CONTINUE

Expand Down
18 changes: 10 additions & 8 deletions src/krux/psbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def _classify_output(self, out_policy, i, out):

def outputs(self):
"""Returns a list of messages describing where amounts are going"""
from .format import format_btc, get_decimal_separator
from .format import format_btc, replace_decimal_separator

inp_amount = 0
for inp in self.psbt.inputs:
Expand Down Expand Up @@ -289,14 +289,16 @@ def outputs(self):
fee = inp_amount - spend_amount - self_amount - change_amount

fee_percent = 0
fee_text = ""
if spend_amount > 0:
import math

fee_percent = math.ceil(fee * 100 / spend_amount * 10) / 10
fee_text = (" (%.1f%%)" % fee_percent).replace(".", get_decimal_separator())

resume_fee_str = t("Fee:") + (" ₿ %s" % format_btc(fee)) + fee_text
fee_percent = (((fee * 10000 // spend_amount) + 9) // 10) / 10

resume_fee_str = (
t("Fee:")
+ (" ₿ %s" % format_btc(fee))
+ " ("
+ replace_decimal_separator("%.1f" % fee_percent)
+ "%)"
)

messages = []
# first screen - resume
Expand Down

0 comments on commit 8cde85e

Please sign in to comment.