Big changes and fixes. Uses action history. Improve role selection. Remove unused logs

This commit is contained in:
2026-02-08 15:41:14 +00:00
parent da096af0fa
commit df57f1b9ad
16 changed files with 1250 additions and 1181 deletions

View File

@@ -9,6 +9,7 @@ import type { XOInvitation } from '@xo-cash/types';
import { Invitation } from './invitation.js';
import { Storage } from './storage.js';
import { SyncServer } from '../utils/sync-server.js';
import { HistoryService } from './history.js';
import { EventEmitter } from '../utils/event-emitter.js';
@@ -31,6 +32,7 @@ export class AppService extends EventEmitter<AppEventMap> {
public engine: Engine;
public storage: Storage;
public config: AppConfig;
public history: HistoryService;
public invitations: Invitation[] = [];
@@ -42,9 +44,6 @@ export class AppService extends EventEmitter<AppEventMap> {
// We want to only prefix the file name
const prefixedStoragePath = `${seedHash.slice(0, 8)}-${config.engineConfig.databaseFilename}`;
console.log('Prefixed storage path:', prefixedStoragePath);
console.log('Engine config:', config.engineConfig);
// Create the engine
const engine = await Engine.create(seed, {
...config.engineConfig,
@@ -75,6 +74,7 @@ export class AppService extends EventEmitter<AppEventMap> {
this.engine = engine;
this.storage = storage;
this.config = config;
this.history = new HistoryService(engine, this.invitations);
}
async createInvitation(invitation: XOInvitation | string): Promise<Invitation> {
@@ -118,12 +118,16 @@ export class AppService extends EventEmitter<AppEventMap> {
const invitationsDb = this.storage.child('invitations');
// Load invitations from storage
console.time('loadInvitations');
const invitations = await invitationsDb.all() as { key: string; value: XOInvitation }[];
console.timeEnd('loadInvitations');
// Start the invitations
for (const { key } of invitations) {
// TODO: This is doing some double work of grabbing the invitation data. We can probably skip it, but who knows.
console.time('createInvitations');
await Promise.all(invitations.map(async ({ key }) => {
await this.createInvitation(key);
}
}));
console.timeEnd('createInvitations');
}
}