From c52d081e1ff7b2f0bf1c66d8b015c43051e4742c Mon Sep 17 00:00:00 2001 From: Gustavo Emanuel Farias Rosa Date: Mon, 20 Jun 2022 08:40:15 -0300 Subject: [PATCH] resolving promise reject when async storage is null (#45) Co-authored-by: Gustavo Emanuel Farias Rosa --- react-native/app/routes/component.tsx | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/react-native/app/routes/component.tsx b/react-native/app/routes/component.tsx index 965bcb5..5109e9e 100644 --- a/react-native/app/routes/component.tsx +++ b/react-native/app/routes/component.tsx @@ -51,8 +51,22 @@ const DeepLink = ()=>{ } async function checkIfHaveTemporaryPortal(){ - const portalsFromStorage = await AsyncStorage.getItem('portal') - const portalsParsed = JSON.parse(portalsFromStorage) + let portalsParsed: IPortal[]|null = null; + try { + let items = await AsyncStorage.getAllKeys(); + if (items.includes('portal')) { + const portalsFromStorage = await AsyncStorage.getItem('portal') + portalsParsed = portalsFromStorage ? JSON.parse(portalsFromStorage) : null + } else { + console.log('Error: Dont Have Portals Storage'); + } + } catch (e) { + console.log('error', e); + } + + if(!portalsParsed){ + return + } const portalsWithoutTemporary = portalsParsed.filter((portal: IPortal)=>{ if(portal.temporary == true) return false if(portal.name == NAME_PORTALS_DEEP_LINK) return false