Merge branch 'master' into ui-2

This commit is contained in:
Jaco Greeff 2017-05-11 09:57:39 +02:00
commit b1a390983b
5 changed files with 51 additions and 68 deletions

2
Cargo.lock generated
View File

@ -1781,7 +1781,7 @@ dependencies = [
[[package]] [[package]]
name = "parity-ui-precompiled" name = "parity-ui-precompiled"
version = "1.4.0" version = "1.4.0"
source = "git+https://github.com/paritytech/js-precompiled.git#eef7f1ac0dfc44527ef1925968235c5e69add959" source = "git+https://github.com/paritytech/js-precompiled.git#d370bad71ec9c573828136f7b64f893173cdacee"
dependencies = [ dependencies = [
"parity-dapps-glue 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-dapps-glue 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
] ]

View File

@ -1,6 +1,6 @@
{ {
"name": "parity.js", "name": "parity.js",
"version": "1.7.73", "version": "1.7.74",
"main": "release/index.js", "main": "release/index.js",
"jsnext:main": "src/index.js", "jsnext:main": "src/index.js",
"author": "Parity Team <admin@parity.io>", "author": "Parity Team <admin@parity.io>",

View File

@ -16,22 +16,11 @@
import store from 'store'; import store from 'store';
import { ERROR_CODES } from '@parity/api/transport/error';
export const LS_REQUESTS_KEY = '_parity::requests'; export const LS_REQUESTS_KEY = '_parity::requests';
export default class SavedRequests { export default class SavedRequests {
network = null;
/**
* Load the network version, and then the related requests
*/
load (api) { load (api) {
return api.net.version() return this.loadRequests(api)
.then((network) => {
this.network = network;
return this.loadRequests(api);
})
.catch((error) => { .catch((error) => {
console.error(error); console.error(error);
return []; return [];
@ -43,28 +32,38 @@ export default class SavedRequests {
*/ */
loadRequests (api) { loadRequests (api) {
const requests = this._get(); const requests = this._get();
return api.parity.localTransactions()
.then((localTransactions) => {
const promises = Object.values(requests).map((request) => { const promises = Object.values(requests).map((request) => {
const { requestId, transactionHash } = request; const { requestId, transactionHash } = request;
// The request hasn't been signed yet
if (transactionHash) { if (transactionHash) {
return request; // The transaction might be from an other
} // chain
if (!localTransactions[transactionHash]) {
return this._requestExists(api, requestId) this.remove(requestId);
.then((exists) => {
if (!exists) {
return null; return null;
} }
return request; return request;
}) }
.catch(() => {
// The request hasn't been signed yet
return this._requestExists(api, requestId)
.then((exists) => {
if (!exists) {
this.remove(requestId); this.remove(requestId);
return null;
}
return request;
}); });
}); });
return Promise.all(promises).then((requests) => requests.filter((request) => request)); return Promise.all(promises);
})
.then((requests) => requests.filter((request) => request));
} }
save (requestId, requestData) { save (requestId, requestData) {
@ -86,33 +85,23 @@ export default class SavedRequests {
} }
_get () { _get () {
const allRequests = store.get(LS_REQUESTS_KEY) || {}; return store.get(LS_REQUESTS_KEY) || {};
return allRequests[this.network] || {};
} }
_set (requests = {}) { _set (requests = {}) {
const allRequests = store.get(LS_REQUESTS_KEY) || {};
if (Object.keys(requests).length > 0) { if (Object.keys(requests).length > 0) {
allRequests[this.network] = requests; return store.set(LS_REQUESTS_KEY, requests);
} else {
delete allRequests[this.network];
} }
return store.set(LS_REQUESTS_KEY, allRequests); return store.remove(LS_REQUESTS_KEY);
} }
_requestExists (api, requestId) { _requestExists (api, requestId) {
return api.parity return api.parity
.checkRequest(requestId) .checkRequest(requestId)
.then(() => true) .then(() => true)
.catch((error) => { .catch(() => {
if (error.code === ERROR_CODES.REQUEST_NOT_FOUND) {
return false; return false;
}
throw error;
}); });
} }
} }

View File

@ -19,23 +19,25 @@ import store from 'store';
import SavedRequests, { LS_REQUESTS_KEY } from './savedRequests'; import SavedRequests, { LS_REQUESTS_KEY } from './savedRequests';
const NETWORK_ID = 42;
const DEFAULT_REQUEST = { const DEFAULT_REQUEST = {
requestId: '0x1', requestId: '0x1',
transaction: {} transaction: {}
}; };
const api = createApi(NETWORK_ID); const SIGNED_REQUEST = {
const api2 = createApi(1); requestId: '0x2',
transactionHash: '0xabcdef',
transaction: {}
};
const api = createApi();
const savedRequests = new SavedRequests(); const savedRequests = new SavedRequests();
function createApi (networkVersion) { function createApi () {
return { return {
parity: { parity: {
checkRequest: sinon.stub().resolves() checkRequest: sinon.stub().resolves(),
}, localTransactions: sinon.stub().resolves([])
net: {
version: sinon.stub().resolves(networkVersion)
} }
}; };
} }
@ -43,9 +45,8 @@ function createApi (networkVersion) {
describe('shell/Requests/savedRequests', () => { describe('shell/Requests/savedRequests', () => {
beforeEach((done) => { beforeEach((done) => {
store.set(LS_REQUESTS_KEY, { store.set(LS_REQUESTS_KEY, {
[NETWORK_ID]: { [DEFAULT_REQUEST.requestId]: DEFAULT_REQUEST,
[DEFAULT_REQUEST.requestId]: DEFAULT_REQUEST [SIGNED_REQUEST.requestId]: SIGNED_REQUEST
}
}); });
savedRequests.load(api) savedRequests.load(api)
@ -75,7 +76,7 @@ describe('shell/Requests/savedRequests', () => {
const requests = savedRequests._get(); const requests = savedRequests._get();
expect(requests).to.deep.equal({}); expect(requests[DEFAULT_REQUEST.requestId]).to.be.undefined;
}); });
it('saves new requests', () => { it('saves new requests', () => {
@ -92,14 +93,7 @@ describe('shell/Requests/savedRequests', () => {
it('loads requests', () => { it('loads requests', () => {
return savedRequests.load(api) return savedRequests.load(api)
.then((requests) => { .then((requests) => {
expect(requests[0]).to.deep.equal(DEFAULT_REQUEST); expect(requests).to.deep.equal([ DEFAULT_REQUEST ]);
});
});
it('loads requests from the right network', () => {
return savedRequests.load(api2)
.then((requests) => {
expect(requests).to.deep.equal([]);
}); });
}); });
}); });

View File

@ -18,7 +18,7 @@ echo "Version: $version" >> $control
echo "Source: parity" >> $control echo "Source: parity" >> $control
echo "Section: science" >> $control echo "Section: science" >> $control
echo "Priority: extra" >> $control echo "Priority: extra" >> $control
echo "Maintainer: Ethcore <devops@parity.io>" >> $control echo "Maintainer: Parity Technologies <devops@parity.io>" >> $control
echo "Build-Depends: debhelper (>=9)" >> $control echo "Build-Depends: debhelper (>=9)" >> $control
echo "Standards-Version: 3.9.5" >> $control echo "Standards-Version: 3.9.5" >> $control
echo "Homepage: https://parity.io" >> $control echo "Homepage: https://parity.io" >> $control
@ -26,7 +26,7 @@ echo "Vcs-Git: git://github.com/paritytech/parity.git" >> $control
echo "Vcs-Browser: https://github.com/paritytech/parity" >> $control echo "Vcs-Browser: https://github.com/paritytech/parity" >> $control
echo "Architecture: $1" >> $control echo "Architecture: $1" >> $control
echo "Depends: libssl1.0.0 (>=1.0.0)" >> $control echo "Depends: libssl1.0.0 (>=1.0.0)" >> $control
echo "Description: Ethereum network client by Ethcore" >> $control echo "Description: Ethereum network client by Parity Technologies" >> $control
#build .deb package #build .deb package
exit exit