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:
+5
-13
@@ -38,28 +38,20 @@ export default Service.extend({
|
|||||||
);
|
);
|
||||||
ethProvider.listAccounts().then((accounts) => {
|
ethProvider.listAccounts().then((accounts) => {
|
||||||
this.set('currentUserAccounts', accounts);
|
this.set('currentUserAccounts', accounts);
|
||||||
resolve(ethProvider);
|
resolve(ethProvider, ethProvider.getSigner());
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
console.debug('[kredits] Creating new instance from npm module class');
|
console.debug('[kredits] Creating new instance from npm module class');
|
||||||
networkId = parseInt(config.contractMetadata.networkId);
|
networkId = parseInt(config.contractMetadata.networkId);
|
||||||
ethProvider = new ethers.providers.JsonRpcProvider(
|
console.log(networkId)
|
||||||
config.web3ProviderUrl,
|
ethProvider = new ethers.providers.InfuraProvider({ chainId: networkId, name: 'kovan' });
|
||||||
{ chainId: networkId }
|
resolve(ethProvider, null);
|
||||||
);
|
|
||||||
resolve(ethProvider);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
setup() {
|
setup() {
|
||||||
return this.getEthProvider().then((ethProvider) => {
|
return this.getEthProvider().then((ethProvider, ethSigner) => {
|
||||||
let ethSigner;
|
|
||||||
|
|
||||||
if (ethProvider.getSigner) {
|
|
||||||
ethSigner = ethProvider.getSigner();
|
|
||||||
}
|
|
||||||
|
|
||||||
let kredits = new Kredits(ethProvider, ethSigner);
|
let kredits = new Kredits(ethProvider, ethSigner);
|
||||||
return kredits
|
return kredits
|
||||||
.init()
|
.init()
|
||||||
|
|||||||
Reference in New Issue
Block a user