diff --git a/package-lock.json b/package-lock.json index b0c9a1a7..de443a27 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,6 +16,7 @@ "date-fns-tz": "^1.1.6", "dot-prop": "^6.0.1", "electron-fetch": "^1.7.4", + "electron-log": "^4.4.1", "electron-notarize": "^1.1.1", "electron-store": "^8.0.0", "material-ui-popup-state": "^1.9.3", @@ -6392,6 +6393,11 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/electron-log": { + "version": "4.4.1", + "resolved": "https://registry.npmjs.org/electron-log/-/electron-log-4.4.1.tgz", + "integrity": "sha512-nK/DwxPLtwWbggPCm27eMQhYHc3gzoZ+cokBK99diO4WsZJKrv5l44EUW8mRfWpmC8ZubnMyp6GTUIJyTc9AJA==" + }, "node_modules/electron-notarize": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/electron-notarize/-/electron-notarize-1.1.1.tgz", @@ -21365,6 +21371,11 @@ "integrity": "sha512-3X99K852Yoqu9AcW50qz3ibYBWY79/pBhlMCab8ToEWS48R0T9tyxRiQhwylE7zQdXrMnx2JKqUJyMPmt5FBqA==", "dev": true }, + "electron-log": { + "version": "4.4.1", + "resolved": "https://registry.npmjs.org/electron-log/-/electron-log-4.4.1.tgz", + "integrity": "sha512-nK/DwxPLtwWbggPCm27eMQhYHc3gzoZ+cokBK99diO4WsZJKrv5l44EUW8mRfWpmC8ZubnMyp6GTUIJyTc9AJA==" + }, "electron-notarize": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/electron-notarize/-/electron-notarize-1.1.1.tgz", diff --git a/package.json b/package.json index 5ea42fed..f51caa4b 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,8 @@ "webpack": "webpack", "dev": "concurrently --kill-others \"npm run react:dev\" \"npm run electron:dev\"", "start": "npm run build && electron dist/main.js", - "rebuild": "./node_modules/.bin/electron-rebuild -f -w better-sqlite3" + "rebuild": "./node_modules/.bin/electron-rebuild -f -w better-sqlite3", + "wpanddev": "webpack && concurrently --kill-others \"npm run react:dev\" \"npm run electron:dev\"" }, "repository": { "type": "git", @@ -83,6 +84,7 @@ "date-fns-tz": "^1.1.6", "dot-prop": "^6.0.1", "electron-fetch": "^1.7.4", + "electron-log": "^4.4.1", "electron-notarize": "^1.1.1", "electron-store": "^8.0.0", "material-ui-popup-state": "^1.9.3", diff --git a/src/app/Features/3Commas/API/3commaslib.ts b/src/main/3Commas/3commaslib.ts similarity index 98% rename from src/app/Features/3Commas/API/3commaslib.ts rename to src/main/3Commas/3commaslib.ts index aab515d4..3ac09ae4 100644 --- a/src/app/Features/3Commas/API/3commaslib.ts +++ b/src/main/3Commas/3commaslib.ts @@ -1,6 +1,8 @@ 'use strict' import crypto from "crypto"; -import fetch from 'electron-fetch' +import fetch from 'electron-fetch'; +const log = require('electron-log'); + const API_URL = 'https://api.3commas.io' @@ -50,7 +52,7 @@ class threeCommasAPI { return await response.json() } catch (e) { - console.log(e); + log.error(e); return false } } diff --git a/src/app/Features/3Commas/API/api.ts b/src/main/3Commas/api.ts similarity index 97% rename from src/app/Features/3Commas/API/api.ts rename to src/main/3Commas/api.ts index 2387362c..7205a5b2 100644 --- a/src/app/Features/3Commas/API/api.ts +++ b/src/main/3Commas/api.ts @@ -1,7 +1,8 @@ -const threeCommasAPI = require('./3commaslib') +const threeCommasAPI = require('./3commaslib'); +const log = require('electron-log'); import { Type_API_bots, Type_Deals_API, Type_MarketOrders} from '@/types/3Commas' -import { getProfileConfig, setProfileConfig, getProfileConfigAll } from '@/utils/config'; +import { getProfileConfig, setProfileConfig, getProfileConfigAll } from '@/main/Config/config'; import { calc_dealHours, @@ -39,7 +40,7 @@ const threeCapi = (profileData?: Type_Profile, key?: string, secret?: string, mo if (key == null || secret == null || mode == null) { - console.error('missing API keys or mode') + log.error('missing API keys or mode') return false } @@ -248,7 +249,7 @@ async function getDealsThatAreUpdated(perSyncOffset: number, profileData:Type_Pr newLastSyncTime = new Date(response[0].updated_at).getTime() } - console.info({ + log.debug({ 'responseArrayLength': responseArray.length, 'currentResponse': response.length, offset, @@ -266,7 +267,7 @@ async function getDealsThatAreUpdated(perSyncOffset: number, profileData:Type_Pr } - console.log('Response data Length: ' + responseArray.length) + log.info('Response data Length: ' + responseArray.length) // updating the last sync time if it's actually changed. if (lastSyncTime != newLastSyncTime) { setProfileConfig('syncStatus.deals.lastSyncTime', newLastSyncTime, profileData.id) } @@ -356,7 +357,7 @@ async function getAccountDetail(profileData:Type_Profile) { const accountIDs = profileData.statSettings.reservedFunds.filter(a => a.is_enabled).map(a => a.id) for (let account of accountData.filter((a:any) => accountIDs.includes(a.id))) { - // console.log('syncing the account ', account.id) + // log.info('syncing the account ', account.id) // this loads the account balances from the exchange to 3C ensuring the numbers are updated await api.accountLoadBalances(account.id); diff --git a/src/app/Features/3Commas/API/index.ts b/src/main/3Commas/index.ts similarity index 89% rename from src/app/Features/3Commas/API/index.ts rename to src/main/3Commas/index.ts index 7cab7e6f..773a8d55 100644 --- a/src/app/Features/3Commas/API/index.ts +++ b/src/main/3Commas/index.ts @@ -1,7 +1,10 @@ -import { update, run, query } from '@/app/Features/Database/database'; +import { update, run, query } from '@/main/Database/database'; const { bots, getAccountDetail, deals, getAccountSummary } = require('./api'); -const { getProfileConfigAll } = require('@/utils/config') -import { findAndNotifyNewDeals } from '@/electron/Notifications/notifications' +const log = require('electron-log'); + +const { getProfileConfigAll } = require('@/main/Config/config') +import { findAndNotifyNewDeals } from '@/main/Notifications/notifications' + import { Type_Deals_API, Type_Query_Accounts, Type_API_bots, Type_UpdateFunction } from '@/types/3Commas' import { Type_Profile } from '@/types/config' @@ -17,17 +20,19 @@ async function updateAPI(type: string, options: Type_UpdateFunction, profileData profileData = getProfileConfigAll() } + log.debug(profileData) + await deals(options.offset, type, profileData) .then((data: Type_Deals_API[]) => { // if notifications need to be enabled for the fullSync then the type below needs to be updated. if (type === 'autoSync' && options.notifications && options.time != undefined) findAndNotifyNewDeals(data, options.time, options.summary) update('deals', data, profileData.id) - // console.log(data) + // log.info(data) }) // if (type !== 'autoSync' || options.syncCount === 20) { - // console.log('updating the accounts!') + // log.info('updating the accounts!') await getAccountData(profileData) // } @@ -92,7 +97,7 @@ async function getAndStoreBotData(profileData: Type_Profile) { }) } catch (error) { - console.error('error getting bot data', error) + log.error('error getting bot data', error) } } diff --git a/src/utils/config.ts b/src/main/Config/config.ts similarity index 84% rename from src/utils/config.ts rename to src/main/Config/config.ts index 1b43d3df..99cbe2fd 100644 --- a/src/utils/config.ts +++ b/src/main/Config/config.ts @@ -1,7 +1,8 @@ import { TconfigValues, Type_Profile } from "@/types/config"; +const log = require('electron-log'); const Store = require('electron-store'); -const { run } = require('@/app/Features/Database/database') +const { run } = require('@/main/Database/database') import { v4 as uuidv4 } from 'uuid'; import { defaultConfig } from '@/utils/defaultConfig'; @@ -13,7 +14,7 @@ const migrateCurrencyToArray = (store: any) => { const migrationToProfiles = (config:any) => { if(config.get('general.version') === 'v0.5.0') { - console.debug('looks like this is already on the latest version.') + log.debug('looks like this is already on the latest version.') return false } const id = uuidv4() @@ -40,8 +41,8 @@ const migrationToProfiles = (config:any) => { run(`UPDATE deals SET profile_id='${id}' WHERE profile_id IS NULL`) }) } catch (e) { - console.error(e) - console.error('error migrating to v0.5 ') + log.error(e) + log.error('error migrating to v0.5 ') } } @@ -51,17 +52,17 @@ const migrationToProfiles = (config:any) => { const config = new Store({ migrations: { // '0.0.3': ( store: any )=>{ - // console.info('migrating the config store to 0.0.2-RC1') + // log.info('migrating the config store to 0.0.2-RC1') // store.set('statSettings.account_id', []); // migrateCurrencyToArray(store) // }, // '0.0.4': ( store: any )=>{ - // console.info('migrating the config store to 0.0.4') - // console.log('adding a reserved funds array.') + // log.info('migrating the config store to 0.0.4') + // log.log('adding a reserved funds array.') // store.set('statSettings.reservedFunds', []); // }, // '0.1.0': ( store: any )=>{ - // console.info('migrating the config store to 0.1.0') + // log.info('migrating the config store to 0.1.0') // run('drop table bots;') // store.set('general.updated', true) // }, @@ -69,13 +70,13 @@ const config = new Store({ // store.set('general.updated', true) // }, '<=0.2.0': () => { - console.log('running the v0.2 migration!!!!!!!!!!!!!!!!!!!!') + log.log('running the v0.2 migration!!!!!!!!!!!!!!!!!!!!') // removing the bots that have been synced so they can be resynced and a new column added run('ALTER TABLE bots ADD COLUMN hide boolean;') run("delete from deals where status in ('failed', 'cancelled') ") }, 'v0.5.0': (store: any) => { - console.info('migrating the config store to 0.5.0') + log.info('migrating the config store to 0.5.0') migrationToProfiles(store) diff --git a/src/app/Features/Database/database.ts b/src/main/Database/database.ts similarity index 97% rename from src/app/Features/Database/database.ts rename to src/main/Database/database.ts index 4288a092..83f05b0b 100644 --- a/src/app/Features/Database/database.ts +++ b/src/main/Database/database.ts @@ -1,5 +1,7 @@ import { app } from "electron"; -import { config } from "@/utils/config"; +import { config } from "@/main/Config/config"; +const log = require('electron-log'); + import path from "path"; import Database from 'better-sqlite3'; @@ -226,7 +228,7 @@ function normalizeData(data: any) { async function update(table: string, data: any[], profileId:string) { if (data.length == 0) { - console.log('no data to write') + log.log('no data to write') return false } @@ -259,7 +261,7 @@ async function update(table: string, data: any[], profileId:string) { async function upsert(table: string, data: any[], id: string, updateColumn: string) { if (data.length == 0) { - console.log('no data to write') + log.log('no data to write') return false } @@ -313,9 +315,9 @@ async function deleteAllData(profileID?: string) { await run(`DELETE FROM bots;'`) await run(`DELETE FROM accountData;`) await run(`DELETE FROM deals;'`) - console.info('deleting all database info.') + log.info('deleting all database info.') } - console.info('deleting all database info.') + log.info('deleting all database info.') await run(`DELETE FROM bots WHERE profile_id = '${profileID}'`) @@ -325,7 +327,7 @@ async function deleteAllData(profileID?: string) { await run(`DELETE FROM deals WHERE profile_id = '${profileID}'`) - console.info('database info deleted.') + log.info('database info deleted.') } diff --git a/src/electron/Notifications/notifications.ts b/src/main/Notifications/notifications.ts similarity index 98% rename from src/electron/Notifications/notifications.ts rename to src/main/Notifications/notifications.ts index 18fb2c39..7a5df38c 100644 --- a/src/electron/Notifications/notifications.ts +++ b/src/main/Notifications/notifications.ts @@ -2,7 +2,7 @@ import { Notification } from 'electron'; import { Type_Deals_API } from '@/types/3Commas' import { parseNumber } from '@/utils/number_formatting' -import { getProfileConfig } from '@/utils/config' +import { getProfileConfig } from '@/main/Config/config' import { convertMiliseconds } from '@/utils/helperFunctions' diff --git a/src/main.ts b/src/main/main.ts similarity index 92% rename from src/main.ts rename to src/main/main.ts index 5917c178..0161f9db 100644 --- a/src/main.ts +++ b/src/main/main.ts @@ -1,13 +1,15 @@ import {app, BrowserWindow, ipcMain, shell, Menu} from 'electron'; -import {config} from './utils/config'; +import {config} from '@/main/Config/config'; // import isDev from 'electron-is-dev'; // New Import +const log = require('electron-log'); + const path = require("path"); const isDev = !app.isPackaged; -import { menu } from './electron/menu'; +import { menu } from './menu'; -const { update, query, checkOrMakeTables, run, deleteAllData, upsert } = require( '@/app/Features/Database/database'); +const { update, query, checkOrMakeTables, run, deleteAllData, upsert } = require( '@/main/Database/database'); let win; @@ -114,7 +116,7 @@ ipcMain.handle('database-deleteAll', (e, profileID: string) => { }); ipcMain.handle('database-checkOrMakeTables', () => { - console.log('attempting to check if tables exist yet.') + log.log('attempting to check if tables exist yet.') checkOrMakeTables() }); @@ -125,7 +127,7 @@ ipcMain.handle('database-checkOrMakeTables', () => { * */ - const { updateAPI, getAndStoreBotData, getAccountSummary } = require('@/app/Features/3Commas/API/index'); + const { updateAPI, getAndStoreBotData, getAccountSummary } = require('@/main/3Commas/index') import {Type_Profile} from '@/types/config' ipcMain.handle('api-updateData', async (event, type, options, profileData?:Type_Profile) => { @@ -156,7 +158,7 @@ ipcMain.handle('binance-getCoins', async (event) => { return await fetchCoinPricesBinance() }); -import { fetchVersions } from './app/Features/UpdateBanner/UpdateApiFetch'; +import { fetchVersions } from '../app/Features/UpdateBanner/UpdateApiFetch'; ipcMain.handle('pm-versions', async (event) => { return await fetchVersions() diff --git a/src/electron/menu.ts b/src/main/menu.ts similarity index 96% rename from src/electron/menu.ts rename to src/main/menu.ts index 3df68b16..cd3bfc35 100644 --- a/src/electron/menu.ts +++ b/src/main/menu.ts @@ -2,10 +2,10 @@ const { app, Menu, dialog, BrowserWindow } = require('electron') const isMac = process.platform === 'darwin' -const {deleteAllData} = require('@/app/Features/Database/database'); -const {setDefaultConfig} = require('@/utils/config') +const {deleteAllData} = require('@/main/Database/database'); +const {setDefaultConfig} = require('@/main/Config/config') -const {win} = require('@/main') +const {win} = require('@/main/main') const template = [ diff --git a/webpack.electron.js b/webpack.electron.js index d6a2f56a..ebea9cd4 100644 --- a/webpack.electron.js +++ b/webpack.electron.js @@ -1,11 +1,11 @@ const path = require('path'); module.exports = { - externals: {'better-sqlite3': 'commonjs2 better-sqlite3', '3commas-api-node': 'commonjs2 3commas-api-node' }, + externals: {'better-sqlite3': 'commonjs2 better-sqlite3'}, // Build Mode mode: 'development', // Electron Entrypoint - entry: './src/main.ts', + entry: './src/main/main.ts', target: 'electron-main', resolve: { alias: {