1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-26 01:18:28 +00:00

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

View File

@ -12,7 +12,7 @@ from trezor.ui.confirm import HoldToConfirmDialog
from trezor.ui.keyboard import MnemonicKeyboard from trezor.ui.keyboard import MnemonicKeyboard
from trezor.ui.scroll import Scrollpage, animate_swipe, paginate from trezor.ui.scroll import Scrollpage, animate_swipe, paginate
from trezor.ui.text import Text 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 import storage
from apps.common.confirm import require_confirm 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: async def check_mnemonic(ctx, mnemonic: str) -> bool:
words = mnemonic.split() words = mnemonic.split()
index = random.uniform(len(words) // 2) # first half 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]: if result != words[index]:
return False return False
index = len(words) // 2 + random.uniform(len(words) // 2) # second half 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] return result == words[index]

View File

@ -34,3 +34,7 @@ def format_amount(amount, decimals):
if amount.endswith('.'): if amount.endswith('.'):
amount = amount[:-1] amount = amount[:-1]
return amount 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')