@@ -159,46 +159,48 @@ function SigningClientProvider({ children }: { children: React.ReactNode }) {
159159 if ( ! process . env . IS_TAURI && window . keplr ) return ;
160160
161161 try {
162- let mnemonic = getMnemonic ( ) ;
162+ let mnemonic : string | null = null ;
163163 let walletSource = 'existing' ;
164164 let accountName = 'Account 1' ;
165165
166- if ( ! mnemonic ) {
167- console . log ( '[Bootstrap] No existing wallet found, checking bootstrap...' ) ;
168- // Check for bootstrap.json from cyb-boot installer (Tauri only)
169- if ( process . env . IS_TAURI ) {
170- try {
171- const { invoke } = await import ( '@tauri-apps/api/core' ) ;
172- console . log ( '[Bootstrap] Invoking read_bootstrap...' ) ;
173- const bootstrap = await invoke ( 'read_bootstrap' ) as { mnemonic ?: string ; referrer ?: string ; name ?: string } | null ;
174- console . log ( '[Bootstrap] read_bootstrap result:' , bootstrap ? 'found' : 'null' ) ;
175- if ( bootstrap ?. mnemonic ) {
176- mnemonic = bootstrap . mnemonic ;
177- walletSource = 'cyb-boot' ;
178- if ( bootstrap . name ) {
179- accountName = bootstrap . name ;
180- }
181- console . log ( '[Bootstrap] Mnemonic imported from cyb-boot, name:' , accountName ) ;
182- if ( bootstrap . referrer ) {
183- const { saveReferrer } = await import ( 'src/pages/Mining/components/ReferralSection' ) ;
184- saveReferrer ( bootstrap . referrer ) ;
185- console . log ( '[Bootstrap] Referrer saved:' , bootstrap . referrer ) ;
186- } else {
187- console . log ( '[Bootstrap] No referrer in bootstrap' ) ;
188- }
166+ // Check bootstrap.json FIRST — it's an explicit user action (download from web)
167+ // and should override any existing wallet
168+ if ( process . env . IS_TAURI ) {
169+ try {
170+ const { invoke } = await import ( '@tauri-apps/api/core' ) ;
171+ console . log ( '[Bootstrap] Invoking read_bootstrap...' ) ;
172+ const bootstrap = await invoke ( 'read_bootstrap' ) as { mnemonic ?: string ; referrer ?: string ; name ?: string } | null ;
173+ console . log ( '[Bootstrap] read_bootstrap result:' , bootstrap ? 'found' : 'null' ) ;
174+ if ( bootstrap ?. mnemonic ) {
175+ mnemonic = bootstrap . mnemonic ;
176+ walletSource = 'cyb-boot' ;
177+ if ( bootstrap . name ) {
178+ accountName = bootstrap . name ;
179+ }
180+ console . log ( '[Bootstrap] Mnemonic imported from cyb-boot, name:' , accountName ) ;
181+ if ( bootstrap . referrer ) {
182+ const { saveReferrer } = await import ( 'src/pages/Mining/components/ReferralSection' ) ;
183+ saveReferrer ( bootstrap . referrer ) ;
184+ console . log ( '[Bootstrap] Referrer saved:' , bootstrap . referrer ) ;
185+ } else {
186+ console . log ( '[Bootstrap] No referrer in bootstrap' ) ;
189187 }
190- } catch ( err ) {
191- console . log ( '[Bootstrap] No bootstrap.json found (normal first launch):' , err ) ;
192188 }
189+ } catch ( err ) {
190+ console . log ( '[Bootstrap] No bootstrap.json found (normal first launch):' , err ) ;
193191 }
194- if ( ! mnemonic ) {
192+ }
193+
194+ if ( ! mnemonic ) {
195+ mnemonic = getMnemonic ( ) ;
196+ if ( mnemonic ) {
197+ console . log ( '[Bootstrap] Restored existing wallet from storage' ) ;
198+ } else {
195199 const { generateMnemonic } = await import ( 'src/utils/offlineSigner' ) ;
196200 mnemonic = await generateMnemonic ( ) ;
197201 walletSource = 'generated' ;
198202 console . log ( '[Bootstrap] Auto-generated new wallet' ) ;
199203 }
200- } else {
201- console . log ( '[Bootstrap] Restored existing wallet from storage' ) ;
202204 }
203205
204206 const mnemonicSigner = await getOfflineSignerFromMnemonic ( mnemonic ) ;
0 commit comments