|
| 1 | +import React from 'react' |
| 2 | +import {useCollapse} from 'react-collapsed' |
| 3 | +import ExpandablePanel from '../../expandabablePanel' |
| 4 | + |
| 5 | +const CertificatesInTxPart = ({getters}) => { |
| 6 | + const {getCollapseProps, getToggleProps, isExpanded} = useCollapse() |
| 7 | + const {certsInTx, votesInTx} = getters |
| 8 | + const amountOfCertsAndVotesInTx = () => certsInTx.length + votesInTx.length |
| 9 | + const getAllInOne = () => { |
| 10 | + const resultArray = [] |
| 11 | + for (const certInTx of certsInTx) { |
| 12 | + const certPartWithName = certInTx.split('\n')[1] |
| 13 | + const cleanCertName = certPartWithName.split('"')[1] |
| 14 | + const certJsonObject = JSON.parse(certInTx) |
| 15 | + resultArray.push([cleanCertName, certJsonObject]) |
| 16 | + } |
| 17 | + for (const voteInTx of votesInTx) { |
| 18 | + const votePartWithName = voteInTx.split('\n')[1] |
| 19 | + const cleanVoteName = votePartWithName.split('"')[1] |
| 20 | + const voteJsonObject = JSON.parse(voteInTx) |
| 21 | + resultArray.push([cleanVoteName, voteJsonObject]) |
| 22 | + } |
| 23 | + return resultArray |
| 24 | + } |
| 25 | + |
| 26 | + return ( |
| 27 | + <div className="border rounded-md bg-gray-700 border-gray-700 px-5 py-2 mt-5"> |
| 28 | + <div {...getToggleProps()}> |
| 29 | + <div> |
| 30 | + <span className="text-m"> |
| 31 | + Certtificates in Tx {`(${amountOfCertsAndVotesInTx()})`} |
| 32 | + {isExpanded ? ( |
| 33 | + <svg |
| 34 | + xmlns="http://www.w3.org/2000/svg" |
| 35 | + width="16" |
| 36 | + height="16" |
| 37 | + viewBox="0 0 16 16" |
| 38 | + fill="none" |
| 39 | + stroke="currentColor" |
| 40 | + strokeWidth="2" |
| 41 | + strokeLinecap="round" |
| 42 | + strokeLinejoin="round" |
| 43 | + className="inline align-text-bottom feather feather-arrow-down" |
| 44 | + > |
| 45 | + <line x1="8" y1="3" x2="8" y2="12"></line> |
| 46 | + <polyline points="13 8 8 12 3 8"></polyline> |
| 47 | + </svg> |
| 48 | + ) : ( |
| 49 | + <svg |
| 50 | + xmlns="http://www.w3.org/2000/svg" |
| 51 | + width="16" |
| 52 | + height="16" |
| 53 | + viewBox="0 0 16 16" |
| 54 | + fill="none" |
| 55 | + stroke="currentColor" |
| 56 | + strokeWidth="2" |
| 57 | + strokeLinecap="round" |
| 58 | + strokeLinejoin="round" |
| 59 | + className="inline align-text-bottom feather feather-arrow-up" |
| 60 | + > |
| 61 | + <line x1="8" y1="3" x2="8" y2="13"></line> |
| 62 | + <polyline points="3 8 8 3 13 8"></polyline> |
| 63 | + </svg> |
| 64 | + )} |
| 65 | + </span> |
| 66 | + </div> |
| 67 | + </div> |
| 68 | + <div {...getCollapseProps()}> |
| 69 | + <div> |
| 70 | + {getAllInOne().map((certInfo) => ( |
| 71 | + <ExpandablePanel |
| 72 | + title={'-> ' + certInfo[0]} |
| 73 | + innerInfo={JSON.stringify(certInfo[1], null, 4)} |
| 74 | + /> |
| 75 | + ))} |
| 76 | + </div> |
| 77 | + </div> |
| 78 | + </div> |
| 79 | + ) |
| 80 | +} |
| 81 | + |
| 82 | +export default CertificatesInTxPart |
0 commit comments