Skip to content

Commit

Permalink
fix: transfer ui optimization (#177)
Browse files Browse the repository at this point in the history
* style: transfer ui optimization

Signed-off-by: Lu1zz <[email protected]>

* fix: ton memo

Signed-off-by: Lu1zz <[email protected]>

---------

Signed-off-by: Lu1zz <[email protected]>
  • Loading branch information
Lu1zz authored Sep 2, 2024
1 parent cca4c8c commit 0dd31ba
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 26 deletions.
23 changes: 12 additions & 11 deletions common/protob/messages-ton.proto
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,18 @@ message TonSignMessage {
optional uint64 jetton_amount = 6; // jetton value (by nanojetton)
optional uint64 fwd_fee = 7 [default=0]; // toncoin is needed to transfer notification message
optional string comment = 8; // message comment
optional uint32 mode = 9 [default=3]; // message modes
required uint32 seqno = 10; // message sequence number
required uint64 expire_at = 11; // message expiration time
optional TonWalletVersion wallet_version = 12 [default=V4R2]; // ton wallet version
optional uint32 wallet_id = 13 [default=698983191]; // 698983191 is the default subwallet_id value
optional TonWorkChain workchain = 14 [default=BASECHAIN]; // 0: BaseChain, 1: MasterChain
optional bool is_bounceable = 15 [default=false]; // bounceable flag
optional bool is_testnet_only = 16 [default=false]; // testnet only flag
repeated string ext_destination = 17;
repeated uint64 ext_ton_amount = 18;
repeated string ext_payload = 19;
optional bool is_raw_data = 9 [default=false]; // raw data flag
optional uint32 mode = 10 [default=3]; // message modes
required uint32 seqno = 11; // message sequence number
required uint64 expire_at = 12; // message expiration time
optional TonWalletVersion wallet_version = 13 [default=V4R2]; // ton wallet version
optional uint32 wallet_id = 14 [default=698983191]; // 698983191 is the default subwallet_id value
optional TonWorkChain workchain = 15 [default=BASECHAIN]; // 0: BaseChain, 1: MasterChain
optional bool is_bounceable = 16 [default=false]; // bounceable flag
optional bool is_testnet_only = 17 [default=false]; // testnet only flag
repeated string ext_destination = 18;
repeated uint64 ext_ton_amount = 19;
repeated string ext_payload = 20;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions core/src/apps/ton/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def require_confirm_fee(
gas_limit: int = 0,
token: tokens.TokenInfo | None = None,
raw_data: bytes | None = None,
is_raw_data: bool = False,
) -> Awaitable[None]:
from trezor.ui.layouts.lvgl.altcoin import confirm_total_ton

Expand All @@ -37,6 +38,7 @@ def require_confirm_fee(
to_address,
format_ton_amount(value + fee_limit, None) if token is None else None,
raw_data=raw_data,
is_raw_data=is_raw_data,
)


Expand Down
10 changes: 8 additions & 2 deletions core/src/apps/ton/sign_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,14 @@ async def sign_message(
raise ValueError("Address cannot be None")
await confirm_unknown_token_transfer(ctx, msg.jetton_master_address)

amount = msg.jetton_amount if is_jetton_transfer else msg.ton_amount
if amount is None:
raise ValueError("Amount cannot be None")

show_details = await require_show_overview(
ctx,
recipient,
msg.ton_amount,
amount,
token,
)

Expand All @@ -77,9 +81,10 @@ async def sign_message(
ctx,
from_address=address,
to_address=recipient,
value=msg.ton_amount,
value=amount,
token=token,
raw_data=comment if comment else None,
is_raw_data=msg.is_raw_data,
)

await confirm_final(ctx, token.symbol if token else "TON")
Expand All @@ -105,6 +110,7 @@ async def sign_message(
seqno=msg.seqno,
expire_at=msg.expire_at,
payload=payload,
is_raw_data=msg.is_raw_data,
send_mode=msg.mode,
ext_to=None if is_jetton_transfer else msg.ext_destination,
ext_amount=None if is_jetton_transfer else msg.ext_ton_amount,
Expand Down
2 changes: 2 additions & 0 deletions core/src/apps/ton/tonsdk/contract/wallet/_wallet_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def create_transaction_digest(
seqno: int,
expire_at: int,
payload: Union[Cell, str, bytes, None] = None,
is_raw_data: bool = False,
send_mode=SendModeEnum.ignore_errors | SendModeEnum.pay_gas_separately,
state_init=None,
ext_to: List[str] = None,
Expand All @@ -56,6 +57,7 @@ def create_transaction_digest(
if payload:
if isinstance(payload, str):
# check payload type
# if is_raw_data:
if payload.startswith("b5ee9c72"):
payload_cell = Cell.one_from_boc(payload)
else:
Expand Down
21 changes: 19 additions & 2 deletions core/src/trezor/lvglui/scrs/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -1563,6 +1563,7 @@ def __init__(
token_id=None,
evm_chain_id=None,
raw_data=None,
is_raw_data=False,
sub_icon_path=None,
striped=False,
):
Expand Down Expand Up @@ -1653,10 +1654,11 @@ def __init__(
self.data = self.data_str
self.item_data = CardItem(
self.container,
_(i18n_keys.LIST_KEY__DATA__COLON),
_(i18n_keys.LIST_KEY__DATA__COLON) if self.data.startswith("b5ee9c72") else _(i18n_keys.LIST_KEY__MEMO__COLON),
self.data,
"A:/res/group-icon-data.png",
"A:/res/group-icon-data.png" if self.data.startswith("b5ee9c72") else "A:/res/group-icon-more.png",
)

if self.long_data:
self.show_full_data = NormalButton(
self.item_data.content, _(i18n_keys.BUTTON__VIEW_DATA)
Expand All @@ -1669,6 +1671,21 @@ def __init__(
self.show_full_data.remove_style(None, lv.PART.MAIN | lv.STATE.PRESSED)
self.show_full_data.add_event_cb(self.on_click, lv.EVENT.CLICKED, None)

def on_click(self, event_obj):
code = event_obj.code
target = event_obj.get_target()
if code == lv.EVENT.CLICKED:
if target == self.show_full_data:
PageAbleMessage(
_(i18n_keys.TITLE__VIEW_DATA),
self.data_str,
None,
primary_color=self.primary_color,
font=font_GeistMono28,
confirm_text=None,
cancel_text=None,
)


class TransactionDetailsTRON(FullSizeWindow):
def __init__(
Expand Down
2 changes: 2 additions & 0 deletions core/src/trezor/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -8709,6 +8709,7 @@ class TonSignMessage(protobuf.MessageType):
jetton_amount: "int | None"
fwd_fee: "int"
comment: "str | None"
is_raw_data: "bool"
mode: "int"
seqno: "int"
expire_at: "int"
Expand Down Expand Up @@ -8737,6 +8738,7 @@ def __init__(
jetton_amount: "int | None" = None,
fwd_fee: "int | None" = None,
comment: "str | None" = None,
is_raw_data: "bool | None" = None,
mode: "int | None" = None,
wallet_version: "TonWalletVersion | None" = None,
wallet_id: "int | None" = None,
Expand Down
2 changes: 2 additions & 0 deletions core/src/trezor/ui/layouts/lvgl/altcoin.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ async def confirm_total_ton(
token_id: int | None = None,
evm_chain_id: int | None = None,
raw_data: bytes | None = None,
is_raw_data: bool = False,
) -> None:
from trezor.lvglui.scrs.template import TransactionDetailsTON

Expand All @@ -187,6 +188,7 @@ async def confirm_total_ton(
token_id=str(token_id),
evm_chain_id=evm_chain_id,
raw_data=raw_data,
is_raw_data=is_raw_data,
sub_icon_path=ctx.icon_path,
striped=striped,
)
Expand Down
3 changes: 3 additions & 0 deletions python/src/trezorlib/cli/ton.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def get_address(client: "TrezorClient",
@click.option("-ja", "--jetton_amount", type=int)
@click.option("-f", "--fwd_fee", type=int)
@click.option("-c", "--comment", type=str)
@click.option("-r", "--is_raw_data", is_flag=True)
@click.option("-m", "--mode", type=int)
@click.option("-s", "--seqno", type=int, required=True)
@click.option("-e", "--expire_at", type=int, required=True)
Expand All @@ -99,6 +100,7 @@ def sign_message(client: "TrezorClient",
seqno: int,
expire_at: int,
comment: str,
is_raw_data: bool,
version: messages.TonWalletVersion,
wallet_id: int,
workchain: messages.TonWorkChain,
Expand All @@ -124,6 +126,7 @@ def sign_message(client: "TrezorClient",
seqno,
expire_at,
comment,
is_raw_data,
version,
wallet_id,
workchain,
Expand Down
25 changes: 14 additions & 11 deletions python/src/trezorlib/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -10799,17 +10799,18 @@ class TonSignMessage(protobuf.MessageType):
6: protobuf.Field("jetton_amount", "uint64", repeated=False, required=False),
7: protobuf.Field("fwd_fee", "uint64", repeated=False, required=False),
8: protobuf.Field("comment", "string", repeated=False, required=False),
9: protobuf.Field("mode", "uint32", repeated=False, required=False),
10: protobuf.Field("seqno", "uint32", repeated=False, required=True),
11: protobuf.Field("expire_at", "uint64", repeated=False, required=True),
12: protobuf.Field("wallet_version", "TonWalletVersion", repeated=False, required=False),
13: protobuf.Field("wallet_id", "uint32", repeated=False, required=False),
14: protobuf.Field("workchain", "TonWorkChain", repeated=False, required=False),
15: protobuf.Field("is_bounceable", "bool", repeated=False, required=False),
16: protobuf.Field("is_testnet_only", "bool", repeated=False, required=False),
17: protobuf.Field("ext_destination", "string", repeated=True, required=False),
18: protobuf.Field("ext_ton_amount", "uint64", repeated=True, required=False),
19: protobuf.Field("ext_payload", "string", repeated=True, required=False),
9: protobuf.Field("is_raw_data", "bool", repeated=False, required=False),
10: protobuf.Field("mode", "uint32", repeated=False, required=False),
11: protobuf.Field("seqno", "uint32", repeated=False, required=True),
12: protobuf.Field("expire_at", "uint64", repeated=False, required=True),
13: protobuf.Field("wallet_version", "TonWalletVersion", repeated=False, required=False),
14: protobuf.Field("wallet_id", "uint32", repeated=False, required=False),
15: protobuf.Field("workchain", "TonWorkChain", repeated=False, required=False),
16: protobuf.Field("is_bounceable", "bool", repeated=False, required=False),
17: protobuf.Field("is_testnet_only", "bool", repeated=False, required=False),
18: protobuf.Field("ext_destination", "string", repeated=True, required=False),
19: protobuf.Field("ext_ton_amount", "uint64", repeated=True, required=False),
20: protobuf.Field("ext_payload", "string", repeated=True, required=False),
}

def __init__(
Expand All @@ -10828,6 +10829,7 @@ def __init__(
jetton_amount: Optional["int"] = None,
fwd_fee: Optional["int"] = 0,
comment: Optional["str"] = None,
is_raw_data: Optional["bool"] = False,
mode: Optional["int"] = 3,
wallet_version: Optional["TonWalletVersion"] = TonWalletVersion.V4R2,
wallet_id: Optional["int"] = 698983191,
Expand All @@ -10848,6 +10850,7 @@ def __init__(
self.jetton_amount = jetton_amount
self.fwd_fee = fwd_fee
self.comment = comment
self.is_raw_data = is_raw_data
self.mode = mode
self.wallet_version = wallet_version
self.wallet_id = wallet_id
Expand Down
2 changes: 2 additions & 0 deletions python/src/trezorlib/ton.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def sign_message(client: "TrezorClient",
seqno: int,
expire_at: int,
comment: str="",
is_raw_data: bool = False,
version: messages.TonWalletVersion=messages.TonWalletVersion.V4R2,
wallet_id: int = 698983191,
workchain: messages.TonWorkChain=messages.TonWorkChain.BASECHAIN,
Expand All @@ -65,6 +66,7 @@ def sign_message(client: "TrezorClient",
seqno=seqno,
expire_at=expire_at,
version=version,
is_raw_data=is_raw_data,
wallet_id=wallet_id,
workchain=workchain,
bounceable=bounceable,
Expand Down

0 comments on commit 0dd31ba

Please sign in to comment.