Skip to content

Commit

Permalink
Merge 2.0.1 into master (#3785)
Browse files Browse the repository at this point in the history
* 🐛 Update autoUpdater to use checkForUpdatesAndNotify
using checkForUpdates causes error (due to outdated interface usage)

* Use tokenMap instead of harcoded values

* Add docs to getAccounts

* Remove redundant conditions

* 🐛 Update webpack baseconfig
Remove process overriding from base webpack config which induces unintended behaviour
electron-updater require node.js process to work as intended

* 🐛 Update ipc for bi-directional communication

Create a safe, bi-directional, synchronous bridge across isolated contexts

* ♻️ revert auto update and ipc filter change

* Mute error messages for disabled commands

* Resolve undefined data stored

* ♻️ Fix eslint errors

* ♻️ Add mainnet as default network
at times the network might not be set, setting it to default which should be mainnet

* ♻️ Show block height in btc trx details

* ♻️ Show amount in btc transaction summary

Co-authored-by: Manu Nelamane Siddalingegowda <[email protected]>
Co-authored-by: reyraa <[email protected]>
Co-authored-by: Manu <[email protected]>
  • Loading branch information
4 people authored Sep 14, 2021
1 parent e8f7100 commit 9212dd8
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 34 deletions.
25 changes: 20 additions & 5 deletions app/src/ipc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
/**
* Add ipcRenderer to the window object
*/
const ipcRenderer = window.require('electron').ipcRenderer;
window.ipc = ipcRenderer;
const {
contextBridge,
ipcRenderer,
} = require('electron');

// Expose protected methods that allow the renderer process to use
// the ipcRenderer without exposing the entire object
contextBridge.exposeInMainWorld(
'ipc',
{
send: (channel, data) => {
ipcRenderer.send(channel, data);
},
on: (channel, func) => {
ipcRenderer.on(channel, (event, ...args) => {
func(event, ...args);
});
},
},
);
5 changes: 1 addition & 4 deletions app/src/modules/autoUpdater.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import i18n from 'i18next';

const getErrorMessage = (error) => {
if (error.indexOf('404 Not Found') > -1) {
if (error.indexOf('404 Not Found') > -1 || error.indexOf('command is disabled') > -1) {
return '';
} if (error.indexOf('DISCONNECTED') > -1 || error.indexOf('net:') > -1) {
return 'Please check your internet connection.';
Expand All @@ -18,9 +18,6 @@ export default ({ // eslint-disable-line max-statements
autoUpdater.autoDownload = false;

autoUpdater.checkForUpdatesAndNotify();
setInterval(() => {
autoUpdater.checkForUpdatesAndNotify();
}, 24 * 60 * 60 * 1000);

autoUpdater.on('error', (error) => {
// eslint-disable-next-line no-console
Expand Down
4 changes: 3 additions & 1 deletion app/src/modules/win.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ const win = {
backgroundThrottling: false,
// Specifies a script that will be loaded before other scripts run in the page.
preload: path.resolve(__dirname, '../src/ipc.js'),
nodeIntegration: true,
// https://www.electronjs.org/docs/latest/tutorial/security#isolation-for-untrusted-content
nodeIntegration: false,
contextIsolation: true,
},
});

Expand Down
5 changes: 0 additions & 5 deletions config/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const webpack = require('webpack');
const { resolve } = require('path');
const { ProvidePlugin } = require('webpack');

const config = {
mode: 'development',
Expand Down Expand Up @@ -89,10 +88,6 @@ const config = {
},
},
plugins: [
new ProvidePlugin({
process: 'process/browser.js',
Buffer: ['buffer', 'Buffer'],
}),
new webpack.EnvironmentPlugin({
NACL_FAST: 'disable',
}),
Expand Down
6 changes: 5 additions & 1 deletion config/webpack.config.react.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { resolve } = require('path');
const { ContextReplacementPlugin, DefinePlugin } = require('webpack');
const { ContextReplacementPlugin, DefinePlugin, ProvidePlugin } = require('webpack');
const StyleLintPlugin = require('stylelint-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
Expand Down Expand Up @@ -99,6 +99,10 @@ const config = {
historyApiFallback: true,
},
plugins: [
new ProvidePlugin({
process: 'process/browser.js',
Buffer: ['buffer', 'Buffer'],
}),
new DefinePlugin({
VERSION: `"${bundleVersion}"`,
}),
Expand Down
3 changes: 2 additions & 1 deletion src/components/shared/transactionInfo/send.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import AccountVisual from '@toolbox/accountVisual';
import LiskAmount from '@shared/liskAmount';
import { toRawLsk } from '@utils/lsk';
import styles from './transactionInfo.css';

const Send = ({
Expand All @@ -26,7 +27,7 @@ const Send = ({
<label>{t('Amount')}</label>
<label className="amount-summary">
<LiskAmount
val={transaction.asset?.amount}
val={transaction.asset?.amount || toRawLsk(fields.amount.value)}
token={token}
/>
</label>
Expand Down
31 changes: 18 additions & 13 deletions src/store/actions/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,19 @@ export const accountLoading = () => ({
type: actionTypes.accountLoading,
});

async function getAccounts({ network, params }) {
return Object.keys(params).reduce(async (accountsPromise, token) => {
/**
* Gets the account info for given addresses of different tokens
* We have getAccounts functions for retrieving multiple accounts of
* a single blockchain. This one is for retrieving accounts of
* different blockchains.
*
* @param {Object} data
* @param {Object} data.network Network config from the Redux store
* @param {Object} data.params addresses in the form of {[token]: [address]}
* @returns {Promise<[object]>}
*/
const getAccounts = async ({ network, params }) =>
Object.keys(params).reduce(async (accountsPromise, token) => {
const accounts = await accountsPromise;
const baseUrl = network.networks[token].serviceUrl;
const account = await getAccount({ network, baseUrl, params: params[token] }, token);
Expand All @@ -39,7 +50,6 @@ async function getAccounts({ network, params }) {
[token]: account,
};
}, Promise.resolve({}));
}

/**
* This action is used to update account balance when new block was forged and
Expand All @@ -50,22 +60,17 @@ async function getAccounts({ network, params }) {
*/
export const accountDataUpdated = tokensTypes =>
async (dispatch, getState) => {
const state = getState();
const { network, settings, account } = state;
const { network, settings, account } = getState();

// Get the list of tokens that are enabled in settings
const activeTokens = tokensTypes === 'enabled'
? Object.keys(settings.token.list)
.filter(key => settings.token.list[key])
: [settings.token.active];

// Collect their addresses to send to the API
const params = activeTokens.reduce((acc, token) => {
if (token === tokenMap.LSK.key) {
acc[token] = { address: account.info[tokenMap.LSK.key].summary.address };
} else {
acc[token] = {
address: account.info[token].summary.address,
passphrase: account.passphrase,
};
}
acc[token] = { address: account.info[token].summary.address };
return acc;
}, {});

Expand Down
2 changes: 1 addition & 1 deletion src/store/middlewares/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ const checkTransactionsAndUpdateAccount = async (store, action) => {
}).length > 0;

showNotificationsForIncomingTransactions(txs, account, token.active);
const recentBtcTransaction = token.active === 'BTC'
const recentBtcTransaction = token.active === tokenMap.BTC.key
&& transactions.confirmed.filter(t => t.confirmations === 1).length > 0;

if (blockContainsRelevantTransaction || recentBtcTransaction) {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/api/network/lsk.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const getNetworkStatus = ({
network,
});

const getServiceUrl = ({ name, address = 'http://localhost:4000' }) => {
const getServiceUrl = ({ name = networkKeys.mainNet, address = 'http://localhost:4000' }) => {
if ([networkKeys.mainNet, networkKeys.testNet].includes(name)) {
return networks[name].serviceUrl;
}
Expand Down
3 changes: 2 additions & 1 deletion src/utils/api/transaction/btc.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const normalizeTransactionsResponse = ({
network,
list,
}) => list.map(({
tx, feeSatoshi, confirmations, timestamp,
tx, feeSatoshi, confirmations, timestamp, height,
}) => {
const extractedAddress = tx.outputs[0].scriptPubKey.addresses[0];
const recipientAddress = validateAddress(tokenMap.BTC.key, extractedAddress, network) === 0
Expand All @@ -37,6 +37,7 @@ const normalizeTransactionsResponse = ({
id: tx.txid,
block: {
timestamp: timestamp ? Number(timestamp) * 1000 : null,
height,
},
confirmations: confirmations || 0,
isPending: !confirmations,
Expand Down
2 changes: 1 addition & 1 deletion src/utils/localJSONStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const getFromStorage = (key, backup, cb) => {
if (ipc) {
ipc.on('configRetrieved', (action, data) => {
info = data[key];
cb(info);
cb(info || backup);
});
ipc.send('retrieveConfig');
} else {
Expand Down

0 comments on commit 9212dd8

Please sign in to comment.