|
| 1 | +import React from "react"; |
| 2 | + |
| 3 | +import ContractViewState from "../../../shared/viewState/contractViewState"; |
| 4 | +import ContractViewRequest from "../../../shared/messages/contractViewRequest"; |
| 5 | +import Hash from "../Hash"; |
| 6 | + |
| 7 | +type Props = { |
| 8 | + viewState: ContractViewState; |
| 9 | + postMessage: (message: ContractViewRequest) => void; |
| 10 | +}; |
| 11 | + |
| 12 | +export default function Contract({ viewState, postMessage }: Props) { |
| 13 | + const hash = viewState.contractHash; |
| 14 | + const name = |
| 15 | + viewState.autoCompleteData.contractNames[hash] || "Unknown contract"; |
| 16 | + const manifest = viewState.autoCompleteData.contractManifests[hash] || {}; |
| 17 | + const extra = (manifest.extra || {}) as any; |
| 18 | + const description = extra["Description"] || undefined; |
| 19 | + const author = extra["Author"] || undefined; |
| 20 | + const email = extra["Email"] || undefined; |
| 21 | + const supportedStandards = manifest.supportedstandards || []; |
| 22 | + const contractPaths = |
| 23 | + viewState.autoCompleteData.contractPaths[hash] || |
| 24 | + viewState.autoCompleteData.contractPaths[name] || |
| 25 | + []; |
| 26 | + return ( |
| 27 | + <div style={{ padding: 10 }}> |
| 28 | + <h1>{name}</h1> |
| 29 | + {!!description && ( |
| 30 | + <p style={{ paddingLeft: 20 }}> |
| 31 | + <div style={{ fontWeight: "bold", marginBottom: 10, marginTop: 15 }}> |
| 32 | + Description: |
| 33 | + </div> |
| 34 | + <div style={{ paddingLeft: 20 }}>{description}</div> |
| 35 | + </p> |
| 36 | + )} |
| 37 | + {(!!author || !!email) && ( |
| 38 | + <p style={{ paddingLeft: 20 }}> |
| 39 | + <div style={{ fontWeight: "bold", marginBottom: 10, marginTop: 15 }}> |
| 40 | + Author: |
| 41 | + </div> |
| 42 | + {!!author && <div style={{ paddingLeft: 20 }}>{author}</div>} |
| 43 | + {!!email && <div style={{ paddingLeft: 20 }}><{email}></div>} |
| 44 | + </p> |
| 45 | + )} |
| 46 | + <p style={{ paddingLeft: 20 }}> |
| 47 | + <div style={{ fontWeight: "bold", marginBottom: 10, marginTop: 15 }}> |
| 48 | + Hash: |
| 49 | + </div> |
| 50 | + <div |
| 51 | + style={{ cursor: "pointer", paddingLeft: 20 }} |
| 52 | + onClick={() => postMessage({ copyHash: true })} |
| 53 | + > |
| 54 | + <strong> |
| 55 | + <Hash hash={hash} /> |
| 56 | + </strong>{" "} |
| 57 | + <em> — click to copy contract hash to clipboard</em> |
| 58 | + </div> |
| 59 | + </p> |
| 60 | + {!!supportedStandards.length && ( |
| 61 | + <p style={{ paddingLeft: 20 }}> |
| 62 | + <div style={{ fontWeight: "bold", marginBottom: 10, marginTop: 15 }}> |
| 63 | + Supported standards: |
| 64 | + </div> |
| 65 | + <ul> |
| 66 | + {supportedStandards.map((_, i) => ( |
| 67 | + <li key={i}>{_}</li> |
| 68 | + ))} |
| 69 | + </ul> |
| 70 | + </p> |
| 71 | + )} |
| 72 | + {!!contractPaths.length && ( |
| 73 | + <p style={{ paddingLeft: 20 }}> |
| 74 | + <div style={{ fontWeight: "bold", marginBottom: 10, marginTop: 15 }}> |
| 75 | + Byte code location: |
| 76 | + </div> |
| 77 | + <ul> |
| 78 | + {contractPaths.map((_, i) => ( |
| 79 | + <li key={i}>{_}</li> |
| 80 | + ))} |
| 81 | + </ul> |
| 82 | + </p> |
| 83 | + )} |
| 84 | + </div> |
| 85 | + ); |
| 86 | +} |
0 commit comments