2018-01-31 02:15:23 +01:00
|
|
|
import React from 'react';
|
2018-02-07 20:30:39 +01:00
|
|
|
import ErrorPage from 'components/ErrorPage';
|
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.getLongClaimId = this.getLongClaimId.bind(this);
|
|
|
|
this.getClaimData = this.getClaimData.bind(this);
|
|
|
|
}
|
|
|
|
componentDidMount () {
|
2018-02-07 19:52:09 +01:00
|
|
|
const { name, modifier } = this.props;
|
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
|
|
|
this.getLongClaimId(params)
|
|
|
|
.then(claimLongId => {
|
2018-02-07 00:05:31 +01:00
|
|
|
return Promise.all([this.getShortClaimId(claimLongId, name), this.getClaimData(claimLongId, name)]);
|
2018-01-31 02:15:23 +01:00
|
|
|
})
|
2018-02-05 02:43:02 +01:00
|
|
|
.then(([shortId, claimData]) => {
|
|
|
|
this.props.onAssetClaimDataUpdate(claimData, shortId);
|
2018-01-31 02:15:23 +01:00
|
|
|
})
|
|
|
|
.catch(error => {
|
2018-02-07 19:52:09 +01:00
|
|
|
this.props.onShowAssetError(error);
|
2018-01-31 02:15:23 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
getLongClaimId (params) {
|
2018-02-07 06:55:04 +01:00
|
|
|
const url = `/api/claim/long-id`;
|
2018-01-31 02:15:23 +01:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
request(url, params)
|
2018-02-05 02:43:02 +01:00
|
|
|
.then(({ success, message, data }) => {
|
2018-01-31 02:15:23 +01:00
|
|
|
console.log('get long claim id response:', message);
|
|
|
|
if (!success) {
|
|
|
|
reject(message);
|
|
|
|
}
|
2018-02-05 02:43:02 +01:00
|
|
|
resolve(data);
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
reject(error.message);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
getShortClaimId (longId, name) {
|
2018-02-07 06:55:04 +01:00
|
|
|
const url = `/api/claim/short-id/${longId}/${name}`;
|
2018-02-05 02:43:02 +01:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
request(url)
|
|
|
|
.then(({ success, message, data }) => {
|
|
|
|
console.log('get short claim id response:', data);
|
|
|
|
if (!success) {
|
|
|
|
reject(message);
|
|
|
|
}
|
|
|
|
resolve(data);
|
2018-01-31 02:15:23 +01:00
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
reject(error.message);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2018-02-05 02:43:02 +01:00
|
|
|
getClaimData (claimId, claimName) {
|
2018-01-31 02:15:23 +01:00
|
|
|
return new Promise((resolve, reject) => {
|
2018-02-07 06:55:04 +01:00
|
|
|
const url = `/api/claim/data/${claimName}/${claimId}`;
|
2018-01-31 02:15:23 +01:00
|
|
|
return request(url)
|
|
|
|
.then(({ success, message }) => {
|
|
|
|
console.log('get claim data response:', message);
|
|
|
|
if (!success) {
|
|
|
|
reject(message);
|
|
|
|
}
|
|
|
|
resolve(message);
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
reject(error.message);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2018-02-05 01:40:28 +01:00
|
|
|
componentWillUnmount () {
|
|
|
|
this.props.onAssetClaimDataClear();
|
|
|
|
}
|
2018-01-31 02:15:23 +01:00
|
|
|
render () {
|
2018-02-07 19:52:09 +01:00
|
|
|
const { error, claimData, extension } = this.props;
|
|
|
|
if (error) {
|
|
|
|
return (
|
2018-02-07 20:30:39 +01:00
|
|
|
<ErrorPage error={error}/>
|
2018-02-07 19:52:09 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
if (claimData) {
|
|
|
|
if (extension) {
|
2018-02-05 02:51:17 +01:00
|
|
|
return (
|
2018-02-07 19:52:09 +01:00
|
|
|
<ShowAssetLite />
|
2018-02-05 02:51:17 +01:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return (
|
2018-02-07 19:52:09 +01:00
|
|
|
<ShowAssetDetails />
|
2018-02-05 02:51:17 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
2018-01-31 02:15:23 +01:00
|
|
|
return (
|
2018-02-07 19:52:09 +01:00
|
|
|
<div> </div>
|
2018-01-31 02:15:23 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ShowAsset;
|