import * as React from "react"; import { ApprovedRevision } from "@joincivil/core"; import { ArticleSignPanelIcon, Modal, Button, buttonSizes } from "@joincivil/components"; import { SignatureData } from "../store/interfaces"; import { PanelWalletStatus } from "./PanelWalletStatus"; import { PostStatus } from "./PostStatus"; import { Signature } from "./Signature"; import { Wrapper, IconWrap, Heading, MainHeading, Intro, Body, BodySection, ErrorText, HelpText, ModalHeader, ModalP, ModalButtonContainer, PrimaryButtonWrap, } from "../styles"; export interface BlockchainSignPanelProps { currentUserId: number; isWpEditor: boolean; signatures: SignatureData; signDisabled: boolean; isDirty: boolean; isSavingPost: boolean; latestRevisionJson: any; postAuthors: any[]; currentUserIsPostAuthor: boolean; signArticle(cb: () => void): Promise; isValidSignature(signature: ApprovedRevision): boolean; } export interface BlockchainSignPanelState { isSignSuccessModalOpen: boolean; } export class BlockchainSignPanelComponent extends React.Component { constructor(props: BlockchainSignPanelProps) { super(props); this.state = { isSignSuccessModalOpen: false, }; } public render(): JSX.Element { const ownSigData = this.props.signatures[this.props.currentUserId]; const ownSigValid = ownSigData && this.props.isValidSignature(ownSigData); const needsReSign = ownSigData && ownSigValid === false; const ownSig = ; const othersSigs = Object.entries(this.props.signatures) .filter( ([userId, sigData]: [string, ApprovedRevision]): boolean => parseInt(userId, 10) !== this.props.currentUserId, ) .map( ([userId, sigData]: [string, ApprovedRevision]): JSX.Element => ( ), ) // create placeholder signature elements for any remaining post authors who haven't signed: .concat( this.props.postAuthors .filter(author => !this.props.signatures[author.ID] && author.ID !== this.props.currentUserId) .map(author => ), ); let buttonText = (needsReSign ? "Re-s" : "S") + "ign Post"; if (ownSigValid === null || this.props.isSavingPost) { buttonText = "Validating..."; } return ( Sign

Sign this post, using your public wallet address, to confirm that you are {this.props.currentUserIsPostAuthor ? " an author of this story and are fully aware of its content. " : " fully aware of its content as a representative of your newsroom. "} Including your signature increases the credibility of this story on the blockchain, but it is optional.

Signatures {!this.props.signDisabled && (needsReSign ? ( Post updated and signature is no longer valid. Needs to be re-signed. ) : (

Post ready to sign.

))} {ownSig} This will open a window and you must sign the statement in MetaMask to confirm. There is no fee.
{this.props.isWpEditor && !!othersSigs.length && {othersSigs}} {this.renderSignSuccessModal()}
); } private renderSignSuccessModal(): JSX.Element | null { if (!this.state.isSignSuccessModalOpen) { return null; } return ( Post signed! Your post was successfully signed. Note that any time an update to your post is published to your site, we recommend you also update your signature. ); } private sign = async () => { await this.props.signArticle(() => { this.setState({ isSignSuccessModalOpen: true }); }); }; }