Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: move store variables to agent specific #603

Merged
merged 12 commits into from
Dec 23, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: streamline store IPC setup and improve default agent settin…
…gs for better initialization
mohandast52 committed Dec 17, 2024
commit 35d4c10ec94688ff633462d18a0c12989dffd805
15 changes: 6 additions & 9 deletions electron/main.js
Original file line number Diff line number Diff line change
@@ -338,15 +338,12 @@ const createMainWindow = async () => {
mainWindow.hide();
});

app.on('ready', () => {
try {
logger.electron('Setting up store IPC');
setupStoreIpc(ipcMain, mainWindow);
} catch (e) {
logger.electron('Store IPC failed:', JSON.stringify(e));
}
});

try {
logger.electron('Setting up store IPC');
setupStoreIpc(ipcMain, mainWindow);
} catch (e) {
logger.electron('Store IPC failed:', JSON.stringify(e));
}
if (isDev) {
mainWindow.webContents.openDevTools();
}
31 changes: 15 additions & 16 deletions electron/store.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
const Store = require('electron-store');

const defaultAgentSettings = {
isInitialFunded: { type: 'boolean', default: false },
firstStakingRewardAchieved: { type: 'boolean', default: false },
firstRewardNotificationShown: { type: 'boolean', default: false },
agentEvictionAlertShown: { type: 'boolean', default: false },
currentStakingProgram: { type: 'string', default: '' },
const defaultInitialAgentSettings = {
isInitialFunded: false,
firstStakingRewardAchieved: false,
firstRewardNotificationShown: false,
agentEvictionAlertShown: false,
currentStakingProgram: false,
};

// Schema for validating store data
const schema = {
environmentName: { type: 'string', default: '' },
lastSelectedAgentType: { type: 'string', default: 'trader' },
isInitialFunded_trader: { type: 'boolean', default: false },
isInitialFunded_memeooorr: { type: 'boolean', default: false },

// Each agent has its own settings
trader: { type: 'object', default: defaultAgentSettings },
memeooorr: { type: 'object', default: defaultAgentSettings },
trader: { type: 'object', default: defaultInitialAgentSettings },
memeooorr: { type: 'object', default: defaultInitialAgentSettings },
};

/**
@@ -37,10 +35,13 @@ const setupStoreIpc = (ipcMain, mainWindow) => {
const traderAgent = {
...(store.get('trader') || {}),
isInitialFunded:
store.get('isInitialFunded_trader') || store.get('isInitialFunded'),
firstRewardNotificationShown: store.get('firstRewardNotificationShown'),
agentEvictionAlertShown: store.get('agentEvictionAlertShown'),
currentStakingProgram: store.get('currentStakingProgram'),
store.get('isInitialFunded_trader') ||
store.get('isInitialFunded') ||
false,
firstRewardNotificationShown:
store.get('firstRewardNotificationShown') || false,
agentEvictionAlertShown: store.get('agentEvictionAlertShown') || false,
currentStakingProgram: store.get('currentStakingProgram') || false,
};

// Set the trader agent and delete old keys
@@ -78,8 +79,6 @@ const setupStoreIpc = (ipcMain, mainWindow) => {
ipcMain.handle('store-set', (_, key, value) => store.set(key, value));
ipcMain.handle('store-delete', (_, key) => store.delete(key));
ipcMain.handle('store-clear', () => store.clear());

console.log('[Store] IPC handlers registered successfully.');
};

module.exports = { setupStoreIpc };
Loading