@@ -50,11 +50,12 @@ import {
5050 startLnd ,
5151 stopLnd ,
5252 expressGraphSync ,
53- LND_FOLDER_MISSING_ERROR
53+ LND_FOLDER_MISSING_ERROR ,
54+ migrateBboltToSqlite
5455} from '../../utils/LndMobileUtils' ;
5556import { localeString , bridgeJavaStrings } from '../../utils/LocaleUtils' ;
5657import { isBatterySaverEnabled } from '../../utils/BatteryUtils' ;
57- import { IS_BACKED_UP_KEY } from '../../utils/MigrationUtils' ;
58+ import MigrationsUtils , { IS_BACKED_UP_KEY } from '../../utils/MigrationUtils' ;
5859import { protectedNavigation } from '../../utils/NavigationUtils' ;
5960import { isLightTheme , themeColor } from '../../utils/ThemeUtils' ;
6061import { restartNeeded } from '../../utils/RestartUtils' ;
@@ -136,6 +137,7 @@ interface WalletState {
136137 initialLoad : boolean ;
137138 loading : boolean ;
138139 pendingShareIntent ?: { qrData ?: string ; base64Image ?: string } ;
140+ migratingDatabase : boolean ;
139141}
140142
141143@inject (
@@ -177,7 +179,8 @@ export default class Wallet extends React.Component<WalletProps, WalletState> {
177179 unlocked : false ,
178180 initialLoad : true ,
179181 loading : false ,
180- pendingShareIntent : undefined
182+ pendingShareIntent : undefined ,
183+ migratingDatabase : false
181184 } ;
182185 this . pan = new Animated . ValueXY ( ) ;
183186 this . panResponder = PanResponder . create ( {
@@ -547,13 +550,63 @@ export default class Wallet extends React.Component<WalletProps, WalletState> {
547550 await CashuStore . initializeWallets ( ) ;
548551
549552 console . log ( 'lndDir' , lndDir ) ;
553+ const currLndDir = lndDir || 'lnd' ;
554+ const needsMigration =
555+ ! isSqlite &&
556+ ( await MigrationsUtils . checkBboltWalletExists (
557+ currLndDir ,
558+ isSqlite
559+ ) ) &&
560+ ! ( await MigrationsUtils . hasDatabaseMigrationBeenAttempted (
561+ currLndDir
562+ ) ) ;
563+
564+ if ( needsMigration ) {
565+ this . setState ( { migratingDatabase : true } ) ;
566+ try {
567+ const success = await migrateBboltToSqlite ( {
568+ lndDir : currLndDir ,
569+ isTestnet : embeddedLndNetwork === 'Testnet' ,
570+ walletPassword : walletPassword || ''
571+ } ) ;
572+
573+ if ( success ) {
574+ await MigrationsUtils . markDatabaseMigrationAttempted (
575+ currLndDir
576+ ) ;
577+ const nodes = settings ?. nodes || [ ] ;
578+ const nodeIndex = nodes . findIndex (
579+ ( n : any ) =>
580+ n . implementation === 'embedded-lnd' &&
581+ ( n . lndDir || 'lnd' ) === currLndDir
582+ ) ;
583+ if ( nodeIndex !== - 1 ) {
584+ const updatedNodes = [ ...nodes ] ;
585+ updatedNodes [ nodeIndex ] = {
586+ ...updatedNodes [ nodeIndex ] ,
587+ isSqlite : true
588+ } ;
589+ await updateSettings ( {
590+ nodes : updatedNodes
591+ } ) ;
592+ }
593+ }
594+ } catch ( error ) {
595+ console . error (
596+ 'Error during database migration:' ,
597+ error
598+ ) ;
599+ } finally {
600+ this . setState ( { migratingDatabase : false } ) ;
601+ }
602+ }
550603
551604 await initializeLnd ( {
552605 lndDir : lndDir || 'lnd' ,
553606 isTestnet : embeddedLndNetwork === 'Testnet' ,
554607 rescan,
555608 compactDb,
556- isSqlite
609+ isSqlite : needsMigration ? true : isSqlite
557610 } ) ;
558611 } catch ( error : any ) {
559612 console . log (
@@ -1383,7 +1436,8 @@ export default class Wallet extends React.Component<WalletProps, WalletState> {
13831436 padding : 8
13841437 } }
13851438 >
1386- { isMigrating
1439+ { isMigrating ||
1440+ this . state . migratingDatabase
13871441 ? localeString (
13881442 'views.Wallet.Wallet.migrating'
13891443 ) . replace ( 'Zeus' , 'ZEUS' )
0 commit comments