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
|
(ns status-im.multiaccounts.update.core
|
||||||
(:require [status-im2.constants :as constants]
|
(:require [status-im.utils.types :as types]
|
||||||
[utils.re-frame :as rf]
|
[status-im2.constants :as constants]
|
||||||
[status-im.utils.types :as types]
|
[taoensso.timbre :as log]
|
||||||
[taoensso.timbre :as log]))
|
[utils.re-frame :as rf]))
|
||||||
|
|
||||||
(rf/defn send-multiaccount-update
|
(rf/defn send-contact-update
|
||||||
[{:keys [db] :as cofx}]
|
[{:keys [db]}]
|
||||||
(let [multiaccount (:multiaccount db)
|
(let [{:keys [name preferred-name display-name address]} (:multiaccount db)]
|
||||||
{:keys [name preferred-name address]} multiaccount]
|
|
||||||
{:json-rpc/call [{:method "wakuext_sendContactUpdates"
|
{: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")}]}))
|
: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
|
(rf/defn multiaccount-update
|
||||||
"Takes effects (containing :db) + new multiaccount fields, adds all effects necessary for 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."
|
Optionally, one can specify a success-event to be dispatched after fields are persisted."
|
||||||
|
@ -25,17 +37,21 @@
|
||||||
(throw
|
(throw
|
||||||
(js/Error.
|
(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"))
|
"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
|
(rf/merge
|
||||||
{:db (if setting-value
|
cofx
|
||||||
(assoc-in db [:multiaccount setting] setting-value)
|
{:db (if setting-value
|
||||||
(update db :multiaccount dissoc setting))
|
(assoc-in db [:multiaccount setting] setting-value)
|
||||||
:json-rpc/call
|
(update db :multiaccount dissoc setting))
|
||||||
[{:method "settings_saveSetting"
|
:json-rpc/call
|
||||||
:params [setting setting-value]
|
[{:method "settings_saveSetting"
|
||||||
:on-success on-success}]}
|
:params [setting setting-value]
|
||||||
(when (and (not dont-sync?)
|
:on-success on-success}]}
|
||||||
(#{:name :prefered-name} setting))
|
|
||||||
(send-multiaccount-update))))))
|
(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
|
(rf/defn clean-seed-phrase
|
||||||
"A helper function that removes seed phrase from storage."
|
"A helper function that removes seed phrase from storage."
|
||||||
|
@ -44,7 +60,7 @@
|
||||||
|
|
||||||
(defn augment-synchronized-recent-stickers
|
(defn augment-synchronized-recent-stickers
|
||||||
"Add 'url' parameter to stickers that are synchronized from other devices.
|
"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]
|
[synced-stickers stickers-from-db]
|
||||||
(mapv #(assoc %
|
(mapv #(assoc %
|
||||||
:url
|
:url
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
(ns status-im.multiaccounts.update.core-test
|
(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]))
|
[status-im.multiaccounts.update.core :as multiaccounts.update]))
|
||||||
|
|
||||||
(deftest test-multiaccount-update
|
(deftest test-multiaccount-update
|
||||||
|
@ -21,3 +21,36 @@
|
||||||
json-rpc (into #{} (map :method (:json-rpc/call efx)))]
|
json-rpc (into #{} (map :method (:json-rpc/call efx)))]
|
||||||
(is (json-rpc "settings_saveSetting"))
|
(is (json-rpc "settings_saveSetting"))
|
||||||
(is (nil? (get-in efx [:db :multiaccount :mnemonic])))))
|
(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]
|
[cofx installation-id]
|
||||||
(rf/merge cofx
|
(rf/merge cofx
|
||||||
(enable installation-id)
|
(enable installation-id)
|
||||||
(multiaccounts.update/send-multiaccount-update)))
|
(multiaccounts.update/send-contact-update)))
|
||||||
|
|
||||||
(rf/defn disable-installation-success
|
(rf/defn disable-installation-success
|
||||||
{:events [:pairing.callback/disable-installation-success]}
|
{:events [:pairing.callback/disable-installation-success]}
|
||||||
[cofx installation-id]
|
[cofx installation-id]
|
||||||
(rf/merge cofx
|
(rf/merge cofx
|
||||||
(disable installation-id)
|
(disable installation-id)
|
||||||
(multiaccounts.update/send-multiaccount-update)))
|
(multiaccounts.update/send-contact-update)))
|
||||||
|
|
Loading…
Reference in New Issue