1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-22 17:33:14 +01:00

Increase robustness of coa fetching routine

This commit is contained in:
Tim Daubenschütz 2015-12-08 14:18:31 +01:00
parent da75353b00
commit 2cc02d9599
7 changed files with 48 additions and 39 deletions

View File

@ -9,6 +9,7 @@ class EditionActions {
'fetchEdition', 'fetchEdition',
'successFetchEdition', 'successFetchEdition',
'successFetchCoa', 'successFetchCoa',
'flushEdition',
'errorCoa', 'errorCoa',
'errorEdition' 'errorEdition'
); );

View File

@ -39,6 +39,7 @@ let Edition = React.createClass({
actionPanelButtonListType: React.PropTypes.func, actionPanelButtonListType: React.PropTypes.func,
furtherDetailsType: React.PropTypes.func, furtherDetailsType: React.PropTypes.func,
edition: React.PropTypes.object, edition: React.PropTypes.object,
coaError: React.PropTypes.object,
currentUser: React.PropTypes.object, currentUser: React.PropTypes.object,
loadEdition: React.PropTypes.func loadEdition: React.PropTypes.func
}, },
@ -77,7 +78,9 @@ let Edition = React.createClass({
title={getLangText('Certificate of Authenticity')} title={getLangText('Certificate of Authenticity')}
show={this.props.edition.acl.acl_coa === true}> show={this.props.edition.acl.acl_coa === true}>
<CoaDetails <CoaDetails
coa={this.props.edition.coa}/> coa={this.props.edition.coa}
coaError={this.props.coaError}
editionId={this.props.edition.bitcoin_id}/>
</CollapsibleParagraph> </CollapsibleParagraph>
<CollapsibleParagraph <CollapsibleParagraph
@ -216,10 +219,28 @@ let EditionSummary = React.createClass({
let CoaDetails = React.createClass({ let CoaDetails = React.createClass({
propTypes: { propTypes: {
coa: React.PropTypes.object editionId: React.PropTypes.string,
coa: React.PropTypes.object,
coaError: React.PropTypes.object
},
contactOnIntercom() {
window.Intercom('showNewMessage', `Hi, I'm having problems generating a Certificate of Authenticity for Edition: ${this.props.editionId}`);
console.logGlobal(new Error(`Coa couldn't be created for edition: ${this.props.editionId}`));
}, },
render() { render() {
if(this.props.coaError) {
return (
<div className="text-center">
<p>{getLangText('There was an error generating your Certificate of Authenticity.')}</p>
<p>
{getLangText('Try to refresh the page. If this happens repeatedly, please ')}
<a style={{ cursor: 'pointer' }} onClick={this.contactOnIntercom}>{getLangText('contact us')}</a>.
</p>
</div>
);
}
if(this.props.coa && this.props.coa.url_safe) { if(this.props.coa && this.props.coa.url_safe) {
return ( return (
<div> <div>

View File

@ -48,6 +48,7 @@ let EditionContainer = React.createClass({
// just reset the edition that is saved in the edition store // just reset the edition that is saved in the edition store
// as it will otherwise display wrong/old data once the user loads // as it will otherwise display wrong/old data once the user loads
// the edition detail a second time // the edition detail a second time
EditionActions.flushEdition();
EditionActions.fetchEdition(this.props.params.editionId); EditionActions.fetchEdition(this.props.params.editionId);
UserActions.fetchCurrentUser(); UserActions.fetchCurrentUser();
@ -95,6 +96,7 @@ let EditionContainer = React.createClass({
actionPanelButtonListType={this.props.actionPanelButtonListType} actionPanelButtonListType={this.props.actionPanelButtonListType}
furtherDetailsType={this.props.furtherDetailsType} furtherDetailsType={this.props.furtherDetailsType}
edition={this.state.edition} edition={this.state.edition}
coaError={this.state.coaMeta.err}
currentUser={this.state.currentUser} currentUser={this.state.currentUser}
loadEdition={() => EditionActions.fetchEdition(this.props.params.editionId)} /> loadEdition={() => EditionActions.fetchEdition(this.props.params.editionId)} />
); );

View File

@ -1,18 +0,0 @@
'use strict';
import requests from '../utils/requests';
let CoaFetcher = {
/**
* Fetch one user from the API.
* If no arg is supplied, load the current user
*/
fetchOne(id) {
return requests.get('coa', {'id': id});
},
create(bitcoinId) {
return requests.post('coa_create', {body: {'bitcoin_id': bitcoinId}});
}
};
export default CoaFetcher;

View File

@ -1,15 +0,0 @@
'use strict';
import requests from '../utils/requests';
let EditionFetcher = {
/**
* Fetch one user from the API.
* If no arg is supplied, load the current user
*/
fetchOne(editionId) {
return requests.get('edition', {'bitcoin_id': editionId});
}
};
export default EditionFetcher;

View File

@ -36,7 +36,7 @@ class EditionStore {
if(this.edition && this.edition.coa && typeof this.edition.coa.constructor !== Object) { if(this.edition && this.edition.coa && typeof this.edition.coa.constructor !== Object) {
this.getInstance().lookupCoa(); this.getInstance().lookupCoa();
} else if(this.edition && !this.edition.coa) { } else if(this.edition && !this.edition.coa && this.edition.acl.acl_coa) {
this.getInstance().performCreateCoa(); this.getInstance().performCreateCoa();
} }
} }
@ -46,11 +46,22 @@ class EditionStore {
this.edition.coa = coa; this.edition.coa = coa;
} }
onEditionError(err) { onFlushEdition() {
this.edition = null;
this.editionMeta = {
err: null,
idToFetch: null
};
this.coaMeta = {
err: null
};
}
onErrorEdition(err) {
this.editionMeta.err = err; this.editionMeta.err = err;
} }
onCoaError(err) { onErrorCoa(err) {
this.coaMeta.err = err; this.coaMeta.err = err;
} }
} }

View File

@ -12,7 +12,14 @@ import { argsToQueryParams } from '../utils/url_utils';
class Requests { class Requests {
unpackResponse(response) { unpackResponse(response) {
if (response.status >= 500) { if (response.status >= 500) {
throw new Error(response.status + ' - ' + response.statusText + ' - on URL:' + response.url); let err = new Error(response.status + ' - ' + response.statusText + ' - on URL:' + response.url);
response
.text()
.then((resText) => JSON.parse(resText))
.then((resJSON) => {
err = new Error(resJSON.errors.pop());
})
.catch(() => { throw err; });
} }
return Q.Promise((resolve, reject) => { return Q.Promise((resolve, reject) => {