import { DetailedHTMLProps, HTMLAttributes, MouseEventHandler, ReactElement } from "react"; import { EventHandler, IOView } from "../types"; import { Link } from "react-router-dom"; import { UserReadPublicResponse } from "@newstackdev/iosdk-newgraph-client-js"; import { UserStake } from "./UserWidget"; import { round } from "lodash"; import { useActions } from "../overmind"; import { useCurrentUserStakeEligibility } from "../hooks/useBlockchainInfo"; import React from "react"; const DefaultPrivateContentView: IOView<{ stakeInfo: ReturnType; onClick?: MouseEventHandler; }> = ({ stakeInfo, onClick }) => (
{/* xyz */}
onClick && e.stopPropagation()} // if the onClick above needs to take us to details this will prevent it from getting the event so that // we can stake from the list of folders directly className="iosdk-premium-content-notification" style={{ background: "rgba(0,0,0,.05)", padding: "20px", borderRadius: "8px", width: "90%", maxWidth: "min(100vw,800px)", marginLeft: "auto", marginRight: "auto", // height: "100%", top: "10%", left: "50%", transform: "translate(-50%, 0)", position: "absolute", }} > Premium content: stake {round(stakeInfo.currentUserNeeds, 2)} ${stakeInfo.currency} to access.
{}} user={stakeInfo.owner} />
); export const PremiumContent: IOView< { stakeToAccess?: number; owner?: UserReadPublicResponse; privateContentView?: IOView<{ stakeInfo: ReturnType; }>; link?: string; } & DetailedHTMLProps, HTMLDivElement> > = ({ stakeToAccess, owner, children, className, style, privateContentView, link, ...rest }) => { const actions = useActions(); const stakeInfo = useCurrentUserStakeEligibility(owner, stakeToAccess); const blur = !stakeInfo.currentUserEligible; className += "iosdk-premium-content"; style = { ...style, ...(blur ? { filter: "blur(2px)", } : {}), }; const PrivateContentView = privateContentView || DefaultPrivateContentView; const onClick = () => link && actions.routing.historyPush({ location: link }); if (!blur) return <>{children}; else return ( <> {/*
{ e.preventDefault(); onClick(); }, } : {})} {...rest} style={style} >
*/} {React.Children.map(children, (c: React.ReactNode) => { return React.cloneElement(c as any, { onClick }); })} {/* {children} */} {blur ? : <>} ); };