const initialContract = props.contract || "curb-contract-3.ws-protocol-63"; const componentOwnerId = props.componentOwnerId || "debeligad.testnet"; const encryptionUrl = props.encryptionUrl || "https://cali-encryption.euw3.staging.gcp.calimero.network/key"; const meroshipUrl = props.meroshipUrl || "wss://cali-meroship.euw3.staging.gcp.calimero.network/ws"; const accountId = context.accountId; const enableCommunities = props.enableCommunities ?? false; const [contract, setContract] = useState(initialContract); const handleContractChange = useCallback((contract) => { setContract(contract); }, []); const [loggedIn, setLoggedIn] = useState(false); const PageContainer = styled.div` background-color: #0e0e10; height: 100%; width: 100%; `; const loginApi = useMemo( () => ({ join: () => Near.fakCalimeroCall(contract, "join"), login: () => Near.requestCalimeroFak(contract), validateKey: () => Near.hasValidCalimeroFak(contract), getMembers: () => Near.asyncCalimeroView(contract, "get_members"), }), [contract] ); const Logo = () => ( <Widget src={`${componentOwnerId}/widget/Calimero.Curb.Navbar.CurbLogo`} props={{ justify: true, }} /> ); // Ping to prepare the new key, needs to be simplified const ping = () => Near.fakCalimeroCall(contract, "ping"); const App = (props) => ( <Widget src={`${componentOwnerId}/widget/Calimero.Curb.WebSocketManager`} props={{ accountId: props.accountId, wsAddress: meroshipUrl, render: ({ wsApi }) => ( <Widget src={`${componentOwnerId}/widget/Calimero.Curb.AppContainer`} props={{ ...props, wsApi, }} /> ), }} /> ); return ( <PageContainer> {!loggedIn || !accountId ? ( <Widget src={`${componentOwnerId}/widget/Calimero.Common.Login.index`} props={{ loginApi, accountId: context.accountId, componentOwnerId, onValidLogin: () => // todo! migrate to meroship ping().then(() => { setLoggedIn(true); }), logo: <Logo />, }} /> ) : ( <App componentOwnerId={componentOwnerId} contract={contract} encryptionUrl={encryptionUrl} accountId={context.accountId} enableCommunities={enableCommunities} handleContractChange={handleContractChange} /> )} </PageContainer> );