mirror of
https://github.com/status-im/status-react.git
synced 2025-01-12 03:54:32 +00:00
feat: support ens profile name in lock screen (#15554)
This commit is contained in:
parent
e1bbf4bc75
commit
a261628b83
@ -1,17 +1,29 @@
|
||||
(ns status-im.multiaccounts.update.core
|
||||
(:require [status-im2.constants :as constants]
|
||||
[utils.re-frame :as rf]
|
||||
[status-im.utils.types :as types]
|
||||
[taoensso.timbre :as log]))
|
||||
(:require [status-im.utils.types :as types]
|
||||
[status-im2.constants :as constants]
|
||||
[taoensso.timbre :as log]
|
||||
[utils.re-frame :as rf]))
|
||||
|
||||
(rf/defn send-multiaccount-update
|
||||
[{:keys [db] :as cofx}]
|
||||
(let [multiaccount (:multiaccount db)
|
||||
{:keys [name preferred-name address]} multiaccount]
|
||||
(rf/defn send-contact-update
|
||||
[{:keys [db]}]
|
||||
(let [{:keys [name preferred-name display-name address]} (:multiaccount db)]
|
||||
{:json-rpc/call [{:method "wakuext_sendContactUpdates"
|
||||
:params [(or preferred-name name) ""]
|
||||
:params [(or preferred-name display-name name) ""]
|
||||
:on-success #(log/debug "sent contact update")}]}))
|
||||
|
||||
(rf/defn update-multiaccount-account-name
|
||||
"This updates the profile name in the profile list before login"
|
||||
{:events [:multiaccounts.ui/update-name]}
|
||||
[{:keys [db] :as cofx} raw-multiaccounts-from-status-go]
|
||||
(let [{:keys [key-uid name preferred-name
|
||||
display-name]} (:multiaccount db)
|
||||
account (some #(and (= (:key-uid %) key-uid) %) raw-multiaccounts-from-status-go)]
|
||||
(when-let [new-name (and account (or preferred-name display-name name))]
|
||||
(rf/merge cofx
|
||||
{:json-rpc/call [{:method "multiaccounts_updateAccount"
|
||||
:params [(assoc account :name new-name)]
|
||||
:on-success #(log/debug "sent multiaccount update")}]}))))
|
||||
|
||||
(rf/defn multiaccount-update
|
||||
"Takes effects (containing :db) + new multiaccount fields, adds all effects necessary for multiaccount update.
|
||||
Optionally, one can specify a success-event to be dispatched after fields are persisted."
|
||||
@ -25,17 +37,21 @@
|
||||
(throw
|
||||
(js/Error.
|
||||
"Please shake the phone to report this error and restart the app. multiaccount is currently empty, which means something went wrong when trying to update it with"))
|
||||
(rf/merge cofx
|
||||
{:db (if setting-value
|
||||
(assoc-in db [:multiaccount setting] setting-value)
|
||||
(update db :multiaccount dissoc setting))
|
||||
:json-rpc/call
|
||||
[{:method "settings_saveSetting"
|
||||
:params [setting setting-value]
|
||||
:on-success on-success}]}
|
||||
(when (and (not dont-sync?)
|
||||
(#{:name :prefered-name} setting))
|
||||
(send-multiaccount-update))))))
|
||||
(rf/merge
|
||||
cofx
|
||||
{:db (if setting-value
|
||||
(assoc-in db [:multiaccount setting] setting-value)
|
||||
(update db :multiaccount dissoc setting))
|
||||
:json-rpc/call
|
||||
[{:method "settings_saveSetting"
|
||||
:params [setting setting-value]
|
||||
:on-success on-success}]}
|
||||
|
||||
(when (#{:name :preferred-name} setting)
|
||||
(constantly {:setup/open-multiaccounts #(rf/dispatch [:multiaccounts.ui/update-name %])}))
|
||||
|
||||
(when (and (not dont-sync?) (#{:name :preferred-name} setting))
|
||||
(send-contact-update))))))
|
||||
|
||||
(rf/defn clean-seed-phrase
|
||||
"A helper function that removes seed phrase from storage."
|
||||
@ -44,7 +60,7 @@
|
||||
|
||||
(defn augment-synchronized-recent-stickers
|
||||
"Add 'url' parameter to stickers that are synchronized from other devices.
|
||||
It is not sent from aanother devices but we have it in our db."
|
||||
It is not sent from another devices but we have it in our db."
|
||||
[synced-stickers stickers-from-db]
|
||||
(mapv #(assoc %
|
||||
:url
|
||||
|
@ -1,5 +1,5 @@
|
||||
(ns status-im.multiaccounts.update.core-test
|
||||
(:require [clojure.test :refer-macros [deftest is]]
|
||||
(:require [clojure.test :refer-macros [deftest is testing]]
|
||||
[status-im.multiaccounts.update.core :as multiaccounts.update]))
|
||||
|
||||
(deftest test-multiaccount-update
|
||||
@ -21,3 +21,36 @@
|
||||
json-rpc (into #{} (map :method (:json-rpc/call efx)))]
|
||||
(is (json-rpc "settings_saveSetting"))
|
||||
(is (nil? (get-in efx [:db :multiaccount :mnemonic])))))
|
||||
|
||||
(deftest test-update-multiaccount-account-name
|
||||
(let [cofx {:db {:multiaccount {:key-uid 1
|
||||
:name "name"
|
||||
:preferred-name "preferred-name"
|
||||
:display-name "display-name"}}}
|
||||
raw-multiaccounts-from-status-go [{:key-uid 1 :name "old-name"}]]
|
||||
(testing "wrong account"
|
||||
(is (nil? (multiaccounts.update/update-multiaccount-account-name cofx []))))
|
||||
(testing "name priority preferred-name > display-name > name"
|
||||
(let [new-account-name= (fn [efx new-name]
|
||||
(-> efx
|
||||
:json-rpc/call
|
||||
first
|
||||
:params
|
||||
first
|
||||
:name
|
||||
(= new-name)))]
|
||||
(is (new-account-name=
|
||||
(multiaccounts.update/update-multiaccount-account-name
|
||||
cofx
|
||||
raw-multiaccounts-from-status-go)
|
||||
"preferred-name"))
|
||||
(is (new-account-name=
|
||||
(multiaccounts.update/update-multiaccount-account-name
|
||||
(update-in cofx [:db :multiaccount] dissoc :preferred-name)
|
||||
raw-multiaccounts-from-status-go)
|
||||
"display-name"))
|
||||
(is (new-account-name=
|
||||
(multiaccounts.update/update-multiaccount-account-name
|
||||
(update-in cofx [:db :multiaccount] dissoc :preferred-name :display-name)
|
||||
raw-multiaccounts-from-status-go)
|
||||
"name"))))))
|
||||
|
@ -247,11 +247,11 @@
|
||||
[cofx installation-id]
|
||||
(rf/merge cofx
|
||||
(enable installation-id)
|
||||
(multiaccounts.update/send-multiaccount-update)))
|
||||
(multiaccounts.update/send-contact-update)))
|
||||
|
||||
(rf/defn disable-installation-success
|
||||
{:events [:pairing.callback/disable-installation-success]}
|
||||
[cofx installation-id]
|
||||
(rf/merge cofx
|
||||
(disable installation-id)
|
||||
(multiaccounts.update/send-multiaccount-update)))
|
||||
(multiaccounts.update/send-contact-update)))
|
||||
|
Loading…
x
Reference in New Issue
Block a user