Skip to content

Commit

Permalink
prevent call methods being not initialized (#228)
Browse files Browse the repository at this point in the history
* prevent from calling methods before SDK initializing SDK

* improve error message

* isInitialized as a util function

* improvements

* remove direct functions export
  • Loading branch information
arekkubaczkowski authored Apr 4, 2022
1 parent c288e1a commit 8a21908
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 36 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -364,17 +364,13 @@ function App() {
Stripe Terminal SDK provides dedicated hook which exposes bunch of methods and props to be used within your App.
Additionally, you have access to the internal state of SDK that contains information about the current connection, discovered readers and loading state.

Alternatively, you can import all of the functions directly from the module but keep in mind that you will lose the access to SDK state.

```tsx
// Screen.ts

import { useStripeTerminal } from '@stripe/stripe-terminal-react-native';

// Alternatively you can import the methods directly.
import {
useStripeTerminal,
discoverReaders,
} from '@stripe/stripe-terminal-react-native';

export default function PaymentScreen() {
Expand Down
7 changes: 6 additions & 1 deletion example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,14 @@ export default function App() {
const { initialize: initStripe } = useStripeTerminal();

const handlePermissionsSuccess = useCallback(async () => {
const { error } = await initStripe();
const { error, reader } = await initStripe();
if (error) {
Alert.alert('StripeTerminal init failed', error.message);
} else if (reader) {
console.log(
'StripeTerminal has been initialized properly and connected to the reader',
reader
);
} else {
console.log('StripeTerminal has been initialized properly');
}
Expand Down
Loading

0 comments on commit 8a21908

Please sign in to comment.