Skip to content
This repository has been archived by the owner on Sep 5, 2023. It is now read-only.

Fix notifications settings that were not remembered #75

Merged
merged 6 commits into from
Nov 2, 2021
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions src/app/Pages/ActiveDeals/ActiveDeals.scss
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
justify-content: flex-start;
padding-bottom: 4px;

.syncToggles{
.notificationsSettings {
flex: 1;
align-self: flex-start;
display: flex;
Expand All @@ -73,7 +73,7 @@
}


.tableButtons{
.tableButtons {
flex-basis: 20%;
align-items: center;
display: flex;
Expand Down
4 changes: 2 additions & 2 deletions src/app/Pages/ActiveDeals/ActiveDeals.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { formatDeals } from '@/app/Components/DataTable/Index'

import { useAppSelector } from '@/app/redux/hooks';
import { Card_ActiveDeals, Card_totalInDeals, Card_ActiveDealReserve, Card_TotalDayProfit, Card_TotalUnrealizedProfit, Card_TotalRoi } from '@/app/Components/Charts/DataCards';
import { SyncToggles } from './Components/index';
import { NotificationsSettings } from './Components/index';

import './ActiveDeals.scss'

Expand Down Expand Up @@ -51,7 +51,7 @@ const ActiveDealsPage = () => {
<div className="boxData flex-column" style={{padding: '.5em 1em 1em', overflow: 'hidden'}}>
<div className="tableSettings">

<SyncToggles />
<NotificationsSettings />

<div className="filters tableButtons" >
<ToggleRefreshButton style={{ width: '250px', margin: '5px', height: '38px' }} className={"ToggleRefreshButton"} />
Expand Down
63 changes: 63 additions & 0 deletions src/app/Pages/ActiveDeals/Components/NotificationsSettings.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { useAppSelector } from '@/app/redux/hooks';
import { Checkbox, FormControlLabel } from '@mui/material';
import React, { useState } from "react";
import { updateNotificationsSettingsGlobal } from '../../../redux/configActions';

/**
*
* @returns Checkboxes for configuring the state of auto sync.
*/
const NotificationsSettings = () => {

const { config } = useAppSelector(state => state.config);

const [summary, setSummary] = useState(() => config.globalSettings.notifications.summary)
const [enabled, setEnabled] = useState(() => config.globalSettings.notifications.enabled)

const changeSummary = (event: React.ChangeEvent<HTMLInputElement>) => {
const checked = event.target.checked
updateNotificationsSettingsGlobal({ summary: checked })
setSummary(checked)
}

const changeEnabled = (event: React.ChangeEvent<HTMLInputElement>) => {
const checked = event.target.checked
updateNotificationsSettingsGlobal({ enabled: checked })
setEnabled(checked)
}

return (
<div className="notificationsSettings">
<FormControlLabel
control={
<Checkbox
checked={enabled}
onChange={changeEnabled}
name="notifications"
color="primary"
style={{ color: 'var(--color-secondary)' }}

/>
}
label="Enable Notifications"

/>
<FormControlLabel
control={
<Checkbox
checked={summary}
onChange={changeSummary}
name="summary"
style={{ color: 'var(--color-secondary)' }}

/>
}
label="Summarize Notifications"
/>


</div>
)
}

export default NotificationsSettings;
71 changes: 0 additions & 71 deletions src/app/Pages/ActiveDeals/Components/SyncToggles.tsx

This file was deleted.

4 changes: 2 additions & 2 deletions src/app/Pages/ActiveDeals/Components/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

import SyncToggles from "./SyncToggles";
import NotificationsSettings from "./NotificationsSettings";
import SubRowAsync from "./Subrow";

export {
SyncToggles,
NotificationsSettings,
SubRowAsync
}
12 changes: 8 additions & 4 deletions src/app/redux/configActions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { setConfig, setCurrentProfile, updateCurrentProfileByPath, deleteProfileById } from '@/app/redux/configSlice'
import { setConfig, setCurrentProfile, updateCurrentProfileByPath, deleteProfileById, updateNotificationsSettings } from '@/app/redux/configSlice'
import {setSyncData} from '@/app/redux/threeCommas/threeCommasSlice'

import { TconfigValues, Type_Profile, Type_ReservedFunds } from '@/types/config';
import { TconfigValues, Type_NotificationsSettings, Type_Profile, Type_ReservedFunds } from '@/types/config';

import { removeDuplicatesInArray } from '@/utils/helperFunctions';

Expand Down Expand Up @@ -127,12 +127,16 @@ const deleteProfileByIdGlobal = (config: TconfigValues, profileId:string, setOpe
}
}


const updateNotificationsSettingsGlobal = async (settings: Partial<Type_NotificationsSettings>) => {
store.dispatch(updateNotificationsSettings(settings))
await storeConfigInFile()
}

export {
updateConfig,
updateReservedFundsArray,
updateNestedCurrentProfile,
storeConfigInFile,
deleteProfileByIdGlobal
deleteProfileByIdGlobal,
updateNotificationsSettingsGlobal,
}
21 changes: 14 additions & 7 deletions src/app/redux/configSlice.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { createSlice } from '@reduxjs/toolkit'
import type { RootState } from './store'
import { TconfigValues, Type_Profile, Type_ReservedFunds } from '@/types/config';
import { defaultConfig, defaultProfile } from '@/utils/defaultConfig';
import { createSlice } from '@reduxjs/toolkit';
import { v4 as uuidv4 } from 'uuid';

import { Type_Profile, TconfigValues, Type_ReservedFunds } from '@/types/config'
import { defaultProfile, defaultConfig } from '@/utils/defaultConfig'


const defaultReservedFunds = {
Expand All @@ -18,7 +17,6 @@ const defaultReservedFunds = {
const initialState = {
config: <TconfigValues>defaultConfig,
currentProfile: <Type_Profile>defaultProfile,
reservedFunds: <Type_ReservedFunds[]>[defaultReservedFunds]
}

const configPaths = {
Expand Down Expand Up @@ -122,15 +120,24 @@ export const configSlice = createSlice({
},
addConfigProfile: state => {
state.currentProfile = { ...defaultProfile, id: uuidv4() }
}
},
updateNotificationsSettings: (state, action) => {
const newConfig = { ...state.config }
newConfig.globalSettings.notifications = {
...state.config.globalSettings.notifications,
...action.payload,
}
state.config = newConfig
},
}
})

export const {
setConfig, setCurrentProfile,
updateCurrentProfileByPath, deleteProfileById, addConfigProfile,
setCurrentProfileById,
updateLastSyncTime
updateLastSyncTime,
updateNotificationsSettings,
} = configSlice.actions;
export { configPaths }

Expand Down
17 changes: 10 additions & 7 deletions src/app/redux/threeCommas/Actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,15 @@ const updateAllData = async (offset: number = 1000, profileData: Type_Profile, t
const syncOptions = store.getState().threeCommas.syncOptions
coltoneshaw marked this conversation as resolved.
Show resolved Hide resolved
store.dispatch(setIsSyncing(true))

let time = (syncOptions.time) ? syncOptions.time : 0;
let syncCount = (syncOptions.syncCount) ? syncOptions.syncCount : 0;
if(type === 'fullSync') syncCount = 0;
const originalTime = syncOptions.time || 0
let time = originalTime
let syncCount = syncOptions.syncCount || 0
if (type === 'fullSync') {
syncCount = 0
time = 0
}
const options = {
syncCount,
summary: (syncOptions.summary) ? syncOptions.summary : false,
notifications: (syncOptions.notifications) ? syncOptions.notifications : false,
time,
offset
}
Expand All @@ -244,10 +246,11 @@ const updateAllData = async (offset: number = 1000, profileData: Type_Profile, t
.then((lastSyncTime) => {
store.dispatch(setSyncData({
syncCount:(type === 'autoSync') ? options.syncCount + 1 : 0,
time: (type === 'autoSync') ? options.time + 15000 : 0
// don't override syncOptions.time in case of a fullSync
// because there might be a concurrent autoSync running
time: (type === 'autoSync') ? originalTime + 15000 : originalTime
}))
store.dispatch(updateLastSyncTime({data: lastSyncTime }))

})

} catch (error) {
Expand Down
2 changes: 0 additions & 2 deletions src/app/redux/threeCommas/initialState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ export const initialState = {
export type typeString = 'botData' | 'profitData' | 'activeDeals' | 'performanceData' | 'metricsData' | 'accountData' | 'balanceData'

export type Type_SyncData = {
summary?: boolean,
notifications?: boolean,
time?: number,
syncCount?: number
}
Expand Down
8 changes: 7 additions & 1 deletion src/main/3Commas/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { update, run, query } from '@/main/Database/database';
import {config} from '@/main/Config/config';
coltoneshaw marked this conversation as resolved.
Show resolved Hide resolved

const { bots, getAccountDetail, deals, getAccountSummary, getDealOrders } = require('./api');
const log = require('electron-log');

Expand Down Expand Up @@ -37,8 +39,12 @@ async function getDealData(type: string, options: Type_UpdateFunction, profileDa

let { deals, lastSyncTime } = data

const enabled = config.get('globalSettings.notifications.enabled')
const summary = config.get('globalSettings.notifications.summary')
// 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 || options.syncCount != 0) findAndNotifyNewDeals(deals, options.time, options.summary)
if (type === 'autoSync' && enabled && options.time != undefined || options.syncCount != 0) {
findAndNotifyNewDeals(deals, options.time, summary)
}
update('deals', deals, profileData.id)
// log.info(data)

Expand Down
2 changes: 0 additions & 2 deletions src/types/3Commas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,6 @@ export type Type_MarketOrders = {
export interface Type_UpdateFunction{
offset: number
time:number
summary: boolean
notifications: boolean
syncCount: number
}

Expand Down
15 changes: 13 additions & 2 deletions src/types/config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import type { supportedCurrencies} from'@/utils/granularity'
import type { supportedCurrencies } from '@/utils/granularity'

export interface TconfigValues {
profiles: Record<string, Type_Profile>,
current: string,
globalSettings: Type_GlobalSettings,
general: {
version: string
},
Expand Down Expand Up @@ -38,6 +39,16 @@ export interface Type_Profile {

}

export interface Type_GlobalSettings {
notifications: Type_NotificationsSettings
}

export interface Type_NotificationsSettings {
enabled: boolean,
summary: boolean,
}


export interface Type_ReservedFunds {
id: number
account_name: string
Expand All @@ -64,7 +75,7 @@ export interface Type_ConfigContext {
currency: string[]
updateCurrency: any
updateApiData: any
apiData: {key: string, secret: string, mode: string}
apiData: { key: string, secret: string, mode: string }
reservedFunds: Type_ReservedFunds[],
updateReservedFunds: any
currentProfileId: string
Expand Down
10 changes: 8 additions & 2 deletions src/utils/defaultConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,15 @@ const defaultProfile:Type_Profile = {
}


const defaultConfig = {
profiles: Object.assign({[currentId]: defaultProfile}),
const defaultConfig: TconfigValues = {
profiles: Object.assign({[currentId]: defaultProfile}),
current: currentId,
globalSettings: {
notifications: {
enabled: true,
summary: false,
},
},
general: {
version : version
},
Expand Down