Compare commits

...
Author SHA1 Message Date
Ajay Sivan 9ebb28ceaf fix: User can sync with expired QR code 2023-08-31 10:03:50 +05:30
6 changed files with 71 additions and 79 deletions
+8 -3
View File
@@ -12,7 +12,8 @@
[quo2.foundations.colors :as colors]
[status-im2.contexts.profile.login.events :as profile.login]
[utils.transforms :as transforms]
[status-im2.contexts.communities.discover.events]))
[status-im2.contexts.communities.discover.events]
[utils.i18n :as i18n]))
(rf/defn summary
[{:keys [db] :as cofx} peers-summary]
@@ -52,7 +53,8 @@
(and (some? account) (some? password)))
multiaccount-data (when received-account?
(merge account {:password password}))
navigate-to-syncing-devices? (and (or connection-success? error-on-pairing?) receiver?)
navigate-to-syncing-devices? (and (and connection-success? (not error-on-pairing?))
receiver?)
user-in-syncing-devices-screen? (or (= (:view-id db) :syncing-progress)
(= (:view-id db) :syncing-progress-intro))
user-in-sign-in-intro-screen? (= (:view-id db) :sign-in-intro)]
@@ -84,7 +86,10 @@
{:dispatch [:toasts/upsert
{:icon :i/alert
:icon-color colors/danger-50
:text error}]}))))
:text (condp = type
constants/local-pairing-event-connection-error
(i18n/label :t/error-this-sync-qr-code-has-expired)
error)}]}))))
(rf/defn process
{:events [:signals/signal-received]}
+3
View File
@@ -271,6 +271,9 @@
An example of a connection string is -> cs2:5vd6J6:Jfc:27xMmHKEYwzRGXcvTtuiLZFfXscMx4Mz8d9wEHUxDj4p7:EG7Z13QScfWBJNJ5cprszzDQ5fBVsYMirXo8MaQFJvpF:3 "
"cs")
(def ^:const local-pairing-timeout 120000)
(def ^:const local-pairing-timeout-warning 60000)
(def ^:const local-pairing-role-sender "sender")
(def ^:const local-pairing-role-receiver "receiver")
+1 -1
View File
@@ -88,7 +88,7 @@
:keystorePath ""
:password sha3-pwd
:deviceType utils.platform/os}
:serverConfig {:timeout 0}}))]
:serverConfig {:timeout constants/local-pairing-timeout}}))]
(native-module/get-connection-string-for-bootstrapping-another-device
config-map
#(show-sheet %)))
@@ -227,49 +227,48 @@
[:f> f-bottom-view insets translate-y])
(defn- check-qr-code-and-navigate
[{:keys [event on-success-scan on-failed-scan]}]
[{:keys [event]}]
(let [connection-string (string/trim (oops/oget event "nativeEvent.codeStringValue"))
valid-connection-string? (sync-utils/valid-connection-string? connection-string)]
;; debounce-and-dispatch used because the QR code scanner performs callbacks too fast
(if valid-connection-string?
(do
(on-success-scan)
(debounce/debounce-and-dispatch
[:syncing/input-connection-string-for-bootstrapping connection-string]
300))
(do
(on-failed-scan)
(debounce/debounce-and-dispatch
[:toasts/upsert
{:icon :i/info
:icon-color colors/danger-50
:theme :dark
:text (i18n/label :t/error-this-is-not-a-sync-qr-code)}]
300)))))
(debounce/debounce-and-dispatch
(if valid-connection-string?
[:syncing/input-connection-string-for-bootstrapping connection-string]
[:toasts/upsert
{:icon :i/info
:icon-color colors/danger-50
:theme :dark
:text (i18n/label :t/error-this-is-not-a-sync-qr-code)}])
300)))
(defn- render-camera
[{:keys [torch-mode qr-view-finder scan-code? set-qr-code-succeeded set-rescan-timeout]}]
[:<>
[rn/view {:style style/camera-container}
[camera-kit/camera
{:style style/camera-style
:camera-type camera-kit/camera-type-back
:zoom-mode :off
:torch-mode torch-mode
:scan-barcode true
:on-read-code #(when scan-code?
(check-qr-code-and-navigate {:event %
:on-success-scan set-qr-code-succeeded
:on-failed-scan set-rescan-timeout}))}]]
[hole-view/hole-view
{:style style/hole
:holes [(assoc qr-view-finder :borderRadius 16)]}
[blur/view
{:style style/absolute-fill
:blur-amount 10
:blur-type :transparent
:overlay-color colors/neutral-80-opa-80
:background-color colors/neutral-80-opa-80}]]])
[]
(let [scan-code? (reagent/atom true)
set-rescan-timeout (fn []
(reset! scan-code? false)
(js/setTimeout #(reset! scan-code? true) 3000))]
(fn [{:keys [torch-mode qr-view-finder]}]
[:<>
[rn/view {:style style/camera-container}
[camera-kit/camera
{:style style/camera-style
:camera-type camera-kit/camera-type-back
:zoom-mode :off
:torch-mode torch-mode
:scan-barcode @scan-code?
:scan-throttle-delay 3000
:on-read-code (fn [event]
(set-rescan-timeout)
(check-qr-code-and-navigate {:event event}))}]]
[hole-view/hole-view
{:style style/hole
:holes [(assoc qr-view-finder :borderRadius 16)]}
[blur/view
{:style style/absolute-fill
:blur-amount 10
:blur-type :transparent
:overlay-color colors/neutral-80-opa-80
:background-color colors/neutral-80-opa-80}]]])))
(defn- reset-animations-and-navigate-fn
[{:keys [render-camera? show-camera?] :as params}]
@@ -289,17 +288,12 @@
(defn f-view
[_]
(let [insets (safe-area/get-insets)
active-tab (reagent/atom 1)
qr-view-finder (reagent/atom {})
render-camera? (reagent/atom false)
torch? (reagent/atom false)
scan-code? (reagent/atom true)
set-rescan-timeout (fn []
(reset! scan-code? false)
(js/setTimeout #(reset! scan-code? true) 3000))]
(fn [{:keys [title show-bottom-view? background animated? qr-code-succeed?
set-qr-code-succeeded]}]
(let [insets (safe-area/get-insets)
active-tab (reagent/atom 1)
qr-view-finder (reagent/atom {})
render-camera? (reagent/atom false)
torch? (reagent/atom false)]
(fn [{:keys [title show-bottom-view? background animated?]}]
(let [torch-mode (if @torch? :on :off)
flashlight-icon (if @torch? :i/flashlight-on :i/flashlight-off)
scan-qr-code-tab? (= @active-tab 1)
@@ -308,8 +302,7 @@
@preflight-check-passed?
(boolean (not-empty @qr-view-finder)))
camera-ready-to-scan? (and (or (not animated?) @render-camera?)
show-camera?
(not qr-code-succeed?))
show-camera?)
title-opacity (reanimated/use-shared-value (if animated? 0 1))
subtitle-opacity (reanimated/use-shared-value (if animated? 0 1))
content-opacity (reanimated/use-shared-value (if animated? 0 1))
@@ -347,11 +340,8 @@
background
(when camera-ready-to-scan?
[render-camera
{:torch-mode torch-mode
:qr-view-finder @qr-view-finder
:scan-code? @scan-code?
:set-qr-code-succeeded set-qr-code-succeeded
:set-rescan-timeout set-rescan-timeout}])
{:torch-mode torch-mode
:qr-view-finder @qr-view-finder}])
[rn/view {:style (style/root-container (:top insets))}
[:f> header
{:active-tab active-tab
@@ -390,13 +380,8 @@
(defn view
[{:keys [screen-name] :as _props}]
(let [qr-code-succeed? (reagent/atom false)]
(navigation.util/create-class-and-bind
screen-name
{:component-did-appear (fn set-qr-code-failed [_this]
(reset! qr-code-succeed? false))}
(fn [props]
(let [new-pops (assoc props
:qr-code-succeed? @qr-code-succeed?
:set-qr-code-succeeded #(reset! qr-code-succeed? true))]
[:f> f-view new-pops])))))
(navigation.util/create-class-and-bind
screen-name
{}
(fn [props]
[:f> f-view props])))
@@ -12,10 +12,8 @@
[status-im2.contexts.syncing.utils :as sync-utils]
[utils.datetime :as datetime]
[utils.i18n :as i18n]
[utils.re-frame :as rf]))
(def code-valid-for-ms 120000)
(def one-min-ms 60000)
[utils.re-frame :as rf]
[status-im2.constants :as constants]))
(defn f-use-interval
[clock cleanup-clock delay]
@@ -25,7 +23,7 @@
(defn view
[]
(let [profile-color (rf/sub [:profile/customization-color])
valid-for-ms (reagent/atom code-valid-for-ms)
valid-for-ms (reagent/atom constants/local-pairing-timeout)
code (reagent/atom nil)
delay (reagent/atom nil)
timestamp (reagent/atom nil)
@@ -35,11 +33,11 @@
(reset! delay 1000)
(reset! code connection-string)))
clock (fn []
(if (pos? (- code-valid-for-ms
(if (pos? (- constants/local-pairing-timeout
(- (* 1000 (js/Math.ceil (/ (datetime/timestamp) 1000)))
@timestamp)))
(swap! valid-for-ms (fn [_]
(- code-valid-for-ms
(- constants/local-pairing-timeout
(- (* 1000
(js/Math.ceil (/ (datetime/timestamp) 1000)))
@timestamp))))
@@ -47,7 +45,7 @@
cleanup-clock (fn []
(reset! code nil)
(reset! timestamp nil)
(reset! valid-for-ms code-valid-for-ms))]
(reset! valid-for-ms constants/local-pairing-timeout))]
(fn []
[rn/view {:style style/container-main}
@@ -102,7 +100,7 @@
(i18n/label :t/sync-code)]
[quo/text
{:size :paragraph-2
:style {:color (if (< @valid-for-ms one-min-ms)
:style {:color (if (< @valid-for-ms constants/local-pairing-timeout-warning)
colors/danger-60
colors/white-opa-40)}}
(i18n/label :t/valid-for-time {:valid-for (datetime/ms-to-duration @valid-for-ms)})]]
+1
View File
@@ -2121,6 +2121,7 @@
"i-dont-have-status-on-another-device": "I dont have Status on another device",
"ensure-qr-code-is-in-focus-to-scan": "Ensure that the QR code is in focus to scan",
"error-this-is-not-a-sync-qr-code": "Oops! This is not a sync QR code",
"error-this-sync-qr-code-has-expired": "Oops! This sync QR code has expired",
"error-syncing-connection-failed": "Oops! Connection failed. Try again",
"camera-permission-denied": "Permission denied",
"enable-biometrics": "Enable biometrics",