-
Notifications
You must be signed in to change notification settings - Fork 987
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change password inside new settings (#19474)
* feat: added change-password screen Signed-off-by: Lungu Cristian <[email protected]> * fix: pw verification error not shown Signed-off-by: Lungu Cristian <[email protected]> * feat: added changing password with confirmation and loading Signed-off-by: Lungu Cristian <[email protected]> * fix: adjusted flow Signed-off-by: Lungu Cristian <[email protected]> * fix: added minimum waiting time when loading Signed-off-by: Lungu Cristian <[email protected]> * ref: moved events to change-password Signed-off-by: Lungu Cristian <[email protected]> * fix: added styles where missing Signed-off-by: Lungu Cristian <[email protected]> * ref: moved header out Signed-off-by: Lungu Cristian <[email protected]> * ref: moved forms into separate namespaces Signed-off-by: Lungu Cristian <[email protected]> * fix: linter promesa alias issue Signed-off-by: Lungu Cristian <[email protected]> * feat: added password-tips quo-component Signed-off-by: Lungu Cristian <[email protected]> * fix: validation message Signed-off-by: Lungu Cristian <[email protected]> * fix: removed bottom-sheet event Signed-off-by: Lungu Cristian <[email protected]> * removed temp file Signed-off-by: Lungu Cristian <[email protected]> * fix: addressed review comments Signed-off-by: Lungu Cristian <[email protected]> * fix: addressed @seanstrom's review comments Signed-off-by: Lungu Cristian <[email protected]> * fix: address @ilmotta's review comments Signed-off-by: Lungu Cristian <[email protected]> * fix: addressed @vkjr's review comments Signed-off-by: Lungu Cristian <[email protected]> * fix: buttom button alignment with keyboard Signed-off-by: Lungu Cristian <[email protected]> * fix: addressed review comments Signed-off-by: Lungu Cristian <[email protected]> * fix: keyboard behavior Signed-off-by: Lungu Cristian <[email protected]> * fix: navigation to loader Signed-off-by: Lungu Cristian <[email protected]> * fix: use-theme usage * fix: button alignment due to alert banner --------- Signed-off-by: Lungu Cristian <[email protected]>
- Loading branch information
Showing
26 changed files
with
673 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
(ns native-module.utils | ||
(:require | ||
[clojure.string :as string] | ||
[promesa.core :as promesa] | ||
[utils.transforms :as types])) | ||
|
||
(defn- promisify-callback | ||
[res rej] | ||
(fn [result] | ||
(let [native-error (let [{:keys [error]} (types/json->clj result)] | ||
(when-not (string/blank? error) | ||
error))] | ||
(if native-error | ||
(rej (ex-info "Native module call error" {:error native-error})) | ||
(res result))))) | ||
|
||
(defn promisify-native-module-call | ||
[f & args] | ||
(promesa/create | ||
(fn [res rej] | ||
(->> [(promisify-callback res rej)] | ||
(concat args) | ||
(apply f))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
(ns quo.components.password.password-tips.style) | ||
|
||
(def password-tips | ||
{:flex-direction :row | ||
:margin-horizontal 20 | ||
:justify-content :space-between}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
(ns quo.components.password.password-tips.view | ||
(:require [quo.components.password.password-tips.style :as style] | ||
[quo.components.password.tips.view :as tips] | ||
[react-native.core :as rn] | ||
[schema.core :as schema] | ||
[utils.i18n :as i18n])) | ||
|
||
(def ?schema | ||
[:=> | ||
[:cat | ||
[:map {:closed true} | ||
[:lower-case? :boolean] | ||
[:upper-case? :boolean] | ||
[:numbers? :boolean] | ||
[:symbols? :boolean]] | ||
[:any]]]) | ||
|
||
(defn- view-internal | ||
[{:keys [lower-case? upper-case? numbers? symbols?]}] | ||
[rn/view {:style style/password-tips} | ||
[tips/view {:completed? lower-case?} | ||
(i18n/label :t/password-creation-tips-1)] | ||
[tips/view {:completed? upper-case?} | ||
(i18n/label :t/password-creation-tips-2)] | ||
[tips/view {:completed? numbers?} | ||
(i18n/label :t/password-creation-tips-3)] | ||
[tips/view {:completed? symbols?} | ||
(i18n/label :t/password-creation-tips-4)]]) | ||
|
||
(def view (schema/instrument #'view-internal ?schema)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/status_im/contexts/preview/quo/password/password_tips.cljs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
(ns status-im.contexts.preview.quo.password.password-tips | ||
(:require | ||
[quo.core :as quo] | ||
[quo.foundations.colors :as colors] | ||
[reagent.core :as reagent] | ||
[status-im.constants :as constant] | ||
[status-im.contexts.preview.quo.preview :as preview])) | ||
|
||
(def init-state | ||
(reduce (fn [acc tip] (assoc acc tip false)) {} constant/password-tips)) | ||
|
||
(defn- make-tip-descriptor | ||
[tip] | ||
{:key tip | ||
:type :boolean}) | ||
|
||
(def descriptor | ||
(map make-tip-descriptor constant/password-tips)) | ||
|
||
(defn view | ||
[] | ||
(let [state (reagent/atom init-state)] | ||
(fn [] | ||
[preview/preview-container | ||
{:state state | ||
:descriptor descriptor | ||
:component-container-style {:padding 20 | ||
:background-color colors/neutral-95}} | ||
[quo/password-tips @state]]))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/status_im/contexts/profile/settings/screens/password/change_password/effects.cljs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
(ns status-im.contexts.profile.settings.screens.password.change-password.effects | ||
(:require [native-module.core :as native-module] | ||
[promesa.core :as promesa] | ||
[status-im.common.keychain.events :as keychain] | ||
[utils.re-frame :as rf] | ||
[utils.security.core :as security])) | ||
|
||
(rf/reg-fx :effects.change-password/change-password | ||
(fn [{:keys [key-uid old-password new-password on-success on-fail]}] | ||
(let [hash-masked-password (fn [password] | ||
(-> password security/hash-masked-password security/safe-unmask-data)) | ||
old-password-hashed (hash-masked-password old-password) | ||
new-password-hashed (hash-masked-password new-password)] | ||
(-> (native-module/reset-password key-uid old-password-hashed new-password-hashed) | ||
(promesa/then #(keychain/save-user-password! key-uid new-password-hashed)) | ||
(promesa/then on-success) | ||
(promesa/catch on-fail))))) |
68 changes: 68 additions & 0 deletions
68
src/status_im/contexts/profile/settings/screens/password/change_password/events.cljs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
(ns status-im.contexts.profile.settings.screens.password.change-password.events | ||
(:require [status-im.contexts.profile.settings.screens.password.change-password.effects] | ||
[taoensso.timbre :as log] | ||
[utils.re-frame :as rf] | ||
[utils.security.core :as security])) | ||
|
||
(rf/reg-event-fx :change-password/verify-old-password | ||
(fn [_ [entered-password]] | ||
(let [hashed-password (-> entered-password | ||
security/hash-masked-password | ||
security/safe-unmask-data)] | ||
{:json-rpc/call [{:method "accounts_verifyPassword" | ||
:params [hashed-password] | ||
:on-success (fn [valid?] | ||
(rf/dispatch [:change-password/password-verify-success valid? | ||
entered-password])) | ||
:on-error (fn [error] | ||
(log/error "accounts_verifyPassword error" | ||
{:error error | ||
:event :password-settings/change-password}))}]}))) | ||
(rf/reg-event-fx :change-password/password-verify-success | ||
(fn [{:keys [db]} [valid? old-password]] | ||
{:db (if valid? | ||
(-> db | ||
(assoc-in [:settings/change-password :old-password] old-password) | ||
(assoc-in [:settings/change-password :current-step] :new-password)) | ||
(assoc-in db [:settings/change-password :verify-error] true))})) | ||
|
||
(rf/reg-event-fx :change-password/reset-error | ||
(fn [{:keys [db]}] | ||
{:db (assoc-in db [:settings/change-password :verify-error] false)})) | ||
|
||
(rf/reg-event-fx :change-password/reset | ||
(fn [{:keys [db]}] | ||
{:db (assoc db :settings/change-password {})})) | ||
|
||
(rf/reg-event-fx :change-password/confirm-new-password | ||
(fn [{:keys [db]} [new-password]] | ||
{:db (assoc-in db [:settings/change-password :new-password] new-password) | ||
:fx [[:dispatch [:change-password/submit]]]})) | ||
|
||
(rf/reg-event-fx :change-password/submit | ||
(fn [{:keys [db]}] | ||
(let [key-uid (get-in db [:profile/profile :key-uid]) | ||
{:keys [new-password old-password]} (get db :settings/change-password)] | ||
{:db (assoc-in db [:settings/change-password :loading?] true) | ||
:fx [[:dispatch [:dismiss-keyboard]] | ||
[:dispatch [:open-modal :screen/change-password-loading]] | ||
[:effects.change-password/change-password | ||
{:key-uid key-uid | ||
:old-password old-password | ||
:new-password new-password | ||
:on-success (fn [] | ||
(rf/dispatch [:change-password/submit-success])) | ||
:on-fail (fn [error] | ||
(rf/dispatch [:change-password/submit-fail error]))}]]}))) | ||
|
||
(rf/reg-event-fx :change-password/submit-fail | ||
(fn [_ [error]] | ||
(log/error "failed to change the password" | ||
{:error error | ||
:event :change-password/submit}) | ||
{:fx [[:dispatch [:change-password/reset]] | ||
[:dispatch [:navigate-back]]]})) | ||
|
||
(rf/reg-event-fx :change-password/submit-success | ||
(fn [{:keys [db]}] | ||
{:db (assoc-in db [:settings/change-password :loading?] false)})) |
19 changes: 19 additions & 0 deletions
19
src/status_im/contexts/profile/settings/screens/password/change_password/header.cljs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
(ns status-im.contexts.profile.settings.screens.password.change-password.header | ||
(:require [quo.core :as quo] | ||
[react-native.core :as rn] | ||
[status-im.contexts.profile.settings.screens.password.change-password.style :as style] | ||
[utils.i18n :as i18n])) | ||
|
||
(defn view | ||
[] | ||
[rn/view {:style style/heading} | ||
[quo/text | ||
{:style style/heading-title | ||
:weight :semi-bold | ||
:size :heading-1} | ||
(i18n/label :t/change-password)] | ||
[quo/text | ||
{:style style/heading-subtitle | ||
:weight :regular | ||
:size :paragraph-1} | ||
(i18n/label :t/change-password-description)]]) |
Oops, something went wrong.