@@ -90,6 +90,12 @@ var DuelScreen = (function() {
9090 duelState . challengeData = challengeData || null ;
9191 duelState . phase = 'pre' ;
9292
93+ // For a brand-new outgoing duel we must not reuse a stale local secret
94+ // from an older attempt against the same opponent.
95+ if ( ! duelState . combatRef ) {
96+ _clearPersistedSecret ( ) ;
97+ }
98+
9399 // Try to restore secret from localStorage (survives page reload)
94100 _restoreSecret ( ) ;
95101
@@ -111,25 +117,39 @@ var DuelScreen = (function() {
111117 var saved = localStorage . getItem ( secretKey ) ;
112118 if ( ! saved ) return ;
113119 var data = JSON . parse ( saved ) ;
114- // Only restore if it matches current duel context
115- if ( data && data . secret && data . secret . hash ) {
116- if ( ( ! duelState . combatRef && data . opponent === duelState . opponent ) ||
117- ( duelState . combatRef && data . combatRef === duelState . combatRef ) ) {
118- duelState . strategySecret = data . secret ;
119- duelState . strategyRound = data . round || 1 ;
120- duelState . selectedIntent = data . secret . intent ;
121- duelState . currentRound = data . round || 1 ;
122- if ( duelState . combatRef ) {
123- duelState . phase = 'waiting' ;
124- }
125- console . log ( 'Duel secret restored from localStorage for round' , data . round || 1 ) ;
126- }
120+ if ( ! data || ! data . secret || ! data . secret . hash ) return ;
121+
122+ var shouldRestore = false ;
123+
124+ // Restore only for an already identified duel after reload.
125+ // For fresh outgoing duels without combatRef, stale secrets must not lock UI.
126+ if ( duelState . combatRef && data . combatRef === duelState . combatRef ) {
127+ shouldRestore = true ;
128+ }
129+
130+ if ( ! shouldRestore ) {
131+ return ;
127132 }
133+
134+ duelState . strategySecret = data . secret ;
135+ duelState . strategyRound = data . round || 1 ;
136+ duelState . selectedIntent = data . secret . intent ;
137+ duelState . currentRound = data . round || 1 ;
138+ duelState . phase = 'waiting' ;
139+ console . log ( 'Duel secret restored from localStorage for combat' , duelState . combatRef , 'round' , data . round || 1 ) ;
128140 } catch ( e ) {
129141 console . log ( 'Could not restore duel secret:' , e ) ;
130142 }
131143 }
132144
145+ function _clearPersistedSecret ( ) {
146+ try {
147+ localStorage . removeItem ( VizMagicConfig . STORAGE_PREFIX + 'duel_secret' ) ;
148+ } catch ( e ) {
149+ console . log ( 'Could not clear duel secret:' , e ) ;
150+ }
151+ }
152+
133153 function _renderPreDuel ( el ) {
134154 var t = Helpers . t ;
135155 var user = VizAccount . getCurrentUser ( ) ;
0 commit comments