Ziya/app/stores/app.ts
rizary 67fb3a203e
feat: implement CEX analysis cards and real-time token monitoring
- Add TokenCard and CexAnalysisCard components for displaying token data
- Implement real-time Redis event streaming for token updates
- Add environment-based configuration system for dev/prod Redis servers
- Create comprehensive hunting ground dashboard with card management
- Add individual and bulk card removal functionality
- Implement browser integration for token details viewing
- Add timestamp utilities and proper type handling for Redis events
- Create production-ready configuration with 154.38.185.112 Redis server
- Add comprehensive documentation in README.md and CONTRIBUTORS.md
- Restructure project architecture with proper Electron-Vue integration

BREAKING CHANGE: Redis configuration now uses environment-based settings
2025-06-23 09:03:39 +07:00

162 lines
4.1 KiB
TypeScript

import { defineStore } from 'pinia';
import { useZiyaConfig } from '../composables/useZiyaConfig';
import { useThemeStore } from './theme';
interface AppState {
isInitialized: boolean;
isLoading: boolean;
error: string | null;
currentUser: { name: string; email: string } | null;
appVersion: string;
toastMessage: string;
toastType: 'success' | 'error' | 'info';
showToast: boolean;
}
export const useAppStore = defineStore('app', {
state: (): AppState => {
// Get config from composable if available (client-side)
const { config } = import.meta.client ? useZiyaConfig() : { config: { app: { version: '1.0.0' } } };
return {
isInitialized: false,
isLoading: false,
error: null,
currentUser: null,
appVersion: config.app.version,
toastMessage: '',
toastType: 'info',
showToast: false,
};
},
getters: {
isAuthenticated: state => state.currentUser !== null,
userInitials: (state) => {
if (!state.currentUser) return '??';
return state.currentUser.name
.split(' ')
.map(n => n[0])
.join('')
.toUpperCase();
},
appInfo: (state) => {
// Get config for additional app info
const { config } = import.meta.client ? useZiyaConfig() : { config: { app: { name: 'Ziya', version: '1.0.0', description: 'Trading Platform', author: 'bismillahDAO' } } };
return {
name: config.app.name,
version: state.appVersion,
description: config.app.description,
author: config.app.author,
};
},
},
actions: {
async initialize() {
if (this.isInitialized) return;
this.isLoading = true;
this.error = null;
try {
// Initialize theme system
const themeStore = useThemeStore();
await themeStore.initializeTheme();
// Mark as initialized
this.isInitialized = true;
}
catch (error) {
this.error = error instanceof Error ? error.message : 'Failed to initialize app';
console.error('App initialization failed:', error);
throw error;
}
finally {
this.isLoading = false;
}
},
setLoading(loading: boolean) {
this.isLoading = loading;
},
showToastMessage(message: string, type: 'success' | 'error' | 'info' = 'info') {
this.toastMessage = message;
this.toastType = type;
this.showToast = true;
setTimeout(() => {
this.showToast = false;
}, 3000);
},
async login(email: string, _password: string) {
this.setLoading(true);
try {
// Simulate API call
await new Promise(resolve => setTimeout(resolve, 1000));
// Mock user data
this.currentUser = {
name: 'John Trader',
email: email,
};
this.showToastMessage('Welcome back!', 'success');
return true;
}
catch {
this.showToastMessage('Login failed. Please try again.', 'error');
return false;
}
finally {
this.setLoading(false);
}
},
async logout() {
this.setLoading(true);
try {
// Simulate API call
await new Promise(resolve => setTimeout(resolve, 500));
this.currentUser = null;
this.showToastMessage('You have been logged out', 'info');
}
finally {
this.setLoading(false);
}
},
// Persist user data to localStorage
async $afterStateRestored() {
if (this.currentUser) {
localStorage.setItem('ziya-user', JSON.stringify(this.currentUser));
}
else {
localStorage.removeItem('ziya-user');
}
},
// Initialize from localStorage
async initializeFromStorage() {
if (import.meta.client) {
const storedUser = localStorage.getItem('ziya-user');
if (storedUser) {
try {
this.currentUser = JSON.parse(storedUser);
}
catch (error) {
console.error('Failed to parse stored user data:', error);
localStorage.removeItem('ziya-user');
}
}
await this.initialize();
}
},
},
});