From 2690736be905be51c9f45dbecff0d1a92f7eb46f Mon Sep 17 00:00:00 2001 From: Maxwell Lasky Date: Tue, 9 Aug 2022 11:56:37 -0600 Subject: [PATCH 1/2] bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 817ffca0a..89d1e0b4e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "Neon", - "version": "2.13.0", + "version": "2.13.1", "main": "./main.js", "description": "Light wallet for NEO blockchain", "homepage": "https://github.com/CityOfZion/neon-wallet", From 2120c3c5c17a7f86c2d210738dc1e3db1074bb79 Mon Sep 17 00:00:00 2001 From: Maxwell Lasky Date: Fri, 12 Aug 2022 08:26:02 -0600 Subject: [PATCH 2/2] Replace all instances of dialog with bridge --- .../GeneratedTransactionModal.jsx | 18 +++--- .../ImportTransactionModal.jsx | 58 +++++++++---------- app/containers/Settings/Settings.jsx | 28 +++++---- .../TransactionHistory/TransactionHistory.jsx | 10 ++-- app/core/storage.js | 17 +++--- main.js | 14 ++++- 6 files changed, 80 insertions(+), 65 deletions(-) diff --git a/app/components/Modals/GeneratedTransactionModal/GeneratedTransactionModal.jsx b/app/components/Modals/GeneratedTransactionModal/GeneratedTransactionModal.jsx index 1d2a77547..393e6a292 100644 --- a/app/components/Modals/GeneratedTransactionModal/GeneratedTransactionModal.jsx +++ b/app/components/Modals/GeneratedTransactionModal/GeneratedTransactionModal.jsx @@ -46,21 +46,20 @@ export default class GeneratedTransactionModal extends React.Component< handleSave = async () => { const { showSuccessNotification, showErrorNotification } = this.props - const { dialog, app } = electron + const { ipcRenderer } = electron + const path = await ipcRenderer.invoke('getPath', 'documents') try { - dialog.showSaveDialog( - { - defaultPath: `${app.getPath( - 'documents', - )}/neon-wallet-transaction-${moment().unix()}`, + ipcRenderer + .invoke('dialog', 'showSaveDialog', { + defaultPath: `${path}/neon-wallet-transaction-${moment().unix()}`, filters: [ { name: 'JSON', extensions: ['json'], }, ], - }, - fileName => { + }) + .then(fileName => { if (fileName === undefined) { return } @@ -82,8 +81,7 @@ export default class GeneratedTransactionModal extends React.Component< } }, ) - }, - ) + }) } catch (err) { console.error(err) showErrorNotification({ diff --git a/app/components/Modals/ImportTransactionModal/ImportTransactionModal.jsx b/app/components/Modals/ImportTransactionModal/ImportTransactionModal.jsx index 998767e39..281e142c8 100644 --- a/app/components/Modals/ImportTransactionModal/ImportTransactionModal.jsx +++ b/app/components/Modals/ImportTransactionModal/ImportTransactionModal.jsx @@ -17,7 +17,7 @@ import SaveIcon from '../../../assets/icons/save-icon.svg' import Button from '../../Button' import Loading from '../../../containers/App/Loading' -const electron = require('electron') +const { ipcRenderer } = require('electron') type Tx = { type: number, @@ -113,27 +113,29 @@ export default class GeneratedTransactionModal extends React.Component< handleImport = async (isSignedRawTx: boolean = false) => { const { showErrorNotification } = this.props - const { dialog } = electron try { - dialog.showOpenDialog(fileName => { - if (fileName === undefined) { - return null - } - const rawData = fs.readFileSync(fileName[0]) + ipcRenderer + .invoke('dialog', { properties: ['openFile'] }) + .then(async fileName => { + if (fileName === undefined) { + return null + } - const data = isSignedRawTx - ? rawData.toString('utf8') - : JSON.parse(rawData) - const transaction = isSignedRawTx ? data : JSON.stringify(data) + const rawData = fs.readFileSync(fileName[0]) - return isSignedRawTx - ? this.setState({ - serializedTransactionInput: transaction, - }) - : this.setState({ - transaction, - }) - }) + const data = isSignedRawTx + ? rawData.toString('utf8') + : JSON.parse(rawData) + const transaction = isSignedRawTx ? data : JSON.stringify(data) + + return isSignedRawTx + ? this.setState({ + serializedTransactionInput: transaction, + }) + : this.setState({ + transaction, + }) + }) } catch (err) { console.error(err) showErrorNotification({ @@ -144,21 +146,20 @@ export default class GeneratedTransactionModal extends React.Component< handleSave = async (isSignedRawTx: boolean = false) => { const { showSuccessNotification, showErrorNotification } = this.props - const { dialog, app } = electron + + const path = await ipcRenderer.invoke('getPath', 'documents') try { - dialog.showSaveDialog( - { - defaultPath: `${app.getPath( - 'documents', - )}/neon-wallet-signed-transaction-${moment().unix()}`, + ipcRenderer + .invoke('dialog', 'showSaveDialog', { + defaultPath: `${path}}/neon-wallet-signed-transaction-${moment().unix()}`, filters: [ { name: isSignedRawTx ? 'TXT' : 'JSON', extensions: isSignedRawTx ? ['txt'] : ['json'], }, ], - }, - fileName => { + }) + .then(fileName => { if (fileName === undefined) { return } @@ -181,8 +182,7 @@ export default class GeneratedTransactionModal extends React.Component< } }, ) - }, - ) + }) } catch (err) { console.error(err) showErrorNotification({ diff --git a/app/containers/Settings/Settings.jsx b/app/containers/Settings/Settings.jsx index 38e93a454..3347af945 100644 --- a/app/containers/Settings/Settings.jsx +++ b/app/containers/Settings/Settings.jsx @@ -35,7 +35,7 @@ import SaveIcon from '../../assets/icons/save-icon.svg' import pack from '../../../package.json' import { LanguageSettingsIcon } from '../../components/Inputs/LanguageSelect/LanguageSelect' -const { dialog, shell } = require('electron') +const { ipcRenderer, shell } = require('electron') type Props = { setAccounts: (Array) => any, @@ -76,7 +76,11 @@ export const loadWalletRecovery = async ( setN3Accounts: (Array) => any, chain: string, ) => { - const { canceled, filePaths } = await dialog.showOpenDialog() + const { canceled, filePaths } = await ipcRenderer.invoke( + 'dialog', + 'showOpenDialog', + { properties: ['openFile'] }, + ) if (canceled || !filePaths) return const filepath = filePaths[0] @@ -148,14 +152,18 @@ export default class Settings extends Component { }) return } - const { filePath, canceled } = await dialog.showSaveDialog({ - filters: [ - { - name: 'JSON', - extensions: ['json'], - }, - ], - }) + const { filePath, canceled } = await await ipcRenderer.invoke( + 'dialog', + 'showSaveDialog', + { + filters: [ + { + name: 'JSON', + extensions: ['json'], + }, + ], + }, + ) if (filePath && !canceled) { fs.writeFile(filePath, content, errorWriting => { diff --git a/app/containers/TransactionHistory/TransactionHistory.jsx b/app/containers/TransactionHistory/TransactionHistory.jsx index f03158563..ac411c0ef 100644 --- a/app/containers/TransactionHistory/TransactionHistory.jsx +++ b/app/containers/TransactionHistory/TransactionHistory.jsx @@ -18,7 +18,7 @@ import { parseAbstractData, } from '../../actions/transactionHistoryActions' -const { dialog, app } = require('electron') +const { ipcRenderer, app } = require('electron') type Props = { chain: string, @@ -154,10 +154,10 @@ export default class TransactionHistory extends Component { }), ) hideNotification(infoNotification) - const result = await dialog.showSaveDialog({ - defaultPath: `${app.getPath( - 'documents', - )}/neon-wallet-activity-${moment().unix()}.csv`, + const path = await ipcRenderer.invoke('getPath', 'documents') + + const result = await ipcRenderer.invoke('dialog', 'showSaveDialog', { + defaultPath: `${path}/neon-wallet-activity-${moment().unix()}.csv`, filters: [ { name: 'CSV', diff --git a/app/core/storage.js b/app/core/storage.js index c81d3048e..b7328f3bd 100644 --- a/app/core/storage.js +++ b/app/core/storage.js @@ -8,7 +8,7 @@ const set = promisify(storage.set, storage) const ENCRYPTED_FILES_WHITELIST = ['address'] export const setStorage = async (key, value, encrypt = false) => { - const path = await ipcRenderer.invoke('getPath') + const path = await ipcRenderer.invoke('getStoragePath') storage.setDataPath(path) const encryptedValue = await ipcRenderer.invoke( 'safeStorageEncrypt', @@ -18,25 +18,22 @@ export const setStorage = async (key, value, encrypt = false) => { } export const getStorage = async key => { - const path = await ipcRenderer.invoke('getPath') + const path = await ipcRenderer.invoke('getStoragePath') storage.setDataPath(path) const value = await get(key) - + const encryptionIsWhitelisted = !!ENCRYPTED_FILES_WHITELIST.find(fileName => + key.toLowerCase().includes(fileName), + ) // If the file name being requested includes address // and is NOT encrypted, we encrypt the file. - if ( - key && - !!ENCRYPTED_FILES_WHITELIST.find(fileName => - key.toLowerCase().includes(fileName), - ) - ) { + if (key && encryptionIsWhitelisted) { // if the value is a valid JS object it has not been encrypted if (typeof value === 'object') { await setStorage(key, value, true) } } // Only encrypted values get stored as strings - if (typeof value === 'string') { + if (typeof value === 'string' && encryptionIsWhitelisted) { const decryptedValue = await ipcRenderer.invoke('safeStorageDecrypt', value) return JSON.parse(decryptedValue) } diff --git a/main.js b/main.js index ef41136ce..7aceed3a8 100644 --- a/main.js +++ b/main.js @@ -7,11 +7,13 @@ const { session, ipcMain, safeStorage, + dialog, } = require('electron') // eslint-disable-line import/no-extraneous-dependencies const path = require('path') const url = require('url') const { autoUpdater } = require('electron-updater') const log = require('electron-log') +const fs = require('fs') const port = process.env.PORT || 3000 @@ -261,7 +263,12 @@ ipcMain.on('closed', () => { app.quit() }) -ipcMain.handle('getPath', async () => `${app.getPath('userData')}/storage`) +ipcMain.handle( + 'getStoragePath', + async () => `${app.getPath('userData')}/storage`, +) + +ipcMain.handle('getPath', async (event, folder) => app.getPath(folder)) ipcMain.handle('safeStorageEncrypt', async (event, value) => { const buffer = safeStorage.encryptString(value) @@ -275,6 +282,11 @@ ipcMain.handle('safeStorageDecrypt', async (event, value) => { return plainText }) +ipcMain.handle('dialog', async (event, method, params) => { + const result = await dialog[method](params) + return result +}) + autoUpdater.logger = log autoUpdater.logger.transports.file.level = 'info'