Newer
Older
CrypticOreWallet / src / krist / wallets / SyncWallets.tsx
@Drew Lemmy Drew Lemmy on 17 Feb 2021 663 bytes feat: wallet data syncing
import { useState, useEffect } from "react";

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

import { syncWallets } from "./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;
}