utils#isLoggedIn TypeScript Examples

The following examples show how to use utils#isLoggedIn. 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: Accounts.tsx    From gear-js with GNU General Public License v3.0 6 votes vote down vote up
function Accounts({ list, onChange }: Props) {
  const { switchAccount } = useAccount();
  const isAnyAccount = list.length > 0;

  const handleAccountButtonClick = (account: InjectedAccountWithMeta) => {
    switchAccount(account);
    // TODO: 'account' to consts
    localStorage.setItem('account', account.address);
    onChange();
  };

  const getAccounts = () =>
    list.map((account) => (
      <li key={account.address}>
        <AccountButton
          address={account.address}
          name={account.meta.name}
          isActive={isLoggedIn(account)}
          onClick={() => handleAccountButtonClick(account)}
          block
        />
      </li>
    ));

  return isAnyAccount ? (
    <ul className={styles.list}>{getAccounts()}</ul>
  ) : (
    <p>
      No accounts found. Please open Polkadot extension, create a new account or import existing one and reload the
      page.
    </p>
  );
}
Example #2
Source File: accounts.ts    From gear-js with GNU General Public License v3.0 6 votes vote down vote up
function useLoggedInAccount() {
  const { api } = useApi();
  const { switchAccount } = useAccount();
  const accounts = useAccounts();

  useEffect(() => {
    const loggedInAccount = accounts?.find(isLoggedIn);
    if (loggedInAccount) switchAccount(loggedInAccount);
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [api, accounts]);
}
Example #3
Source File: useLoggedInAccount.tsx    From gear-js with GNU General Public License v3.0 6 votes vote down vote up
function useLoggedInAccount() {
  const { api } = useApi();
  const { switchAccount } = useAccount();
  const accounts = useAccounts();

  useEffect(() => {
    const loggedInAccount = accounts?.find(isLoggedIn);
    if (loggedInAccount) {
      switchAccount(loggedInAccount);
    }
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [api, accounts]);
}