From f695dbf1156222e1921476fbfe2c35b853dd18c9 Mon Sep 17 00:00:00 2001 From: Mohsen Date: Mon, 4 Dec 2023 17:48:45 +0300 Subject: [PATCH] [#17909] fix: unhandled error when app launched in offline mode (#17973) --- .../ethereum/StatusOkHttpClientFactory.java | 40 ++++++++++++++----- src/status_im2/contexts/profile/events.cljs | 4 +- src/status_im2/contexts/profile/rpc.cljs | 12 +++--- 3 files changed, 38 insertions(+), 18 deletions(-) diff --git a/android/app/src/main/java/im/status/ethereum/StatusOkHttpClientFactory.java b/android/app/src/main/java/im/status/ethereum/StatusOkHttpClientFactory.java index 31efae585f..9db192e7e4 100644 --- a/android/app/src/main/java/im/status/ethereum/StatusOkHttpClientFactory.java +++ b/android/app/src/main/java/im/status/ethereum/StatusOkHttpClientFactory.java @@ -27,18 +27,23 @@ class StatusOkHttpClientFactory implements OkHttpClientFactory { X509Certificate cert = null; HandshakeCertificates clientCertificates; String certPem = ""; + // Get TLS PEM certificate from status-go + try { + // induce half second sleep because sometimes a cert is not immediately available + // TODO : remove sleep if App no longer crashes on Android 10 devices with + // java.lang.RuntimeException: Could not invoke WebSocketModule.connect + Thread.sleep(500); + certPem = getCertificatePem(); + } catch(Exception e) { + Log.e(TAG, "Could not getImageTLSCert",e); + } - // Get TLS PEM certificate from status-go - try { - // induce half second sleep because sometimes a cert is not immediately available - // TODO : remove sleep if App no longer crashes on Android 10 devices with - // java.lang.RuntimeException: Could not invoke WebSocketModule.connect - Thread.sleep(500); - certPem = StatusPackage.getImageTLSCert(); - } catch(Exception e) { - Log.e(TAG, "Could not getImageTLSCert",e); - } - // Convert PEM certificate string to X509Certificate object + if (certPem.isEmpty()) { + Log.e(TAG, "Certificate is empty, cannot create OkHttpClient without a valid certificate"); + return null; + } + + // Convert PEM certificate string to X509Certificate object try { // induce half second sleep because sometimes a cert is not immediately available // TODO : remove sleep if App no longer crashes on Android 10 devices @@ -74,4 +79,17 @@ class StatusOkHttpClientFactory implements OkHttpClientFactory { return null; } } + private String getCertificatePem() { + try { + String certPem = StatusPackage.getImageTLSCert(); + if (certPem == null || certPem.trim().isEmpty()) { + Log.e(TAG, "Certificate PEM string is null or empty"); + return ""; + } + return certPem; + } catch (Exception e) { + Log.e(TAG, "Could not getImageTLSCert", e); + return ""; + } + } } diff --git a/src/status_im2/contexts/profile/events.cljs b/src/status_im2/contexts/profile/events.cljs index 2490fd0404..d359f21bf0 100644 --- a/src/status_im2/contexts/profile/events.cljs +++ b/src/status_im2/contexts/profile/events.cljs @@ -43,10 +43,10 @@ {:keys [key-uid]} (first (sort-by :timestamp > (vals profiles)))] (rf/merge cofx (navigation/init-root :profiles) - (init-profiles-overview profiles key-uid) + (when key-uid (init-profiles-overview profiles key-uid)) ;;we check if biometric is available, and try to login with it, ;;if succeed "node.login" signal will be triggered - (profile.login/login-with-biometric-if-available key-uid))) + (when key-uid (profile.login/login-with-biometric-if-available key-uid)))) (navigation/init-root cofx :intro))) (rf/defn update-setting-from-backup diff --git a/src/status_im2/contexts/profile/rpc.cljs b/src/status_im2/contexts/profile/rpc.cljs index a7c6a6d6b9..528c65b800 100644 --- a/src/status_im2/contexts/profile/rpc.cljs +++ b/src/status_im2/contexts/profile/rpc.cljs @@ -5,8 +5,10 @@ (defn rpc->profiles-overview [{:keys [customizationColor keycard-pairing] :as profile}] - (-> profile - (dissoc :customizationColor) - (assoc :customization-color (keyword customizationColor)) - (assoc :ens-name? (utils.ens/is-valid-eth-name? (:name profile))) - (assoc :keycard-pairing (when-not (string/blank? keycard-pairing) keycard-pairing)))) + (if (map? profile) + (-> profile + (dissoc :customizationColor) + (assoc :customization-color (keyword customizationColor)) + (assoc :ens-name? (utils.ens/is-valid-eth-name? (:name profile))) + (assoc :keycard-pairing (when-not (string/blank? keycard-pairing) keycard-pairing))) + profile))