const contract = props.contract || 'docschain.ws-protocol-63'; const componentOwnerId = props.componentOwnerId; const redirectConfig = !componentOwnerId || componentOwnerId === 'calimero.near' ? {} : { redirect: (url) => url.replace('calimero.near', componentOwnerId) }; const accountId = props.accountId ?? context.accountId; if (!accountId) { return ( <Widget src={`calimero.near/widget/Calimero.DocsChain.Popups.TextPopup`} config={redirectConfig} props={{ componentOwnerId, popupText: 'Please login to NEAR Socials to continue!', }} /> ); } const PageContainer = styled.div` width: 100%; height: 100vh; padding-left: 60px; padding-right: 60px; background-color: #0e0e10; `; const FunctionButton = styled.button` background-color: #5765f2; :hover { background-color: #717cf0; } color: #fff; border-radius: 4px; padding-top: 0.5rem; padding-bottom: 0.5rem; border: none; width: 100%; `; State.init({ bootstraping: true, createPage: { open: false, private: false }, onOpenCreatePage: (isPrivate) => State.update({ openCreatePage: { open: true, private: isPrivate } }), }); const joinDocs = () => { Near.requestCalimeroFak(contract); }; const isMember = () => { return Near.calimeroView(contract, 'get_account', { account_id: context.accountId, }); }; const verifyKey = () => { Near.hasValidCalimeroFak(contract).then((result) => { State.update({ bootstraping: false, loggedIn: result }); if (result) { if (!isMember()) { Near.fakCalimeroCall(contract, 'join'); } } }); }; if (state.bootstraping) { verifyKey(); } return ( <PageContainer> <> {state.bootstraping ? ( <Widget src={'calimero.near/widget/Calimero.DocsChain.Popups.TextPopup'} config={redirectConfig} props={{ popupText: 'Loading...', }} /> ) : ( <> {isMember(context.accountId) ? ( <> <Widget src={ 'calimero.near/widget/Calimero.DocsChain.Navbar.HorizontalNavbar' } config={redirectConfig} /> <div className="d-flex"> <Widget src={ 'calimero.near/widget/Calimero.DocsChain.Sidebar.DocsSidebar' } config={redirectConfig} props={{ onOpenCreatePage: state.onOpenCreatePage, createPageOpen: state.createPage.open, }} /> </div> </> ) : ( <Widget src={'calimero.near/widget/Calimero.DocsChain.Popups.JoinPopup'} config={redirectConfig} props={{ join: () => joinDocs(), }} /> )} </> )} </> </PageContainer> );