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));