1
0
mirror of https://github.com/ascribe/onion.git synced 2025-01-03 18:35:09 +01:00
This commit is contained in:
diminator 2015-09-30 11:26:31 +02:00
parent ea4805caa0
commit 55f5d959ff
2 changed files with 8 additions and 14 deletions

View File

@ -13,7 +13,7 @@ class CoaActions {
); );
} }
fetchOne(id) { fetchOrCreate(id, bitcoinId) {
return Q.Promise((resolve, reject) => { return Q.Promise((resolve, reject) => {
CoaFetcher.fetchOne(id) CoaFetcher.fetchOne(id)
.then((res) => { .then((res) => {
@ -22,10 +22,8 @@ class CoaActions {
resolve(res.coa); resolve(res.coa);
} }
else { else {
this.actions.updateCoa(null); this.actions.create(bitcoinId);
resolve(null);
} }
}) })
.catch((err) => { .catch((err) => {
console.logGlobal(err); console.logGlobal(err);
@ -35,9 +33,9 @@ class CoaActions {
}); });
} }
create(edition) { create(bitcoinId) {
return Q.Promise((resolve, reject) => { return Q.Promise((resolve, reject) => {
CoaFetcher.create(edition.bitcoin_id) CoaFetcher.create(bitcoinId)
.then((res) => { .then((res) => {
this.actions.updateCoa(res.coa); this.actions.updateCoa(res.coa);
}) })

View File

@ -336,17 +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);
.then((res) => {
if (res === null){
CoaActions.create(this.props.edition);
}
});
} }
else { else {
CoaActions.create(this.props.edition); CoaActions.create(edition.bitcoin_id);
} }
}, },