import * as React from "react"; import styled from "styled-components/macro"; import { BigNumber } from "@joincivil/typescript-types"; import { CivilContext, Table, Tr, Td, ParameterizerTd, StyledTableAccentText, mediaQueries, ICivilContext, } from "@joincivil/components"; import { getFormattedParameterValue, transformGraphQLDataIntoParamProposal } from "@joincivil/utils"; import { Proposal } from "./Proposal"; import { Query } from "react-apollo"; import gql from "graphql-tag"; export const StyledHiddenOnMobile = styled.div` ${mediaQueries.MOBILE} { display: none; } `; const PARAMETER_PROPOSALS_QUERY = gql` query ParamProposals($input: String!) { paramProposals: paramProposals(paramName: $input) { id propID name value deposit appExpiry challengeID proposer accepted expired } } `; export interface ParameterProps { parameterName: string; parameterDisplayName: string | JSX.Element; parameterValue: BigNumber; canShowCreateProposal: boolean; isGovtProposal?: boolean; handleCreateProposal(paramName: string, currentValue: string): void; handleProposalAction( paramName: string, currentValue: string, newValue: string, proposal: any, actionType: string, ): void; } class ParameterComponent extends React.Component { public static contextType = CivilContext; public context: ICivilContext; public render(): JSX.Element { return ( {this.props.parameterDisplayName} {this.getFormattedValue(this.props.parameterValue)} {this.props.canShowCreateProposal && this.renderCreateProposalAction()} {this.renderProposals()}
); return <>; } private renderCreateProposalAction(): JSX.Element { return ( Propose New Value ); } private renderProposals(): JSX.Element { return ( {({ loading, error, data }) => { if (loading || error) { return <>; } return data.paramProposals.map(prop => { const proposal = transformGraphQLDataIntoParamProposal(prop); return ( ); }); }} ); } private onCreateProposal = (event: any) => { this.props.handleCreateProposal(this.props.parameterName, this.getFormattedValue(this.props.parameterValue)); }; private getFormattedValue = (parameterValue: BigNumber): string => { const { civil } = this.context; return getFormattedParameterValue(this.props.parameterName, civil.toBigNumber(parameterValue.toString())); }; } export const Parameter = ParameterComponent;