new profile hook and capacities
Signed-off-by: Andrey Shovkoplyas <motor4ik@gmail.com>
This commit is contained in:
parent
b721f4810f
commit
0fb9cabcfc
|
@ -29,7 +29,8 @@
|
|||
[status-im.utils.ethereum.core :as ethereum]
|
||||
[status-im.chat.commands.sending :as commands-sending]
|
||||
[status-im.browser.core :as browser]
|
||||
[status-im.utils.platform :as platform]))
|
||||
[status-im.utils.platform :as platform]
|
||||
[status-im.utils.datetime :as datetime]))
|
||||
|
||||
(re-frame/reg-fx
|
||||
::identity-event
|
||||
|
@ -128,8 +129,16 @@
|
|||
|
||||
(re-frame/reg-sub
|
||||
:store/get
|
||||
(fn [db [_ {id :id} {:keys [key]}]]
|
||||
(get-in db [:extensions/store id key])))
|
||||
(fn [db [_ {id :id} {:keys [key] :as params}]]
|
||||
(let [result (get-in db [:extensions/store id key])]
|
||||
(if (:reverse params)
|
||||
(reverse result)
|
||||
result))))
|
||||
|
||||
(re-frame/reg-sub
|
||||
:store/get-in
|
||||
(fn [db [_ {id :id} {:keys [keys]}]]
|
||||
(get-in db (into [] (concat [:extensions/store id] keys)))))
|
||||
|
||||
(defn- ->contact [{:keys [photo-path address name public-key]}]
|
||||
{:photo photo-path
|
||||
|
@ -158,6 +167,11 @@
|
|||
(fn [{:keys [db]} [_ {id :id} {:keys [key value]}]]
|
||||
{:db (put-or-dissoc db id key value)}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
:store/put-in
|
||||
(fn [{:keys [db]} [_ {id :id} {:keys [keys value]}]]
|
||||
{:db (assoc-in db (into [] (concat [:extensions/store id] keys)) value)}))
|
||||
|
||||
(handlers/register-handler-fx
|
||||
:store/puts
|
||||
(fn [{:keys [db]} [_ {id :id} {:keys [value]}]]
|
||||
|
@ -322,12 +336,17 @@
|
|||
(js/clearTimeout id))
|
||||
(reset! current (js/setTimeout #(on-input-change-text on-change value) delay)))
|
||||
|
||||
(defn input [{:keys [keyboard-type style on-change change-delay placeholder placeholder-text-color selection-color]}]
|
||||
(defn input [{:keys [keyboard-type style on-change change-delay placeholder placeholder-text-color selection-color
|
||||
auto-focus on-submit default-value]}]
|
||||
[react/text-input (merge {:placeholder placeholder}
|
||||
(when placeholder-text-color {:placeholder-text-color placeholder-text-color})
|
||||
(when selection-color {:selection-color selection-color})
|
||||
(when style {:style style})
|
||||
(when keyboard-type {:keyboard-type keyboard-type})
|
||||
(when auto-focus {:auto-focus auto-focus})
|
||||
(when default-value {:default-value default-value})
|
||||
(when on-submit
|
||||
{:on-submit-editing #(on-submit {})})
|
||||
(when on-change
|
||||
{:on-change-text
|
||||
(if change-delay
|
||||
|
@ -417,6 +436,16 @@
|
|||
(defn icon [{:keys [key] :as o}]
|
||||
[icons/icon key o])
|
||||
|
||||
(re-frame/reg-sub
|
||||
:store/get-vals
|
||||
(fn [db [_ {id :id} {:keys [key]}]]
|
||||
(vals (get-in db [:extensions/store id key]))))
|
||||
|
||||
(re-frame/reg-sub
|
||||
:extensions.time/now
|
||||
(fn [_ _]
|
||||
(.toLocaleString (js/Date.))))
|
||||
|
||||
(def capacities
|
||||
{:components {'view {:data view}
|
||||
'scroll-view {:data scroll-view :properties {:keyboard-should-persist-taps :keyword :content-container-style :map}}
|
||||
|
@ -425,7 +454,9 @@
|
|||
'touchable-opacity {:data touchable-opacity :properties {:on-press :event}}
|
||||
'icon {:data icon :properties {:key :keyword :color :any}}
|
||||
'image {:data image :properties {:uri :string :source :string}}
|
||||
'input {:data input :properties {:on-change :event :placeholder :string :keyboard-type :keyword :change-delay? :number :placeholder-text-color :any :selection-color :any}}
|
||||
'input {:data input :properties {:on-change :event :placeholder :string :keyboard-type :keyword
|
||||
:change-delay? :number :placeholder-text-color :any :selection-color :any
|
||||
:auto-focus? :boolean :on-submit :event :default-value :any}}
|
||||
'button {:data button :properties {:enabled :boolean :disabled :boolean :on-click :event}}
|
||||
'link {:data link :properties {:uri :string :text? :string :open-in? {:one-of #{:device :status}}}}
|
||||
'list {:data list :properties {:data :vector :item-view :view :key? :keyword}}
|
||||
|
@ -446,7 +477,10 @@
|
|||
:on-change :event}}
|
||||
'map-link {:data map-link :properties {:text :string :lng :any :lat :any}}}
|
||||
:queries {'identity {:data :extensions/identity :arguments {:value :map}}
|
||||
'store/get {:data :store/get :arguments {:key :string}}
|
||||
'store/get {:data :store/get :arguments {:key :string :reverse? :boolean}}
|
||||
'store/get-in {:data :store/get-in :arguments {:key :vector}}
|
||||
'store/get-vals {:data :store/get-vals :arguments {:key :string}}
|
||||
'time/now {:data :extensions.time/now}
|
||||
'contacts/all {:data :extensions.contacts/all} ;; :photo :name :address :public-key
|
||||
'wallet/collectibles {:data :get-collectible-token :arguments {:token :string :symbol :string}}
|
||||
'wallet/balance {:data :extensions.wallet/balance :arguments {:token :string}}
|
||||
|
@ -536,6 +570,10 @@
|
|||
{:permissions [:read]
|
||||
:data :store/put
|
||||
:arguments {:key :string :value :any}}
|
||||
'store/put-in
|
||||
{:permissions [:read]
|
||||
:data :store/put-in
|
||||
:arguments {:keys :vector :value :any}}
|
||||
'store/puts
|
||||
{:permissions [:read]
|
||||
:data :store/puts
|
||||
|
@ -819,7 +857,13 @@
|
|||
{:permissions [:read]
|
||||
:data :extensions/shh-get-messages
|
||||
:arguments {:id :string}}}
|
||||
:hooks {:wallet.settings
|
||||
:hooks {:profile.settings
|
||||
{:properties
|
||||
{:label :string
|
||||
:view :view
|
||||
:on-open? :event
|
||||
:on-close? :event}}
|
||||
:wallet.settings
|
||||
{:properties
|
||||
{:label :string
|
||||
:view :view
|
||||
|
|
|
@ -21,9 +21,16 @@
|
|||
(defmethod hook-for "wallet.settings" [_]
|
||||
(reify Hook
|
||||
(hook-in [_ id _ m {:keys [db]}]
|
||||
{:db (assoc-in db [:wallet :settings id] m)})
|
||||
(fn [{:keys [db]}] {:db (assoc-in db [:wallet :settings id] m)}))
|
||||
(unhook [_ id _ _ {:keys [db]}]
|
||||
{:db (update-in db [:wallet :settings] dissoc id)})))
|
||||
(fn [{:keys [db]}] {:db (update-in db [:wallet :settings] dissoc id)}))))
|
||||
|
||||
(defmethod hook-for "profile.settings" [_]
|
||||
(reify Hook
|
||||
(hook-in [_ id _ m {:keys [db]}]
|
||||
(fn [{:keys [db]}] {:db (assoc-in db [:extensions/profile :settings id] m)}))
|
||||
(unhook [_ id _ _ {:keys [db]}]
|
||||
(fn [{:keys [db]}] {:db (update-in db [:extensions/profile :settings] dissoc id)}))))
|
||||
|
||||
(defmethod hook-for "chat.command" [_]
|
||||
(reify Hook
|
||||
|
@ -56,7 +63,8 @@
|
|||
(preview [_ props] (when preview (preview props)))
|
||||
protocol/Extension
|
||||
(extension-id [_] extension-id)))]
|
||||
(commands/load-commands cofx [new-command])))
|
||||
(fn [cofx]
|
||||
(commands/load-commands cofx [new-command]))))
|
||||
(unhook [_ id _ {:keys [scope]} {:keys [db] :as cofx}]
|
||||
(when-let [command (get-in db [:id->command [(name id) scope] :type])]
|
||||
(commands/remove-command command cofx)))))
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
:open-dapp {:type :main}
|
||||
:my-profile {:type :main}
|
||||
:profile-stack {:type :main}
|
||||
:my-profile-ext-settings {:type :main}
|
||||
:contacts-list {:type :main}
|
||||
:browser {:type :main}
|
||||
:mobile-network-settings {:type :main}
|
||||
|
|
|
@ -197,6 +197,7 @@
|
|||
(spec/def :stickers/packs-installed (spec/nilable map?))
|
||||
(spec/def :stickers/selected-pack (spec/nilable any?))
|
||||
(spec/def :stickers/recent (spec/nilable vector?))
|
||||
(spec/def :extensions/profile (spec/nilable any?))
|
||||
|
||||
(spec/def ::db (spec/keys :opt [:contacts/contacts
|
||||
:contacts/dapps
|
||||
|
@ -272,7 +273,8 @@
|
|||
:stickers/packs-owned
|
||||
:stickers/packs-pendning
|
||||
:bottom-sheet/show?
|
||||
:bottom-sheet/view]
|
||||
:bottom-sheet/view
|
||||
:extensions/profile]
|
||||
:opt-un [::modal
|
||||
::was-modal?
|
||||
::rpc-url
|
||||
|
|
|
@ -103,8 +103,12 @@
|
|||
|
||||
(defn- my-profile-settings [{:keys [seed-backed-up? mnemonic]}
|
||||
{:keys [dev-mode?
|
||||
settings]} currency logged-in?]
|
||||
(let [show-backup-seed? (and (not seed-backed-up?) (not (string/blank? mnemonic)))]
|
||||
settings]}
|
||||
currency
|
||||
logged-in?
|
||||
extensions]
|
||||
(let [show-backup-seed? (and (not seed-backed-up?) (not (string/blank? mnemonic)))
|
||||
extensions-settings (vals (get extensions :settings))]
|
||||
[react/view
|
||||
[profile.components/settings-title (i18n/label :t/settings)]
|
||||
[profile.components/settings-item {:label-kw :t/ens-names
|
||||
|
@ -151,6 +155,13 @@
|
|||
{:label-kw :t/dapps-permissions
|
||||
:accessibility-label :dapps-permissions-button
|
||||
:action-fn #(re-frame/dispatch [:navigate-to :dapps-permissions])}]
|
||||
(when extensions-settings
|
||||
(for [{:keys [label] :as st} extensions-settings]
|
||||
[react/view
|
||||
[profile.components/settings-item-separator]
|
||||
[profile.components/settings-item
|
||||
{:item-text label
|
||||
:action-fn #(re-frame/dispatch [:navigate-to :my-profile-ext-settings st])}]]))
|
||||
[profile.components/settings-item-separator]
|
||||
[profile.components/settings-item
|
||||
{:label-kw :t/need-help
|
||||
|
@ -268,21 +279,29 @@
|
|||
|
||||
(defn tribute-to-talk-item [snt-amount seen?]
|
||||
[list.views/big-list-item
|
||||
(cond->
|
||||
{:text (i18n/label :t/tribute-to-talk)
|
||||
:icon :main-icons/tribute-to-talk
|
||||
:accessibility-label :notifications-button
|
||||
:new? (not seen?)
|
||||
:action-fn #(re-frame/dispatch
|
||||
[:tribute-to-talk.ui/menu-item-pressed])}
|
||||
(cond-> {:text (i18n/label :t/tribute-to-talk)
|
||||
:icon :main-icons/tribute-to-talk
|
||||
:accessibility-label :notifications-button
|
||||
:new? (not seen?)
|
||||
:action-fn #(re-frame/dispatch
|
||||
[:tribute-to-talk.ui/menu-item-pressed])}
|
||||
snt-amount
|
||||
(assoc :accessory-value (str snt-amount " SNT"))
|
||||
(not (and seen? snt-amount))
|
||||
(assoc :subtext (i18n/label :t/tribute-to-talk-desc)))])
|
||||
(assoc :subtext (i18n/label :t/tribute-to-talk-desc)))])
|
||||
|
||||
(defview extensions-settings []
|
||||
(letsubs [{:keys [label view on-close]} [:get-screen-params :my-profile-ext-settings]]
|
||||
[react/keyboard-avoiding-view {:style {:flex 1}}
|
||||
[status-bar/status-bar {:type :main}]
|
||||
[toolbar/simple-toolbar label]
|
||||
[react/scroll-view
|
||||
[view]]]))
|
||||
|
||||
(defview my-profile []
|
||||
(letsubs [{:keys [public-key photo-path] :as current-account} [:account/account]
|
||||
editing? [:get :my-profile/editing?]
|
||||
extensions [:get :extensions/profile]
|
||||
changed-account [:get :my-profile/profile]
|
||||
currency [:wallet/currency]
|
||||
login-data [:get :accounts/login]
|
||||
|
@ -324,6 +343,6 @@
|
|||
[contacts-list-item active-contacts-count]
|
||||
(when config/tr-to-talk-enabled?
|
||||
[tribute-to-talk-item snt-amount tribute-to-talk-seen?])
|
||||
[my-profile-settings current-account shown-account currency (nil? login-data)]
|
||||
[my-profile-settings current-account shown-account currency (nil? login-data) extensions]
|
||||
(when (nil? login-data)
|
||||
[advanced shown-account on-show-advanced])]]])))
|
||||
|
|
|
@ -28,7 +28,8 @@
|
|||
:mobile-network-settings
|
||||
:backup-seed
|
||||
:tribute-to-talk
|
||||
:qr-scanner]
|
||||
:qr-scanner
|
||||
:my-profile-ext-settings]
|
||||
|
||||
config/hardwallet-enabled?
|
||||
(concat [:hardwallet-authentication-method
|
||||
|
|
|
@ -117,6 +117,7 @@
|
|||
:wallet-settings-assets [:modal wallet-settings/manage-assets]
|
||||
:wallet-transactions-filter [:modal wallet-transactions/filter-history]
|
||||
:my-profile profile.user/my-profile
|
||||
:my-profile-ext-settings profile.user/extensions-settings
|
||||
:contacts-list contacts-list/contacts-list
|
||||
:blocked-users-list contacts-list/blocked-users-list
|
||||
:profile-photo-capture photo-capture/profile-photo-capture
|
||||
|
|
Loading…
Reference in New Issue