Clean up and fixes
This commit is contained in:
97
src/app.ts
97
src/app.ts
@@ -1,72 +1,43 @@
|
||||
/**
|
||||
* Application bootstrap and lifecycle management.
|
||||
* Coordinates initialization of all CLI components.
|
||||
* Simplified to render TUI immediately and let it handle AppService creation.
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { render, type Instance } from 'ink';
|
||||
import { App as AppComponent } from './tui/App.js';
|
||||
import { WalletController } from './controllers/wallet-controller.js';
|
||||
import { InvitationController } from './controllers/invitation-controller.js';
|
||||
import { SyncClient } from './services/sync-client.js';
|
||||
|
||||
/**
|
||||
* Configuration options for the CLI application.
|
||||
*/
|
||||
export interface AppConfig {
|
||||
/** URL of the sync server (default: http://localhost:3000) */
|
||||
syncServerUrl?: string;
|
||||
syncServerUrl: string;
|
||||
/** Database path for wallet state storage */
|
||||
databasePath?: string;
|
||||
databasePath: string;
|
||||
/** Database filename */
|
||||
databaseFilename?: string;
|
||||
databaseFilename: string;
|
||||
/** Path for invitation storage database */
|
||||
invitationStoragePath: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Main application class that orchestrates all CLI components.
|
||||
* Main application class that orchestrates the CLI.
|
||||
* Renders the TUI immediately and passes config for later AppService creation.
|
||||
*/
|
||||
export class App {
|
||||
/** Ink render instance */
|
||||
private inkInstance: Instance | null = null;
|
||||
|
||||
/** Wallet controller for engine operations */
|
||||
private walletController: WalletController;
|
||||
|
||||
/** Invitation controller for collaborative transactions */
|
||||
private invitationController: InvitationController;
|
||||
|
||||
/** HTTP client for sync server communication */
|
||||
private syncClient: SyncClient;
|
||||
|
||||
/** Application configuration */
|
||||
private config: Required<AppConfig>;
|
||||
private config: AppConfig;
|
||||
|
||||
/**
|
||||
* Creates a new App instance.
|
||||
* @param config - Application configuration options
|
||||
*/
|
||||
private constructor(config: AppConfig = {}) {
|
||||
// Set default configuration
|
||||
this.config = {
|
||||
syncServerUrl: config.syncServerUrl ?? 'http://localhost:3000',
|
||||
databasePath: config.databasePath ?? './',
|
||||
databaseFilename: config.databaseFilename ?? 'xo-wallet',
|
||||
};
|
||||
|
||||
// Initialize sync client
|
||||
this.syncClient = new SyncClient(this.config.syncServerUrl);
|
||||
|
||||
// Initialize wallet controller (engine will be created when seed is provided)
|
||||
this.walletController = new WalletController({
|
||||
databasePath: this.config.databasePath,
|
||||
databaseFilename: this.config.databaseFilename,
|
||||
});
|
||||
|
||||
// Initialize invitation controller
|
||||
this.invitationController = new InvitationController(
|
||||
this.walletController,
|
||||
this.syncClient,
|
||||
);
|
||||
private constructor(config: AppConfig) {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -74,22 +45,32 @@ export class App {
|
||||
* @param config - Application configuration options
|
||||
* @returns Running App instance
|
||||
*/
|
||||
static async create(config: AppConfig = {}): Promise<App> {
|
||||
const app = new App(config);
|
||||
static async create(config: Partial<AppConfig> = {}): Promise<App> {
|
||||
// Set default configuration
|
||||
const fullConfig: AppConfig = {
|
||||
syncServerUrl: config.syncServerUrl ?? 'http://localhost:3000',
|
||||
databasePath: config.databasePath ?? './',
|
||||
databaseFilename: config.databaseFilename ?? 'xo-wallet.db',
|
||||
invitationStoragePath: config.invitationStoragePath ?? './xo-invitations.db',
|
||||
};
|
||||
|
||||
console.log('Full config:', fullConfig);
|
||||
|
||||
const app = new App(fullConfig);
|
||||
await app.start();
|
||||
return app;
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the application.
|
||||
* Renders the Ink-based TUI.
|
||||
* Renders the Ink-based TUI immediately.
|
||||
*/
|
||||
async start(): Promise<void> {
|
||||
// Render the Ink app
|
||||
// Render the Ink app with config
|
||||
// TUI will handle AppService creation after seed input
|
||||
this.inkInstance = render(
|
||||
React.createElement(AppComponent, {
|
||||
walletController: this.walletController,
|
||||
invitationController: this.invitationController,
|
||||
config: this.config,
|
||||
})
|
||||
);
|
||||
|
||||
@@ -101,34 +82,10 @@ export class App {
|
||||
* Stops the application and cleans up resources.
|
||||
*/
|
||||
async stop(): Promise<void> {
|
||||
// Stop the wallet engine if running
|
||||
await this.walletController.stop();
|
||||
|
||||
// Unmount Ink app
|
||||
if (this.inkInstance) {
|
||||
this.inkInstance.unmount();
|
||||
this.inkInstance = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the wallet controller for external access.
|
||||
*/
|
||||
getWalletController(): WalletController {
|
||||
return this.walletController;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the invitation controller for external access.
|
||||
*/
|
||||
getInvitationController(): InvitationController {
|
||||
return this.invitationController;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the sync client for external access.
|
||||
*/
|
||||
getSyncClient(): SyncClient {
|
||||
return this.syncClient;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user