import * as React from "react"; import { Stake as Entity, IStakeState as Data } from "@daostack/arc.js"; import { Arc as Protocol, ArcConfig as ProtocolConfig, Component, ComponentLogs, ComponentProps, } from "../"; import { CreateContextFeed } from "../runtime/ContextFeed"; interface RequiredProps extends ComponentProps { // Stake ID id: string; } interface InferredProps extends RequiredProps { config: ProtocolConfig; } class InferredStake 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, "Stake" ); } public static get Data() { return CreateContextFeed( this.DataContext.Consumer, this.LogsContext.Consumer, "Stake" ); } public static get Logs() { return CreateContextFeed( this.LogsContext.Consumer, this.LogsContext.Consumer, "Stake" ); } public static EntityContext = React.createContext( undefined ); public static DataContext = React.createContext(undefined); public static LogsContext = React.createContext( undefined ); } function useStake(): [Data | undefined, Entity | undefined] { const data = React.useContext(InferredStake.DataContext); const entity = React.useContext( InferredStake.EntityContext ); return [data, entity]; } class Stake extends React.Component { public render() { const { id, children } = this.props; return ( {(config: ProtocolConfig) => ( {children} )} ); } public static get Entity() { return InferredStake.Entity; } public static get Data() { return InferredStake.Data; } public static get Logs() { return InferredStake.Logs; } } export default Stake; export { Stake, InferredStake, Entity as StakeEntity, Data as StakeData, useStake, };