Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memoize StripeTerminalProvider values #221

Merged
merged 7 commits into from
Mar 30, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"private": true,
"scripts": {
"android": "react-native run-android",
"android:all": "concurrently \"yarn start\" \"yarn start:server\" \"yarn ios\"",
"android:all": "concurrently \"yarn start\" \"yarn start:server\" \"yarn android\"",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops

"bootstrap": "cd .. && yarn bootstrap",
"build:server": "babel server --out-dir dist --extensions '.ts,.tsx' --ignore '**/__tests__/**' --source-maps --copy-files --delete-dir-on-start",
"ios": "react-native run-ios",
Expand Down
25 changes: 12 additions & 13 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,17 @@ export default function App() {
const { initialize: initStripe } = useStripeTerminal();

useEffect(() => {
const handlePermissionsSuccess = async () => {
const { error } = await initStripe({
logLevel: 'verbose',
});
if (error) {
Alert.alert('StripeTerminal init failed', error.message);
} else {
console.log('StripeTerminal has been initialized properly');
}
};

async function handlePermissions() {
try {
const granted = await PermissionsAndroid.request(
Expand Down Expand Up @@ -157,26 +168,14 @@ export default function App() {
} else {
handlePermissionsSuccess();
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
}, [initStripe]);

const handlePermissionsError = () => {
console.error(
'Location and BT services are required in order to connect to a reader.'
);
};

const handlePermissionsSuccess = async () => {
const { error } = await initStripe({
logLevel: 'verbose',
});
if (error) {
Alert.alert('StripeTerminal init failed', error.message);
} else {
console.log('StripeTerminal has been initialized properly');
}
};

const hasGrantedPermission = (status: string) => {
return status === PermissionsAndroid.RESULTS.GRANTED;
};
Expand Down
4 changes: 2 additions & 2 deletions example/src/screens/LocationListScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ export default function LocationListScreen() {

useEffect(() => {
async function init() {
console.log('getting locations');
const { locations } = await getLocations({ limit: 20 });
if (locations) {
setList(locations);
}
}
init();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
}, [getLocations]);

const renderItem = (item: Location) => (
<ListItem
Expand Down