1
0
mirror of https://github.com/ascribe/onion.git synced 2024-06-28 08:37:59 +02: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 CoaFetcher from '../fetchers/coa_fetcher';
import Q from 'q';
class CoaActions {
constructor() {
@ -13,22 +14,39 @@ class CoaActions {
}
fetchOne(id) {
CoaFetcher.fetchOne(id)
.then((res) => {
this.actions.updateCoa(res.coa);
})
.catch((err) => {
console.logGlobal(err);
});
return Q.Promise((resolve, reject) => {
CoaFetcher.fetchOne(id)
.then((res) => {
if (res.coa) {
this.actions.updateCoa(res.coa);
resolve(res.coa);
}
else {
this.actions.updateCoa(null);
resolve(null);
}
})
.catch((err) => {
console.logGlobal(err);
this.actions.updateCoa(null);
reject(err);
});
});
}
create(edition) {
CoaFetcher.create(edition.bitcoin_id)
.then((res) => {
this.actions.updateCoa(res.coa);
})
.catch((err) => {
console.logGlobal(err);
});
return Q.Promise((resolve, reject) => {
CoaFetcher.create(edition.bitcoin_id)
.then((res) => {
this.actions.updateCoa(res.coa);
})
.catch((err) => {
console.logGlobal(err);
this.actions.updateCoa(null);
reject(err);
});
});
}
}

View File

@ -338,7 +338,12 @@ let CoaDetails = React.createClass({
componentDidMount() {
CoaStore.listen(this.onChange);
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 {
CoaActions.create(this.props.edition);