1
0
mirror of https://github.com/ascribe/onion.git synced 2025-01-05 11:25:09 +01:00

create CoA when not found

This commit is contained in:
diminator 2015-09-30 09:14:57 +02:00
parent e356570bc8
commit ea4805caa0
2 changed files with 38 additions and 15 deletions

View File

@ -3,6 +3,7 @@
import alt from '../alt'; import alt from '../alt';
import CoaFetcher from '../fetchers/coa_fetcher'; import CoaFetcher from '../fetchers/coa_fetcher';
import Q from 'q';
class CoaActions { class CoaActions {
constructor() { constructor() {
@ -13,21 +14,38 @@ class CoaActions {
} }
fetchOne(id) { fetchOne(id) {
return Q.Promise((resolve, reject) => {
CoaFetcher.fetchOne(id) CoaFetcher.fetchOne(id)
.then((res) => { .then((res) => {
if (res.coa) {
this.actions.updateCoa(res.coa); this.actions.updateCoa(res.coa);
resolve(res.coa);
}
else {
this.actions.updateCoa(null);
resolve(null);
}
}) })
.catch((err) => { .catch((err) => {
console.logGlobal(err); console.logGlobal(err);
this.actions.updateCoa(null);
reject(err);
});
}); });
} }
create(edition) { create(edition) {
return Q.Promise((resolve, reject) => {
CoaFetcher.create(edition.bitcoin_id) CoaFetcher.create(edition.bitcoin_id)
.then((res) => { .then((res) => {
this.actions.updateCoa(res.coa); this.actions.updateCoa(res.coa);
}) })
.catch((err) => { .catch((err) => {
console.logGlobal(err); console.logGlobal(err);
this.actions.updateCoa(null);
reject(err);
});
}); });
} }
} }

View File

@ -338,7 +338,12 @@ let CoaDetails = React.createClass({
componentDidMount() { componentDidMount() {
CoaStore.listen(this.onChange); CoaStore.listen(this.onChange);
if(this.props.edition.coa) { if(this.props.edition.coa) {
CoaActions.fetchOne(this.props.edition.coa); CoaActions.fetchOne(this.props.edition.coa)
.then((res) => {
if (res === null){
CoaActions.create(this.props.edition);
}
});
} }
else { else {
CoaActions.create(this.props.edition); CoaActions.create(this.props.edition);