Merge branch 'master' into chore/travis_node

This commit is contained in:
2019-04-05 13:44:45 +02:00
2 changed files with 40 additions and 18 deletions
+38 -16
View File
@@ -33,20 +33,10 @@ export default Service.extend({
// this is called in the routes beforeModel(). So it is initialized before everything else // this is called in the routes beforeModel(). So it is initialized before everything else
// and we can rely on the ethProvider and the potential currentUserAccounts to be available // and we can rely on the ethProvider and the potential currentUserAccounts to be available
getEthProvider: function() { getEthProvider: function() {
return new RSVP.Promise((resolve) => { let ethProvider;
let ethProvider;
if (typeof window.web3 !== 'undefined') { return new RSVP.Promise(async (resolve) => {
console.debug('[kredits] Using user-provided instance, e.g. from Mist browser or Metamask'); function instantiateWithoutAccount () {
ethProvider = new ethers.providers.Web3Provider(window.web3.currentProvider);
ethProvider.listAccounts().then((accounts) => {
this.set('currentUserAccounts', accounts);
const ethSigner = accounts.length === 0 ? null : ethProvider.getSigner();
resolve({
ethProvider,
ethSigner
});
});
} else {
console.debug('[kredits] Creating new instance from npm module class'); console.debug('[kredits] Creating new instance from npm module class');
console.debug(`[kredits] providerURL: ${config.web3ProviderUrl}`); console.debug(`[kredits] providerURL: ${config.web3ProviderUrl}`);
ethProvider = new ethers.providers.JsonRpcProvider(config.web3ProviderUrl); ethProvider = new ethers.providers.JsonRpcProvider(config.web3ProviderUrl);
@@ -55,6 +45,39 @@ export default Service.extend({
ethSigner: null ethSigner: null
}); });
} }
function instantiateWithAccount (web3, context) {
console.debug('[kredits] Using user-provided instance, e.g. from Mist browser or Metamask');
ethProvider = new ethers.providers.Web3Provider(web3.currentProvider);
ethProvider.listAccounts().then(accounts => {
context.set('currentUserAccounts', accounts);
const ethSigner = accounts.length === 0 ? null : ethProvider.getSigner();
resolve({
ethProvider,
ethSigner
});
});
}
if (window.ethereum) {
window.web3 = new window.Web3(window.ethereum);
try {
// Request account access if needed
await window.ethereum.enable();
// Acccounts now exposed
instantiateWithAccount(window.web3, this);
} catch (error) {
instantiateWithoutAccount();
}
}
// Legacy dapp browsers...
else if (window.web3) {
instantiateWithAccount(window.web3, this);
}
// Non-dapp browsers...
else {
instantiateWithoutAccount();
}
}); });
}, },
@@ -148,7 +171,6 @@ export default Service.extend({
return this.kredits.Contributor return this.kredits.Contributor
.functions.getContributorIdByAddress(this.get('currentUserAccounts.firstObject')) .functions.getContributorIdByAddress(this.get('currentUserAccounts.firstObject'))
.then((id) => { .then((id) => {
id = id.toNumber();
// check if the user is a contributor or not // check if the user is a contributor or not
if (id === 0) { if (id === 0) {
return RSVP.resolve(); return RSVP.resolve();
@@ -211,7 +233,7 @@ export default Service.extend({
this.contributors this.contributors
.findBy('id', contributorId.toString()) .findBy('id', contributorId.toString())
.incrementProperty('balance', amount.toNumber()); .incrementProperty('balance', amount);
}, },
handleTransfer(from, to, value) { handleTransfer(from, to, value) {
+2 -2
View File
@@ -35,7 +35,7 @@ module.exports = function(environment) {
] ]
}, },
web3ProviderUrl: 'https://kovan.infura.io/keUVk6OMaAvpmRF3m57n', web3ProviderUrl: 'https://rinkeby.infura.io/v3/d4f788b7a6584f7db2fc3c268d4d09e9',
ipfs: { ipfs: {
host: 'ipfs.kosmos.org', host: 'ipfs.kosmos.org',
@@ -50,7 +50,7 @@ module.exports = function(environment) {
// ENV.APP.LOG_TRANSITIONS = true; // ENV.APP.LOG_TRANSITIONS = true;
// ENV.APP.LOG_TRANSITIONS_INTERNAL = true; // ENV.APP.LOG_TRANSITIONS_INTERNAL = true;
// ENV.APP.LOG_VIEW_LOOKUPS = true; // ENV.APP.LOG_VIEW_LOOKUPS = true;
ENV.web3ProviderUrl = 'https://kovan.infura.io/keUVk6OMaAvpmRF3m57n'; ENV.web3ProviderUrl = 'https://rinkeby.infura.io/v3/d4f788b7a6584f7db2fc3c268d4d09e9';
ENV.ipfs = { ENV.ipfs = {
host: 'localhost', host: 'localhost',