1
0
mirror of https://github.com/ascribe/onion.git synced 2025-01-03 18:35:09 +01:00

Merge remote-tracking branch 'remotes/origin/AD-772-coa-doesnt-render' into AD-806-webapp-users-cannot-withdraw-a-pe

This commit is contained in:
diminator 2015-09-30 11:45:56 +02:00
commit 009d12ee53
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,23 +13,38 @@ class CoaActions {
); );
} }
fetchOne(id) { fetchOrCreate(id, bitcoinId) {
CoaFetcher.fetchOne(id) return Q.Promise((resolve, reject) => {
.then((res) => { CoaFetcher.fetchOne(id)
this.actions.updateCoa(res.coa); .then((res) => {
}) if (res.coa) {
.catch((err) => { this.actions.updateCoa(res.coa);
console.logGlobal(err); resolve(res.coa);
}); }
else {
this.actions.create(bitcoinId);
}
})
.catch((err) => {
console.logGlobal(err);
this.actions.updateCoa(null);
reject(err);
});
});
} }
create(edition) {
CoaFetcher.create(edition.bitcoin_id) create(bitcoinId) {
.then((res) => { return Q.Promise((resolve, reject) => {
this.actions.updateCoa(res.coa); CoaFetcher.create(bitcoinId)
}) .then((res) => {
.catch((err) => { this.actions.updateCoa(res.coa);
console.logGlobal(err); })
}); .catch((err) => {
console.logGlobal(err);
this.actions.updateCoa(null);
reject(err);
});
});
} }
} }

View File

@ -344,12 +344,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);
} }
}, },