Newer
Older
CrypticOreWallet / src / components / wallets / SyncWallets.tsx
@Drew Lemmy Drew Lemmy on 17 Feb 2021 681 bytes feat: show existing wallet categories
import { useState, useEffect } from "react";

import { useDispatch, useSelector, shallowEqual } from "react-redux";
import { RootState } from "../../store";

import { syncWallets } from "../../krist/wallets/Wallet";

/** Sync the wallets with the Krist node on startup. */
export function SyncWallets(): JSX.Element | null {
  const { wallets } = useSelector((s: RootState) => s.wallets, shallowEqual);
  const dispatch = useDispatch();

  const [synced, setSynced] = useState(false);

  useEffect(() => {
    if (synced) return;
    setSynced(true);

    // TODO: show errors to the user?
    syncWallets(dispatch, wallets).catch(console.error);
  }, [synced]);

  return null;
}