Skip to content

Commit 03bf33c

Browse files
committed
Better UX when Trezor signing is cancelled by user
1 parent 5a1e5cf commit 03bf33c

1 file changed

Lines changed: 30 additions & 27 deletions

File tree

autonity_cli/auth.py

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -98,33 +98,36 @@ def sign_transaction(self, params: "TxParams") -> SignedTransaction:
9898
assert "to" in params
9999
assert "value" in params
100100
data_bytes = HexBytes(params["data"] if "data" in params else b"")
101-
if "gasPrice" in params and params["gasPrice"]:
102-
v_int, r_bytes, s_bytes = trezor_eth.sign_tx(
103-
self.client,
104-
self.path,
105-
nonce=cast(int, params["nonce"]),
106-
gas_price=cast(int, params["gasPrice"]),
107-
gas_limit=params["gas"],
108-
to=cast(str, params["to"]),
109-
value=cast(int, params["value"]),
110-
data=data_bytes,
111-
chain_id=params["chainId"],
112-
)
113-
else:
114-
assert "maxFeePerGas" in params
115-
assert "maxPriorityFeePerGas" in params
116-
v_int, r_bytes, s_bytes = trezor_eth.sign_tx_eip1559(
117-
self.client,
118-
self.path,
119-
nonce=cast(int, params["nonce"]),
120-
gas_limit=params["gas"],
121-
to=cast(str, params["to"]),
122-
value=cast(int, params["value"]),
123-
data=data_bytes,
124-
chain_id=params["chainId"],
125-
max_gas_fee=int(params["maxFeePerGas"]),
126-
max_priority_fee=int(params["maxPriorityFeePerGas"]),
127-
)
101+
try:
102+
if "gasPrice" in params and params["gasPrice"]:
103+
v_int, r_bytes, s_bytes = trezor_eth.sign_tx(
104+
self.client,
105+
self.path,
106+
nonce=cast(int, params["nonce"]),
107+
gas_price=cast(int, params["gasPrice"]),
108+
gas_limit=params["gas"],
109+
to=cast(str, params["to"]),
110+
value=cast(int, params["value"]),
111+
data=data_bytes,
112+
chain_id=params["chainId"],
113+
)
114+
else:
115+
assert "maxFeePerGas" in params
116+
assert "maxPriorityFeePerGas" in params
117+
v_int, r_bytes, s_bytes = trezor_eth.sign_tx_eip1559(
118+
self.client,
119+
self.path,
120+
nonce=cast(int, params["nonce"]),
121+
gas_limit=params["gas"],
122+
to=cast(str, params["to"]),
123+
value=cast(int, params["value"]),
124+
data=data_bytes,
125+
chain_id=params["chainId"],
126+
max_gas_fee=int(params["maxFeePerGas"]),
127+
max_priority_fee=int(params["maxPriorityFeePerGas"]),
128+
)
129+
except Cancelled as exc: # user cancelled optional passphrase prompt
130+
raise click.Abort() from exc
128131
r_int = to_int(r_bytes)
129132
s_int = to_int(s_bytes)
130133
filtered_tx = dict((k, v) for (k, v) in params.items() if k not in ("from"))

0 commit comments

Comments
 (0)