Allow operation when no registry is available (#2980)

* Allow retrieval of native network balances without registry

* Remove debugging address

* Disable dapps when no registry is available
This commit is contained in:
Jaco Greeff 2016-10-31 14:24:33 +01:00 committed by Gav Wood
parent 1255105490
commit ea784d7419
3 changed files with 34 additions and 15 deletions

View File

@ -32,6 +32,7 @@ export default class Balances {
this._api = api;
this._store = store;
this._accountsInfo = null;
this._tokens = [];
}
start () {
@ -50,7 +51,10 @@ export default class Balances {
this._retrieveBalances();
})
.then((subscriptionId) => {
console.log('balances._subscribeAccountsInfo', 'subscriptionId', subscriptionId);
console.log('_subscribeAccountsInfo', 'subscriptionId', subscriptionId);
})
.catch((error) => {
console.warn('_subscribeAccountsInfo', error);
});
}
@ -64,7 +68,10 @@ export default class Balances {
this._retrieveTokens();
})
.then((subscriptionId) => {
console.log('balances._subscribeBlockNumber', 'subscriptionId', subscriptionId);
console.log('_subscribeBlockNumber', 'subscriptionId', subscriptionId);
})
.catch((error) => {
console.warn('_subscribeBlockNumber', error);
});
}
@ -130,12 +137,13 @@ export default class Balances {
this._retrieveBalances();
})
.catch((error) => {
console.error('balances._retrieveTokens', error);
console.warn('_retrieveTokens', error);
this._retrieveBalances();
});
}
_retrieveBalances () {
if (!this._accountsInfo || !this._tokens) {
if (!this._accountsInfo) {
return;
}
@ -186,7 +194,7 @@ export default class Balances {
this._store.dispatch(getBalances(this._balances));
})
.catch((error) => {
console.error('balances._retrieveBalances', error);
console.warn('_retrieveBalances', error);
});
}
}

View File

@ -14,9 +14,11 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
import BigNumber from 'bignumber.js';
import { parityNode } from '../../environment';
const builtinApps = [
const apps = [
{
id: '0xf9f2d620c2e08f83e45555247146c62185e4ab7cf82a4b9002a265a0d020348f',
url: 'basiccoin',
@ -73,7 +75,7 @@ const builtinApps = [
}
];
export default function () {
export default function (api) {
return fetch(`${parityNode}/api/apps`)
.then((response) => {
return response.ok
@ -85,8 +87,19 @@ export default function () {
return [];
})
.then((localApps) => {
return builtinApps
.concat(localApps.filter((app) => !['ui'].includes(app.id)))
.sort((a, b) => a.name.localeCompare(b.name));
return api.ethcore
.registryAddress()
.then((registryAddress) => {
if (new BigNumber(registryAddress).eq(0)) {
return [];
}
return apps;
})
.then((builtinApps) => {
return builtinApps
.concat(localApps.filter((app) => !['ui'].includes(app.id)))
.sort((a, b) => a.name.localeCompare(b.name));
});
});
}

View File

@ -42,16 +42,14 @@ export default class Dapps extends Component {
}
componentDidMount () {
fetchAvailable()
.then((available) => {
const { api } = this.context;
fetchAvailable(api).then((available) => {
this.setState({
available,
hidden: readHiddenApps()
});
this.loadImages();
})
.catch((err) => {
console.error('error fetching available apps', err);
});
}