Submit reimbursements
This commit is contained in:
@@ -3,6 +3,7 @@ import { tracked } from '@glimmer/tracking';
|
|||||||
import { action } from '@ember/object';
|
import { action } from '@ember/object';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import isValidAmount from 'kredits-web/utils/is-valid-amount';
|
import isValidAmount from 'kredits-web/utils/is-valid-amount';
|
||||||
|
import { isPresent } from '@ember/utils';
|
||||||
|
|
||||||
export default class AddExpenseItemComponent extends Component {
|
export default class AddExpenseItemComponent extends Component {
|
||||||
// @tracked newExpense = Expense.create();
|
// @tracked newExpense = Expense.create();
|
||||||
@@ -69,20 +70,21 @@ export default class AddExpenseItemComponent extends Component {
|
|||||||
const [ date ] = dateInput.toISOString().split('T');
|
const [ date ] = dateInput.toISOString().split('T');
|
||||||
|
|
||||||
const isValid = this.validateForm();
|
const isValid = this.validateForm();
|
||||||
|
if (!isValid) return false;
|
||||||
|
|
||||||
if (isValid) {
|
|
||||||
const expense = {
|
const expense = {
|
||||||
amount: parseFloat(this.amount),
|
amount: parseFloat(this.amount),
|
||||||
currency: this.currency,
|
currency: this.currency,
|
||||||
date: date,
|
date: date,
|
||||||
title: this.title,
|
title: this.title,
|
||||||
description: this.description,
|
description: isPresent(this.description) ? this.description : undefined,
|
||||||
url: this.url,
|
url: isPresent(this.url) ? this.url : undefined,
|
||||||
tags: this.tags.split(',').map(t => t.trim())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isPresent(this.tags)) {
|
||||||
|
expense.tags = this.tags.split(',').map(t => t.trim());
|
||||||
|
}
|
||||||
|
|
||||||
this.args.addExpenseItem(expense);
|
this.args.addExpenseItem(expense);
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,16 +5,17 @@ import { inject as service } from '@ember/service';
|
|||||||
import { action } from '@ember/object';
|
import { action } from '@ember/object';
|
||||||
import { A } from '@ember/array';
|
import { A } from '@ember/array';
|
||||||
import { scheduleOnce } from '@ember/runloop';
|
import { scheduleOnce } from '@ember/runloop';
|
||||||
import Reimbursement from 'kredits-web/models/reimbursement';
|
|
||||||
import isValidAmount from 'kredits-web/utils/is-valid-amount';
|
import isValidAmount from 'kredits-web/utils/is-valid-amount';
|
||||||
|
import config from 'kredits-web/config/environment';
|
||||||
|
|
||||||
export default class AddReimbursementComponent extends Component {
|
export default class AddReimbursementComponent extends Component {
|
||||||
|
@service router;
|
||||||
@service kredits;
|
@service kredits;
|
||||||
@service exchangeRates;
|
@service exchangeRates;
|
||||||
|
|
||||||
@alias('kredits.contributorsSorted') contributors;
|
@alias('kredits.contributorsSorted') contributors;
|
||||||
|
|
||||||
@tracked recipientId = null;
|
@tracked contributorId = null;
|
||||||
@tracked title = '';
|
@tracked title = '';
|
||||||
@tracked total = '0';
|
@tracked total = '0';
|
||||||
@tracked expenses = A([]);
|
@tracked expenses = A([]);
|
||||||
@@ -106,9 +107,30 @@ export default class AddReimbursementComponent extends Component {
|
|||||||
@action
|
@action
|
||||||
submit (e) {
|
submit (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
// TODO
|
const contributor = this.contributors.findBy('id', this.contributorId);
|
||||||
// amount = parseFloat(this.total)
|
|
||||||
// token = "WBTC" (or token address)
|
const attributes = {
|
||||||
// title = "Expenses covered by contributor.name"
|
amount: parseInt(parseFloat(this.total) * 100000000), // convert to sats
|
||||||
|
token: config.tokens['WBTC'],
|
||||||
|
contributorId: parseInt(this.contributorId),
|
||||||
|
title: `Expenses covered by ${contributor.name}`,
|
||||||
|
description: this.description,
|
||||||
|
url: this.url,
|
||||||
|
expenses: JSON.parse(JSON.stringify((this.expenses)))
|
||||||
|
}
|
||||||
|
|
||||||
|
this.inProgress = true;
|
||||||
|
|
||||||
|
this.kredits.addReimbursement(attributes)
|
||||||
|
.then((/* reimbursement */) => {
|
||||||
|
this.router.transitionTo('budget');
|
||||||
|
})
|
||||||
|
.catch(e => {
|
||||||
|
console.error('Could not add reimbursement:', e);
|
||||||
|
window.alert('Something went wrong. Please check the browser console.')
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
this.inProgress = false;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
<label>
|
<label>
|
||||||
<p class="label">Contributor:</p>
|
<p class="label">Contributor:</p>
|
||||||
<p>
|
<p>
|
||||||
<select required onchange={{action (mut this.recipientId) value="target.value"}}>
|
<select required onchange={{action (mut this.contributorId) value="target.value"}}>
|
||||||
<option value="" selected disabled hidden></option>
|
<option value="" selected disabled hidden></option>
|
||||||
{{#each this.contributors as |contributor|}}
|
{{#each this.contributors as |contributor|}}
|
||||||
<option value={{contributor.id}} selected={{eq this.contributorId contributor.id}}>{{contributor.name}}</option>
|
<option value={{contributor.id}} selected={{eq this.contributorId contributor.id}}>{{contributor.name}}</option>
|
||||||
@@ -71,8 +71,13 @@
|
|||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
<p class="actions">
|
<p class="actions">
|
||||||
|
{{#if this.inProgress}}
|
||||||
|
{{input type="submit" value="Submitting..." disabled=true
|
||||||
|
title="Submit/propose this reimbursement"}}
|
||||||
|
{{else}}
|
||||||
{{input type="submit" value="Submit" disabled=this.submitButtonDisabled
|
{{input type="submit" value="Submit" disabled=this.submitButtonDisabled
|
||||||
title="Submit/propose this reimbursement"}}
|
title="Submit/propose this reimbursement"}}
|
||||||
|
{{/if}}
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
{{#if this.expenseFormVisible}}
|
{{#if this.expenseFormVisible}}
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
import EmberObject, { computed } from '@ember/object';
|
import EmberObject, { computed } from '@ember/object';
|
||||||
import { isEmpty, isPresent } from '@ember/utils';
|
import { isPresent } from '@ember/utils';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
|
|
||||||
export default EmberObject.extend({
|
export default EmberObject.extend({
|
||||||
|
|
||||||
// Contract
|
// Contract
|
||||||
id: null,
|
id: null,
|
||||||
contributorId: null,
|
recipientId: null,
|
||||||
token: null,
|
token: null,
|
||||||
amount: null,
|
amount: null,
|
||||||
confirmedAt: null,
|
confirmedAt: null,
|
||||||
@@ -14,7 +14,7 @@ export default EmberObject.extend({
|
|||||||
ipfsHash: null,
|
ipfsHash: null,
|
||||||
|
|
||||||
// contributor model instance
|
// contributor model instance
|
||||||
contributor: null,
|
recipient: null,
|
||||||
|
|
||||||
// TODO contributor who submitted the reimbursement
|
// TODO contributor who submitted the reimbursement
|
||||||
// recordedBy: null,
|
// recordedBy: null,
|
||||||
@@ -24,10 +24,6 @@ export default EmberObject.extend({
|
|||||||
|
|
||||||
pendingTx: null,
|
pendingTx: null,
|
||||||
|
|
||||||
init () {
|
|
||||||
this._super(...arguments);
|
|
||||||
},
|
|
||||||
|
|
||||||
iso8601Date: computed('date', 'time', function() {
|
iso8601Date: computed('date', 'time', function() {
|
||||||
return this.time ? `${this.date}T${this.time}` : this.date;
|
return this.time ? `${this.date}T${this.time}` : this.date;
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -577,6 +577,23 @@ export default Service.extend({
|
|||||||
return obj;
|
return obj;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
addReimbursement (attributes) {
|
||||||
|
console.debug('[kredits] add reimbursement', attributes);
|
||||||
|
|
||||||
|
return this.kredits.Reimbursement.add(attributes, { gasLimit: 300000 })
|
||||||
|
.then(data => {
|
||||||
|
console.debug('[kredits] add reimbursement response', data);
|
||||||
|
const reimbursement = Reimbursement.create(processReimbursementData(data));
|
||||||
|
reimbursement.setProperties({
|
||||||
|
contributor: this.contributors.findBy('id', attributes.contributorId),
|
||||||
|
pendingTx: data,
|
||||||
|
confirmedAtBlock: this.currentBlock + 40320
|
||||||
|
});
|
||||||
|
this.reimbursements.pushObject(reimbursement);
|
||||||
|
return reimbursement;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
//
|
//
|
||||||
// Contract events
|
// Contract events
|
||||||
//
|
//
|
||||||
|
|||||||
Reference in New Issue
Block a user