@@ -247,34 +247,33 @@ def get_onekey_features() -> OnekeyFeatures:
247247async def handle_Initialize (
248248 ctx : wire .Context | wire .QRContext , msg : Initialize
249249) -> Features :
250- if hasattr (msg , "is_contains_attach" ) and msg .is_contains_attach is not None :
250+ has_attach = (
251+ hasattr (msg , "is_contains_attach" ) and msg .is_contains_attach is not None
252+ )
253+ if has_attach :
251254 storage .cache .set (storage .cache .APP_COMMON_CLIENT_CONTAINS_ATTACH , b"\x01 " )
252255 else :
253256 storage .cache .delete (storage .cache .APP_COMMON_CLIENT_CONTAINS_ATTACH )
257+ ps_raw = getattr (msg , "passphrase_state" , None )
258+ if isinstance (ps_raw , bytes ):
259+ passphrase_state = ps_raw .decode () if ps_raw else None
260+ elif isinstance (ps_raw , str ):
261+ passphrase_state = ps_raw
262+ else :
263+ passphrase_state = None
254264
255- if (
256- hasattr (msg , "passphrase_state" )
257- and msg .passphrase_state is not None
258- and msg .passphrase_state != ""
259- and se_thd89 .check_passphrase_btc_test_address (
260- msg .passphrase_state
261- if isinstance (msg .passphrase_state , str )
262- else msg .passphrase_state .decode ()
263- )
265+ session_id_in_msg = getattr (msg , "session_id" , None )
266+ if passphrase_state and se_thd89 .check_passphrase_btc_test_address (
267+ passphrase_state
264268 ):
265269 session_id = storage .cache .start_session ()
266- elif msg .session_id is not None :
267- if (
268- not hasattr (msg , "passphrase_state" )
269- or msg .passphrase_state is None
270- or msg .passphrase_state == ""
271- ):
272- session_id = storage .cache .start_session ()
273- else :
274- session_id = storage .cache .start_session (msg .session_id )
275- else :
270+ elif has_attach and session_id_in_msg is not None and passphrase_state is None :
276271 session_id = storage .cache .start_session ()
272+ else :
273+ session_id = storage .cache .start_session (session_id_in_msg )
274+
277275 if not utils .BITCOIN_ONLY :
276+
278277 if utils .USE_THD89 :
279278 if msg .derive_cardano is not None and msg .derive_cardano :
280279 state = se_thd89 .get_session_state ()
0 commit comments