From 52e6429127d8876974b6573b1fc505df48008e23 Mon Sep 17 00:00:00 2001 From: noumantahir <nouman.hawkdev@gmail.com> Date: Sun, 15 May 2022 13:52:22 +0500 Subject: [PATCH] wrapped optional login items in try catch --- src/providers/hive/auth.js | 24 ++++++++++++------- .../container/applicationContainer.js | 24 +++++++++++++------ .../pinCode/container/pinCodeContainer.js | 13 +++++++--- 3 files changed, 43 insertions(+), 18 deletions(-) diff --git a/src/providers/hive/auth.js b/src/providers/hive/auth.js index f8c4b67af..e78b3cd20 100644 --- a/src/providers/hive/auth.js +++ b/src/providers/hive/auth.js @@ -68,10 +68,14 @@ export const login = async (username, password, isPinCodeOpen) => { const code = await makeHsCode(account.name, signerPrivateKey); const scTokens = await getSCAccessToken(code); - const accessToken = scTokens?.access_token; - account.unread_activity_count = await getUnreadNotificationCount(accessToken); - account.pointsSummary = await getPointsSummary(account.username); - account.mutes = await getMutes(account.username); + try { + const accessToken = scTokens?.access_token; + account.unread_activity_count = await getUnreadNotificationCount(accessToken); + account.pointsSummary = await getPointsSummary(account.username); + account.mutes = await getMutes(account.username); + } catch (err) { + console.warn('Optional user data fetch failed, account can still function without them', err); + } let jsonMetadata; try { @@ -134,10 +138,14 @@ export const loginWithSC2 = async (code, isPinCodeOpen) => { let avatar = ''; return new Promise(async (resolve, reject) => { - const accessToken = scTokens ? scTokens.access_token : ''; - account.unread_activity_count = await getUnreadNotificationCount(accessToken); - account.pointsSummary = await getPointsSummary(account.username); - account.mutes = await getMutes(account.username); + try { + const accessToken = scTokens ? scTokens.access_token : ''; + account.unread_activity_count = await getUnreadNotificationCount(accessToken); + account.pointsSummary = await getPointsSummary(account.username); + account.mutes = await getMutes(account.username); + } catch (err) { + console.warn('Optional user data fetch failed, account can still function without them', err); + } let jsonMetadata; try { diff --git a/src/screens/application/container/applicationContainer.js b/src/screens/application/container/applicationContainer.js index 566c44507..6b0f376e2 100644 --- a/src/screens/application/container/applicationContainer.js +++ b/src/screens/application/container/applicationContainer.js @@ -775,9 +775,16 @@ class ApplicationContainer extends Component { accountData = await this._refreshAccessToken(accountData); } - accountData.unread_activity_count = await getUnreadNotificationCount(); - accountData.mutes = await getMutes(realmObject.username); - accountData.pointsSummary = await getPointsSummary(realmObject.username); + try { + accountData.unread_activity_count = await getUnreadNotificationCount(); + accountData.mutes = await getMutes(realmObject.username); + accountData.pointsSummary = await getPointsSummary(realmObject.username); + } catch (err) { + console.warn( + 'Optional user data fetch failed, account can still function without them', + err, + ); + } dispatch(updateCurrentAccount(accountData)); dispatch(fetchSubscribedCommunities(realmObject.username)); this._connectNotificationServer(accountData.name); @@ -956,10 +963,13 @@ class ApplicationContainer extends Component { //update refresh token _currentAccount = await this._refreshAccessToken(_currentAccount); - //TODO decrypt access token here; - _currentAccount.unread_activity_count = await getUnreadNotificationCount(); - _currentAccount.pointsSummary = await getPointsSummary(_currentAccount.username); - _currentAccount.mutes = await getMutes(_currentAccount.username); + try { + _currentAccount.unread_activity_count = await getUnreadNotificationCount(); + _currentAccount.pointsSummary = await getPointsSummary(_currentAccount.username); + _currentAccount.mutes = await getMutes(_currentAccount.username); + } catch (err) { + console.warn('Optional user data fetch failed, account can still function without them', err); + } dispatch(updateCurrentAccount(_currentAccount)); dispatch(fetchSubscribedCommunities(_currentAccount.username)); diff --git a/src/screens/pinCode/container/pinCodeContainer.js b/src/screens/pinCode/container/pinCodeContainer.js index 2e19226ec..794493694 100644 --- a/src/screens/pinCode/container/pinCodeContainer.js +++ b/src/screens/pinCode/container/pinCodeContainer.js @@ -319,9 +319,16 @@ class PinCodeContainer extends Component { } //get unread notifications - _currentAccount.unread_activity_count = await getUnreadNotificationCount(); - _currentAccount.pointsSummary = await getPointsSummary(_currentAccount.username); - _currentAccount.mutes = await getMutes(_currentAccount.username); + try { + _currentAccount.unread_activity_count = await getUnreadNotificationCount(); + _currentAccount.pointsSummary = await getPointsSummary(_currentAccount.username); + _currentAccount.mutes = await getMutes(_currentAccount.username); + } catch (err) { + console.warn( + 'Optional user data fetch failed, account can still function without them', + err, + ); + } dispatch(updateCurrentAccount({ ..._currentAccount })); dispatch(fetchSubscribedCommunities(_currentAccount.username));