@@ -49,11 +49,12 @@ import {
4949 initializeLnd ,
5050 startLnd ,
5151 stopLnd ,
52- expressGraphSync
52+ expressGraphSync ,
53+ migrateBboltToSqlite
5354} from '../../utils/LndMobileUtils' ;
5455import { localeString , bridgeJavaStrings } from '../../utils/LocaleUtils' ;
5556import { isBatterySaverEnabled } from '../../utils/BatteryUtils' ;
56- import { IS_BACKED_UP_KEY } from '../../utils/MigrationUtils' ;
57+ import MigrationsUtils , { IS_BACKED_UP_KEY } from '../../utils/MigrationUtils' ;
5758import { protectedNavigation } from '../../utils/NavigationUtils' ;
5859import { isLightTheme , themeColor } from '../../utils/ThemeUtils' ;
5960import { restartNeeded } from '../../utils/RestartUtils' ;
@@ -129,6 +130,7 @@ interface WalletState {
129130 initialLoad : boolean ;
130131 loading : boolean ;
131132 pendingShareIntent ?: { qrData ?: string ; base64Image ?: string } ;
133+ migratingDatabase : boolean ;
132134}
133135
134136@inject (
@@ -169,7 +171,8 @@ export default class Wallet extends React.Component<WalletProps, WalletState> {
169171 unlocked : false ,
170172 initialLoad : true ,
171173 loading : false ,
172- pendingShareIntent : undefined
174+ pendingShareIntent : undefined ,
175+ migratingDatabase : false
173176 } ;
174177 this . pan = new Animated . ValueXY ( ) ;
175178 this . panResponder = PanResponder . create ( {
@@ -475,12 +478,63 @@ export default class Wallet extends React.Component<WalletProps, WalletState> {
475478 await CashuStore . initializeWallets ( ) ;
476479
477480 console . log ( 'lndDir' , lndDir ) ;
481+ const currLndDir = lndDir || 'lnd' ;
482+ const needsMigration =
483+ ! isSqlite &&
484+ ( await MigrationsUtils . checkBboltWalletExists (
485+ currLndDir ,
486+ isSqlite
487+ ) ) &&
488+ ! ( await MigrationsUtils . hasDatabaseMigrationBeenAttempted (
489+ currLndDir
490+ ) ) ;
491+
492+ if ( needsMigration ) {
493+ this . setState ( { migratingDatabase : true } ) ;
494+ try {
495+ const success = await migrateBboltToSqlite ( {
496+ lndDir : currLndDir ,
497+ isTestnet : embeddedLndNetwork === 'Testnet' ,
498+ walletPassword : walletPassword || ''
499+ } ) ;
500+
501+ if ( success ) {
502+ await MigrationsUtils . markDatabaseMigrationAttempted (
503+ currLndDir
504+ ) ;
505+ const nodes = settings ?. nodes || [ ] ;
506+ const nodeIndex = nodes . findIndex (
507+ ( n : any ) =>
508+ n . implementation === 'embedded-lnd' &&
509+ ( n . lndDir || 'lnd' ) === currLndDir
510+ ) ;
511+ if ( nodeIndex !== - 1 ) {
512+ const updatedNodes = [ ...nodes ] ;
513+ updatedNodes [ nodeIndex ] = {
514+ ...updatedNodes [ nodeIndex ] ,
515+ isSqlite : true
516+ } ;
517+ await updateSettings ( {
518+ nodes : updatedNodes
519+ } ) ;
520+ }
521+ }
522+ } catch ( error ) {
523+ console . error (
524+ 'Error during database migration:' ,
525+ error
526+ ) ;
527+ } finally {
528+ this . setState ( { migratingDatabase : false } ) ;
529+ }
530+ }
531+
478532 await initializeLnd ( {
479- lndDir : lndDir || 'lnd' ,
533+ lndDir : currLndDir ,
480534 isTestnet : embeddedLndNetwork === 'Testnet' ,
481535 rescan,
482536 compactDb,
483- isSqlite
537+ isSqlite : needsMigration ? true : isSqlite
484538 } ) ;
485539
486540 // on initial load, do not run EGS
@@ -1250,7 +1304,11 @@ export default class Wallet extends React.Component<WalletProps, WalletState> {
12501304 padding : 8
12511305 } }
12521306 >
1253- { CashuStore . initializing
1307+ { this . state . migratingDatabase
1308+ ? localeString (
1309+ 'views.Wallet.Wallet.migratingDatabase'
1310+ ) . replace ( 'Zeus' , 'ZEUS' )
1311+ : CashuStore . initializing
12541312 ? CashuStore . loadingMsg
12551313 : settings . nodes &&
12561314 loggedIn &&
0 commit comments