├── .env
├── .env.example
├── .eslintrc.json
├── .github
└── workflows
│ ├── pull_request.yml
│ ├── release.yml
│ └── stale.yml
├── .gitignore
├── .gitmodules
├── LICENSE
├── README.md
├── clear.sh
├── logs
└── .keep
├── package-lock.json
├── package.json
├── public
├── constants.js
├── electron.js
├── entitlements.mac.plist
├── entitlements.mas.inherit.plist
├── icon.icns
├── icon.png
├── lib
│ ├── app.js
│ └── preload.js
├── trayIcon.png
├── trayIcon@2x.png
└── utils
│ ├── appMenu.js
│ ├── saveStrategiesToZIP.js
│ ├── syncReadUserSettings.js
│ └── tray.js
├── res
└── bfx-hf-ui.png
└── scripts
├── auto-updater
└── bfx.mac.updater.js
├── change-loading-win-visibility-state.js
├── db
└── .keep
├── enforce-macos-app-location.js
├── helpers
└── manage-window.js
├── ipcs.js
├── postbuild.bat
├── start-api-server.js
├── start-ds-bitfinex.js
├── window-creators.js
└── windows.js
/.env:
--------------------------------------------------------------------------------
1 | REACT_APP_WSS_URL=ws://localhost:45000
2 | REACT_APP_DS_URL=ws://localhost:23521
3 | REACT_APP_UFX_API_URL=http://localhost:45001
4 | REACT_APP_UFX_PUBLIC_API_URL=http://localhost:45001
5 | REACT_APP_UFX_WSS_URL=wss://api-pub.bitfinex.com/ws/2
6 | REACT_APP_IS_ELECTRON_APP=true
7 | GENERATE_SOURCEMAP=false
8 | SKIP_PREFLIGHT_CHECK=true
9 | ALGO_LOG=true
10 | ALGO_LOG_DIR=logs
11 | NODE_OPTIONS=--openssl-legacy-provider
12 |
13 |
--------------------------------------------------------------------------------
/.env.example:
--------------------------------------------------------------------------------
1 | REACT_APP_WSS_URL=ws://localhost:45000
2 | REACT_APP_DS_URL=ws://localhost:23521
3 | REACT_APP_UFX_API_URL=http://localhost:45001
4 | REACT_APP_UFX_PUBLIC_API_URL=http://localhost:45001
5 | REACT_APP_UFX_WSS_URL=wss://api-pub.bitfinex.com/ws/2
6 | REACT_APP_IS_ELECTRON_APP=true
7 | GENERATE_SOURCEMAP=false
8 | ALGO_LOG=true
9 | ALGO_LOG_DIR=logs
10 |
--------------------------------------------------------------------------------
/.eslintrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "env": {
3 | "node": true
4 | },
5 | "extends": ["airbnb-base"],
6 | "parserOptions": {
7 | "ecmaVersion": 2020
8 | },
9 | "rules": {
10 | "arrow-body-style": "off",
11 | "arrow-parens": "off",
12 | "import/no-cycle": "off",
13 | "import/no-named-as-default": "off",
14 | "import/no-named-as-default-member": "off",
15 | "import/prefer-default-export": "off",
16 | "linebreak-style": "off",
17 | "lines-between-class-members": "off",
18 | "max-len": "off",
19 | "no-console": "off",
20 | "no-empty-function": "off",
21 | "no-nested-ternary": "off",
22 | "no-plusplus": "off",
23 | "no-underscore-dangle": "off",
24 | "no-unused-vars": "warn",
25 | "semi": ["warn", "never"],
26 | "consistent-return": "off",
27 | "strict": "off"
28 | },
29 | "settings": { "import/core-modules": ["electron"] }
30 | }
31 |
--------------------------------------------------------------------------------
/.github/workflows/pull_request.yml:
--------------------------------------------------------------------------------
1 | name: Pull request verify workflow
2 |
3 | on:
4 | # Trigger the workflow on push or pull request,
5 | # but only for the default(master) branch
6 | push:
7 | branches: [master]
8 | pull_request:
9 | branches: [master]
10 | types: [opened, labeled, synchronize, ready_for_review]
11 |
12 | jobs:
13 | checks:
14 | runs-on: macos-latest
15 | env:
16 | # dont treat warning as error
17 | CI: false
18 |
19 | strategy:
20 | matrix:
21 | node-version: [18.18.x]
22 |
23 | steps:
24 | - name: Install sha256sum
25 | run: brew install coreutils
26 |
27 | - name: Checkout Repository
28 | uses: actions/checkout@v3
29 | with:
30 | persist-credentials: false
31 |
32 | - name: Setup Node.js ${{ matrix.node-version }}
33 | uses: actions/setup-node@v3
34 | with:
35 | node-version: ${{ matrix.node-version }}
36 |
37 | - name: Pull bfx-hf-ui-core
38 | run: npm run fetch-core
39 |
40 | - name: Install
41 | run: npm install
42 |
43 | - name: Build for linux/mac/windows
44 | run: npm run build-all
45 |
46 | - name: Results
47 | run: ls -l dist
48 |
49 | - name: Upload builds
50 | uses: actions/upload-artifact@v4
51 | with:
52 | name: artifacts
53 | retention-days: 1
54 | path: |
55 | dist/*-linux.AppImage
56 | dist/*.exe
57 | dist/*-mac.zip
58 |
59 | - name: Annotate Checks
60 | uses: tarcisiozf/ci-checks-action@master
61 | with:
62 | ghToken: ${{ secrets.GITHUB_TOKEN }}
63 | checks: '[
64 | {
65 | "name": "build",
66 | "fileName": ".build-report.json",
67 | "prChangesOnly": true
68 | },
69 | {
70 | "name": "lint",
71 | "fileName": ".lint-report.json",
72 | "prChangesOnly": true
73 | }
74 | ]'
75 |
--------------------------------------------------------------------------------
/.github/workflows/release.yml:
--------------------------------------------------------------------------------
1 | name: Github release workflow
2 |
3 | on: workflow_dispatch
4 |
5 | jobs:
6 | checks:
7 | runs-on: macos-latest
8 | env:
9 | # dont treat warning as error
10 | CI: false
11 |
12 | strategy:
13 | matrix:
14 | node-version: [18.18.x]
15 |
16 | steps:
17 | - name: Install sha256sum
18 | run: brew install coreutils
19 |
20 | - name: Checkout Repository
21 | uses: actions/checkout@v3
22 | with:
23 | persist-credentials: false
24 |
25 | - name: Setup Node.js ${{ matrix.node-version }}
26 | uses: actions/setup-node@v3
27 | with:
28 | node-version: ${{ matrix.node-version }}
29 |
30 | - name: Pull bfx-hf-ui-core
31 | run: npm run fetch-core
32 |
33 | - name: Install
34 | run: npm install
35 |
36 | - name: Release+Build for linux/mac/windows
37 | env:
38 | APPLE_TEAM_ID: ${{ secrets.BFX_APPLE_TEAM_ID }}
39 | APPLE_ID: ${{ secrets.BFX_APPLE_ID_USERNAME }}
40 | APPLE_APP_SPECIFIC_PASSWORD: ${{ secrets.BFX_APPLE_ID_HONEY_PASSWORD }}
41 | APPLEID: ${{ secrets.BFX_APPLE_ID_USERNAME }}
42 | APPLEIDPASS: ${{ secrets.BFX_APPLE_ID_HONEY_PASSWORD }}
43 | CSC_LINK: ${{ secrets.BFX_APPLE_BUILD_CERTIFICATE_B64 }}
44 | CSC_KEY_PASSWORD: ${{ secrets.BFX_APPLE_BUILD_CERTIFICATE_PASSWORD }}
45 |
46 |
47 | run: npm run deploy
48 |
49 | - name: Results
50 | run: ls -l dist
51 |
--------------------------------------------------------------------------------
/.github/workflows/stale.yml:
--------------------------------------------------------------------------------
1 | # This workflow warns and then closes issues and PRs that have had no activity for a specified amount of time.
2 | #
3 | # You can adjust the behavior by modifying this file.
4 | # For more information, see:
5 | # https://github.com/actions/stale
6 | name: Mark stale issues and pull requests
7 |
8 | on:
9 | schedule:
10 | - cron: '29 0 * * *'
11 |
12 | jobs:
13 | stale:
14 |
15 | runs-on: ubuntu-latest
16 | permissions:
17 | issues: write
18 | pull-requests: write
19 |
20 | steps:
21 | - uses: actions/stale@v3
22 | with:
23 | repo-token: ${{ secrets.GITHUB_TOKEN }}
24 | stale-issue-message: 'Stale issue message'
25 | stale-pr-message: 'Stale pull request message'
26 | stale-issue-label: 'no-issue-activity'
27 | stale-pr-label: 'no-pr-activity'
28 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /node_modules
2 | /build
3 | /scripts/db/*
4 | !/scripts/db/.keep
5 | /dist
6 |
7 | .DS_Store
8 |
9 | npm-debug.log*
10 | yarn-debug.log*
11 | yarn-error.log*
12 |
13 | src/**/*.css
14 | yarn.lock
15 |
16 | todo
17 | /db
18 |
19 | !logs/.keep
20 | logs/*
21 |
22 | .undodir
23 | Session.vim
24 |
25 | .vscode
26 |
27 |
28 | electron-builder.yml
29 | crowdin.yml
30 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "bfx-hf-ui-core"]
2 | path = bfx-hf-ui-core
3 | url = https://github.com/bitfinexcom/bfx-hf-ui-core.git
4 | branch = main
5 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## IMPORTANT NOTICES
2 |
3 | ### REPOSITORY DEPRECATION NOTICE
4 | As of March 25, 2025 this repository and other associated repositories, as well as the associated releases are no longer maintained. This repository is made available for historical, archival and other informational purposes. The use of any information in this repository could lead to unexpected results, including unexpected trading behaviors. The contents of this repository are made available pursuant to the [Apache-2.0 License](https://github.com/bitfinexcom/bfx-hf-ui/blob/master/LICENSE), including Section 7 (Disclaimer of Warranty) and 8 (Limitation of Liability).
5 |
6 | ### DMS DEPRECATION NOTICE
7 | As [announced](https://www.bitfinex.com/posts/1072/), on November 6, 2024 Bitfinex Honey will no longer support the 'dead-man switch' or 'DMS' feature. This will apply to all versions of Bitfinex Honey. Your version of Bitfinex Honey will be affected.
8 | This change will mean that the orders you created using any version of Bitfinex Honey will continue running even if you turn off the machine running Bitfinex Honey. Previously, the DMS feature would have stopped those orders when you disconnected. If you do not want those orders to continue, you can close open orders before you disconnect Bitfinex Honey, or close them manually by logging into Bitfinex.
9 | Please plan accordingly for this change.
10 |
11 | # Bitfinex Honey UI
12 |
13 | - Creates HF services as background processes
14 | - Enables order types (Accum/Dist, Ping/Pong, Iceberg, TWAP and OCOCO)
15 | - Define and backtest trading strategies
16 |
17 | ## Installation
18 |
19 | Steps to install
20 |
21 | ```bash
22 | git clone https://github.com/bitfinexcom/bfx-hf-ui
23 | cd bfx-hf-ui
24 | npm run fetch-core
25 | npm install
26 | ```
27 |
28 | Create folder to store local db
29 |
30 | ```
31 | mkdir ~/.bitfinexhoney
32 | touch ~/.bitfinexhoney/algos.json
33 | touch ~/.bitfinexhoney/hf-bitfinex.json
34 | touch ~/.bitfinexhoney/ui.json
35 | touch ~/.bitfinexhoney/strategy-executions.json
36 | ```
37 |
38 | ## Run Electron version in the browser
39 |
40 | ```bash
41 | npm run start-ds-bitfinex
42 | npm run start-api-server
43 | npm run build-css
44 | npm run start
45 | ```
46 |
47 | ## Fetch latest submodule
48 |
49 | ```bash
50 | npm run update-core
51 | ```
52 |
53 | ## Build Electron app manually
54 |
55 | Generates an installable application to run independently from the browser. Once you have ran the below command navigate to the `/dist` folder and select the instillation executable file for the operating system that you are using.
56 |
57 | ```bash
58 | npm run build
59 | npm run dist-win-unpruned # for windows
60 | npm run dist-mac # for mac
61 | npm run dist-linux # for linux
62 | ```
63 |
64 | ## Install pre-built Electron app
65 |
66 | Head to the latest cut [releases](https://github.com/bitfinexcom/bfx-hf-ui/releases) and locate the most recent release. Once there you will see installers attached for `linux`, `mac` and `windows`. Run the installer for the operating system that you are using.
67 |
68 | ## The UI
69 |
70 | Starting the Bitfinex Honey UI will spawn all of the Bitfinex Honey services that are needed to register custom algo-order definitions in the background. Currently (as of release 1.0.0) the UI will register the built in default order types which will be instantly available for use in the bitfinex.com UI. For more info on how to use algo orders once the UI is running head [here](https://medium.com/bitfinex/announcing-the-honey-framework-algorithmic-orders-8065fb70c65c).
71 |
72 | 
73 |
74 | ## API Key Permissions
75 |
76 | To login to the HF application, please use API keys generated from bitfinex platform. Minimum required API key permissions are as following:
77 |
78 | - Get orders and statuses.
79 | - Create and cancel orders.
80 | - Get wallet balances and addresses.
81 |
82 |
83 |
84 | ## Contributing
85 |
86 | 1. Fork it (https://github.com/bitfinexcom/bfx-hf-ui)
87 | 2. Create your feature branch (`git checkout -b my-new-feature)
88 | 3. Commit your changes (`git commit -am 'Add some feature'`)
89 | 4. Push to the branch (`git push origin my-new-feature`)
90 | 5. Create a new Pull Request
91 |
--------------------------------------------------------------------------------
/clear.sh:
--------------------------------------------------------------------------------
1 | find ./node_modules -maxdepth 1 -type d -name '*babel*' -exec rm -rf {} \;
2 | find ./node_modules -maxdepth 1 -type d -name '*css*' -exec rm -rf {} \;
3 | find ./node_modules -maxdepth 1 -type d -name '*jest*' -exec rm -rf {} \;
4 |
--------------------------------------------------------------------------------
/logs/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitfinexcom/bfx-hf-ui/2c41bdbbfd035e349515058ca432c0464d30687c/logs/.keep
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "bfx-hf-ui",
3 | "version": "4.0.0",
4 | "description": "Official Bitfinex Honey UI - for live trading and executing algorithmic orders/strategies",
5 | "engines": {
6 | "node": ">=18"
7 | },
8 | "type": "commonjs",
9 | "main": "./build/electron.js",
10 | "homepage": "./",
11 | "productName": "Bitfinex Honey",
12 | "build": {
13 | "productName": "Bitfinex Honey",
14 | "files": [
15 | "build/**/*",
16 | "node_modules/**/*",
17 | "src/**/*",
18 | "scripts/**/*",
19 | "clear.sh"
20 | ],
21 | "asar": false,
22 | "appId": "com.bitfinex.honey",
23 | "directories": {
24 | "buildResources": "public"
25 | },
26 | "mac": {
27 | "type": "development",
28 | "icon": "build/icon.png",
29 | "hardenedRuntime": true,
30 | "gatekeeperAssess": false,
31 | "artifactName": "${productName}-${version}-${arch}-${os}.${ext}",
32 | "category": "public.app-category.productivity",
33 | "target": [
34 | "dir",
35 | "zip"
36 | ]
37 | },
38 | "win": {
39 | "icon": "build/icon.png",
40 | "target": [
41 | "zip",
42 | "nsis"
43 | ],
44 | "publisherName": "Bitfinex Honey UI",
45 | "verifyUpdateCodeSignature": false
46 | },
47 | "linux": {
48 | "icon": "build/icon.png",
49 | "artifactName": "${productName}-${version}-${arch}-${os}.${ext}",
50 | "description": "Bitfinex Honey UI",
51 | "maintainer": "",
52 | "category": "Network",
53 | "target": [
54 | "zip",
55 | "AppImage"
56 | ]
57 | },
58 | "dmg": {
59 | "iconSize": 100,
60 | "contents": [
61 | {
62 | "x": 380,
63 | "y": 280,
64 | "type": "link",
65 | "path": "/Applications"
66 | },
67 | {
68 | "x": 110,
69 | "y": 280,
70 | "type": "file"
71 | }
72 | ],
73 | "window": {
74 | "width": 500,
75 | "height": 500
76 | }
77 | }
78 | },
79 | "scripts": {
80 | "preinstall": "cd ./bfx-hf-ui-core && npm install --omit='optional'",
81 | "build-css": "cd ./bfx-hf-ui-core && npm run build-css",
82 | "watch-css": "cd ./bfx-hf-ui-core && npm run watch-css",
83 | "start-server": "cross-env concurrently --kill-others \"npm run start-api-server\" \"npm run start-ds-bitfinex\"",
84 | "start-api-server": "env-cmd node scripts/start-api-server.js",
85 | "start-ds-bitfinex": "cross-env node scripts/start-ds-bitfinex.js",
86 | "start": "cd ./bfx-hf-ui-core && cross-env REACT_APP_DEV=1 env-cmd -f ../.env npx react-scripts start",
87 | "prebuild": "cd ./bfx-hf-ui-core && git checkout -- .",
88 | "build": "npm run fetch-core && npm run update-core && npm run preinstall && cd bfx-hf-ui-core && env-cmd -f ../.env npm run build-css && env-cmd -f ../.env npx react-scripts build",
89 | "update-core": "git submodule update --remote --merge",
90 | "fetch-core": "git submodule update --init --recursive",
91 | "postbuild": "run-script-os",
92 | "postbuild:win32": "call %CD%\\scripts\\postbuild.bat",
93 | "postbuild:darwin:linux": "rm -rf ./build && mv ./bfx-hf-ui-core/build ./build && cp -r ./public/* ./build",
94 | "dev": "cross-env concurrently --kill-others \"npm run start-server\" \"npm run start\"",
95 | "electron-dev": "cross-env concurrently \"BROWSER=none npm run start-server\" & electron .",
96 | "electron": "cross-env electron .",
97 | "electron-debug": "cross-env REACT_APP_ELECTRON_DEBUG='true' electron --inspect=9229 --remote-debugging-port=9222 .",
98 | "pack": "cross-env ./node_modules/.bin/electron-builder --dir",
99 | "deploy": "npm run build && cross-env electron-builder build -c.extraMetadata.main=build/electron.js -lwm --publish always",
100 | "build-all": "npm run build && cross-env electron-builder build -c.extraMetadata.main=build/electron.js -lwm --publish never",
101 | "dist-win-unpruned": "cross-env electron-builder --win -c.extraMetadata.main=build/electron.js --publish never",
102 | "dist-win": "cross-env npm run dist-win-unpruned && npm run package-win",
103 | "dist-mac": "cross-env electron-packager --prune . --overwrite --platform=mas --arch=x64 --icon=build/icon.png --out=dist && npm run package-mac",
104 | "dist-linux": "cross-env electron-builder --linux -c.extraMetadata.main=build/electron.js --publish never && npm run package-linux",
105 | "package-mac": "cd dist/bfx-hf-ui-mas-x64/bfx-hf-ui.app/Contents/Resources/app && sh clear.sh && node-prune && cd ../../../../../../ && zip --symlinks -r ./dist/bfx-hf-ui-mac-x64.zip ./dist/bfx-hf-ui-mas-x64 && cd ./dist/ && sha256sum bfx-hf-ui-mac-x64.zip >> sha256sums.asc && cd ..",
106 | "package-win": "cd dist/win-unpacked/resources/app && sh clear.sh && node-prune && cd ../../../../ && zip --symlinks -r ./dist/The.Honey.Framework-win.zip ./dist/win-unpacked && cd ./dist/ && sha256sum The.Honey.Framework-win.zip >> sha256sums.asc && cd ..",
107 | "package-linux": "cd dist/linux-unpacked/resources/app && sh clear.sh && node-prune && cd ../../../.. && zip --symlinks -r ./dist/The.Honey.Framework-x64-linux.zip ./dist/linux-unpacked && cd ./dist/ && sha256sum The.Honey.Framework-x64-linux.zip >> sha256sums.asc && cd ..",
108 | "release": "electron-builder -p always",
109 | "lint": "cross-env eslint --fix public && eslint --fix scripts"
110 | },
111 | "author": "Bitfinex",
112 | "license": "Apache-2.0",
113 | "bugs": {
114 | "url": "https://github.com/bitfinexcom/bfx-hf-ui/issues"
115 | },
116 | "repository": {
117 | "type": "git",
118 | "url": "https://github.com/bitfinexcom/bfx-hf-ui.git"
119 | },
120 | "keywords": [
121 | "bitfinex",
122 | "bitcoin",
123 | "BTC"
124 | ],
125 | "devDependencies": {
126 | "babel-preset-react-app": "^10.0.1",
127 | "browserslist": "^4.22.0",
128 | "electron": "^26.2.3",
129 | "electron-builder": "^24.6.4",
130 | "electron-packager": "17.1.2",
131 | "eslint": "^8.50.0",
132 | "eslint-config-airbnb-base": "^15.0.0",
133 | "eslint-plugin-import": "^2.28.1",
134 | "node-prune": "^1.0.2",
135 | "run-script-os": "^1.1.6"
136 | },
137 | "dependencies": {
138 | "adm-zip": "^0.5.10",
139 | "bfx-hf-data-server": "git+https://github.com/bitfinexcom/bfx-hf-data-server.git#v5.0.0",
140 | "bfx-hf-ext-plugin-bitfinex": "git+https://github.com/bitfinexcom/bfx-hf-ext-plugin-bitfinex.git#v1.0.13",
141 | "bfx-hf-models": "git+https://github.com/bitfinexcom/bfx-hf-models.git#v4.0.1",
142 | "bfx-hf-models-adapter-lowdb": "git+https://github.com/bitfinexcom/bfx-hf-models-adapter-lowdb.git#v1.0.6",
143 | "bfx-hf-server": "git+https://github.com/bitfinexcom/bfx-hf-server.git#v10.1.1",
144 | "bfx-hf-util": "git+https://github.com/bitfinexcom/bfx-hf-util#v1.0.12",
145 | "concurrently": "^8.2.1",
146 | "cross-env": "^7.0.3",
147 | "dotenv": "^16.3.1",
148 | "electron-log": "^4.4.8",
149 | "electron-root-path": "git+https://github.com/dmytroshch/npm-electron-root-path.git#update-deps",
150 | "electron-serve": "^1.1.0",
151 | "electron-updater": "^6.1.4",
152 | "electron-util": "^0.17.2",
153 | "electron-window-state": "^5.0.3",
154 | "env-cmd": "^10.1.0",
155 | "extract-zip": "^2.0.1"
156 | },
157 | "browserslist": {
158 | "production": [
159 | ">0.2%",
160 | "not dead",
161 | "not op_mini all"
162 | ],
163 | "development": [
164 | "last 1 chrome version",
165 | "last 1 firefox version",
166 | "last 1 safari version"
167 | ]
168 | },
169 | "babel": {
170 | "presets": [
171 | "react-app"
172 | ]
173 | }
174 | }
175 |
--------------------------------------------------------------------------------
/public/constants.js:
--------------------------------------------------------------------------------
1 | const os = require('os')
2 |
3 | const LOG_PATH = `${os.tmpdir()}/bfx-hf-ui-logs`
4 | const LOG_PATH_DS_BITFINEX = `${LOG_PATH}/ds-bitfinex-server.log`
5 | const LOG_PATH_API_SERVER = `${LOG_PATH}/api-server.log`
6 |
7 | const SCRIPT_PATH = `${__dirname}/../scripts`
8 | const SCRIPT_PATH_DS_BITFINEX = `${SCRIPT_PATH}/start-ds-bitfinex.js`
9 | const SCRIPT_PATH_API_SERVER = `${SCRIPT_PATH}/start-api-server.js`
10 |
11 | const LOCAL_STORE_CWD = `${os.homedir()}/.bitfinexhoney`
12 |
13 | const ELECTRON_CONTEXT_ALLOWED_URLS = ['https://app.eu.pendo.io']
14 |
15 | module.exports = {
16 | LOG_PATH,
17 | LOG_PATH_DS_BITFINEX,
18 | LOG_PATH_API_SERVER,
19 | SCRIPT_PATH,
20 | SCRIPT_PATH_DS_BITFINEX,
21 | SCRIPT_PATH_API_SERVER,
22 | LOCAL_STORE_CWD,
23 | ELECTRON_CONTEXT_ALLOWED_URLS,
24 | }
25 |
--------------------------------------------------------------------------------
/public/electron.js:
--------------------------------------------------------------------------------
1 | const { app } = require('electron') // eslint-disable-line
2 | const fs = require('fs')
3 | const path = require('path')
4 | const { fork } = require('child_process')
5 | // const logger = require('electron-log')
6 | const HFUIApplication = require('./lib/app')
7 | const {
8 | LOG_PATH,
9 | LOG_PATH_DS_BITFINEX,
10 | LOG_PATH_API_SERVER,
11 | SCRIPT_PATH_DS_BITFINEX,
12 | SCRIPT_PATH_API_SERVER,
13 | LOCAL_STORE_CWD,
14 | } = require('./constants')
15 |
16 | const REQUIRED_PATHS = [LOCAL_STORE_CWD, LOG_PATH]
17 |
18 | REQUIRED_PATHS.forEach((dir) => {
19 | if (!fs.existsSync(dir)) {
20 | fs.mkdirSync(dir)
21 | }
22 | })
23 |
24 | const SCRIPT_SPAWN_OPTS = {
25 | env: { ELECTRON_RUN_AS_NODE: '1' },
26 | }
27 |
28 | const dsLogStream = fs.openSync(LOG_PATH_DS_BITFINEX, 'a')
29 | const apiLogStream = fs.openSync(LOG_PATH_API_SERVER, 'a')
30 |
31 | const childDSProcess = fork(path.resolve(SCRIPT_PATH_DS_BITFINEX), [], {
32 | ...SCRIPT_SPAWN_OPTS,
33 | stdio: [null, dsLogStream, dsLogStream, 'ipc'],
34 | })
35 |
36 | const childAPIProcess = fork(path.resolve(SCRIPT_PATH_API_SERVER), [], {
37 | ...SCRIPT_SPAWN_OPTS,
38 | stdio: [null, apiLogStream, apiLogStream, 'ipc'],
39 | })
40 |
41 | new HFUIApplication({ // eslint-disable-line
42 | app,
43 | onExit: () => {
44 | childAPIProcess.kill('SIGKILL')
45 | childDSProcess.kill('SIGKILL')
46 | },
47 | })
48 |
--------------------------------------------------------------------------------
/public/entitlements.mac.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | com.apple.security.app-sandbox
5 |
6 | com.apple.security.network.client
7 |
8 | com.apple.security.network.server
9 |
10 | com.apple.security.files.user-selected.read-only
11 |
12 | com.apple.security.files.user-selected.read-write
13 |
14 | com.apple.security.files.user-selected.executable
15 |
16 | com.apple.security.device.audio-video-bridging
17 |
18 | com.apple.security.personal-information.location
19 |
20 | com.apple.security.cs.allow-unsigned-executable-memory
21 |
22 | com.apple.security.cs.disable-library-validation
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/public/entitlements.mas.inherit.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | com.apple.security.app-sandbox
6 |
7 | com.apple.security.inherit
8 |
9 | com.apple.security.network.client
10 |
11 | com.apple.security.network.server
12 |
13 | com.apple.security.files.user-selected.read-only
14 |
15 | com.apple.security.files.user-selected.read-write
16 |
17 | com.apple.security.files.user-selected.executable
18 |
19 | com.apple.security.device.audio-video-bridging
20 |
21 | com.apple.security.personal-information.location
22 |
23 | com.apple.security.cs.allow-unsigned-executable-memory
24 |
25 | com.apple.security.cs.disable-library-validation
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/public/icon.icns:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitfinexcom/bfx-hf-ui/2c41bdbbfd035e349515058ca432c0464d30687c/public/icon.icns
--------------------------------------------------------------------------------
/public/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitfinexcom/bfx-hf-ui/2c41bdbbfd035e349515058ca432c0464d30687c/public/icon.png
--------------------------------------------------------------------------------
/public/lib/app.js:
--------------------------------------------------------------------------------
1 | const url = require('url')
2 | const path = require('path')
3 | const {
4 | BrowserWindow,
5 | protocol,
6 | shell,
7 | ipcMain,
8 | dialog,
9 | screen,
10 | } = require('electron')
11 | const { autoUpdater: _autoUpdater } = require('electron-updater')
12 | const logger = require('electron-log')
13 | const windowStateKeeper = require('electron-window-state')
14 | const os = require('os')
15 | const { appendFile, mkdir } = require('fs/promises')
16 | const { existsSync } = require('fs')
17 | const enforceMacOSAppLocation = require('../../scripts/enforce-macos-app-location')
18 | const BfxMacUpdater = require('../../scripts/auto-updater/bfx.mac.updater')
19 | const {
20 | showLoadingWindow,
21 | hideLoadingWindow,
22 | } = require('../../scripts/change-loading-win-visibility-state')
23 | const { createAppMenu } = require('../utils/appMenu')
24 | const { createAppTray } = require('../utils/tray')
25 | const syncReadUserSettings = require('../utils/syncReadUserSettings')
26 | const saveStrategiesToZIP = require('../utils/saveStrategiesToZIP')
27 | const { ELECTRON_CONTEXT_ALLOWED_URLS } = require('../constants')
28 |
29 | const LOG_DIR_PATH = `${os.tmpdir()}/bfx-hf-ui-logs`
30 | const APP_LOG_PATH = `${LOG_DIR_PATH}/app.log`
31 |
32 | const isElectronDebugMode = process.env.REACT_APP_ELECTRON_DEBUG === 'true'
33 |
34 | let autoUpdater = _autoUpdater
35 |
36 | if (process.platform === 'darwin') {
37 | autoUpdater = new BfxMacUpdater()
38 | autoUpdater.addInstallingUpdateEventHandler(() => {
39 | return showLoadingWindow({
40 | description: 'Updating...',
41 | isRequiredToCloseAllWins: true,
42 | })
43 | })
44 | }
45 |
46 | autoUpdater.allowPrerelease = false
47 | autoUpdater.logger = logger
48 | autoUpdater.logger.transports.file.level = 'info'
49 | autoUpdater.autoDownload = false
50 |
51 | const CHECK_APP_UPDATES_EVERY_MS = 30 * 60 * 1000 // 30 min
52 | let appUpdatesIntervalRef = null
53 | module.exports = class HFUIApplication {
54 | static createWindow() {
55 | const fullscreen = syncReadUserSettings()?.fullScreen
56 |
57 | const { width: monitorWidth, height: monitorHeight } = screen.getPrimaryDisplay().workAreaSize
58 | const minWidth = Math.min(1200, monitorWidth)
59 | const minHeight = Math.min(600, monitorHeight)
60 |
61 | const mainWindowState = windowStateKeeper({
62 | defaultWidth: 1500,
63 | defaultHeight: 850,
64 | path: path.resolve(os.homedir(), '.bitfinexhoney'),
65 | })
66 |
67 | const win = new BrowserWindow({
68 | width: mainWindowState.width,
69 | height: mainWindowState.height,
70 | minHeight,
71 | minWidth,
72 | x: mainWindowState.x,
73 | y: mainWindowState.y,
74 | icon: path.resolve(__dirname, '../icon.png'),
75 | show: true,
76 | webPreferences: {
77 | preload: path.join(__dirname, 'preload.js'),
78 | },
79 | fullscreen,
80 | fullscreenable: true,
81 | })
82 |
83 | mainWindowState.manage(win)
84 |
85 | win.loadURL(
86 | url.format({
87 | pathname: 'index.html',
88 | protocol: 'file',
89 | slashes: true,
90 | }),
91 | )
92 |
93 | return win
94 | }
95 |
96 | static handleURLRedirect({ url: _url }) {
97 | const isURLAllowed = ELECTRON_CONTEXT_ALLOWED_URLS.some((extUrl) => _url?.includes(extUrl))
98 | if (isURLAllowed) {
99 | return {
100 | action: 'allow',
101 | }
102 | }
103 |
104 | shell.openExternal(_url)
105 | return { action: 'deny' }
106 | }
107 |
108 | constructor({ app, onExit }) {
109 | this.mainWindow = null
110 | this.tray = null
111 | this.onExitCB = onExit
112 | this.app = app
113 |
114 | this.onReady = this.onReady.bind(this)
115 | this.onActivate = this.onActivate.bind(this)
116 | this.onAllWindowsClosed = this.onAllWindowsClosed.bind(this)
117 | this.onMainWindowClosed = this.onMainWindowClosed.bind(this)
118 | this.sendOpenSettingsModalMessage = this.sendOpenSettingsModalMessage.bind(this)
119 |
120 | const isLocked = app.requestSingleInstanceLock()
121 |
122 | if (!isLocked) {
123 | app.quit()
124 | } else {
125 | app.on('second-instance', () => {
126 | if (this.mainWindow) {
127 | this.mainWindow.show()
128 | this.mainWindow.focus()
129 | dialog.showErrorBox(
130 | 'Bitfinex Honey',
131 | 'Application has been already launched',
132 | )
133 | }
134 | })
135 | }
136 |
137 | // increase memory size
138 | app.commandLine.appendSwitch('js-flags', '--max-old-space-size=2048')
139 | app.on('ready', this.onReady)
140 | app.on('window-all-closed', this.onAllWindowsClosed)
141 | app.on('activate', this.onActivate)
142 | app.on('before-quit', () => {
143 | if (this.mainWindow) {
144 | this.mainWindow.removeAllListeners('close')
145 | this.mainWindow.close()
146 | }
147 | })
148 | }
149 |
150 | spawnMainWindow() {
151 | if (this.mainWindow !== null) {
152 | return
153 | }
154 |
155 | this.mainWindow = HFUIApplication.createWindow()
156 | this.mainWindow.on('closed', this.onMainWindowClosed)
157 | this.mainWindow.on('close', (e) => {
158 | if (this.mainWindow !== null) {
159 | e.preventDefault()
160 |
161 | const shouldHideOnClose = syncReadUserSettings()?.hideOnClose
162 | if (shouldHideOnClose) {
163 | this.mainWindow.hide()
164 | } else {
165 | this.mainWindow.webContents.send('app-close')
166 | }
167 | }
168 | })
169 |
170 | this.mainWindow.on('hide', () => {
171 | this.mainWindow.webContents.send('app_hidden')
172 | this.mainWindow.once('show', () => this.mainWindow.webContents.send('app_restored'))
173 | })
174 |
175 | this.mainWindow.once('ready-to-show', () => {
176 | autoUpdater.checkForUpdates()
177 |
178 | appUpdatesIntervalRef = setInterval(() => {
179 | autoUpdater.checkForUpdates()
180 | }, CHECK_APP_UPDATES_EVERY_MS)
181 | })
182 |
183 | this.mainWindow.webContents.setWindowOpenHandler(
184 | HFUIApplication.handleURLRedirect,
185 | )
186 |
187 | this.mainWindow.webContents.once('did-finish-load', () => {
188 | const isFullscreen = this.mainWindow.isFullScreen()
189 |
190 | if (isFullscreen) {
191 | this.mainWindow.webContents.send('app_fullscreen_changed', {
192 | fullscreen: true,
193 | })
194 | }
195 | })
196 |
197 | this.mainWindow.on('enter-full-screen', () => {
198 | this.mainWindow.webContents.send('app_fullscreen_changed', {
199 | fullscreen: true,
200 | })
201 | })
202 |
203 | this.mainWindow.on('leave-full-screen', () => {
204 | this.mainWindow.webContents.send('app_fullscreen_changed', {
205 | fullscreen: false,
206 | })
207 | })
208 |
209 | ipcMain.on('app_should_restored', () => {
210 | this.mainWindow.show()
211 | })
212 |
213 | ipcMain.on('app-closed', () => {
214 | if (appUpdatesIntervalRef) {
215 | clearInterval(appUpdatesIntervalRef)
216 | }
217 | if (this.mainWindow) {
218 | this.mainWindow.removeAllListeners('close')
219 | this.mainWindow.close()
220 | }
221 | })
222 |
223 | ipcMain.on('restart_app', () => {
224 | autoUpdater.quitAndInstall(false, true)
225 | })
226 |
227 | ipcMain.on('clear_app_update_timer', () => {
228 | if (appUpdatesIntervalRef) {
229 | clearInterval(appUpdatesIntervalRef)
230 | }
231 | })
232 |
233 | ipcMain.on('app_change_fullscreen', (_, { fullscreen }) => {
234 | this.mainWindow.setFullScreen(fullscreen)
235 | })
236 |
237 | ipcMain.on('dump_log_data', async (_, _data) => {
238 | try {
239 | if (!existsSync(LOG_DIR_PATH)) {
240 | await mkdir(LOG_DIR_PATH)
241 | }
242 | let data
243 | if (_data instanceof Object) {
244 | data = JSON.stringify(_data)
245 | } else {
246 | data = _data
247 | }
248 |
249 | await appendFile(APP_LOG_PATH, `${data}${os.EOL}`)
250 | } catch (e) {
251 | console.error('[dump_log_data] (electron) Error:', e)
252 | }
253 | })
254 |
255 | ipcMain.on('download_update', () => {
256 | autoUpdater.downloadUpdate()
257 | })
258 |
259 | ipcMain.on('app_save_all_strategies.request', (_, { strategies }) => {
260 | saveStrategiesToZIP(this.app, this.mainWindow, strategies)
261 | })
262 |
263 | autoUpdater.on('update-available', (args) => {
264 | this.mainWindow.webContents.send('update_available', args)
265 | })
266 |
267 | autoUpdater.on('download-progress', (args) => {
268 | this.mainWindow.webContents.send('update_in_progress', args)
269 | })
270 |
271 | autoUpdater.on('update-downloaded', (info) => {
272 | const { downloadedFile } = { ...info }
273 | if (autoUpdater instanceof BfxMacUpdater) {
274 | autoUpdater.setDownloadedFilePath(downloadedFile)
275 | }
276 |
277 | this.mainWindow.webContents.send('update_downloaded', info)
278 | })
279 |
280 | autoUpdater.on('error', async (err) => {
281 | try {
282 | // Skip error when can't get code signature on mac
283 | if (/Could not get code signature/gi.test(err.toString())) {
284 | return
285 | }
286 | // Skip error when can't find app-update.yml. The error appears in zip packages
287 | if (/app-update.yml/gi.test(err.toString())) {
288 | return
289 | }
290 |
291 | this.mainWindow.webContents.send('update_error')
292 | await hideLoadingWindow({ isRequiredToShowMainWin: false })
293 | } catch (_err) {
294 | logger.error('autoUpdater error: ', _err)
295 | }
296 | })
297 | }
298 |
299 | sendOpenSettingsModalMessage() {
300 | const isVisible = this.mainWindow.isVisible()
301 | if (!isVisible) {
302 | this.mainWindow.show()
303 | }
304 | this.mainWindow.webContents.send('open_settings')
305 | }
306 |
307 | async onReady() {
308 | protocol.interceptFileProtocol(
309 | 'file',
310 | (request, callback) => {
311 | const fileURL = request.url.substr(7) // all urls start with 'file://'
312 | const pathfinal = path.normalize(`${__dirname}/../${fileURL}`)
313 | callback({ path: pathfinal })
314 | },
315 | (err) => {
316 | if (err) {
317 | logger.error('Failed to register protocol')
318 | }
319 | },
320 | )
321 |
322 | if (!isElectronDebugMode) {
323 | await enforceMacOSAppLocation()
324 | }
325 |
326 | createAppMenu({
327 | app: this.app,
328 | sendOpenSettingsModalMessage: this.sendOpenSettingsModalMessage,
329 | })
330 |
331 | this.spawnMainWindow()
332 |
333 | this.tray = createAppTray({
334 | win: this.mainWindow,
335 | sendOpenSettingsModalMessage: this.sendOpenSettingsModalMessage,
336 | })
337 | }
338 |
339 | async onActivate() {
340 | this.spawnMainWindow()
341 | }
342 |
343 | onMainWindowClosed() {
344 | this.mainWindow = null
345 | }
346 |
347 | onAllWindowsClosed() {
348 | this.onExitCB()
349 | this.app.quit()
350 | }
351 | }
352 |
--------------------------------------------------------------------------------
/public/lib/preload.js:
--------------------------------------------------------------------------------
1 | const { contextBridge, ipcRenderer } = require('electron')
2 |
3 | contextBridge.exposeInMainWorld(
4 | 'electronService',
5 | {
6 | sendAppClosedEvent: () => ipcRenderer.send('app-closed'),
7 | sendRestartAppEvent: () => ipcRenderer.send('restart_app'),
8 | sendClearAppUpdateTimerEvent: () => ipcRenderer.send('clear_app_update_timer'),
9 | sendDownloadUpdateEvent: () => ipcRenderer.send('download_update'),
10 | sendRestoreAppMessage: () => ipcRenderer.send('app_should_restored'),
11 | sendChangeFullscreenEvent: (fullscreen) => ipcRenderer.send('app_change_fullscreen', { fullscreen }),
12 |
13 | addAppUpdateAvailableEventListener: (cb) => ipcRenderer.on('update_available', cb),
14 | addAppUpdateDownloadProgressListener: (cb) => ipcRenderer.on('update_in_progress', cb),
15 | addAppUpdateDownloadedEventListener: (cb) => ipcRenderer.on('update_downloaded', cb),
16 | addAppUpdateErrorListener: (cb) => ipcRenderer.on('update_error', cb),
17 |
18 | dumpLogData: (data) => ipcRenderer.send('dump_log_data', data),
19 |
20 | removeAllAppUpdateEventListeners: () => {
21 | ipcRenderer.removeAllListeners('update_available')
22 | ipcRenderer.removeAllListeners('update_in_progress')
23 | ipcRenderer.removeAllListeners('update_downloaded')
24 | ipcRenderer.removeAllListeners('update_error')
25 | },
26 |
27 | getAllEvents: () => ipcRenderer.eventNames(),
28 |
29 | addAppCloseEventListener: (cb) => ipcRenderer.on('app-close', cb),
30 | addOpenSettingsModalListener: (cb) => ipcRenderer.on('open_settings', cb),
31 | addAppHiddenListener: (cb) => ipcRenderer.on('app_hidden', cb),
32 | addAppRestoredListener: (cb) => ipcRenderer.on('app_restored', cb),
33 | addFullscreenChangeListener: (cb) => ipcRenderer.on('app_fullscreen_changed', cb),
34 |
35 | sendSaveAllStrategiesEvent: (strategies) => ipcRenderer.send('app_save_all_strategies.request', { strategies }),
36 | addSaveAllStrategiesResultListner: (cb) => ipcRenderer.on('app_save_all_strategies.result', cb),
37 | removeSaveAllStrategiesResultListener: () => ipcRenderer.removeAllListeners('app_save_all_strategies.result'),
38 |
39 | removeAllGlobalListeners: () => {
40 | ipcRenderer.removeAllListeners('app-close')
41 | ipcRenderer.removeAllListeners('open_settings')
42 | ipcRenderer.removeAllListeners('app_hidden')
43 | ipcRenderer.removeAllListeners('app_restored')
44 | ipcRenderer.removeAllListeners('app_fullscreen_changed')
45 | },
46 | },
47 | )
48 |
--------------------------------------------------------------------------------
/public/trayIcon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitfinexcom/bfx-hf-ui/2c41bdbbfd035e349515058ca432c0464d30687c/public/trayIcon.png
--------------------------------------------------------------------------------
/public/trayIcon@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitfinexcom/bfx-hf-ui/2c41bdbbfd035e349515058ca432c0464d30687c/public/trayIcon@2x.png
--------------------------------------------------------------------------------
/public/utils/appMenu.js:
--------------------------------------------------------------------------------
1 | const { Menu, shell } = require('electron')
2 | const os = require('os')
3 | const url = require('url')
4 | // const { app } = require('electron')
5 |
6 | const {
7 | LOG_PATH,
8 | LOG_PATH_DS_BITFINEX,
9 | LOG_PATH_API_SERVER,
10 | } = require('../constants')
11 |
12 | const RC_KEYWORD = '-rc'
13 | const isElectronDebugMode = process.env.REACT_APP_ELECTRON_DEBUG === 'true'
14 |
15 | const DEBUG_MENU = [
16 | {
17 | label: 'Toggle Developer Tools',
18 | accelerator: (function getKeys() {
19 | const platform = os.platform()
20 | if (platform === 'darwin') {
21 | return 'Alt+Command+I'
22 | }
23 | return 'Ctrl+Shift+I'
24 | }()),
25 | click(item, focusedWindow) {
26 | if (focusedWindow) {
27 | focusedWindow.toggleDevTools()
28 | }
29 | },
30 | },
31 | {
32 | label: 'Reload',
33 | accelerator: 'Command+R',
34 | click: (item, focusedWindow) => {
35 | if (focusedWindow) {
36 | focusedWindow.webContents.loadURL(
37 | url.format({
38 | pathname: 'index.html',
39 | protocol: 'file',
40 | slashes: true,
41 | }),
42 | )
43 | }
44 | },
45 | },
46 | {
47 | label: 'Pendo Visual Design Studio',
48 | click: async (_, focusedWindow) => {
49 | if (focusedWindow) {
50 | await focusedWindow.webContents.executeJavaScript(
51 | 'window.pendo?.designerv2.launchInAppDesigner()',
52 | )
53 | }
54 | },
55 | },
56 | ]
57 |
58 | const getTemplate = ({ app, sendOpenSettingsModalMessage }) => {
59 | const appVersion = app.getVersion()
60 | const isRCMode = appVersion && appVersion.includes(RC_KEYWORD)
61 |
62 | return [
63 | {
64 | label: 'Application',
65 | submenu: [
66 | {
67 | label: 'Open settings',
68 | click: sendOpenSettingsModalMessage,
69 | },
70 | {
71 | label: 'Toggle fullscreen',
72 | role: 'togglefullscreen',
73 | accelerator: (function getKeys() {
74 | const platform = os.platform()
75 | if (platform === 'darwin') {
76 | return 'Cmd+F11'
77 | }
78 | return 'F11'
79 | }()),
80 | },
81 | {
82 | label: 'Quit',
83 | accelerator: 'CmdOrCtrl+Q',
84 | click: () => {
85 | app.quit()
86 | },
87 | },
88 | ],
89 | },
90 | {
91 | label: 'Edit',
92 | submenu: [
93 | { label: 'Undo', accelerator: 'CmdOrCtrl+Z', selector: 'undo:' },
94 | { label: 'Redo', accelerator: 'Shift+CmdOrCtrl+Z', selector: 'redo:' },
95 | { type: 'separator' },
96 | { label: 'Cut', accelerator: 'CmdOrCtrl+X', selector: 'cut:' },
97 | { label: 'Copy', accelerator: 'CmdOrCtrl+C', selector: 'copy:' },
98 | { label: 'Paste', accelerator: 'CmdOrCtrl+V', selector: 'paste:' },
99 | {
100 | label: 'Select All',
101 | accelerator: 'CmdOrCtrl+A',
102 | selector: 'selectAll:',
103 | },
104 | ],
105 | },
106 | {
107 | label: 'Diagnostics',
108 | submenu: [
109 | {
110 | label: 'Open Logs Folder',
111 | click: () => {
112 | shell.openPath(LOG_PATH).catch((e) => {
113 | console.error(`failed to open logs folder: ${e.message}`)
114 | })
115 | },
116 | },
117 | {
118 | label: 'Open Data Server Log',
119 | click: () => {
120 | shell.openPath(LOG_PATH_DS_BITFINEX).catch((e) => {
121 | console.error(
122 | `failed to open data server log file: ${e.message}`,
123 | )
124 | })
125 | },
126 | },
127 | {
128 | label: 'Open API Server Log',
129 | click: () => {
130 | shell.openPath(LOG_PATH_API_SERVER).catch((e) => {
131 | console.error(`failed to open api server log file: ${e.message}`)
132 | })
133 | },
134 | },
135 | ...(isRCMode || isElectronDebugMode ? DEBUG_MENU : []),
136 | ],
137 | },
138 | ]
139 | }
140 |
141 | const createAppMenu = (params) => {
142 | Menu.setApplicationMenu(Menu.buildFromTemplate(getTemplate(params)))
143 | }
144 |
145 | module.exports = {
146 | createAppMenu,
147 | }
148 |
--------------------------------------------------------------------------------
/public/utils/saveStrategiesToZIP.js:
--------------------------------------------------------------------------------
1 | const { dialog } = require('electron')
2 | const path = require('path')
3 | const AdmZip = require('adm-zip')
4 |
5 | module.exports = (app, mainWindow, strategies) => {
6 | const savePath = dialog.showSaveDialogSync(mainWindow, {
7 | title: 'Export strategies to...',
8 | message: 'Export strategies to...',
9 | defaultPath: path.join(
10 | app.getPath('downloads'),
11 | 'BitfinexHoney_strategies.zip',
12 | ),
13 | })
14 |
15 | if (!savePath) {
16 | mainWindow.webContents.send('app_save_all_strategies.result', {
17 | isSuccess: false,
18 | })
19 | return
20 | }
21 |
22 | const zip = new AdmZip()
23 |
24 | strategies.forEach((strategy) => {
25 | const filename = `${strategy.label}_${new Date(strategy.savedTs)
26 | .toLocaleString()}.json`.replace(/\//g, '_')
27 |
28 | zip.addFile(filename, Buffer.from(JSON.stringify(strategy)), 'utf-8')
29 | })
30 |
31 | zip
32 | .writeZipPromise(savePath)
33 | .then(() => {
34 | mainWindow.webContents.send('app_save_all_strategies.result', {
35 | isSuccess: true,
36 | })
37 | })
38 | .catch(() => mainWindow.webContents.send('app_save_all_strategies.result', {
39 | isSuccess: false,
40 | }))
41 | }
42 |
--------------------------------------------------------------------------------
/public/utils/syncReadUserSettings.js:
--------------------------------------------------------------------------------
1 | const fs = require('fs')
2 | const os = require('os')
3 | const path = require('path')
4 |
5 | module.exports = () => {
6 | const filePath = path.resolve(
7 | os.homedir(),
8 | '.bitfinexhoney',
9 | 'ui.json',
10 | )
11 |
12 | const settingsObject = JSON.parse(
13 | fs.readFileSync(filePath, { encoding: 'utf-8' }),
14 | )?.user_settings?.userSettings
15 |
16 | return settingsObject
17 | }
18 |
--------------------------------------------------------------------------------
/public/utils/tray.js:
--------------------------------------------------------------------------------
1 | const { nativeImage, Tray, Menu } = require('electron')
2 | const path = require('path')
3 |
4 | const getTemplate = ({ win, sendOpenSettingsModalMessage }) => [
5 | { label: 'Bitfinex Honey', enabled: false },
6 | { type: 'separator' },
7 | {
8 | label: 'Hide/show application',
9 | click: () => (win.isVisible() ? win.hide() : win.show()),
10 | },
11 | {
12 | label: 'Open settings',
13 | click: sendOpenSettingsModalMessage,
14 | },
15 | {
16 | role: 'quit',
17 | },
18 | ]
19 |
20 | const createAppTray = (params) => {
21 | const img = nativeImage.createFromPath(
22 | path.resolve(__dirname, '../trayIcon.png'),
23 | )
24 | const tray = new Tray(img)
25 | tray.setContextMenu(Menu.buildFromTemplate(getTemplate(params)))
26 | return tray
27 | }
28 |
29 | module.exports = {
30 | createAppTray,
31 | }
32 |
--------------------------------------------------------------------------------
/res/bfx-hf-ui.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitfinexcom/bfx-hf-ui/2c41bdbbfd035e349515058ca432c0464d30687c/res/bfx-hf-ui.png
--------------------------------------------------------------------------------
/scripts/auto-updater/bfx.mac.updater.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | const path = require('path')
4 | const fs = require('fs')
5 | const { spawn } = require('child_process')
6 | const { MacUpdater } = require('electron-updater')
7 | const extract = require('extract-zip')
8 |
9 | const { rootPath: appDir } = require('electron-root-path')
10 | const logger = require('electron-log')
11 |
12 | class BfxMacUpdater extends MacUpdater {
13 | constructor(...args) {
14 | super(...args)
15 |
16 | this.quitAndInstallCalled = false
17 | this.quitHandlerAdded = false
18 |
19 | this.EVENT_INSTALLING_UPDATE = 'EVENT_INSTALLING_UPDATE'
20 |
21 | this.installingUpdateEventHandlers = []
22 | // eslint-disable-next-line no-unused-expressions
23 | this._logger === logger
24 | }
25 |
26 | setDownloadedFilePath(downloadedFilePath) {
27 | this.downloadedFilePath = downloadedFilePath
28 | }
29 |
30 | getDownloadedFilePath() {
31 | return this.downloadedFilePath
32 | }
33 |
34 | addInstallingUpdateEventHandler(handler) {
35 | this.installingUpdateEventHandlers.push(handler)
36 | }
37 |
38 | async install(isSilent, isForceRunAfter) {
39 | try {
40 | if (this.quitAndInstallCalled) {
41 | return false
42 | }
43 |
44 | this.quitAndInstallCalled = true
45 |
46 | if (!isSilent) {
47 | await this.dispatchInstallingUpdate()
48 | }
49 |
50 | const downloadedFilePath = this.getDownloadedFilePath()
51 |
52 | const root = path.join(appDir, '../../..')
53 | const dist = path.join(root, '..')
54 | const productName = 'Bitfinex Honey'
55 | const exec = path.join(root, `Contents/MacOS/${productName}`)
56 |
57 | await fs.promises.rmdir(root, { recursive: true, force: true })
58 |
59 | await extract(
60 | downloadedFilePath,
61 | {
62 | dir: dist,
63 | defaultDirMode: '0o744',
64 | defaultFileMode: '0o744',
65 | },
66 | )
67 |
68 | if (!isForceRunAfter) {
69 | return true
70 | }
71 |
72 | spawn(exec, [], {
73 | detached: true,
74 | stdio: 'ignore',
75 | env: {
76 | ...process.env,
77 | },
78 | }).unref()
79 | return true
80 | } catch (err) {
81 | // this.dispatchError(err)
82 | this._logger.error(err)
83 |
84 | return false
85 | }
86 | }
87 |
88 | async asyncQuitAndInstall(isSilent, isForceRunAfter) {
89 | const isInstalled = await this.install(
90 | isSilent,
91 | isSilent
92 | ? isForceRunAfter
93 | : true,
94 | )
95 |
96 | if (isInstalled) {
97 | setImmediate(() => this.app.quit())
98 |
99 | return
100 | }
101 |
102 | this.quitAndInstallCalled = false
103 | }
104 |
105 | quitAndInstall(...args) {
106 | const downloadedFilePath = this.getDownloadedFilePath()
107 |
108 | if (!fs.existsSync(downloadedFilePath)) {
109 | return
110 | }
111 | if (path.extname(downloadedFilePath) !== '.zip') {
112 | return super.quitAndInstall(...args)
113 | }
114 |
115 | return this.asyncQuitAndInstall(...args)
116 | }
117 |
118 | async dispatchInstallingUpdate() {
119 | this.emit(this.EVENT_INSTALLING_UPDATE)
120 |
121 | // eslint-disable-next-line no-restricted-syntax
122 | for (const handler of this.installingUpdateEventHandlers) {
123 | if (typeof handler !== 'function') {
124 | return
125 | }
126 |
127 | // eslint-disable-next-line no-await-in-loop
128 | await handler()
129 | }
130 | }
131 |
132 | dispatchUpdateDownloaded(...args) {
133 | super.dispatchUpdateDownloaded(...args)
134 |
135 | this.addQuitHandler()
136 | }
137 |
138 | addQuitHandler() {
139 | if (
140 | this.quitHandlerAdded
141 | || !this.autoInstallOnAppQuit
142 | ) {
143 | return
144 | }
145 |
146 | this.quitHandlerAdded = true
147 |
148 | // this.app.onQuit((exitCode) => {
149 | // if (exitCode === 0) {
150 |
151 | // }
152 | // })
153 |
154 | // Need to use this.app.app prop due this.app is ElectronAppAdapter
155 | this.app.app.once('will-quit', (e) => {
156 | if (this.quitAndInstallCalled) {
157 | return
158 | }
159 |
160 | e.preventDefault()
161 | this.install(true, true).then((isInstalled) => {
162 | if (isInstalled) {
163 | setImmediate(() => this.app.quit())
164 |
165 | return
166 | }
167 |
168 | setImmediate(() => this.app.app.exit(1))
169 | })
170 | })
171 | }
172 | }
173 |
174 | module.exports = BfxMacUpdater
175 |
--------------------------------------------------------------------------------
/scripts/change-loading-win-visibility-state.js:
--------------------------------------------------------------------------------
1 | const { BrowserWindow, ipcMain } = require('electron')
2 | const logger = require('electron-log')
3 |
4 | const wins = require('./windows')
5 | const {
6 | hideWindow,
7 | showWindow,
8 | centerWindow,
9 | } = require('./helpers/manage-window')
10 | const windowCreators = require('./window-creators')
11 |
12 | let intervalMarker
13 |
14 | const _closeAllWindows = () => {
15 | const _wins = BrowserWindow.getAllWindows()
16 | .filter((win) => win !== wins.loadingWindow)
17 |
18 | const promises = _wins.map((win) => hideWindow(win))
19 |
20 | return Promise.all(promises)
21 | }
22 |
23 | const _setParentWindow = (noParent) => {
24 | if (wins.loadingWindow.isFocused()) {
25 | return
26 | }
27 |
28 | const win = BrowserWindow.getFocusedWindow()
29 |
30 | if (
31 | noParent
32 | || Object.values(wins).every((w) => w !== win)
33 | ) {
34 | wins.loadingWindow.setParentWindow(null)
35 |
36 | return
37 | }
38 |
39 | wins.loadingWindow.setParentWindow(win)
40 | }
41 |
42 | const _runProgressLoader = (opts = {}) => {
43 | const {
44 | win = wins.loadingWindow,
45 | isIndeterminateMode = false,
46 | } = { ...opts }
47 |
48 | if (
49 | !win
50 | || typeof win !== 'object'
51 | || win.isDestroyed()
52 | ) {
53 | return
54 | }
55 | if (isIndeterminateMode) {
56 | // Change to indeterminate mode when progress > 1
57 | win.setProgressBar(2)
58 |
59 | return
60 | }
61 |
62 | const fps = 50
63 | const duration = 3000 // ms
64 | const interval = duration / fps // ms
65 | const step = 1 / (duration / interval)
66 | let progress = 0
67 |
68 | intervalMarker = setInterval(() => {
69 | if (progress >= 1) {
70 | progress = 0
71 | }
72 |
73 | progress += step
74 |
75 | if (
76 | !win
77 | || typeof win !== 'object'
78 | || win.isDestroyed()
79 | ) {
80 | clearInterval(intervalMarker)
81 |
82 | return
83 | }
84 |
85 | win.setProgressBar(progress)
86 | }, interval).unref()
87 | }
88 |
89 | const _stopProgressLoader = (
90 | win = wins.loadingWindow,
91 | ) => {
92 | clearInterval(intervalMarker)
93 |
94 | if (
95 | !win
96 | || typeof win !== 'object'
97 | || win.isDestroyed()
98 | ) {
99 | return
100 | }
101 |
102 | // Remove progress bar when progress < 0
103 | win.setProgressBar(-1)
104 | }
105 |
106 | const _setLoadingDescription = (win, description) => {
107 | return new Promise((resolve) => {
108 | try {
109 | if (
110 | !win
111 | || typeof win !== 'object'
112 | || win.isDestroyed()
113 | || typeof description !== 'string'
114 | ) {
115 | resolve()
116 |
117 | return
118 | }
119 |
120 | ipcMain.once('loading:description-ready', (event, err) => {
121 | if (err) {
122 | logger.error('loading:description-ready error: ', err)
123 | }
124 |
125 | resolve()
126 | })
127 |
128 | win.webContents.send(
129 | 'loading:description',
130 | description,
131 | )
132 | } catch (err) {
133 | logger.error('_setLoadingDescription error: ', err)
134 |
135 | resolve()
136 | }
137 | })
138 | }
139 |
140 | const showLoadingWindow = async (opts = {}) => {
141 | try {
142 | const {
143 | description = '',
144 | isRequiredToCloseAllWins = false,
145 | isNotRunProgressLoaderRequired = false,
146 | isIndeterminateMode = false,
147 | noParent = false,
148 | } = { ...opts }
149 |
150 | if (isRequiredToCloseAllWins) {
151 | _closeAllWindows()
152 | }
153 |
154 | if (
155 | !wins.loadingWindow
156 | || typeof wins.loadingWindow !== 'object'
157 | || wins.loadingWindow.isDestroyed()
158 | ) {
159 | await windowCreators.createLoadingWindow()
160 | }
161 |
162 | _setParentWindow(isRequiredToCloseAllWins || noParent)
163 |
164 | if (!isNotRunProgressLoaderRequired) {
165 | _runProgressLoader({ isIndeterminateMode })
166 | }
167 |
168 | await _setLoadingDescription(
169 | wins.loadingWindow,
170 | description,
171 | )
172 |
173 | if (wins.loadingWindow.isVisible()) {
174 | return
175 | }
176 |
177 | centerWindow(wins.loadingWindow)
178 |
179 | return showWindow(wins.loadingWindow)
180 | } catch (err) {
181 | logger.error('showLoadingWindow error: ', err)
182 | }
183 | }
184 |
185 | const hideLoadingWindow = async (opts = {}) => {
186 | const {
187 | isRequiredToShowMainWin = false,
188 | } = { ...opts }
189 |
190 | if (isRequiredToShowMainWin) {
191 | await showWindow(wins.mainWindow)
192 | }
193 |
194 | // need to empty description
195 | await _setLoadingDescription(
196 | wins.loadingWindow,
197 | '',
198 | )
199 | _stopProgressLoader()
200 |
201 | return hideWindow(wins.loadingWindow)
202 | }
203 |
204 | module.exports = {
205 | showLoadingWindow,
206 | hideLoadingWindow,
207 | }
208 |
--------------------------------------------------------------------------------
/scripts/db/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitfinexcom/bfx-hf-ui/2c41bdbbfd035e349515058ca432c0464d30687c/scripts/db/.keep
--------------------------------------------------------------------------------
/scripts/enforce-macos-app-location.js:
--------------------------------------------------------------------------------
1 | const { app, dialog } = require('electron')
2 |
3 | const productName = 'Bitfinex Honey'
4 | const {
5 | showLoadingWindow,
6 | hideLoadingWindow,
7 | } = require('./change-loading-win-visibility-state')
8 |
9 | module.exports = async () => {
10 | if (
11 | process.env.NODE_ENV === 'development1'
12 | || process.platform !== 'darwin'
13 | ) {
14 | return
15 | }
16 | if (app.isInApplicationsFolder()) {
17 | return
18 | }
19 |
20 | const clickedButtonIndex = dialog.showMessageBoxSync({
21 | type: 'error',
22 | message: 'Move to Applications folder?',
23 | detail: `${productName} must live in the Applications folder to be able to run correctly.`,
24 | buttons: [
25 | 'Move to Applications folder',
26 | `Quit ${productName}`,
27 | ],
28 | defaultId: 0,
29 | cancelId: 1,
30 | })
31 |
32 | if (clickedButtonIndex === 1) {
33 | app.quit()
34 |
35 | return
36 | }
37 |
38 | await showLoadingWindow({
39 | description: 'Moving the app...',
40 | isRequiredToCloseAllWins: true,
41 | isIndeterminateMode: true,
42 | })
43 |
44 | app.moveToApplicationsFolder({
45 | conflictHandler: (conflict) => {
46 | if (conflict === 'existsAndRunning') {
47 | dialog.showMessageBoxSync({
48 | type: 'error',
49 | message: `Another version of ${productName} is currently running. Quit it, then launch this version of the app again.`,
50 | buttons: [
51 | 'OK',
52 | ],
53 | })
54 |
55 | app.quit()
56 | }
57 |
58 | return true
59 | },
60 | })
61 |
62 | await hideLoadingWindow()
63 | }
64 |
--------------------------------------------------------------------------------
/scripts/helpers/manage-window.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | const electron = require('electron')
4 |
5 | const hideWindow = (win) => {
6 | return new Promise((resolve, reject) => {
7 | try {
8 | if (
9 | !win
10 | || typeof win !== 'object'
11 | || win.isDestroyed()
12 | || !win.isVisible()
13 | ) {
14 | resolve()
15 |
16 | return
17 | }
18 |
19 | win.once('hide', resolve)
20 |
21 | win.hide()
22 | } catch (err) {
23 | reject(err)
24 | }
25 | })
26 | }
27 |
28 | const showWindow = (win) => {
29 | return new Promise((resolve, reject) => {
30 | try {
31 | if (
32 | !win
33 | || typeof win !== 'object'
34 | || win.isDestroyed()
35 | || win.isVisible()
36 | ) {
37 | resolve()
38 |
39 | return
40 | }
41 |
42 | win.once('show', resolve)
43 |
44 | win.show()
45 | } catch (err) {
46 | reject(err)
47 | }
48 | })
49 | }
50 |
51 | const centerWindow = (win, workArea) => {
52 | const screen = electron.screen || electron.remote.screen
53 | const { getCursorScreenPoint, getDisplayNearestPoint } = screen
54 |
55 | // doesn't center the window on mac
56 | // https://github.com/electron/electron/issues/26362
57 | // https://github.com/electron/electron/issues/22324
58 | win.center()
59 |
60 | const _workArea = workArea
61 | && typeof workArea === 'object'
62 | && Number.isFinite(workArea.width)
63 | && Number.isFinite(workArea.height)
64 | && Number.isFinite(workArea.x)
65 | && Number.isFinite(workArea.y)
66 | ? workArea
67 | : getDisplayNearestPoint(getCursorScreenPoint()).workArea
68 |
69 | const { width, height } = win.getContentBounds()
70 | const {
71 | width: screenWidth, height: screenHeight, x, y,
72 | } = _workArea
73 |
74 | const boundsOpts = {
75 | x: Math.round(x + (screenWidth - width) / 2),
76 | y: Math.round(y + (screenHeight - height) / 2),
77 | }
78 |
79 | win.setBounds(boundsOpts)
80 | }
81 |
82 | module.exports = {
83 | hideWindow,
84 | showWindow,
85 | centerWindow,
86 | }
87 |
--------------------------------------------------------------------------------
/scripts/ipcs.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | module.exports = {
4 | serverIpc: null,
5 | }
6 |
--------------------------------------------------------------------------------
/scripts/postbuild.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 |
3 | if exist %CD%\build (
4 | del /s /f /q %CD%\build
5 | rd /s /q .\build
6 | )
7 |
8 | mkdir build
9 | robocopy %CD%\bfx-hf-ui-core\build %CD%\build /e
10 | robocopy %CD%\public %CD%\build /e
11 |
12 | exit /b 0
13 |
--------------------------------------------------------------------------------
/scripts/start-api-server.js:
--------------------------------------------------------------------------------
1 | process.env.DEBUG = 'bfx:hf:*'
2 | process.env.DEBUG_TRACE = true
3 |
4 | require('dotenv').config()
5 | require('bfx-hf-util/lib/catch_uncaught_errors')
6 |
7 | const startHFServer = require('bfx-hf-server')
8 | const os = require('os')
9 | const { version } = require('../package.json')
10 |
11 | const dir = `${os.homedir()}/.bitfinexhoney`
12 | const { locale } = Intl.DateTimeFormat().resolvedOptions()
13 |
14 | startHFServer({
15 | dataDir: dir,
16 | uiDBPath: `${dir}/ui.json`,
17 | algoDBPath: `${dir}/algos.json`,
18 |
19 | bfxWSURL: process.env.WS_URL,
20 | bfxRestURL: 'https://api.bitfinex.com/',
21 | bfxHostedWsUrl: process.env.HOSTED_WS_URL,
22 | strategyExecutionPath: `${dir}/strategy-executions.json`,
23 |
24 | bfxMetricsWsUrl: process.env.METRICS_SERVER_URL || 'wss://h.bitfinex.com/ws/metrics/',
25 | os: process.platform,
26 | releaseVersion: version,
27 | isRC: version.includes('rc'),
28 | locale,
29 |
30 | // Data servers are started by individual scripts
31 | // hfBitfinexDBPath: `${__dirname}/db/hf-bitfinex.json`,
32 | })
33 |
--------------------------------------------------------------------------------
/scripts/start-ds-bitfinex.js:
--------------------------------------------------------------------------------
1 | process.env.DEBUG = 'bfx:hf:*'
2 |
3 | require('dotenv').config()
4 | require('bfx-hf-util/lib/catch_uncaught_errors')
5 |
6 | const HFDB = require('bfx-hf-models')
7 | const os = require('os')
8 | const DataServer = require('bfx-hf-data-server')
9 | const HFDBLowDBAdapter = require('bfx-hf-models-adapter-lowdb')
10 | const { schema: HFDBBitfinexSchema } = require('bfx-hf-ext-plugin-bitfinex')
11 |
12 | // const dir = `${os.homedir()}/.bitfinexhoney`
13 |
14 | const dbBitfinex = new HFDB({
15 | schema: HFDBBitfinexSchema,
16 | adapter: HFDBLowDBAdapter({
17 | dbPath: `${os.homedir()}/.bitfinexhoney/hf-bitfinex.json`,
18 | }),
19 | })
20 |
21 | const dsBitfinex = new DataServer({
22 | port: 23521,
23 | db: dbBitfinex,
24 | sqlitePath: `${os.homedir()}/.bitfinexhoney`,
25 | })
26 |
27 | dsBitfinex.open()
28 | .catch(err => {
29 | console.error(err)
30 | })
31 |
--------------------------------------------------------------------------------
/scripts/window-creators.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | const electron = require('electron')
4 | // const serve = require('electron-serve')
5 | const path = require('path')
6 | const url = require('url')
7 | // const logger = require('electron-log')
8 |
9 | const { BrowserWindow } = electron
10 | // const isDevEnv = process.env.NODE_ENV === 'development'
11 |
12 | const wins = require('./windows')
13 | const ipcs = require('./ipcs')
14 | const {
15 | showLoadingWindow,
16 | // hideLoadingWindow,
17 | } = require('./change-loading-win-visibility-state')
18 | const { showWindow, centerWindow } = require('./helpers/manage-window')
19 |
20 | const pathToLayoutAppInit = path.join('', 'app_init.html')
21 |
22 | const _createWindow = async (
23 | { pathname = null, winName = 'mainWindow' } = {},
24 | props = {},
25 | ) => {
26 | const point = electron.screen.getCursorScreenPoint()
27 | const { bounds, workAreaSize } = electron.screen.getDisplayNearestPoint(point)
28 | const { width: defaultWidth, height: defaultHeight } = workAreaSize
29 | const isMainWindow = winName === 'mainWindow'
30 | const {
31 | width = defaultWidth,
32 | height = defaultHeight,
33 | x,
34 | y,
35 | isMaximized,
36 | manage,
37 | } = {}
38 | const _props = {
39 | autoHideMenuBar: true,
40 | width,
41 | height,
42 | minWidth: 1000,
43 | minHeight: 650,
44 | x: !x ? bounds.x : x,
45 | y: !y ? bounds.y : y,
46 | icon: path.join(__dirname, '../build/icon.png'),
47 | backgroundColor: '#172d3e',
48 | show: true,
49 | // webPreferences: {
50 | // preload: path.join(__dirname, '../build/preload.js'),
51 | // },
52 | ...props,
53 | }
54 |
55 | wins[winName] = new BrowserWindow(_props)
56 |
57 | const startUrl = pathname
58 | ? url.format({
59 | pathname,
60 | protocol: 'file:',
61 | slashes: true,
62 | })
63 | : 'app://-'
64 |
65 | if (!pathname) {
66 | // eslint-disable-next-line no-undef
67 | await loadURL(wins[winName])
68 | }
69 |
70 | wins[winName].on('closed', () => {
71 | wins[winName] = null
72 |
73 | if (ipcs.serverIpc && typeof ipcs.serverIpc === 'object') {
74 | ipcs.serverIpc.kill('SIGINT')
75 | }
76 | })
77 |
78 | await wins[winName].loadURL(startUrl)
79 |
80 | const res = {
81 | isMaximized,
82 | isMainWindow,
83 | manage,
84 | win: wins[winName],
85 | }
86 |
87 | if (!pathname) {
88 | // eslint-disable-next-line no-use-before-define
89 | await createLoadingWindow()
90 |
91 | return res
92 | }
93 | if (_props.center) {
94 | centerWindow(wins[winName])
95 | }
96 |
97 | await showWindow(wins[winName])
98 |
99 | return res
100 | }
101 |
102 | const _createChildWindow = async (pathname, winName, opts = {}) => {
103 | const { width = 500, height = 500 } = { ...opts }
104 |
105 | const point = electron.screen.getCursorScreenPoint()
106 | const { bounds } = electron.screen.getDisplayNearestPoint(point)
107 | const x = Math.ceil(bounds.x + (bounds.width - width) / 2)
108 | const y = Math.ceil(bounds.y + (bounds.height - height) / 2)
109 |
110 | const winProps = await _createWindow(
111 | {
112 | pathname,
113 | winName,
114 | },
115 | {
116 | minWidth: width,
117 | minHeight: height,
118 | x,
119 | y,
120 | resizable: false,
121 | center: true,
122 | parent: wins.mainWindow,
123 | frame: false,
124 | ...opts,
125 | },
126 | )
127 |
128 | winProps.win.on('closed', () => {
129 | if (wins.mainWindow) {
130 | wins.mainWindow.close()
131 | }
132 |
133 | wins.mainWindow = null
134 | })
135 |
136 | return winProps
137 | }
138 |
139 | const createLoadingWindow = async () => {
140 | if (
141 | wins.loadingWindow
142 | && typeof wins.loadingWindow === 'object'
143 | && !wins.loadingWindow.isDestroyed()
144 | && !wins.loadingWindow.isVisible()
145 | ) {
146 | await showLoadingWindow()
147 |
148 | return {}
149 | }
150 |
151 | const winProps = await _createChildWindow(
152 | pathToLayoutAppInit,
153 | 'loadingWindow',
154 | {
155 | width: 350,
156 | height: 350,
157 | webPreferences: {
158 | nodeIntegration: true,
159 | contextIsolation: false,
160 | },
161 | },
162 | )
163 |
164 | return winProps
165 | }
166 | module.exports = {
167 | createLoadingWindow,
168 | }
169 |
--------------------------------------------------------------------------------
/scripts/windows.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | module.exports = {
4 | mainWindow: null,
5 | loadingWindow: null,
6 | errorWindow: null,
7 | }
8 |
--------------------------------------------------------------------------------