import * as React from "react"; import { Vote as Entity, IVoteState as Data } from "@daostack/arc.js"; import { Component, ComponentLogs, ComponentProps } from "../runtime"; import { CreateContextFeed } from "../runtime/ContextFeed"; import { Arc as Protocol, ArcConfig as ProtocolConfig } from "../protocol"; interface RequiredProps extends ComponentProps { // Vote ID id: string; } interface InferredProps extends RequiredProps { config: ProtocolConfig; } class InferredVote extends Component { protected createEntity(): Entity { const { config, id } = this.props; if (!config) { throw Error( "Arc Config Missing: Please provide this field as a prop, or use the inference component." ); } return new Entity(config.connection, id); } public static get Entity() { return CreateContextFeed( this.EntityContext.Consumer, this.LogsContext.Consumer, "Vote" ); } public static get Data() { return CreateContextFeed( this.DataContext.Consumer, this.LogsContext.Consumer, "Vote" ); } public static get Logs() { return CreateContextFeed( this.LogsContext.Consumer, this.LogsContext.Consumer, "Vote" ); } public static EntityContext = React.createContext( undefined ); public static DataContext = React.createContext(undefined); public static LogsContext = React.createContext( undefined ); } function useVote(): [Data | undefined, Entity | undefined] { const data = React.useContext(InferredVote.DataContext); const entity = React.useContext( InferredVote.EntityContext ); return [data, entity]; } class Vote extends React.Component { public render() { const { id, children } = this.props; return ( {(config: ProtocolConfig) => ( {children} )} ); } public static get Entity() { return InferredVote.Entity; } public static get Data() { return InferredVote.Data; } public static get Logs() { return InferredVote.Logs; } } export default Vote; export { Vote, InferredVote, Entity as VoteEntity, Data as VoteData, useVote };