这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [4.9.2] - 2023-08-02

### Changed

- Removed the `Cumulative Weighted Price` column and corresponding logic from the `Weighted Averages` report according to the latest requirements. Added `Cost` and `Sale` columns to the `Weighted Averages` report. PRs: [bfx-report#319](https://github.com/bitfinexcom/bfx-report/pull/319), [bfx-reports-framework#302](https://github.com/bitfinexcom/bfx-reports-framework/pull/302), [bfx-report-ui#681](https://github.com/bitfinexcom/bfx-report-ui/pull/681)
- Improved sync time estimation flow as follows: in addition to existing emitting `WS` events when the next collection is syncing to not hold the previous time value (some collections can sync very long) adds an ability to emit the `progress` event every `1sec` with new values `spentTime` and `leftTime` for better UX (so that the user does not think that sync has stalled). PR: [bfx-reports-framework#303](https://github.com/bitfinexcom/bfx-reports-framework/pull/303)
- Changed `Rate Limits` for public endpoints: `trades` to 15 req/min, `candles` to 60 req/min. PR: [bfx-reports-framework#304](https://github.com/bitfinexcom/bfx-reports-framework/pull/304)

### Fixed

- Fixed issues with the incorrect synchronization estimation time conversion and representation. PR: [bfx-report-ui#680](https://github.com/bitfinexcom/bfx-report-ui/pull/680)
- Fixed handling bfx api `ERR_AUTH_API: ERR_INVALID_CREDENTIALS` error to prevent showing `500 Internal Server Error` and error modal dialog in the electron app. PR: [bfx-report#318](https://github.com/bitfinexcom/bfx-report/pull/318)
- Fixed the issue [#215](https://github.com/bitfinexcom/bfx-report-electron/issues/215) related to `MaxListenersExceededWarning` warning for the electron windows. PR: [bfx-report-electron#229](https://github.com/bitfinexcom/bfx-report-electron/pull/229)

## [4.9.1] - 2023-07-12

### Added
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bfx-report-electron",
"version": "4.9.1",
"version": "4.9.2",
"repository": "https://github.com/bitfinexcom/bfx-report-electron",
"description": "Reporting tool",
"author": "bitfinex.com",
Expand Down
29 changes: 16 additions & 13 deletions src/auto-updater/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ const {
closeAlert
} = require('../modal-dialog-src/utils')
const parseEnvValToBool = require('../helpers/parse-env-val-to-bool')
const {
WINDOW_EVENT_NAMES,
addOnceProcEventHandler
} = require('../window-event-manager')

const isAutoUpdateDisabled = parseEnvValToBool(process.env.IS_AUTO_UPDATE_DISABLED)

Expand Down Expand Up @@ -53,13 +57,11 @@ const script = `<script type="text/javascript">${toastScript}</script>`
const sound = { freq: 'F2', type: 'triange', duration: 1.5 }

const _sendProgress = (progress) => {
if (
!toast ||
!toast.browserWindow ||
!Number.isFinite(progress)
) return
if (!Number.isFinite(progress)) {
return
}

toast.browserWindow.webContents.send(
toast?.browserWindow?.webContents.send(
'progress',
progress
)
Expand Down Expand Up @@ -90,9 +92,10 @@ const _fireToast = (
const alert = new Alert([fonts, style, script])
toast = alert

const _closeAlert = () => closeAlert(alert)

win.once('closed', _closeAlert)
const eventHandlerCtx = addOnceProcEventHandler(
WINDOW_EVENT_NAMES.CLOSED,
() => closeAlert(alert)
)

const bwOptions = {
frame: false,
Expand Down Expand Up @@ -151,7 +154,7 @@ const _fireToast = (
alert.browserWindow.hide()
},
didClose: () => {
win.removeListener('closed', _closeAlert)
eventHandlerCtx.removeListener()

didClose(alert)
}
Expand Down Expand Up @@ -387,14 +390,16 @@ const _autoUpdaterFactory = () => {
})
autoUpdater.on('download-progress', async (progressObj) => {
try {
const { percent } = { ...progressObj }
const { percent } = progressObj ?? {}

if (isProgressToastEnabled) {
_sendProgress(percent)

return
}

isProgressToastEnabled = true

await _fireToast(
{
title: 'Downloading...',
Expand All @@ -404,8 +409,6 @@ const _autoUpdaterFactory = () => {
didOpen: (alert) => {
_sendProgress(percent)
alert.showLoading()

isProgressToastEnabled = true
},
didClose: () => {
isProgressToastEnabled = false
Expand Down
20 changes: 16 additions & 4 deletions src/change-sync-frequency.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ const { getConfigsKeeperByName } = require('./configs-keeper')
const getAlertCustomClassObj = require(
'./helpers/get-alert-custom-class-obj'
)
const {
WINDOW_EVENT_NAMES,
addOnceProcEventHandler
} = require('./window-event-manager')

const _getSchedulerRule = (timeFormat, alertRes) => {
if (timeFormat.value === 'days') {
Expand Down Expand Up @@ -219,8 +223,16 @@ module.exports = () => {

return async () => {
const win = electron.BrowserWindow.getFocusedWindow()
win.once('closed', closeTimeFormatAlert)
win.once('closed', closeAlert)
const timeFormatAlertEventHandlerCtx = addOnceProcEventHandler(
WINDOW_EVENT_NAMES.CLOSED,
closeTimeFormatAlert,
win
)
const alertEventHandlerCtx = addOnceProcEventHandler(
WINDOW_EVENT_NAMES.CLOSED,
closeAlert,
win
)

try {
const savedSchedulerRule = await configsKeeper
Expand All @@ -234,7 +246,7 @@ module.exports = () => {
inputValue: timeData.timeFormat
}
)
win.removeListener('closed', closeTimeFormatAlert)
timeFormatAlertEventHandlerCtx.removeListener()

if (timeFormat.dismiss) {
return
Expand All @@ -244,7 +256,7 @@ module.exports = () => {
alert,
getAlertOpts(timeFormat, timeData)
)
win.removeListener('closed', closeAlert)
alertEventHandlerCtx.removeListener()

if (alertRes.dismiss) {
return
Expand Down
12 changes: 9 additions & 3 deletions src/error-manager/show-modal-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ const isMainWinAvailable = require(
const {
closeAlert
} = require('../modal-dialog-src/utils')
const {
WINDOW_EVENT_NAMES,
addOnceProcEventHandler
} = require('../window-event-manager')

const mdStyle = fs.readFileSync(path.join(
rootPath, 'node_modules', 'github-markdown-css/github-markdown.css'
Expand Down Expand Up @@ -69,9 +73,11 @@ const _fireAlert = (params) => {
const maxHeight = Math.floor(screenHeight * 0.90)

const alert = new Alert([mdS, fonts, style, script])
const _close = () => closeAlert(alert)

win.once('closed', _close)
const eventHandlerCtx = addOnceProcEventHandler(
WINDOW_EVENT_NAMES.CLOSED,
() => closeAlert(alert)
)

const bwOptions = {
frame: false,
Expand Down Expand Up @@ -138,7 +144,7 @@ const _fireAlert = (params) => {
alert.browserWindow.hide()
},
didClose: () => {
win.removeListener('closed', _close)
eventHandlerCtx.removeListener()
}
}

Expand Down
12 changes: 9 additions & 3 deletions src/restore-db/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ const {
const {
DbRestoringError
} = require('../errors')
const {
WINDOW_EVENT_NAMES,
addOnceProcEventHandler
} = require('../window-event-manager')

const fontsStyle = fs.readFileSync(path.join(
rootPath, 'bfx-report-ui/build/fonts/roboto.css'
Expand Down Expand Up @@ -79,9 +83,11 @@ const _fireAlert = (params) => {
const maxHeight = Math.floor(screenHeight * 0.90)

const alert = new Alert([fonts, style, script])
const _close = () => closeAlert(alert)

win.once('closed', _close)
const eventHandlerCtx = addOnceProcEventHandler(
WINDOW_EVENT_NAMES.CLOSED,
() => closeAlert(alert)
)

const bwOptions = {
resizable: true,
Expand Down Expand Up @@ -154,7 +160,7 @@ const _fireAlert = (params) => {
alert.browserWindow.hide()
},
didClose: () => {
win.removeListener('closed', _close)
eventHandlerCtx.removeListener()
}
}

Expand Down
12 changes: 9 additions & 3 deletions src/show-docs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ const mdUserManual = fs.readFileSync(
path.join(rootPath, 'docs/user-manual.md'),
'utf8'
)
const {
WINDOW_EVENT_NAMES,
addOnceProcEventHandler
} = require('../window-event-manager')

const mdStyle = fs.readFileSync(path.join(
rootPath, 'node_modules', 'github-markdown-css/github-markdown.css'
Expand Down Expand Up @@ -75,9 +79,11 @@ const _fireAlert = (params) => {
const maxHeight = Math.floor(screenHeight * 0.90)

const alert = new Alert([mdS, fonts, style, script])
const _close = () => closeAlert(alert)

win.once('closed', _close)
const eventHandlerCtx = addOnceProcEventHandler(
WINDOW_EVENT_NAMES.CLOSED,
() => closeAlert(alert)
)

const bwOptions = {
frame: false,
Expand Down Expand Up @@ -143,7 +149,7 @@ const _fireAlert = (params) => {
alert.browserWindow.hide()
},
didClose: () => {
win.removeListener('closed', _close)
eventHandlerCtx.removeListener()
}
}

Expand Down
93 changes: 93 additions & 0 deletions src/window-event-manager/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
'use strict'

const wins = require('../windows')

const WINDOW_EVENT_NAMES = {
CLOSED: 'closed'
}

const windowMap = new Map()

const addOnceProcEventHandler = (eventName, handler, window) => {
const _window = window ?? wins.mainWindow

if (
!_window ||
!eventName ||
typeof eventName !== 'string' ||
typeof handler !== 'function'
) {
return {
isAdded: false,
removeListener: () => {}
}
}

const handlerSet = _setWinEventHandler(eventName, handler, _window)

const ctx = {
isAdded: true,
removeListener: () => handlerSet.delete(handler)
}

return ctx
}

const _setWinEventHandler = (eventName, handler, window) => {
const winEventHandlerMap = _getWinEventHandlerMap(window)
const foundHandlerSet = winEventHandlerMap.get(eventName)?.handlerSet

if (foundHandlerSet instanceof Set) {
foundHandlerSet.add(handler)

return foundHandlerSet
}

const handlerSet = new Set([handler])
const rootHandler = () => {
winEventHandlerMap.delete(eventName)

for (const handler of handlerSet) {
try {
handlerSet.delete(handler)

const res = handler()

if (!(res instanceof Promise)) {
return
}

res.then(() => {}, (err) => { console.error(err) })
} catch (err) {
console.error(err)
}
}
}

window.once(eventName, rootHandler)
winEventHandlerMap.set(eventName, {
rootHandler,
handlerSet
})

return handlerSet
}

const _getWinEventHandlerMap = (window) => {
const foundWinEventHandlerMap = windowMap.get(window)

if (foundWinEventHandlerMap instanceof Map) {
return foundWinEventHandlerMap
}

const winEventHandlerMap = new Map()
windowMap.set(window, winEventHandlerMap)

return winEventHandlerMap
}

module.exports = {
WINDOW_EVENT_NAMES,

addOnceProcEventHandler
}