Notify to change selected network #143
@@ -7,19 +7,55 @@ export default Route.extend({
|
||||
beforeModel(transition) {
|
||||
const kredits = this.kredits;
|
||||
|
||||
return kredits.setup().then(() => {
|
||||
kredits.get('kredits').preflightChecks().catch((error) => {
|
||||
console.error('Kredits preflight check failed!');
|
||||
console.error(error);
|
||||
});
|
||||
if (kredits.get('accountNeedsUnlock')) {
|
||||
if (confirm('It looks like you have an Ethereum wallet available. Please unlock your account.')) {
|
||||
transition.retry();
|
||||
let selectedNetworkId = window.ethereum.networkVersion;
|
||||
let kreditsNetwork = kredits.getKreditsDeployedNetwork();
|
||||
let kreditsNetworkName;
|
||||
|
||||
switch(kreditsNetwork) {
|
||||
case '1':
|
||||
kreditsNetworkName = "Main";
|
||||
break;
|
||||
case '2':
|
||||
kreditsNetworkName = "Morden Test";
|
||||
break;
|
||||
case '3':
|
||||
kreditsNetworkName = "Ropsten Test";
|
||||
|
|
||||
break;
|
||||
case '4':
|
||||
kreditsNetworkName = "Rinkeby Test";
|
||||
break;
|
||||
case '42':
|
||||
kreditsNetworkName = "Kovan Test";
|
||||
break;
|
||||
default:
|
||||
kreditsNetworkName = "Rinkeby Test";
|
||||
}
|
||||
|
||||
if(selectedNetworkId == kreditsNetwork) {
|
||||
return kredits.setup().then(() => {
|
||||
kredits.get('kredits').preflightChecks().catch((error) => {
|
||||
console.error('Kredits preflight check failed!');
|
||||
console.error(error);
|
||||
});
|
||||
if (kredits.get('accountNeedsUnlock')) {
|
||||
if (confirm('It looks like you have an Ethereum wallet available. Please unlock your account.')) {
|
||||
transition.retry();
|
||||
}
|
||||
}
|
||||
}).catch((error) => {
|
||||
console.log('Error initializing Kredits', error);
|
||||
});
|
||||
}
|
||||
else {
|
||||
//need to better display this one maybe
|
||||
if(confirm(`Please change to ${kreditsNetworkName} network!`)) {
|
||||
transition.abort();
|
||||
}
|
||||
}).catch((error) => {
|
||||
console.log('Error initializing Kredits', error);
|
||||
});
|
||||
}
|
||||
|
||||
window.ethereum.on('networkChanged', function() {
|
||||
transition.retry();
|
||||
})
|
||||
},
|
||||
|
||||
afterModel() {
|
||||
|
||||
@@ -136,6 +136,10 @@ export default Service.extend({
|
||||
});
|
||||
},
|
||||
|
||||
getKreditsDeployedNetwork() {
|
||||
return Kredits.availableNetworks();
|
||||
|
I don't understand how one can get a single network from a list of networks without filtering here. I don't understand how one can get a single network from a list of networks without filtering here.
mm I thought that there will be only the network where kredits is deployed at (etiher rinkeby, ropsten, mainnet...), or no ? mm I thought that there will be only the network where kredits is deployed at (etiher rinkeby, ropsten, mainnet...), or no ?
We run a local network for development, making it at least two. But also, there could be more networks in the future, hence the plural in We talked about this in the call yesterday and @bumi had some good ideas. Would be good to write them down in either the issue or PR. @haythem96 By the way, it would be super useful if you could join the weekly call from time to time to talk things through with other people and also stay up to date with the rest of the project. We run a local network for development, making it at least two. But also, there could be more networks in the future, hence the plural in `availableNetworks()` (as opposed to `getNetwork()` or similar).
We talked about this in the call yesterday and @bumi had some good ideas. Would be good to write them down in either the issue or PR.
@haythem96 By the way, it would be super useful if you could join the weekly call from time to time to talk things through with other people and also stay up to date with the rest of the project.
yeah really sorry for missing the last calls... was trying to join but I miss for some reasons... I will be available on the next ones. yeah really sorry for missing the last calls... was trying to join but I miss for some reasons... I will be available on the next ones.
|
||||
},
|
||||
|
||||
setup () {
|
||||
return this.getEthProvider().then((providerAndSigner) => {
|
||||
let kredits = new Kredits(providerAndSigner.ethProvider, providerAndSigner.ethSigner, {
|
||||
|
||||
@@ -10815,7 +10815,7 @@
|
||||
"bs58": "^4.0.1",
|
||||
"buffer": "^5.2.1",
|
||||
"cids": "~0.5.5",
|
||||
"concat-stream": "github:hugomrdias/concat-stream#feat/smaller",
|
||||
"concat-stream": "github:hugomrdias/concat-stream#057bc7b5d6d8df26c8cf00a3f151b6721a0a8034",
|
||||
"debug": "^4.1.0",
|
||||
"detect-node": "^2.0.4",
|
||||
"end-of-stream": "^1.4.1",
|
||||
@@ -10837,7 +10837,7 @@
|
||||
"multibase": "~0.6.0",
|
||||
"multicodec": "~0.5.0",
|
||||
"multihashes": "~0.4.14",
|
||||
"ndjson": "github:hugomrdias/ndjson#feat/readable-stream3",
|
||||
"ndjson": "github:hugomrdias/ndjson#4db16da6b42e5b39bf300c3a7cde62abb3fa3a11",
|
||||
"once": "^1.4.0",
|
||||
"peer-id": "~0.12.2",
|
||||
"peer-info": "~0.15.1",
|
||||
|
||||
This belongs in a separate function or config. But from what I remember I'm pretty sure you can get network names from the
ether.jslibrary/API anyway, so there's no need to re-implement our own version of this.