@ -674,15 +674,51 @@ export class WebPlatformService implements PlatformService {
async updateDefaultSettings (
settings : Record < string , unknown > ,
) : Promise < void > {
// Get current active DID and update that identity's settings
const activeIdentity = await this . getActiveIdentity ( ) ;
const activeDid = activeIdentity . activeDid ;
if ( ! activeDid ) {
logger . warn (
"[WebPlatformService] No active DID found, cannot update default settings" ,
) ;
return ;
}
const keys = Object . keys ( settings ) ;
const setClause = keys . map ( ( key ) = > ` ${ key } = ? ` ) . join ( ", " ) ;
const sql = ` UPDATE settings SET ${ setClause } WHERE id = 1 ` ;
const params = keys . map ( ( key ) = > settings [ key ] ) ;
const sql = ` UPDATE settings SET ${ setClause } WHERE accountDid = ? ` ;
const params = [ . . . keys . map ( ( key ) = > settings [ key ] ) , activeDid ] ;
await this . dbExec ( sql , params ) ;
}
async updateActiveDid ( did : string ) : Promise < void > {
await this . dbExec (
"INSERT OR REPLACE INTO active_identity (id, activeDid, lastUpdated) VALUES (1, ?, ?)" ,
[ did , new Date ( ) . toISOString ( ) ] ,
) ;
}
async getActiveIdentity ( ) : Promise < { activeDid : string } > {
const result = await this . dbQuery (
"SELECT activeDid FROM active_identity WHERE id = 1" ,
) ;
return {
activeDid : ( result ? . values ? . [ 0 ] ? . [ 0 ] as string ) || "" ,
} ;
}
async insertNewDidIntoSettings ( did : string ) : Promise < void > {
await this . dbExec ( "INSERT INTO settings (accountDid) VALUES (?)" , [ did ] ) ;
// Import constants dynamically to avoid circular dependencies
const { DEFAULT_ENDORSER_API_SERVER , DEFAULT_PARTNER_API_SERVER } =
await import ( "@/constants/app" ) ;
// Use INSERT OR REPLACE to handle case where settings already exist for this DID
// This prevents duplicate accountDid entries and ensures data integrity
await this . dbExec (
"INSERT OR REPLACE INTO settings (accountDid, finishedOnboarding, apiServer, partnerApiServer) VALUES (?, ?, ?, ?)" ,
[ did , false , DEFAULT_ENDORSER_API_SERVER , DEFAULT_PARTNER_API_SERVER ] ,
) ;
}
async updateDidSpecificSettings (