Skip to content

Commit

Permalink
refactor: enhance store schema by adding first-time user settings and…
Browse files Browse the repository at this point in the history
… removing obsolete keys for improved clarity
  • Loading branch information
mohandast52 committed Dec 20, 2024
1 parent 01c9237 commit 311e20e
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions electron/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@ const Store = require('electron-store');

const defaultInitialAgentSettings = {
isInitialFunded: false,
firstStakingRewardAchieved: false,
firstRewardNotificationShown: false,
agentEvictionAlertShown: false,
currentStakingProgram: false,
};

// Schema for validating store data
const schema = {
// Global settings
environmentName: { type: 'string', default: '' },
lastSelectedAgentType: { type: 'string', default: 'trader' },

// First time user settings
firstStakingRewardAchieved: { type: 'boolean', default: false },
firstRewardNotificationShown: { type: 'boolean', default: false },
agentEvictionAlertShown: { type: 'boolean', default: false },

// Each agent has its own settings
trader: { type: 'object', default: defaultInitialAgentSettings },
memeooorr: { type: 'object', default: defaultInitialAgentSettings },
Expand All @@ -38,21 +40,13 @@ const setupStoreIpc = (ipcMain, mainWindow) => {
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
store.set('trader', traderAgent);
[
'isInitialFunded',
'isInitialFunded_trader',
'firstRewardNotificationShown',
'agentEvictionAlertShown',
'currentStakingProgram',
].forEach((key) => store.delete(key));
['isInitialFunded', 'isInitialFunded_trader'].forEach((key) =>
store.delete(key),
);

/**
* agent: memeooorr Migration
Expand All @@ -78,7 +72,7 @@ const setupStoreIpc = (ipcMain, mainWindow) => {
ipcMain.handle('store-get', (_, key) => store.get(key));
ipcMain.handle('store-set', (_, key, value) => store.set(key, value));
ipcMain.handle('store-delete', (_, key) => store.delete(key));
ipcMain.handle('store-clear', () => store.clear());
ipcMain.handle('store-clear', (_) => store.clear());
};

module.exports = { setupStoreIpc };

0 comments on commit 311e20e

Please sign in to comment.