2018-01-31 02:15:23 +01:00
|
|
|
import React from 'react';
|
2018-02-02 20:10:58 +01:00
|
|
|
import ShowAssetLite from 'components/ShowAssetLite';
|
|
|
|
import ShowAssetDetails from 'components/ShowAssetDetails';
|
2018-01-31 02:15:23 +01:00
|
|
|
import request from 'utils/request';
|
|
|
|
|
|
|
|
class ShowAsset extends React.Component {
|
|
|
|
constructor (props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
2018-02-02 21:46:18 +01:00
|
|
|
error : null,
|
|
|
|
claimData: null,
|
2018-01-31 02:15:23 +01:00
|
|
|
};
|
|
|
|
this.getLongClaimId = this.getLongClaimId.bind(this);
|
|
|
|
this.getClaimData = this.getClaimData.bind(this);
|
|
|
|
}
|
|
|
|
componentDidMount () {
|
|
|
|
console.log('ShowAsset did mount');
|
|
|
|
console.log('ShowAsset props', this.props);
|
2018-02-02 20:10:58 +01:00
|
|
|
const modifier = this.props.modifier;
|
|
|
|
const name = this.props.claim;
|
2018-02-02 04:36:08 +01:00
|
|
|
// create request params
|
2018-01-31 02:15:23 +01:00
|
|
|
let body = {};
|
2018-02-02 04:36:08 +01:00
|
|
|
if (modifier) {
|
2018-02-02 22:02:30 +01:00
|
|
|
if (modifier.id) {
|
|
|
|
body['claimId'] = modifier.id;
|
|
|
|
} else {
|
2018-02-02 04:36:08 +01:00
|
|
|
body['channelName'] = modifier.channel.name;
|
|
|
|
body['channelClaimId'] = modifier.channel.id;
|
2018-01-31 02:15:23 +01:00
|
|
|
}
|
|
|
|
}
|
2018-02-02 04:36:08 +01:00
|
|
|
body['claimName'] = name;
|
2018-01-31 02:15:23 +01:00
|
|
|
const params = {
|
|
|
|
method : 'POST',
|
|
|
|
headers: new Headers({
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
}),
|
|
|
|
body: JSON.stringify(body),
|
|
|
|
}
|
2018-02-02 04:36:08 +01:00
|
|
|
// make request
|
2018-01-31 02:15:23 +01:00
|
|
|
const that = this;
|
|
|
|
this.getLongClaimId(params)
|
|
|
|
.then(claimLongId => {
|
2018-02-02 04:36:08 +01:00
|
|
|
return that.getClaimData(name, claimLongId);
|
2018-01-31 02:15:23 +01:00
|
|
|
})
|
|
|
|
.then(claimData => {
|
2018-02-02 21:46:18 +01:00
|
|
|
this.setState({claimData});
|
2018-01-31 02:15:23 +01:00
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
this.setState({error});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
getLongClaimId (params) {
|
|
|
|
const url = `/api/claim-get-long-id`;
|
|
|
|
console.log('params:', params);
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
request(url, params)
|
|
|
|
.then(({ success, message }) => {
|
|
|
|
console.log('get long claim id response:', message);
|
|
|
|
if (!success) {
|
|
|
|
reject(message);
|
|
|
|
}
|
|
|
|
resolve(message);
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
reject(error.message);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
getClaimData (claimName, claimId) {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
const url = `/api/claim-get-data/${claimName}/${claimId}`;
|
|
|
|
return request(url)
|
|
|
|
.then(({ success, message }) => {
|
|
|
|
console.log('get claim data response:', message);
|
|
|
|
if (!success) {
|
|
|
|
reject(message);
|
|
|
|
}
|
|
|
|
resolve(message);
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
reject(error.message);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
render () {
|
2018-02-02 20:10:58 +01:00
|
|
|
if (this.props.extension) {
|
2018-01-31 02:15:23 +01:00
|
|
|
return (
|
2018-02-01 04:12:54 +01:00
|
|
|
<ShowAssetLite
|
2018-01-31 02:15:23 +01:00
|
|
|
error={this.state.error}
|
2018-02-02 21:46:18 +01:00
|
|
|
claimData={this.state.claimData}
|
2018-01-31 02:15:23 +01:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return (
|
2018-02-01 04:12:54 +01:00
|
|
|
<ShowAssetDetails
|
2018-01-31 02:15:23 +01:00
|
|
|
error={this.state.error}
|
2018-02-02 21:46:18 +01:00
|
|
|
claimData={this.state.claimData}
|
2018-01-31 02:15:23 +01:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ShowAsset;
|