mirror of
https://github.com/embarklabs/embark.git
synced 2025-02-27 12:50:43 +00:00
feat(@embark/embarkjs): introduce Blockchain.isAvailable() API
This is in order to be consistent with existing `isAvailable()` APIs on the `EmbarkJS` module. Another reason this API is needed, is because we need a way to fire `EmbarkJS.onReady()` even if no blockchain is available. Prior to this commit, `EmbarkJS.onReady()` was purely relying on an API on `EmbarkJS.Blockchain` that would break if the blockchain feature was disabled, causing `EmbarkJS.onReady()` to never fire.
This commit is contained in:
parent
70115a20e0
commit
fdf0ef4f5f
@ -27,13 +27,16 @@ class App extends React.Component {
|
|||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
EmbarkJS.onReady((err) => {
|
EmbarkJS.onReady((err) => {
|
||||||
this.setState({blockchainEnabled: true});
|
|
||||||
if (err) {
|
if (err) {
|
||||||
// If err is not null then it means something went wrong connecting to ethereum
|
// If err is not null then it means something went wrong connecting to ethereum
|
||||||
// you can use this to ask the user to enable metamask for e.g
|
// you can use this to ask the user to enable metamask for e.g
|
||||||
return this.setState({error: err.message || err});
|
return this.setState({error: err.message || err});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EmbarkJS.Blockchain.isAvailable().then(result => {
|
||||||
|
this.setState({blockchainEnabled: result});
|
||||||
|
});
|
||||||
|
|
||||||
EmbarkJS.Messages.isAvailable().then(result => {
|
EmbarkJS.Messages.isAvailable().then(result => {
|
||||||
this.setState({whisperEnabled: result});
|
this.setState({whisperEnabled: result});
|
||||||
});
|
});
|
||||||
|
@ -89,6 +89,13 @@ Blockchain.setProvider = function(providerName, options) {
|
|||||||
provider.init(options);
|
provider.init(options);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Blockchain.isAvailable = function () {
|
||||||
|
if (!this.blockchainConnector) {
|
||||||
|
return Promise.resolve(false);
|
||||||
|
}
|
||||||
|
return this.blockchainConnector.getNetworkId().then(_ => true);
|
||||||
|
};
|
||||||
|
|
||||||
Blockchain.doConnect = function(connectionList, opts, doneCb) {
|
Blockchain.doConnect = function(connectionList, opts, doneCb) {
|
||||||
const self = this;
|
const self = this;
|
||||||
|
|
||||||
|
@ -6,7 +6,13 @@ import Utils from './utils';
|
|||||||
|
|
||||||
var EmbarkJS = {
|
var EmbarkJS = {
|
||||||
onReady: function (cb) {
|
onReady: function (cb) {
|
||||||
Blockchain.execWhenReady(cb);
|
Blockchain.isAvailable()
|
||||||
|
.then(available => {
|
||||||
|
if (available) {
|
||||||
|
return Blockchain.execWhenReady(cb);
|
||||||
|
}
|
||||||
|
cb();
|
||||||
|
});
|
||||||
},
|
},
|
||||||
enableEthereum: function () {
|
enableEthereum: function () {
|
||||||
return Blockchain.enableEthereum();
|
return Blockchain.enableEthereum();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user