1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-23 01:39:36 +01:00

Merged in AD-772-coa-doesnt-render (pull request #89)

create CoA when not found
This commit is contained in:
diminator 2015-09-30 12:03:34 +02:00
commit 2aef82be0b
2 changed files with 36 additions and 19 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() {
@ -12,22 +13,37 @@ class CoaActions {
); );
} }
fetchOne(id) { fetchOrCreate(id, bitcoinId) {
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.create(bitcoinId);
}
}) })
.catch((err) => { .catch((err) => {
console.logGlobal(err); console.logGlobal(err);
this.actions.updateCoa(null);
reject(err);
});
}); });
} }
create(edition) {
CoaFetcher.create(edition.bitcoin_id) create(bitcoinId) {
return Q.Promise((resolve, reject) => {
CoaFetcher.create(bitcoinId)
.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

@ -336,12 +336,13 @@ let CoaDetails = React.createClass({
}, },
componentDidMount() { componentDidMount() {
let { edition } = this.props;
CoaStore.listen(this.onChange); CoaStore.listen(this.onChange);
if(this.props.edition.coa) { if(edition.coa) {
CoaActions.fetchOne(this.props.edition.coa); CoaActions.fetchOrCreate(edition.coa, edition.bitcoin_id);
} }
else { else {
CoaActions.create(this.props.edition); CoaActions.create(edition.bitcoin_id);
} }
}, },