src/apps/management: use format_ordinal in reset and recovery workflows

This commit is contained in:
Pavol Rusnak 2018-02-25 15:05:32 +01:00
parent 872c44c477
commit 6fd7782ac7
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
3 changed files with 10 additions and 5 deletions

View File

@ -9,6 +9,7 @@ from trezor.pin import pin_to_int
from trezor.ui.keyboard import MnemonicKeyboard
from trezor.ui.text import Text
from trezor.ui.word_select import WordSelector
from trezor.utils import format_ordinal
from apps.common import storage
from apps.management.change_pin import request_pin_confirm
@ -71,8 +72,8 @@ async def request_mnemonic(ctx, count: int) -> str:
words = []
board = MnemonicKeyboard()
for i in range(0, count):
board.prompt = 'Type %s. word' % (i + 1)
for i in range(count):
board.prompt = 'Type the %s word:' % format_ordinal(i + 1)
word = await board
words.append(word)

View File

@ -12,7 +12,7 @@ from trezor.ui.confirm import HoldToConfirmDialog
from trezor.ui.keyboard import MnemonicKeyboard
from trezor.ui.scroll import Scrollpage, animate_swipe, paginate
from trezor.ui.text import Text
from trezor.utils import chunks
from trezor.utils import chunks, format_ordinal
from apps.common import storage
from apps.common.confirm import require_confirm
@ -178,9 +178,9 @@ async def show_mnemonic_page(page: int, page_count: int, pages: list):
async def check_mnemonic(ctx, mnemonic: str) -> bool:
words = mnemonic.split()
index = random.uniform(len(words) // 2) # first half
result = await MnemonicKeyboard('Type %s. word' % (index + 1))
result = await MnemonicKeyboard('Type the %s word:' % format_ordinal(index + 1))
if result != words[index]:
return False
index = len(words) // 2 + random.uniform(len(words) // 2) # second half
result = await MnemonicKeyboard('Type %s. word' % (index + 1))
result = await MnemonicKeyboard('Type the %s word:' % format_ordinal(index + 1))
return result == words[index]

View File

@ -34,3 +34,7 @@ def format_amount(amount, decimals):
if amount.endswith('.'):
amount = amount[:-1]
return amount
def format_ordinal(number):
return str(number) + {1: 'st', 2: 'nd', 3: 'rd'}.get(4 if 10 <= number % 100 < 20 else number % 10, 'th')