Fix/update adding contributors #108

Merged
raucao merged 2 commits from feature/add_contributor into master 2019-04-29 11:44:16 +00:00
7 changed files with 42 additions and 34 deletions
+14 -11
View File
@@ -2,7 +2,6 @@ import Component from '@ember/component';
import { and, notEmpty } from '@ember/object/computed'; import { and, notEmpty } from '@ember/object/computed';
import { inject as service } from '@ember/service'; import { inject as service } from '@ember/service';
export default Component.extend({ export default Component.extend({
kredits: service(), kredits: service(),
@@ -14,6 +13,7 @@ export default Component.extend({
isValidURL: notEmpty('url'), isValidURL: notEmpty('url'),
isValidGithubUID: notEmpty('github_uid'), isValidGithubUID: notEmpty('github_uid'),
isValidGithubUsername: notEmpty('github_username'), isValidGithubUsername: notEmpty('github_username'),
isValidGiteaUsername: notEmpty('gitea_username'),
isValidWikiUsername: notEmpty('wiki_username'), isValidWikiUsername: notEmpty('wiki_username'),
isValid: and( isValid: and(
'isValidAccount', 'isValidAccount',
@@ -21,10 +21,11 @@ export default Component.extend({
'isValidGithubUID' 'isValidGithubUID'
), ),
inProgress: false,
init () { init () {
this._super(...arguments); this._super(...arguments);
// Default attributes used by reset
this.set('attributes', { this.set('attributes', {
account: null, account: null,
name: null, name: null,
@@ -32,8 +33,8 @@ export default Component.extend({
url: null, url: null,
github_username: null, github_username: null,
github_uid: null, github_uid: null,
wiki_username: null, gitea_username: null,
isCore: false wiki_username: null
}); });
}, },
@@ -53,17 +54,19 @@ export default Component.extend({
return; return;
} }
let attributes = Object.keys(this.attributes); const attributes = Object.keys(this.attributes);
let contributor = this.getProperties(attributes); const contributor = this.getProperties(attributes);
let saved = this.save(contributor);
// The promise handles inProgress this.set('inProgress', true);
this.set('inProgress', saved);
saved.then(() => { this.save(contributor).then(() => {
this.reset(); this.reset();
window.scroll(0,0); window.scroll(0,0);
window.alert('Contributor added.'); }).catch(err => {
console.log(err);
window.alert('Something went wrong. Please check the browser console.');
}).finally(() => {
this.set('inProgress', false);
}); });
} }
} }
+9 -11
View File
@@ -1,13 +1,4 @@
<form {{action "submit" on="submit"}}> <form {{action "submit" on="submit"}}>
<p>
{{input name="is-core"
type="checkbox"
id="is-core"
checked=isCore}}
<label for="is-core" class="checkbox">
Core team member (can add contributors)
</label>
</p>
<p> <p>
{{input name="account" {{input name="account"
type="text" type="text"
@@ -49,6 +40,13 @@
value=github_username value=github_username
class=(if isValidGithubUsername "valid" "")}} class=(if isValidGithubUsername "valid" "")}}
</p> </p>
<p>
{{input name="gitea_username"
type="text"
placeholder="Gitea username"
value=gitea_username
class=(if isValidGiteaUsername "valid" "")}}
</p>
<p> <p>
{{input name="wiki_username" {{input name="wiki_username"
type="text" type="text"
@@ -58,7 +56,7 @@
</p> </p>
<p class="actions"> <p class="actions">
{{input type="submit" {{input type="submit"
disabled=(is-pending inProgress) disabled=inProgress
value=(if (is-pending inProgress) "Processing" "Save")}} value=(if inProgress "Processing" "Save")}}
</p> </p>
</form> </form>
+1 -1
View File
@@ -13,7 +13,7 @@
<tr class="metadata {{if (is-current-user contributor) "current-user"}} {{if contributor.showMetadata "visible"}}"> <tr class="metadata {{if (is-current-user contributor) "current-user"}} {{if contributor.showMetadata "visible"}}">
<td colspan="2"> <td colspan="2">
<ul> <ul>
<li><a href="https://testnet.etherscan.io/address/{{contributor.account}}">Inspect Ethereum transactions</a></li> <li><a href="https://rinkeby.etherscan.io/address/{{contributor.account}}">Inspect Ethereum transactions</a></li>
{{#if contributor.ipfsHash}} {{#if contributor.ipfsHash}}
<li><a href="https://ipfs.io/ipfs/{{contributor.ipfsHash}}">Inspect IPFS profile</a></li> <li><a href="https://ipfs.io/ipfs/{{contributor.ipfsHash}}">Inspect IPFS profile</a></li>
{{/if}} {{/if}}
+4 -2
View File
@@ -2,6 +2,7 @@ import Controller from '@ember/controller';
import { alias, filter, sort } from '@ember/object/computed'; import { alias, filter, sort } from '@ember/object/computed';
import { inject as service } from '@ember/service'; import { inject as service } from '@ember/service';
import { computed } from '@ember/object'; import { computed } from '@ember/object';
import { isPresent } from '@ember/utils';
export default Controller.extend({ export default Controller.extend({
kredits: service(), kredits: service(),
@@ -9,7 +10,8 @@ export default Controller.extend({
contributors: alias('kredits.contributors'), contributors: alias('kredits.contributors'),
contributorsWithKredits: filter('contributors', function(contributor) { contributorsWithKredits: filter('contributors', function(contributor) {
return contributor.get('totalKreditsEarnedRaw').gt(0); return isPresent(contributor.totalKreditsEarnedRaw) &&
contributor.totalKreditsEarnedRaw.gt(0);
}), }),
contributorsSorting: Object.freeze(['totalKreditsEarned:desc']), contributorsSorting: Object.freeze(['totalKreditsEarned:desc']),
contributorsSorted: sort('contributorsWithKredits', 'contributorsSorting'), contributorsSorted: sort('contributorsWithKredits', 'contributorsSorting'),
@@ -47,7 +49,7 @@ export default Controller.extend({
save (contributor) { save (contributor) {
return this.kredits.addContributor(contributor) return this.kredits.addContributor(contributor)
.then((contributor) => { .then(contributor => {
this.contributors.pushObject(contributor); this.contributors.pushObject(contributor);
return contributor; return contributor;
}); });
+7 -2
View File
@@ -130,10 +130,15 @@ export default Service.extend({
}, },
addContributor(attributes) { addContributor(attributes) {
if (attributes.github_uid) {
const uidInt = parseInt(attributes.github_uid);
attributes.github_uid = uidInt;
}
console.debug('[kredits] add contributor', attributes); console.debug('[kredits] add contributor', attributes);
return this.kredits.Contributor.add(attributes) return this.kredits.Contributor.add(attributes, { gasLimit: 350000 })
.then((data) => { .then(data => {
console.debug('[kredits] add contributor response', data); console.debug('[kredits] add contributor response', data);
bumi commented 2019-04-25 20:32:11 +00:00 (Migrated from github.com)
Review

as this is only for development we should set this manually in the metamask interface.
I have the "Advanced gas controls" setting turned on - so the gas settings form is directly displayed when the transaction needs to be confirmed. This makes it easy to change them.

as this is only for development we should set this manually in the metamask interface. I have the "Advanced gas controls" setting turned on - so the gas settings form is directly displayed when the transaction needs to be confirmed. This makes it easy to change them.
raucao commented 2019-04-25 22:18:57 +00:00 (Migrated from github.com)
Review

Without this, I don't even get to the confirmation screen. The error happens beforehand, because the limit is too high.

Without this, I don't even get to the confirmation screen. The error happens beforehand, because the limit is too high.
bumi commented 2019-04-25 22:23:23 +00:00 (Migrated from github.com)
Review

hmmm, will test it here again tomorrow. thought it worked for me, but maybe I was missing something.

do you have an idea how we can best handle this? because so far it seems it is some development issue - and is not needed with rinkeby.

hmmm, will test it here again tomorrow. thought it worked for me, but maybe I was missing something. do you have an idea how we can best handle this? because so far it seems it is some development issue - and is not needed with rinkeby.
raucao commented 2019-04-25 22:27:17 +00:00 (Migrated from github.com)
Review

It happens to me on Rinkeby.

It happens to me on Rinkeby.
return Contributor.create(attributes); return Contributor.create(attributes);
}); });
+6 -6
View File
@@ -10911,9 +10911,9 @@
} }
}, },
"kredits-contracts": { "kredits-contracts": {
"version": "5.2.0", "version": "5.3.0",
"resolved": "https://registry.npmjs.org/kredits-contracts/-/kredits-contracts-5.2.0.tgz", "resolved": "https://registry.npmjs.org/kredits-contracts/-/kredits-contracts-5.3.0.tgz",
"integrity": "sha512-XS8PN01SEiSNDKUhH28KVmGJ7hS3HlhT+CsaAMgqvU9ACcE1Wizqd0AxoRutUmJkILic6W6bQQ5gRqSHcBpPBA==", "integrity": "sha512-Wz4zuA6yo0Q4WbVEO61fvFin+6VTNjkBqHPhHCqq6dIoGdFSjUZ3BCKan1ei0axIAda7ZDP+eebe2vCr+eqcHg==",
"dev": true, "dev": true,
"requires": { "requires": {
"ethers": "^4.0.27", "ethers": "^4.0.27",
@@ -17139,9 +17139,9 @@
"dev": true "dev": true
}, },
"pull-to-stream": { "pull-to-stream": {
"version": "0.1.0", "version": "0.1.1",
"resolved": "https://registry.npmjs.org/pull-to-stream/-/pull-to-stream-0.1.0.tgz", "resolved": "https://registry.npmjs.org/pull-to-stream/-/pull-to-stream-0.1.1.tgz",
"integrity": "sha512-LMvdE0JwT7XQZMFjc7JDl/G9gmoZ8Zo8e86SG4ZZUcjuwvod803KxpAK8WrmdxzHsMRK9DETlIzuA0tbEVv6jg==", "integrity": "sha512-thZkMv6F9PILt9zdvpI2gxs19mkDrlixYKX6cOBxAW16i1NZH+yLAmF4r8QfJ69zuQh27e01JZP9y27tsH021w==",
"dev": true, "dev": true,
"requires": { "requires": {
"readable-stream": "^3.1.1" "readable-stream": "^3.1.1"
+1 -1
View File
@@ -56,7 +56,7 @@
"eslint-plugin-ember": "^5.2.0", "eslint-plugin-ember": "^5.2.0",
"ethers": "^4.0.27", "ethers": "^4.0.27",
"kosmos-schemas": "^2.0.0", "kosmos-schemas": "^2.0.0",
"kredits-contracts": "^5.2.0", "kredits-contracts": "^5.3.0",
"loader.js": "^4.7.0", "loader.js": "^4.7.0",
"qunit-dom": "^0.8.0", "qunit-dom": "^0.8.0",
"tv4": "^1.3.0" "tv4": "^1.3.0"