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]]
name = "parity-ui-precompiled"
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 = [
"parity-dapps-glue 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
]

View File

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

View File

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

View File

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

View File

@ -18,7 +18,7 @@ echo "Version: $version" >> $control
echo "Source: parity" >> $control
echo "Section: science" >> $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 "Standards-Version: 3.9.5" >> $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 "Architecture: $1" >> $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
exit