hooks#useLoggedInAccount TypeScript Examples
The following examples show how to use
hooks#useLoggedInAccount.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: App.tsx From gear-js with GNU General Public License v3.0 | 6 votes |
function Component() {
const { isApiReady } = useApi();
useBalanceSubscription();
useLoggedInAccount();
return (
<>
<Header />
<main>{isApiReady ? <Routing /> : <ApiLoader />}</main>
<Footer />
</>
);
}
Example #2
Source File: App.tsx From gear-js with GNU General Public License v3.0 | 5 votes |
Component = () => {
globalStyles();
const alert = useAlert();
const events = useEvents();
const { isApiReady } = useApi();
const [searchParams, setSearchParams] = useSearchParams();
useLoggedInAccount();
useEffect(() => {
if (isApiReady) {
subscribeToEvents(alert);
}
}, [isApiReady, alert]);
useEffect(() => {
const urlNodeAddress = searchParams.get(NODE_ADRESS_URL_PARAM);
if (!urlNodeAddress) {
searchParams.set(NODE_ADRESS_URL_PARAM, nodeApi.address);
setSearchParams(searchParams, { replace: true });
}
}, [searchParams, setSearchParams]);
const isFooterHidden = () => {
const locationPath = window.location.pathname.replaceAll('/', '');
const privacyPath = routes.privacyPolicy.replaceAll('/', '');
const termsOfUsePath = routes.termsOfUse.replaceAll('/', '');
return locationPath === privacyPath || locationPath === termsOfUsePath;
};
// we'll get rid of multiple paths in one route anyway, so temp solution
const getMultipleRoutes = (paths: string[], element: JSX.Element) =>
paths.map((path) => <Route key={path} path={path} element={element} />);
return (
<div className="app">
<Header />
<Main>
{isApiReady ? (
<Routes>
{getMultipleRoutes(mainRoutes, <Programs />)}
{getMultipleRoutes(utilRoutes, <Document />)}
{/* temp solution since in react-router v6 optional parameters are gone */}
<Route path={routes.explorer}>
<Route path="" element={<Explorer events={events} />} />
<Route path=":blockId" element={<Explorer events={events} />} />
</Route>
<Route path={routes.program} element={<Program />} />
<Route path={routes.message} element={<Message />} />
<Route path={routes.state} element={<State />} />
<Route path={routes.send}>
<Route path={routes.sendMessage} element={<Send />} />
<Route path={routes.reply} element={<Send />} />
</Route>
<Route path={routes.meta} element={<Meta />} />
<Route path={routes.editor} element={<EditorPage />} />
<Route path={routes.mailbox} element={<Mailbox />} />
<Route path="*" element={<PageNotFound />} />
</Routes>
) : (
<Loader />
)}
</Main>
{isFooterHidden() || <Footer />}
</div>
);
}