merge master into jr-reverse-caching
This commit is contained in:
@@ -86,7 +86,7 @@ export default class Balances {
|
||||
// If syncing, only retrieve balances once every
|
||||
// few seconds
|
||||
if (syncing) {
|
||||
this.shortThrottledFetch();
|
||||
this.shortThrottledFetch.cancel();
|
||||
return this.longThrottledFetch();
|
||||
}
|
||||
|
||||
|
||||
@@ -173,18 +173,15 @@ export function fetchTokens (_tokenIds) {
|
||||
export function fetchBalances (_addresses) {
|
||||
return (dispatch, getState) => {
|
||||
const { api, personal } = getState();
|
||||
const { visibleAccounts, accountsInfo } = personal;
|
||||
const { visibleAccounts, accounts } = personal;
|
||||
|
||||
const addresses = uniq((_addresses || visibleAccounts || []).concat(Object.keys(accountsInfo)));
|
||||
|
||||
if (addresses.length === 0) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
const addresses = uniq(_addresses || visibleAccounts || []);
|
||||
|
||||
// With only a single account, more info will be displayed.
|
||||
const fullFetch = addresses.length === 1;
|
||||
|
||||
const addressesToFetch = uniq(addresses);
|
||||
// Add accounts addresses (for notifications, accounts selection, etc.)
|
||||
const addressesToFetch = uniq(addresses.concat(Object.keys(accounts)));
|
||||
|
||||
return Promise
|
||||
.all(addressesToFetch.map((addr) => fetchAccount(addr, api, fullFetch)))
|
||||
|
||||
@@ -218,6 +218,7 @@ export default class CertificationsMiddleware {
|
||||
const _addresses = action.addresses || [];
|
||||
addresses = uniq(addresses.concat(_addresses));
|
||||
fetchConfirmedEvents();
|
||||
next(action);
|
||||
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -1,69 +0,0 @@
|
||||
// Copyright 2015, 2016 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Parity.
|
||||
|
||||
// Parity is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Parity is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import PromiseWorker from 'promise-worker';
|
||||
import runtime from 'serviceworker-webpack-plugin/lib/runtime';
|
||||
|
||||
let workerRegistration;
|
||||
|
||||
// Setup the Service Worker
|
||||
if ('serviceWorker' in navigator) {
|
||||
workerRegistration = runtime
|
||||
.register()
|
||||
.then(() => navigator.serviceWorker.ready)
|
||||
.then((registration) => {
|
||||
const _worker = registration.active;
|
||||
_worker.controller = registration.active;
|
||||
const worker = new PromiseWorker(_worker);
|
||||
|
||||
return worker;
|
||||
});
|
||||
} else {
|
||||
workerRegistration = Promise.reject('Service Worker is not available in your browser.');
|
||||
}
|
||||
|
||||
export function setWorker (worker) {
|
||||
return {
|
||||
type: 'setWorker',
|
||||
worker
|
||||
};
|
||||
}
|
||||
|
||||
export function setError (error) {
|
||||
return {
|
||||
type: 'setError',
|
||||
error
|
||||
};
|
||||
}
|
||||
|
||||
export function setupWorker () {
|
||||
return (dispatch, getState) => {
|
||||
const state = getState();
|
||||
|
||||
if (state.compiler.worker) {
|
||||
return;
|
||||
}
|
||||
|
||||
workerRegistration
|
||||
.then((worker) => {
|
||||
dispatch(setWorker(worker));
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('sw', error);
|
||||
dispatch(setWorker(null));
|
||||
});
|
||||
};
|
||||
}
|
||||
@@ -22,7 +22,7 @@ export Status from './status';
|
||||
export apiReducer from './apiReducer';
|
||||
export balancesReducer from './balancesReducer';
|
||||
export blockchainReducer from './blockchainReducer';
|
||||
export compilerReducer from './compilerReducer';
|
||||
export workerReducer from './workerReducer';
|
||||
export imagesReducer from './imagesReducer';
|
||||
export personalReducer from './personalReducer';
|
||||
export signerReducer from './signerReducer';
|
||||
|
||||
@@ -122,7 +122,7 @@ export function setVisibleAccounts (addresses) {
|
||||
return;
|
||||
}
|
||||
|
||||
dispatch(fetchBalances(addresses));
|
||||
dispatch(_setVisibleAccounts(addresses));
|
||||
dispatch(fetchBalances(addresses));
|
||||
};
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ export default handleActions({
|
||||
setVisibleAccounts (state, action) {
|
||||
const addresses = (action.addresses || []).sort();
|
||||
|
||||
if (isEqual(addresses, state.addresses)) {
|
||||
if (isEqual(addresses, state.visibleAccounts)) {
|
||||
return state;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
import * as actions from './signerActions';
|
||||
|
||||
import { inHex } from '~/api/format/input';
|
||||
import { Wallet } from '../../util/wallet';
|
||||
import { Signer } from '../../util/signer';
|
||||
|
||||
export default class SignerMiddleware {
|
||||
constructor (api) {
|
||||
@@ -58,6 +58,7 @@ export default class SignerMiddleware {
|
||||
promise
|
||||
.then((txHash) => {
|
||||
console.log('confirmRequest', id, txHash);
|
||||
|
||||
if (!txHash) {
|
||||
store.dispatch(actions.errorConfirmRequest({ id, err: 'Unable to confirm.' }));
|
||||
return;
|
||||
@@ -73,33 +74,49 @@ export default class SignerMiddleware {
|
||||
|
||||
// Sign request in-browser
|
||||
const transaction = payload.sendTransaction || payload.signTransaction;
|
||||
|
||||
if (wallet && transaction) {
|
||||
(transaction.nonce.isZero()
|
||||
const noncePromise = transaction.nonce.isZero()
|
||||
? this._api.parity.nextNonce(transaction.from)
|
||||
: Promise.resolve(transaction.nonce)
|
||||
).then(nonce => {
|
||||
let txData = {
|
||||
to: inHex(transaction.to),
|
||||
nonce: inHex(transaction.nonce.isZero() ? nonce : transaction.nonce),
|
||||
gasPrice: inHex(transaction.gasPrice),
|
||||
gasLimit: inHex(transaction.gas),
|
||||
value: inHex(transaction.value),
|
||||
data: inHex(transaction.data)
|
||||
};
|
||||
: Promise.resolve(transaction.nonce);
|
||||
|
||||
try {
|
||||
// NOTE: Derving the key takes significant amount of time,
|
||||
// make sure to display some kind of "in-progress" state.
|
||||
const signer = Wallet.fromJson(wallet, password);
|
||||
const rawTx = signer.signTransaction(txData);
|
||||
const { worker } = store.getState().worker;
|
||||
|
||||
handlePromise(this._api.signer.confirmRequestRaw(id, rawTx));
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
const signerPromise = worker && worker._worker.state === 'activated'
|
||||
? worker
|
||||
.postMessage({
|
||||
action: 'getSignerSeed',
|
||||
data: { wallet, password }
|
||||
})
|
||||
.then((result) => {
|
||||
const seed = Buffer.from(result.data);
|
||||
return new Signer(seed);
|
||||
})
|
||||
: Signer.fromJson(wallet, password);
|
||||
|
||||
// NOTE: Derving the key takes significant amount of time,
|
||||
// make sure to display some kind of "in-progress" state.
|
||||
return Promise
|
||||
.all([ signerPromise, noncePromise ])
|
||||
.then(([ signer, nonce ]) => {
|
||||
const txData = {
|
||||
to: inHex(transaction.to),
|
||||
nonce: inHex(transaction.nonce.isZero() ? nonce : transaction.nonce),
|
||||
gasPrice: inHex(transaction.gasPrice),
|
||||
gasLimit: inHex(transaction.gas),
|
||||
value: inHex(transaction.value),
|
||||
data: inHex(transaction.data)
|
||||
};
|
||||
|
||||
return signer.signTransaction(txData);
|
||||
})
|
||||
.then((rawTx) => {
|
||||
return handlePromise(this._api.signer.confirmRequestRaw(id, rawTx));
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error.message);
|
||||
store.dispatch(actions.errorConfirmRequest({ id, err: error.message }));
|
||||
}
|
||||
});
|
||||
return;
|
||||
});
|
||||
}
|
||||
|
||||
handlePromise(this._api.signer.confirmRequest(id, { gas, gasPrice }, password));
|
||||
|
||||
@@ -125,12 +125,13 @@ export default class Status {
|
||||
this._store.dispatch(statusCollection(status));
|
||||
this._status = status;
|
||||
}
|
||||
|
||||
nextTimeout();
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('_pollStatus', error);
|
||||
nextTimeout();
|
||||
});
|
||||
|
||||
nextTimeout();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
68
js/src/redux/providers/worker.js
Normal file
68
js/src/redux/providers/worker.js
Normal file
@@ -0,0 +1,68 @@
|
||||
// Copyright 2015, 2016 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Parity.
|
||||
|
||||
// Parity is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Parity is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import PromiseWorker from 'promise-worker';
|
||||
import runtime from 'serviceworker-webpack-plugin/lib/runtime';
|
||||
|
||||
import { setWorker } from './workerActions';
|
||||
|
||||
function getWorker () {
|
||||
// Setup the Service Worker
|
||||
if ('serviceWorker' in navigator) {
|
||||
return runtime
|
||||
.register()
|
||||
.then(() => navigator.serviceWorker.ready)
|
||||
.then((registration) => {
|
||||
const worker = registration.active;
|
||||
worker.controller = registration.active;
|
||||
|
||||
return new PromiseWorker(worker);
|
||||
});
|
||||
}
|
||||
|
||||
return Promise.reject('Service Worker is not available in your browser.');
|
||||
}
|
||||
|
||||
export const setupWorker = (store) => {
|
||||
const { dispatch, getState } = store;
|
||||
|
||||
const state = getState();
|
||||
const stateWorker = state.worker.worker;
|
||||
|
||||
if (stateWorker !== undefined && !(stateWorker && stateWorker._worker.state === 'redundant')) {
|
||||
return;
|
||||
}
|
||||
|
||||
getWorker()
|
||||
.then((worker) => {
|
||||
if (worker) {
|
||||
worker._worker.addEventListener('statechange', (event) => {
|
||||
console.warn('worker state changed to', worker._worker.state);
|
||||
|
||||
// Re-install the new Worker
|
||||
if (worker._worker.state === 'redundant') {
|
||||
setupWorker(store);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
dispatch(setWorker(worker));
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('sw', error);
|
||||
dispatch(setWorker(null));
|
||||
});
|
||||
};
|
||||
29
js/src/redux/providers/workerActions.js
Normal file
29
js/src/redux/providers/workerActions.js
Normal file
@@ -0,0 +1,29 @@
|
||||
// Copyright 2015, 2016 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Parity.
|
||||
|
||||
// Parity is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Parity is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
export function setWorker (worker) {
|
||||
return {
|
||||
type: 'setWorker',
|
||||
worker
|
||||
};
|
||||
}
|
||||
|
||||
export function setError (error) {
|
||||
return {
|
||||
type: 'setError',
|
||||
error
|
||||
};
|
||||
}
|
||||
@@ -24,7 +24,7 @@ const initialState = {
|
||||
export default handleActions({
|
||||
setWorker (state, action) {
|
||||
const { worker } = action;
|
||||
return Object.assign({}, state, { worker });
|
||||
return Object.assign({}, state, { worker: worker || null });
|
||||
},
|
||||
|
||||
setError (state, action) {
|
||||
@@ -19,7 +19,7 @@ import { routerReducer } from 'react-router-redux';
|
||||
|
||||
import {
|
||||
apiReducer, balancesReducer, blockchainReducer,
|
||||
compilerReducer, imagesReducer, personalReducer,
|
||||
workerReducer, imagesReducer, personalReducer,
|
||||
signerReducer, statusReducer as nodeStatusReducer,
|
||||
snackbarReducer, walletReducer
|
||||
} from './providers';
|
||||
@@ -41,13 +41,13 @@ export default function () {
|
||||
balances: balancesReducer,
|
||||
certifications: certificationsReducer,
|
||||
blockchain: blockchainReducer,
|
||||
compiler: compilerReducer,
|
||||
images: imagesReducer,
|
||||
nodeStatus: nodeStatusReducer,
|
||||
personal: personalReducer,
|
||||
registry: registryReducer,
|
||||
signer: signerReducer,
|
||||
snackbar: snackbarReducer,
|
||||
wallet: walletReducer,
|
||||
registry: registryReducer
|
||||
worker: workerReducer
|
||||
});
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import initMiddleware from './middleware';
|
||||
import initReducers from './reducers';
|
||||
|
||||
import { load as loadWallet } from './providers/walletActions';
|
||||
import { setupWorker } from './providers/worker';
|
||||
|
||||
import {
|
||||
Balances as BalancesProvider,
|
||||
@@ -43,6 +44,7 @@ export default function (api, browserHistory) {
|
||||
new StatusProvider(store, api).start();
|
||||
|
||||
store.dispatch(loadWallet(api));
|
||||
setupWorker(store);
|
||||
|
||||
return store;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user