diff --git a/frontend/src/components/CheckSignature.js b/frontend/src/components/CheckSignature.js new file mode 100644 index 0000000..bffa99e --- /dev/null +++ b/frontend/src/components/CheckSignature.js @@ -0,0 +1,99 @@ +import getWeb3 from '../utils/web3'; +import DeviceManager from '../DeviceManager'; + +import React, { Component } from 'react'; +import { Link } from 'react-router-dom'; +import { Tag, Divider, Spin, Alert } from 'antd'; + +class CheckSignature extends Component { + constructor(props) { + super(props); + + this.state = { + signatureId: this.props.match.params.signatureId, + loading: true, + showError: false + } + } + + componentWillReceiveProps({ match }) { + this.setState({ + ...this.state, + showError: false, + signatureId: match.params.signatureId + }, () => this.updateSignatureData()); + } + + async componentWillMount() { + try { + let web3 = (await getWeb3).web3; + let instance = await DeviceManager; + + this.setState({ + web3, + instance + }); + + await this.updateSignatureData(); + } catch (error) { + console.log(error); + //message.error(error.message); + this.setState({ + loading: false, + showError: true + }) + } + } + + async updateSignatureData() { + try { + const { instance, signatureId } = this.state; + let signature = await instance.signatures(signatureId); + + this.setState({ + loading: false, + signer: signature[0], + deviceId: signature[1].toNumber(), + expiryTime: signature[2].toNumber(), + revoked: signature[3], + }); + } catch (error) { + console.log(error); + //message.error(error.message); + this.setState({ + loading: false, + showError: true + }) + } + } + + render() { + const { loading, showError, signer, deviceId, expiryTime, revoked } = this.state; + + return ( +
+ + {loading === false && showError === false && +
+

Signature created by {signer} 

+ +
For device with  ID {deviceId}
+
Expires on {new Date(expiryTime * 1000).toString()} 
+ {revoked === true ?
This signature has been revoked! 
:
} +
+ } + {loading === false && showError && + + } +
+
+ ); + } +} + +export default CheckSignature; \ No newline at end of file