@@ -128,7 +128,8 @@ import {
128128 addSpotBalanceToAccountState ,
129129 aggregateAccountStates ,
130130} from '../utils/accountUtils' ;
131- import { ensureError } from '../utils/errorUtils' ;
131+ import { ensureError , isKeyringLockedError } from '../utils/errorUtils' ;
132+ import { shouldDeferUnifiedAccountSetup } from '../utils/hyperLiquidAbstraction' ;
132133import {
133134 adaptAccountStateFromSDK ,
134135 adaptHyperLiquidLedgerUpdateToUserHistoryItem ,
@@ -627,7 +628,8 @@ export class HyperLiquidProvider implements PerpsProvider {
627628 const network = this . #clientService. isTestnetMode ( ) ? 'testnet' : 'mainnet' ;
628629
629630 // Check global cache first to avoid repeated signing requests
630- // This is CRITICAL for hardware wallets to prevent QR popup spam
631+ // This is CRITICAL for hardware wallets to prevent repeated signing prompts
632+ // while browsing.
631633 const cachedStatus = TradingReadinessCache . get ( network , userAddress ) ;
632634 if ( cachedStatus ?. attempted ) {
633635 this . #deps. debugLogger . log (
@@ -726,14 +728,14 @@ export class HyperLiquidProvider implements PerpsProvider {
726728 return ;
727729 }
728730
729- // Defer the user-signed transition until the user attempts an action.
731+ // Defer signing-backed transitions until the user attempts an action.
730732 // Cache is intentionally left untouched so the next entry re-evaluates;
731733 // the read-only userAbstraction call is cheap and gated by the in-flight
732734 // lock, preventing concurrent prompts.
733- if ( currentMode === 'dexAbstraction' && ! allowUserSigning ) {
735+ if ( shouldDeferUnifiedAccountSetup ( currentMode , allowUserSigning ) ) {
734736 this . #deps. debugLogger . log (
735- 'HyperLiquidProvider: Deferring dexAbstraction → unifiedAccount migration to action time' ,
736- { user : userAddress , network } ,
737+ 'HyperLiquidProvider: Deferring unified account migration to action time' ,
738+ { user : userAddress , network, mode : currentMode } ,
737739 ) ;
738740 completeInFlight ( ) ;
739741 return ;
@@ -927,10 +929,10 @@ export class HyperLiquidProvider implements PerpsProvider {
927929 }
928930
929931 // Attempt Unified Account migration as early as possible so users aren't
930- // blocked when they try to trade. Software-wallet dexAbstraction users can
931- // complete the one-time EIP-712 migration during initial setup so the first
932- // trade sees the unified balance. Hardware wallets remain deferred to
933- // action time to avoid QR / Ledger prompt spam while browsing.
932+ // blocked when they try to trade. Software wallets can complete the
933+ // signing-backed migration during initial setup so the first trade sees
934+ // the unified balance. Hardware wallets remain deferred to action time to
935+ // avoid repeated signing prompts while browsing.
934936 await this . #ensureUnifiedAccountEnabled( {
935937 allowUserSigning : ! this . #walletService. isSelectedHardwareWallet ( ) ,
936938 } ) ;
@@ -963,7 +965,7 @@ export class HyperLiquidProvider implements PerpsProvider {
963965 * - Builder fee approval (required for orders)
964966 * - Referral code setup (attribution)
965967 *
966- * These operations are DEFERRED from ensureReady() to avoid QR popup spam
968+ * These operations are DEFERRED from ensureReady() to avoid hardware wallet prompt spam
967969 * when users are just viewing the Perps section (critical for hardware wallets).
968970 *
969971 * Call this method before any trading operation (placeOrder, cancelOrder, etc.)
@@ -2542,11 +2544,12 @@ export class HyperLiquidProvider implements PerpsProvider {
25422544 const cacheKey = this . #getCacheKey( network , userAddress ) ;
25432545
25442546 // Check GLOBAL cache first to avoid repeated signing requests across reconnections
2545- // This is CRITICAL for hardware wallets to prevent QR popup spam
2547+ // This is CRITICAL for hardware wallets to prevent repeated signing prompts
2548+ // while browsing.
25462549 const globalCached = PerpsSigningCache . getBuilderFee ( network , userAddress ) ;
25472550 if ( globalCached ?. attempted ) {
25482551 this . #deps. debugLogger . log (
2549- '[ensureBuilderFeeApproval] Using global cache (prevents QR popup spam)' ,
2552+ '[ensureBuilderFeeApproval] Using global cache (prevents hardware wallet prompt spam)' ,
25502553 { network, success : globalCached . success } ,
25512554 ) ;
25522555 if ( globalCached . success ) {
@@ -8377,7 +8380,7 @@ export class HyperLiquidProvider implements PerpsProvider {
83778380 const globalCached = PerpsSigningCache . getReferral ( network , userAddress ) ;
83788381 if ( globalCached ?. attempted ) {
83798382 this . #deps. debugLogger . log (
8380- '[ensureReferralSet] Using global cache (prevents QR popup spam)' ,
8383+ '[ensureReferralSet] Using global cache (prevents hardware wallet prompt spam)' ,
83818384 { network, success : globalCached . success } ,
83828385 ) ;
83838386 return ;
0 commit comments