Use infura hosted provider if web3 is not available

If the user does not have metamask or similar (no web3 provider is
availale) we will load data from the infura node.

No signer is available for the infura node but the ethers provider would
throw an error if we try to access it - so this moves the decision of
choosing the provider to the ethProvider function.
This commit is contained in:
2018-04-22 18:40:59 +02:00
parent 3e7fe1b5be
commit f5dc8f86cf
+5 -13
View File
@@ -38,28 +38,20 @@ export default Service.extend({
);
ethProvider.listAccounts().then((accounts) => {
this.set('currentUserAccounts', accounts);
resolve(ethProvider);
resolve(ethProvider, ethProvider.getSigner());
});
} else {
console.debug('[kredits] Creating new instance from npm module class');
networkId = parseInt(config.contractMetadata.networkId);
ethProvider = new ethers.providers.JsonRpcProvider(
config.web3ProviderUrl,
{ chainId: networkId }
);
resolve(ethProvider);
console.log(networkId)
ethProvider = new ethers.providers.InfuraProvider({ chainId: networkId, name: 'kovan' });
resolve(ethProvider, null);
}
});
},
setup() {
return this.getEthProvider().then((ethProvider) => {
let ethSigner;
if (ethProvider.getSigner) {
ethSigner = ethProvider.getSigner();
}
return this.getEthProvider().then((ethProvider, ethSigner) => {
let kredits = new Kredits(ethProvider, ethSigner);
return kredits
.init()