#yoyosaur_error

1 messages ยท Page 1 of 1 (latest)

slow crescentBOT
#

๐Ÿ‘‹ Welcome to your new thread!

โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

๐Ÿ”— This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1384958805913112609

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

deep moth
#

Adding some context like I said:
First file is my Root.

/**
 * The root component is where we handle our providers.
 * Providers are used to manage state in an isolated way, and is a standard react-native pattern.
 */
export default function Root() {
  const fetchTokenProvider: () => Promise<string> = async () => {
    try {
      const response = await fetch('myUrlToGetToken');
      const {data} = await response.json();
      const {secret} = data;
      return secret;
    } catch (e) {
      console.log("error", e);
    }
  };

  useEffect(() => {
    init();
  }, []);

  return (
    <StripeTerminalProvider logLevel="verbose" tokenProvider={fetchTokenProvider}>
      <AuthProvider />
      <StripeProvider />
      <App />
    </StripeTerminalProvider>
  );
}
#

The StripeProvider is then simple as well

import {useEffect} from "react";
import {useStripeTerminal} from "@stripe/stripe-terminal-react-native";
import {useStripe} from "../store/stripe";

export default function StripeProvider() {
  const {initialize, getConnectedReader, discoverReaders} = useStripeTerminal({
    onUpdateDiscoveredReaders: (readers) => {
      if (readers.length > 0) {
        const currentReader = readers[0];
        useStripe.getState().setReaderInfo({
          name: currentReader.label ?? currentReader.id,
          serialNumber: currentReader.serialNumber,
          stripeTerminalId: currentReader.id,
        });
      }
    },
  });

  useEffect(() => {
    const initStripe = async () => {
      try {
        await initialize();
        const {error} = await discoverReaders({
          discoveryMethod: "handoff",
        });
        if (error) {
          console.error("Error discovering readers:", error);
        }
      } catch (error) {
        console.error("Error initializing Stripe:", error);
      }
    };

    initStripe();
  }, [initialize, discoverReaders]);

  return null;
} 
#

What's interesting is, eventually, it finds them in the onUpdateDiscoveredReaders. But, I always get the
ERROR First initialize the Stripe Terminal SDK before performing any action
Every time.

#

Let me know what further context, if any, is needed!

last charm
#

Looking into this!

deep moth
#

Thanks mossy! Anything I can provide is fine.

I should note, the behavior works, I eventually get the CardReader information.

slow fossil
#

๐Ÿ‘‹

#

Stepping in

#

What happens if you just call initialize first with a separate useStripeTerminal() instance.

#

Like just do:

 const { initialize } = useStripeTerminal();
#

Then after that:

const { discoverReaders, discoveredReaders } =
    useStripeTerminal({
      onUpdateDiscoveredReaders: (readers) => {
...
slow crescentBOT
deep moth
#

That still produces the error of:
ERROR First initialize the Stripe Terminal SDK before performing any action
ERROR Error initializing Stripe: [Error: First initialize the Stripe Terminal SDK before performing any action]

export default function StripeProvider() {
  const {setReaderInfo} = useStripe();
  const {setIsLoadingStripe} = useAppState();
  const {initialize} = useStripeTerminal();
  const {discoverReaders} = useStripeTerminal({
    onUpdateDiscoveredReaders: (readers) => {
      if (readers.length > 0) {
        const currentReader = readers[0];
        setReaderInfo({
          name: currentReader.label ?? currentReader.id,
          serialNumber: currentReader.serialNumber,
          stripeTerminalId: currentReader.id,
        });
        setIsLoadingStripe(false);
      }
    },
  });

  useEffect(() => {
    const initStripe = async () => {
      try {
        await initialize();
        const {error} = await discoverReaders({
          discoveryMethod: "handoff",
        });
        if (error) {
          console.error("Error discovering readers:", error);
        }
      } catch (error) {
        console.error("Error initializing Stripe:", error);
      }
    };

    initStripe();
  }, [initialize, discoverReaders]);

  return null;
} 

I saw this error log, might just be something weird with a state setting inside the terminal code?
https://github.com/stripe/stripe-terminal-react-native/issues/659#issuecomment-2764579895

Could just be a weird bug logging an erorr, but not actually causing issues?

GitHub

In my Root(index.js) I initialized and API call for token and in App.js useEffect call the const { initialize } = useStripeTerminal() as per the documentation but still I get ERROR First initia...

#

I'm just OCD and hate seeing the ERROR log ๐Ÿ˜ฆ

slow fossil
#

Ah good find

deep moth
#

If this is just a non-issue I'm fine with that and will just wait for the stripe RN update that fixes this nit

slow fossil
#

Yeah I mean if you are just seeing this error but still seeing the connection be successful and able to discover readers then it does seem like overall a no-op

#

I think flagging in that Github issue with your code would be great and I'll also flag internally.

deep moth
#

Alright cool

slow fossil
#

Unless you are seeing any sort of connection/discovery issue then I do think this is just an no-impact error.

deep moth
#

No, I am not, was just worried something sinister was lurking beneath

slow fossil
#

Yeah I'm not aware of anything