mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-19 12:58:13 +00:00
nem: properties in swiping pages
This commit is contained in:
parent
9f4cef923b
commit
c425a8baf9
@ -1,7 +1,9 @@
|
||||
from apps.common.confirm import *
|
||||
from trezor import ui
|
||||
from trezor.messages import ButtonRequestType
|
||||
from trezor.messages.NEMMosaicDefinition import NEMMosaicDefinition
|
||||
from trezor.ui.text import Text
|
||||
from trezor.ui.scroll import Scrollpage, animate_swipe, paginate
|
||||
from trezor.utils import chunks, format_amount, split_words
|
||||
from .helpers import *
|
||||
|
||||
@ -22,10 +24,55 @@ async def require_confirm_action(ctx, action: str):
|
||||
await require_confirm(ctx, content, ButtonRequestType.ConfirmOutput)
|
||||
|
||||
|
||||
@ui.layout
|
||||
async def _show_page(page: int, page_count: int, content):
|
||||
content = Scrollpage(content[page], page, page_count)
|
||||
if page + 1 == page_count:
|
||||
await ConfirmDialog(content)
|
||||
else:
|
||||
content.render()
|
||||
await animate_swipe()
|
||||
|
||||
|
||||
async def require_confirm_properties(ctx, definition: NEMMosaicDefinition):
|
||||
properties = _get_mosaic_properties(definition)
|
||||
first_page = const(0)
|
||||
paginator = paginate(_show_page, len(properties), first_page, properties)
|
||||
await ctx.wait(paginator)
|
||||
|
||||
|
||||
def _get_mosaic_properties(definition: NEMMosaicDefinition):
|
||||
properties = []
|
||||
if definition.description:
|
||||
t = Text('Confirm properties', ui.ICON_SEND,
|
||||
ui.BOLD, 'Description:',
|
||||
ui.NORMAL, definition.description)
|
||||
properties.append(t)
|
||||
if definition.transferable:
|
||||
transferable = 'Yes'
|
||||
else:
|
||||
transferable = 'No'
|
||||
t = Text('Confirm properties', ui.ICON_SEND,
|
||||
ui.BOLD, 'Transferable?',
|
||||
ui.NORMAL, transferable)
|
||||
properties.append(t)
|
||||
if definition.mutable_supply:
|
||||
imm = 'mutable'
|
||||
else:
|
||||
imm = 'immutable'
|
||||
if definition.supply:
|
||||
t = Text('Confirm properties', ui.ICON_SEND,
|
||||
ui.BOLD, 'Initial supply:',
|
||||
ui.NORMAL, format_amount(definition.supply, definition.divisibility),
|
||||
ui.NORMAL, imm)
|
||||
properties.append(t)
|
||||
return properties
|
||||
|
||||
|
||||
async def require_confirm_final(ctx, action: str, fee: int):
|
||||
content = Text('Confirm sending', ui.ICON_SEND,
|
||||
ui.NORMAL, 'Create ', action,
|
||||
ui.BOLD, 'paying ' + format_amount(fee, NEM_MAX_DIVISIBILITY) + ' NEM',
|
||||
ui.BOLD, 'paying ' + format_amount(fee, NEM_MAX_DIVISIBILITY) + ' XEM',
|
||||
ui.NORMAL, 'for transaction fee?',
|
||||
icon_color=ui.GREEN)
|
||||
await require_hold_to_confirm(ctx, content, ButtonRequestType.SignTx) # we use SignTx, not ConfirmOutput, for compatibility with T1
|
||||
|
@ -35,13 +35,7 @@ async def nem_sign_tx(ctx, msg: NEMSignTx):
|
||||
async def _mosaic_creation(ctx, node, msg: NEMSignTx) -> bytearray:
|
||||
await require_confirm_action(ctx, 'Create mosaic "' + msg.mosaic_creation.definition.mosaic + '" under namespace "'
|
||||
+ msg.mosaic_creation.definition.namespace + '"?')
|
||||
if msg.mosaic_creation.definition.description:
|
||||
await require_confirm_action(ctx, 'Create mosaic with description: '
|
||||
+ msg.mosaic_creation.definition.description)
|
||||
if msg.mosaic_creation.definition.mutable_supply:
|
||||
await require_confirm_action(ctx, 'Create mosaic with mutable supply')
|
||||
else:
|
||||
await require_confirm_action(ctx, 'Create mosaic with immutable supply')
|
||||
await require_confirm_properties(ctx, msg.mosaic_creation.definition)
|
||||
await require_confirm_final(ctx, 'mosaic', msg.transaction.fee)
|
||||
|
||||
return nem_transaction_create_mosaic_creation(
|
||||
|
@ -87,7 +87,7 @@ def _validate_common(common: NEMTransactionCommon, inner: bool=False):
|
||||
else:
|
||||
raise ValueError('No ' + err + ' provided')
|
||||
|
||||
if common.signer:
|
||||
if common.signer is not None:
|
||||
_validate_public_key(common.signer, 'Invalid signer public key in inner transaction')
|
||||
|
||||
|
||||
@ -151,6 +151,11 @@ def _validate_mosaic_creation(mosaic_creation: NEMMosaicCreation, network: int):
|
||||
if mosaic_creation.definition.mosaic is None:
|
||||
raise ValueError('No mosaic name provided')
|
||||
|
||||
if mosaic_creation.definition.supply is not None and mosaic_creation.definition.divisibility is None:
|
||||
raise ValueError('Definition divisibility needs to be provided when supply is')
|
||||
if mosaic_creation.definition.supply is None and mosaic_creation.definition.divisibility is not None:
|
||||
raise ValueError('Definition supply needs to be provided when divisibility is')
|
||||
|
||||
if mosaic_creation.definition.levy is not None:
|
||||
if mosaic_creation.definition.fee is None:
|
||||
raise ValueError('No levy fee provided')
|
||||
@ -199,7 +204,7 @@ def _validate_transfer(transfer: NEMTransfer, network: int):
|
||||
if transfer.amount is None:
|
||||
raise ValueError('No amount provided')
|
||||
|
||||
if transfer.public_key:
|
||||
if transfer.public_key is not None:
|
||||
_validate_public_key(transfer.public_key, 'Invalid recipient public key')
|
||||
|
||||
if not nem.validate_address(transfer.recipient, network):
|
||||
|
Loading…
Reference in New Issue
Block a user