Update kredits-contracts and ethers.js

This uses the new ethers.js 4.x API which is required by the new
kredits-contracts.
Also Operator is now Proposal in the new kredits-contracts wrapper
This commit is contained in:
2019-03-29 19:54:45 +01:00
parent 2954955e39
commit b75ac5c8b9
4 changed files with 5932 additions and 5907 deletions
+8 -15
View File
@@ -39,11 +39,7 @@ export default Service.extend({
let networkId;
if (typeof window.web3 !== 'undefined') {
console.debug('[kredits] Using user-provided instance, e.g. from Mist browser or Metamask');
networkId = parseInt(window.web3.version.network);
ethProvider = new ethers.providers.Web3Provider(
window.web3.currentProvider,
{ chainId: networkId }
);
ethProvider = new ethers.providers.Web3Provider(window.web3.currentProvider);
ethProvider.listAccounts().then((accounts) => {
this.set('currentUserAccounts', accounts);
const ethSigner = accounts.length === 0 ? null : ethProvider.getSigner();
@@ -56,10 +52,7 @@ export default Service.extend({
console.debug('[kredits] Creating new instance from npm module class');
networkId = parseInt(config.contractMetadata.networkId);
console.debug(`[kredits] networkId=${networkId} providerURL: ${config.web3ProviderUrl}`);
ethProvider = new ethers.providers.JsonRpcProvider(
config.web3ProviderUrl,
{ chainId: networkId }
);
ethProvider = new ethers.providers.JsonRpcProvider(config.web3ProviderUrl);
resolve({
ethProvider: ethProvider,
ethSigner: null
@@ -121,7 +114,7 @@ export default Service.extend({
addProposal(attributes) {
console.debug('[kredits] add proposal', attributes);
return this.kredits.Operator.addProposal(attributes)
return this.kredits.Proposal.addProposal(attributes)
.then((data) => {
console.debug('[kredits] add proposal response', data);
attributes.contributor = this.contributors.findBy('id', attributes.contributorId);
@@ -130,7 +123,7 @@ export default Service.extend({
},
getProposals() {
return this.kredits.Operator.all()
return this.kredits.Proposal.all()
.then((proposals) => {
return proposals.map((proposal) => {
proposal.contributor = this.contributors.findBy('id', proposal.contributorId.toString());
@@ -142,7 +135,7 @@ export default Service.extend({
vote(proposalId) {
console.debug('[kredits] vote for', proposalId);
return this.kredits.Operator.functions.vote(proposalId)
return this.kredits.Proposal.functions.vote(proposalId)
.then((data) => {
console.debug('[kredits] vote response', data);
return data;
@@ -172,8 +165,8 @@ export default Service.extend({
// Contract events
addContractEventHandlers() {
// Operator events
this.kredits.Operator
// Proposal events
this.kredits.Proposal
.on('ProposalCreated', this.handleProposalCreated.bind(this))
.on('ProposalVoted', this.handleProposalVoted.bind(this))
.on('ProposalExecuted', this.handleProposalExecuted.bind(this));
@@ -191,7 +184,7 @@ export default Service.extend({
return;
}
this.kredits.Operator.getById(proposalId)
this.kredits.Proposal.getById(proposalId)
.then((proposal) => {
proposal.contributor = this.contributors.findBy('id', proposal.contributorId.toString());
this.proposals.pushObject(Proposal.create(proposal));
-4
View File
@@ -52,7 +52,6 @@ module.exports = function(environment) {
// ENV.APP.LOG_TRANSITIONS = true;
// ENV.APP.LOG_TRANSITIONS_INTERNAL = true;
// ENV.APP.LOG_VIEW_LOOKUPS = true;
ENV.contractMetadata['networkId'] = '42';
ENV.web3ProviderUrl = 'https://kovan.infura.io/keUVk6OMaAvpmRF3m57n';
ENV.ipfs = {
@@ -78,9 +77,6 @@ module.exports = function(environment) {
// here you can enable a production-specific feature
}
if (process.env.NETWORK_ID) {
ENV.contractMetadata['networkId'] = process.env.NETWORK_ID;
}
if (process.env.WEB3_PROVIDER_URL) {
ENV.web3ProviderUrl = process.env.WEB3_PROVIDER_URL;
}
+5922 -5886
View File
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -15,7 +15,7 @@
"lint:js": "eslint .",
"start": "ember serve",
"test": "ember test",
"start:local": "NETWORK_ID=100 WEB3_PROVIDER_URL=http://localhost:7545 ember s",
"start:local": "WEB3_PROVIDER_URL=http://localhost:7545 ember s",
"build": "ember build",
"build-prod": "ember build --environment production",
"update-version-file": "bash scripts/update-version-file.sh",
@@ -54,7 +54,7 @@
"ember-source": "~3.8.0",
"ember-truth-helpers": "github:jmurphyau/ember-truth-helpers#31a14373a31f1f82c77537720549b47a95c28e5f",
"eslint-plugin-ember": "^5.2.0",
"ethers": "3.0.15",
"ethers": "^4.0.27",
"kosmos-schemas": "^1.1.2",
"kredits-contracts": "^3.x",
"loader.js": "^4.7.0",