2016-10-20 11:22:25 +02:00
|
|
|
// Copyright 2015, 2016 Ethcore (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/>.
|
|
|
|
|
2016-10-31 14:24:33 +01:00
|
|
|
import BigNumber from 'bignumber.js';
|
|
|
|
|
2016-11-02 11:27:28 +01:00
|
|
|
const builtinApps = [
|
2016-10-20 11:22:25 +02:00
|
|
|
{
|
2016-10-22 15:49:39 +02:00
|
|
|
id: '0xf9f2d620c2e08f83e45555247146c62185e4ab7cf82a4b9002a265a0d020348f',
|
|
|
|
url: 'basiccoin',
|
2016-10-20 11:22:25 +02:00
|
|
|
name: 'Token Deployment',
|
|
|
|
description: 'Deploy new basic tokens that you are able to send around',
|
2016-10-22 15:49:39 +02:00
|
|
|
author: 'Parity Team <admin@ethcore.io>',
|
2016-11-02 11:27:28 +01:00
|
|
|
version: '1.0.0'
|
2016-10-20 11:22:25 +02:00
|
|
|
},
|
|
|
|
{
|
2016-10-22 15:49:39 +02:00
|
|
|
id: '0xd1adaede68d344519025e2ff574650cd99d3830fe6d274c7a7843cdc00e17938',
|
|
|
|
url: 'registry',
|
2016-10-20 11:22:25 +02:00
|
|
|
name: 'Registry',
|
|
|
|
description: 'A global registry of addresses on the network',
|
2016-10-22 15:49:39 +02:00
|
|
|
author: 'Parity Team <admin@ethcore.io>',
|
2016-11-02 11:27:28 +01:00
|
|
|
version: '1.0.0'
|
2016-10-20 11:22:25 +02:00
|
|
|
},
|
|
|
|
{
|
2016-10-22 15:49:39 +02:00
|
|
|
id: '0x0a8048117e51e964628d0f2d26342b3cd915248b59bcce2721e1d05f5cfa2208',
|
|
|
|
url: 'tokenreg',
|
2016-10-20 11:22:25 +02:00
|
|
|
name: 'Token Registry',
|
|
|
|
description: 'A registry of transactable tokens on the network',
|
2016-10-22 15:49:39 +02:00
|
|
|
author: 'Parity Team <admin@ethcore.io>',
|
2016-11-02 11:27:28 +01:00
|
|
|
version: '1.0.0'
|
2016-10-20 11:22:25 +02:00
|
|
|
},
|
|
|
|
{
|
2016-10-22 15:49:39 +02:00
|
|
|
id: '0xf49089046f53f5d2e5f3513c1c32f5ff57d986e46309a42d2b249070e4e72c46',
|
|
|
|
url: 'signaturereg',
|
2016-10-20 11:22:25 +02:00
|
|
|
name: 'Method Registry',
|
|
|
|
description: 'A registry of method signatures for lookups on transactions',
|
2016-10-22 15:49:39 +02:00
|
|
|
author: 'Parity Team <admin@ethcore.io>',
|
2016-11-02 11:27:28 +01:00
|
|
|
version: '1.0.0'
|
2016-10-20 11:22:25 +02:00
|
|
|
},
|
|
|
|
{
|
2016-10-22 15:49:39 +02:00
|
|
|
id: '0x058740ee9a5a3fb9f1cfa10752baec87e09cc45cd7027fd54708271aca300c75',
|
|
|
|
url: 'githubhint',
|
2016-10-20 11:22:25 +02:00
|
|
|
name: 'GitHub Hint',
|
|
|
|
description: 'A mapping of GitHub URLs to hashes for use in contracts as references',
|
2016-10-22 15:49:39 +02:00
|
|
|
author: 'Parity Team <admin@ethcore.io>',
|
2016-11-06 12:51:53 +01:00
|
|
|
version: '1.0.0',
|
|
|
|
secure: true
|
2016-10-20 11:22:25 +02:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2016-11-02 11:27:28 +01:00
|
|
|
// TODO: This is just since we are moving gavcoin to its own repo, for a proper network solution
|
|
|
|
// we need to pull the network apps from the dapp registry. (Builtins & local apps unaffected)
|
|
|
|
// TODO: Manifest needs to be pulled from the content as well, however since the content may or may
|
|
|
|
// not be available locally (and refreshes work for index, and will give a 503), we are putting it
|
|
|
|
// in here. This part needs to be cleaned up.
|
|
|
|
const networkApps = [
|
|
|
|
{
|
|
|
|
id: '0xd798a48831b4ccdbc71de206a1d6a4aa73546c7b6f59c22a47452af414dc64d6',
|
|
|
|
name: 'GAVcoin',
|
|
|
|
description: 'Manage your GAVcoins, the hottest new property in crypto',
|
|
|
|
author: 'Gavin Wood',
|
|
|
|
version: '1.0.0'
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2016-11-04 23:08:12 +01:00
|
|
|
function getHost (api) {
|
|
|
|
return process.env.NODE_ENV === 'production'
|
|
|
|
? api.dappsUrl
|
|
|
|
: '';
|
|
|
|
}
|
|
|
|
|
2016-11-02 11:27:28 +01:00
|
|
|
export function fetchAvailable (api) {
|
2016-11-04 23:08:12 +01:00
|
|
|
return fetch(`${getHost(api)}/api/apps`)
|
2016-10-22 15:49:39 +02:00
|
|
|
.then((response) => {
|
|
|
|
return response.ok
|
|
|
|
? response.json()
|
|
|
|
: [];
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
2016-11-02 11:27:28 +01:00
|
|
|
console.warn('fetchAvailable', error);
|
2016-10-22 15:49:39 +02:00
|
|
|
return [];
|
|
|
|
})
|
2016-11-02 11:27:28 +01:00
|
|
|
.then((_localApps) => {
|
|
|
|
const localApps = _localApps
|
|
|
|
.filter((app) => !['ui'].includes(app.id))
|
|
|
|
.map((app) => {
|
2016-11-06 12:51:53 +01:00
|
|
|
app.type = 'local';
|
2016-11-02 11:27:28 +01:00
|
|
|
return app;
|
|
|
|
});
|
|
|
|
|
2016-11-06 12:51:53 +01:00
|
|
|
return api.parity
|
2016-10-31 14:24:33 +01:00
|
|
|
.registryAddress()
|
|
|
|
.then((registryAddress) => {
|
|
|
|
if (new BigNumber(registryAddress).eq(0)) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
2016-11-02 11:27:28 +01:00
|
|
|
const _builtinApps = builtinApps
|
|
|
|
.map((app) => {
|
2016-11-06 12:51:53 +01:00
|
|
|
app.type = 'builtin';
|
2016-11-02 11:27:28 +01:00
|
|
|
return app;
|
|
|
|
});
|
|
|
|
|
|
|
|
return networkApps
|
|
|
|
.map((app) => {
|
2016-11-06 12:51:53 +01:00
|
|
|
app.type = 'network';
|
2016-11-02 11:27:28 +01:00
|
|
|
return app;
|
|
|
|
})
|
|
|
|
.concat(_builtinApps);
|
2016-10-31 14:24:33 +01:00
|
|
|
})
|
2016-11-02 11:27:28 +01:00
|
|
|
.then((registryApps) => {
|
|
|
|
return registryApps
|
|
|
|
.concat(localApps)
|
|
|
|
.sort((a, b) => (a.name || '').localeCompare(b.name || ''));
|
2016-10-31 14:24:33 +01:00
|
|
|
});
|
2016-11-02 11:27:28 +01:00
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
console.warn('fetchAvailable', error);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-11-04 23:08:12 +01:00
|
|
|
export function fetchManifest (api, app, contentHash) {
|
|
|
|
return fetch(`${getHost(api)}/${contentHash}/manifest.json`)
|
2016-11-02 11:27:28 +01:00
|
|
|
.then((response) => {
|
|
|
|
return response.ok
|
|
|
|
? response.json()
|
|
|
|
: {};
|
|
|
|
})
|
|
|
|
.then((manifest) => {
|
|
|
|
Object.keys.forEach((key) => {
|
|
|
|
app[key] = manifest[key];
|
|
|
|
});
|
|
|
|
|
|
|
|
return app;
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
console.warn('fetchManifest', error);
|
2016-10-22 15:49:39 +02:00
|
|
|
});
|
2016-10-20 11:22:25 +02:00
|
|
|
}
|