Merge pull request #67 from 67P/eth-signer-loading

Pass ETH signer only if it can actually sign
This commit was merged in pull request #67.
This commit is contained in:
2018-06-14 15:14:23 +02:00
committed by GitHub
+12 -10
View File
@@ -38,36 +38,38 @@ export default Service.extend({
); );
ethProvider.listAccounts().then((accounts) => { ethProvider.listAccounts().then((accounts) => {
this.set('currentUserAccounts', accounts); this.set('currentUserAccounts', accounts);
resolve(ethProvider); const ethSigner = accounts.length === 0 ? null : ethProvider.getSigner();
resolve({
ethProvider,
ethSigner
});
}); });
} 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);
console.debug(`[kredits] networkId=${networkId} providerURL: ${config.web3ProviderUrl}`);
ethProvider = new ethers.providers.JsonRpcProvider( ethProvider = new ethers.providers.JsonRpcProvider(
config.web3ProviderUrl, config.web3ProviderUrl,
{ chainId: networkId } { chainId: networkId }
); );
resolve(ethProvider); resolve({
ethProvider: ethProvider,
ethSigner: null
});
} }
}); });
}, },
setup() { setup() {
return this.getEthProvider().then((ethProvider) => { return this.getEthProvider().then((providerAndSigner) => {
let ethSigner;
if (ethProvider.getSigner) { let kredits = new Kredits(providerAndSigner.ethProvider, providerAndSigner.ethSigner, {
ethSigner = ethProvider.getSigner();
}
let kredits = new Kredits(ethProvider, ethSigner, {
ipfsConfig: config.ipfs ipfsConfig: config.ipfs
}); });
return kredits return kredits
.init() .init()
.then((kredits) => { .then((kredits) => {
this.set('kredits', kredits); this.set('kredits', kredits);
if (this.currentUserAccounts && this.currentUserAccounts.length > 0) { if (this.currentUserAccounts && this.currentUserAccounts.length > 0) {
this.getCurrentUser.then((contributorData) => { this.getCurrentUser.then((contributorData) => {
this.set('currentUser', contributorData); this.set('currentUser', contributorData);