From 2f215f9c1fe4d901a69d7ec96dc64f2afeb539aa Mon Sep 17 00:00:00 2001 From: Turtuvshin Date: Tue, 20 Feb 2024 18:05:48 +0800 Subject: [PATCH] fixed store and photos screen crash --- src/features/Network/screens/StoreScreen.js | 2 +- src/features/Shared/StorePhotosScreen.js | 4 ++-- src/hooks/use-storefront.js | 14 +++++++++----- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/features/Network/screens/StoreScreen.js b/src/features/Network/screens/StoreScreen.js index 4d558f5..6481365 100644 --- a/src/features/Network/screens/StoreScreen.js +++ b/src/features/Network/screens/StoreScreen.js @@ -445,7 +445,7 @@ const StoreScreen = ({ navigation, route }) => { /> )} {isInfoWidgetEnabled && } - {isPhotosWidgetEnabled && store.getAttribute('media', []).length > 0 && ( + {isPhotosWidgetEnabled && store.getAttribute('media', [])?.length > 0 && ( { const isModalVisible = viewingPhoto !== null && viewingPhoto !== undefined; const medias = store.getAttribute('media', []); - const currentIndex = medias.indexOf(viewingPhoto); + const currentIndex = medias?.indexOf(viewingPhoto); return ( @@ -54,7 +54,7 @@ const StorePhotosScreen = ({ navigation, route }) => { - {medias.map((media, index) => ( + {medias?.map((media, index) => ( setViewingPhoto(media)} diff --git a/src/hooks/use-storefront.js b/src/hooks/use-storefront.js index 5e0a1d2..72f8378 100644 --- a/src/hooks/use-storefront.js +++ b/src/hooks/use-storefront.js @@ -1,15 +1,19 @@ import Storefront from '@fleetbase/storefront'; import config from 'config'; -import { get } from 'utils/Storage'; +const { STOREFRONT_KEY, FLEETBASE_HOST } = config; +let storefront, adapter; -let { STOREFRONT_KEY, FLEETBASE_HOST } = config; +try { + storefront = new Storefront('network_f7c72f15ff4be9fd3f6fa25ed30271af', { host: FLEETBASE_HOST }); + adapter = storefront.getAdapter(); +} catch (error) { + storefront = error; +} const useStorefront = () => { - const storefront = new Storefront(STOREFRONT_KEY || 'store_726cc5fe346591e99edfa2aed2102148', { host: 'https://460a-202-131-229-106.ngrok-free.app' }); - const adapter = storefront.getAdapter(); - return storefront; }; export default useStorefront; +export { adapter };