reformat status-im.ui.* namespaces

This commit is contained in:
Roman Volosovskyi 2018-05-08 09:32:05 +03:00
parent 6c620728da
commit 6fc03fc217
No known key found for this signature in database
GPG Key ID: 0238A4B5ECEE70DE
82 changed files with 2024 additions and 2037 deletions

View File

@ -16,7 +16,6 @@
:align-items :center :align-items :center
:padding-horizontal 12}) :padding-horizontal 12})
(defn- border [position] (defn- border [position]
(let [radius (if platform/ios? 8 4)] (let [radius (if platform/ios? 8 4)]
(case position (case position
@ -53,7 +52,6 @@
{:android {:opacity 0.4} {:android {:opacity 0.4}
:ios {:opacity 0.6}}) :ios {:opacity 0.6}})
(defstyle button-borders (defstyle button-borders
{:border-radius 8 {:border-radius 8
:ios {;; Border radius is ignored with transparent background unless overflow "hidden" is used :ios {;; Border radius is ignored with transparent background unless overflow "hidden" is used
@ -62,14 +60,14 @@
(def primary-button (def primary-button
(merge (merge
button-borders button-borders
{:background-color styles/color-blue4})) {:background-color styles/color-blue4}))
(def primary-button-text {:color styles/color-white}) (def primary-button-text {:color styles/color-white})
(def secondary-button (def secondary-button
(merge (merge
button-borders button-borders
{:background-color styles/color-blue4-transparent})) {:background-color styles/color-blue4-transparent}))
(def secondary-button-text {:color styles/color-blue4}) (def secondary-button-text {:color styles/color-blue4})

View File

@ -158,8 +158,8 @@
[react/view (styles/profile-icon-mask size)]) [react/view (styles/profile-icon-mask size)])
(when edit? (when edit?
[react/view (styles/profile-icon-edit-text-containter size) [react/view (styles/profile-icon-edit-text-containter size)
[react/text {:style styles/profile-icon-edit-text} [react/text {:style styles/profile-icon-edit-text}
(i18n/label :t/edit)]]) (i18n/label :t/edit)]])
(if (and photo-path (seq photo-path)) (if (and photo-path (seq photo-path))
[chat-icon photo-path styles] [chat-icon photo-path styles]
[default-chat-icon name styles])])) [default-chat-icon name styles])]))

View File

@ -25,6 +25,6 @@
r (js/parseInt (subs hex 0 2) 16) r (js/parseInt (subs hex 0 2) 16)
g (js/parseInt (subs hex 2 4) 16) g (js/parseInt (subs hex 2 4) 16)
b (js/parseInt (subs hex 4 6) 16)] b (js/parseInt (subs hex 4 6) 16)]
(str "rgba(" r "," g "," b "," opacity")"))) (str "rgba(" r "," g "," b "," opacity ")")))
(def text black) (def text black)

View File

@ -91,12 +91,12 @@
(defn image-contain [_ _] (defn image-contain [_ _]
(let [content-width (reagent/atom 0)] (let [content-width (reagent/atom 0)]
(reagent/create-class (reagent/create-class
{:reagent-render {:reagent-render
(fn [{:keys [container-style style]} {:keys [image width height]}] (fn [{:keys [container-style style]} {:keys [image width height]}]
[react/view {:style (merge styles/image-contain container-style) [react/view {:style (merge styles/image-contain container-style)
:on-layout #(reset! content-width (-> % .-nativeEvent .-layout .-width))} :on-layout #(reset! content-width (-> % .-nativeEvent .-layout .-width))}
[react/image {:source image [react/image {:source image
:resize-mode :contain :resize-mode :contain
:style (merge style :style (merge style
{:width @content-width {:width @content-width
:height (/ (* @content-width height) width)})}]])}))) :height (/ (* @content-width height) width)})}]])})))

View File

@ -110,14 +110,14 @@
(defn logo-container [size shadow?] (defn logo-container [size shadow?]
(merge (merge
{:width size {:width size
:height size :height size
:border-radius size :border-radius size
:background-color colors/blue :background-color colors/blue
:align-items :center :align-items :center
:justify-content :center} :justify-content :center}
(when shadow? (when shadow?
logo-shaddow))) logo-shaddow)))
(defn logo [icon-size] (defn logo [icon-size]
{:color :white {:color :white
@ -136,12 +136,12 @@
(defn button [style background?] (defn button [style background?]
(merge (merge
{:padding-vertical 12 {:padding-vertical 12
:padding-horizontal 42 :padding-horizontal 42
:border-radius 8} :border-radius 8}
style style
(when background? (when background?
{:background-color (colors/alpha colors/blue 0.1)}))) {:background-color (colors/alpha colors/blue 0.1)})))
(def button-label (def button-label
{:font-size 15 {:font-size 15

View File

@ -10,8 +10,8 @@
(defn start-error-animation [offline-opacity] (defn start-error-animation [offline-opacity]
(animation/start (animation/start
(animation/timing offline-opacity {:toValue 1.0 (animation/timing offline-opacity {:toValue 1.0
:duration 250}))) :duration 250})))
(defn error-view [_] (defn error-view [_]
(let [offline? (re-frame/subscribe [:offline?]) (let [offline? (re-frame/subscribe [:offline?])
@ -24,18 +24,18 @@
current-chat-contact (re-frame/subscribe [:get-current-chat-contact]) current-chat-contact (re-frame/subscribe [:get-current-chat-contact])
view-id (re-frame/subscribe [:get :view-id])] view-id (re-frame/subscribe [:get :view-id])]
(reagent/create-class (reagent/create-class
{:component-did-mount {:component-did-mount
on-update on-update
:component-did-update :component-did-update
on-update on-update
:display-name "connectivity-error-view" :display-name "connectivity-error-view"
:reagent-render :reagent-render
(fn [{:keys [top]}] (fn [{:keys [top]}]
(when (or @offline? @connection-problem?) (when (or @offline? @connection-problem?)
(let [pending? (and (:pending @current-chat-contact) (= :chat @view-id))] (let [pending? (and (:pending @current-chat-contact) (= :chat @view-id))]
[react/animated-view {:style (styles/offline-wrapper top offline-opacity window-width pending?)} [react/animated-view {:style (styles/offline-wrapper top offline-opacity window-width pending?)}
[react/view [react/view
[react/text {:style styles/offline-text} [react/text {:style styles/offline-text}
(i18n/label (if @connection-problem? (i18n/label (if @connection-problem?
:t/connection-problem :t/connection-problem
:t/offline))]]])))}))) :t/offline))]]])))})))

View File

@ -17,7 +17,7 @@
[chat-icon/contact-icon-contacts-tab contact]] [chat-icon/contact-icon-contacts-tab contact]]
[react/view styles/info-container [react/view styles/info-container
[react/text (merge {:style styles/name-text [react/text (merge {:style styles/name-text
:number-of-lines 1} :number-of-lines 1}
(when dapp? {:accessibility-label :dapp-name}) (when dapp? {:accessibility-label :dapp-name})
props) props)
(if (pos? (count (:name contact))) (if (pos? (count (:name contact)))
@ -34,18 +34,18 @@
[react/touchable-highlight (merge {:accessibility-label accessibility-label} [react/touchable-highlight (merge {:accessibility-label accessibility-label}
(when-not extended? (when-not extended?
{:on-press (when on-press #(on-press contact))})) {:on-press (when on-press #(on-press contact))}))
[react/view styles/contact-container [react/view styles/contact-container
[contact-inner-view {:contact contact :info info :style style :props inner-props}] [contact-inner-view {:contact contact :info info :style style :props inner-props}]
(when show-forward? (when show-forward?
[react/view styles/forward-btn [react/view styles/forward-btn
[vector-icons/icon :icons/forward]]) [vector-icons/icon :icons/forward]])
(when (and extended? (not (empty? extend-options))) (when (and extended? (not (empty? extend-options)))
[react/view styles/more-btn-container [react/view styles/more-btn-container
[react/touchable-highlight {:on-press #(list-selection/show {:options extend-options [react/touchable-highlight {:on-press #(list-selection/show {:options extend-options
:title extend-title}) :title extend-title})
:accessibility-label :menu-option} :accessibility-label :menu-option}
[react/view styles/more-btn [react/view styles/more-btn
[vector-icons/icon :icons/options {:accessibility-label :options}]]]])]]) [vector-icons/icon :icons/options {:accessibility-label :options}]]]])]])
(views/defview toogle-contact-view [{:keys [whisper-identity] :as contact} selected-key on-toggle-handler] (views/defview toogle-contact-view [{:keys [whisper-identity] :as contact} selected-key on-toggle-handler]
(views/letsubs [checked [selected-key whisper-identity]] (views/letsubs [checked [selected-key whisper-identity]]

View File

@ -1,11 +1,11 @@
(ns status-im.ui.components.desktop.views (ns status-im.ui.components.desktop.views
(:require (:require
[status-im.ui.components.icons.vector-icons :as icons] [status-im.ui.components.icons.vector-icons :as icons]
[status-im.ui.components.common.styles :as styles] [status-im.ui.components.common.styles :as styles]
[status-im.ui.components.action-button.styles :as st] [status-im.ui.components.action-button.styles :as st]
[status-im.ui.components.styles :as common] [status-im.ui.components.styles :as common]
[status-im.ui.components.checkbox.styles :as checkbox.styles] [status-im.ui.components.checkbox.styles :as checkbox.styles]
[status-im.ui.components.react :as react])) [status-im.ui.components.react :as react]))
(defn checkbox [{:keys [on-value-change checked?]}] (defn checkbox [{:keys [on-value-change checked?]}]
[react/touchable-highlight {:style checkbox.styles/wrapper :on-press #(do (when on-value-change (on-value-change (not checked?))))} [react/touchable-highlight {:style checkbox.styles/wrapper :on-press #(do (when on-value-change (on-value-change (not checked?))))}

View File

@ -99,20 +99,20 @@
:accessibility-label accessibility-label} :accessibility-label accessibility-label}
(if-let [icon-fn (get icons (normalize-property-name name))] (if-let [icon-fn (get icons (normalize-property-name name))]
(let [icon-vec (icon-fn (let [icon-vec (icon-fn
(cond (cond
(keyword? color) (keyword? color)
(case color (case color
:dark styles/icon-dark-color :dark styles/icon-dark-color
:gray styles/icon-gray-color :gray styles/icon-gray-color
:blue styles/color-light-blue :blue styles/color-light-blue
:active styles/color-blue4 :active styles/color-blue4
:white styles/color-white :white styles/color-white
:red styles/icon-red-color :red styles/icon-red-color
styles/icon-dark-color) styles/icon-dark-color)
(string? color) (string? color)
color color
:else :else
styles/icon-dark-color))] styles/icon-dark-color))]
(if width (if width
(update icon-vec 1 assoc :width width :height height) (update icon-vec 1 assoc :width width :height height)
icon-vec)) icon-vec))

View File

@ -76,8 +76,8 @@
(def separator (def separator
(merge (merge
base-separator base-separator
{:margin-left 70})) {:margin-left 70}))
(defstyle list-header-footer-spacing (defstyle list-header-footer-spacing
{:android {:background-color colors/white {:android {:background-color colors/white

View File

@ -54,7 +54,7 @@
[vector-icons/icon icon (merge icon-opts {:style styles/item-icon})]]) [vector-icons/icon icon (merge icon-opts {:style styles/item-icon})]])
(defn item-image (defn item-image
[{:keys[source style image-style]}] [{:keys [source style image-style]}]
[react/view {:style style} [react/view {:style style}
[react/image {:source source [react/image {:source source
:style (merge styles/item-image image-style)}]]) :style (merge styles/item-image image-style)}]])
@ -168,10 +168,10 @@
(defn- wrap-per-section-render-fn [props] (defn- wrap-per-section-render-fn [props]
(update (update
(if-let [f (:render-fn props)] (if-let [f (:render-fn props)]
(assoc (dissoc props :render-fn) :renderItem (wrap-render-fn f)) (assoc (dissoc props :render-fn) :renderItem (wrap-render-fn f))
props) props)
:data wrap-data)) :data wrap-data))
(defn section-list (defn section-list
"A wrapper for SectionList. "A wrapper for SectionList.
@ -203,7 +203,6 @@
label] label]
item-icon-forward]]]) item-icon-forward]]])
(defn action-list [actions {:keys [container-style action-separator-style] :as styles}] (defn action-list [actions {:keys [container-style action-separator-style] :as styles}]
[react/view (merge styles/action-list container-style) [react/view (merge styles/action-list container-style)
[flat-list [flat-list

View File

@ -6,8 +6,8 @@
(defn qr-code [props] (defn qr-code [props]
(reagent/create-element (reagent/create-element
rn-dependencies/qr-code rn-dependencies/qr-code
(clj->js (merge {:inverted true} props)))) (clj->js (merge {:inverted true} props))))
(defn- footer [style value] (defn- footer [style value]
[react/view styles/footer [react/view styles/footer

View File

@ -12,10 +12,10 @@
[react/view {:style (merge (styles/input-container height) container)} [react/view {:style (merge (styles/input-container height) container)}
[react/text-input [react/text-input
(merge (merge
{:style (merge styles/input style) {:style (merge styles/input style)
:placeholder-text-color colors/gray :placeholder-text-color colors/gray
:auto-focus true :auto-focus true
:auto-capitalize :none} :auto-capitalize :none}
(dissoc props :style :height))]] (dissoc props :style :height))]]
(when error (when error
[tooltip/tooltip error (styles/error label)])]) [tooltip/tooltip error (styles/error label)])])

View File

@ -4,9 +4,9 @@
(defn animate-tooltip [bottom-value bottom-anim-value opacity-value] (defn animate-tooltip [bottom-value bottom-anim-value opacity-value]
(fn [] (fn []
(animation/start (animation/start
(animation/parallel (animation/parallel
[(animation/timing opacity-value {:toValue 1 [(animation/timing opacity-value {:toValue 1
:duration 500}) :duration 500})
(animation/timing bottom-anim-value {:toValue (- bottom-value 10) (animation/timing bottom-anim-value {:toValue (- bottom-value 10)
:easing (.bezier (animation/easing) 0.685, 0.000, 0.025, 1.185) :easing (.bezier (animation/easing) 0.685, 0.000, 0.025, 1.185)
:duration 500})])))) :duration 500})]))))

View File

@ -32,13 +32,13 @@
(spec/def :account/seed-backed-up? (spec/nilable boolean?)) (spec/def :account/seed-backed-up? (spec/nilable boolean?))
(spec/def :accounts/account (allowed-keys (spec/def :accounts/account (allowed-keys
:req-un [:account/name :account/address :account/public-key :req-un [:account/name :account/address :account/public-key
:account/photo-path :account/signing-phrase] :account/photo-path :account/signing-phrase]
:opt-un [:account/debug? :account/status :account/last-updated :opt-un [:account/debug? :account/status :account/last-updated
:account/email :account/signed-up? :account/network :account/email :account/signed-up? :account/network
:account/networks :account/settings :account/wnode :account/networks :account/settings :account/wnode
:account/last-sign-in :account/sharing-usage-data? :account/dev-mode? :account/last-sign-in :account/sharing-usage-data? :account/dev-mode?
:account/seed-backed-up? :account/mnemonic])) :account/seed-backed-up? :account/mnemonic]))
(spec/def :accounts/accounts (spec/nilable (spec/map-of :account/address :accounts/account))) (spec/def :accounts/accounts (spec/nilable (spec/map-of :account/address :accounts/account)))

View File

@ -22,31 +22,31 @@
;;;; COFX ;;;; COFX
(re-frame/reg-cofx (re-frame/reg-cofx
::get-signing-phrase ::get-signing-phrase
(fn [coeffects _] (fn [coeffects _]
(assoc coeffects :signing-phrase (signing-phrase/generate)))) (assoc coeffects :signing-phrase (signing-phrase/generate))))
(re-frame/reg-cofx (re-frame/reg-cofx
::get-status ::get-status
(fn [coeffects _] (fn [coeffects _]
(assoc coeffects :status (rand-nth statuses/data)))) (assoc coeffects :status (rand-nth statuses/data))))
;;;; FX ;;;; FX
(re-frame/reg-fx (re-frame/reg-fx
::create-account ::create-account
(fn [password] (fn [password]
(status/create-account (status/create-account
password password
#(re-frame/dispatch [::account-created (json->clj %) password])))) #(re-frame/dispatch [::account-created (json->clj %) password]))))
;;;; Handlers ;;;; Handlers
(handlers/register-handler-fx (handlers/register-handler-fx
:create-account :create-account
(fn [{{:accounts/keys [create] :as db} :db} _] (fn [{{:accounts/keys [create] :as db} :db} _]
{:db (update db :accounts/create assoc :step :account-creating :error nil) {:db (update db :accounts/create assoc :step :account-creating :error nil)
::create-account (:password create)})) ::create-account (:password create)}))
(defn add-account (defn add-account
"Takes db and new account, creates map of effects describing adding account to database and realm" "Takes db and new account, creates map of effects describing adding account to database and realm"
@ -60,51 +60,51 @@
;; TODO(janherich) we have this handler here only because of the tests, refactor/improve tests ASAP ;; TODO(janherich) we have this handler here only because of the tests, refactor/improve tests ASAP
(handlers/register-handler-fx (handlers/register-handler-fx
:add-account :add-account
(fn [{:keys [db]} [_ new-account]] (fn [{:keys [db]} [_ new-account]]
(add-account db new-account))) (add-account db new-account)))
(handlers/register-handler-fx (handlers/register-handler-fx
::account-created ::account-created
[re-frame/trim-v (re-frame/inject-cofx ::get-signing-phrase) (re-frame/inject-cofx ::get-status)] [re-frame/trim-v (re-frame/inject-cofx ::get-signing-phrase) (re-frame/inject-cofx ::get-status)]
(fn [{:keys [signing-phrase status db] :as cofx} [{:keys [pubkey address mnemonic]} password]] (fn [{:keys [signing-phrase status db] :as cofx} [{:keys [pubkey address mnemonic]} password]]
(let [normalized-address (utils.hex/normalize-hex address) (let [normalized-address (utils.hex/normalize-hex address)
account {:public-key pubkey account {:public-key pubkey
:address normalized-address :address normalized-address
:name (generate-gfy pubkey) :name (generate-gfy pubkey)
:status status :status status
:signed-up? true :signed-up? true
:photo-path (identicon pubkey) :photo-path (identicon pubkey)
:signing-phrase signing-phrase :signing-phrase signing-phrase
:mnemonic mnemonic :mnemonic mnemonic
:settings constants/default-account-settings}] :settings constants/default-account-settings}]
(log/debug "account-created") (log/debug "account-created")
(when-not (str/blank? pubkey) (when-not (str/blank? pubkey)
(-> (add-account db account) (-> (add-account db account)
(assoc :dispatch [:login-account normalized-address password])))))) (assoc :dispatch [:login-account normalized-address password]))))))
(handlers/register-handler-fx (handlers/register-handler-fx
:load-accounts :load-accounts
[(re-frame/inject-cofx :data-store/get-all-accounts)] [(re-frame/inject-cofx :data-store/get-all-accounts)]
(fn [{:keys [db all-accounts]} _] (fn [{:keys [db all-accounts]} _]
(let [accounts (->> all-accounts (let [accounts (->> all-accounts
(map (fn [{:keys [address] :as account}] (map (fn [{:keys [address] :as account}]
[address account])) [address account]))
(into {})) (into {}))
;;workaround for realm bug, migrating account v4 ;;workaround for realm bug, migrating account v4
events (mapv #(when (empty? (:networks %)) [:account-update-networks (:address %)]) (vals accounts))] events (mapv #(when (empty? (:networks %)) [:account-update-networks (:address %)]) (vals accounts))]
(merge (merge
{:db (assoc db :accounts/accounts accounts)} {:db (assoc db :accounts/accounts accounts)}
(when-not (empty? events) (when-not (empty? events)
{:dispatch-n events}))))) {:dispatch-n events})))))
(handlers/register-handler-fx (handlers/register-handler-fx
:account-update-networks :account-update-networks
(fn [{{:accounts/keys [accounts] :networks/keys [networks] :as db} :db} [_ id]] (fn [{{:accounts/keys [accounts] :networks/keys [networks] :as db} :db} [_ id]]
(let [current-account (get accounts id) (let [current-account (get accounts id)
new-account (assoc current-account :networks networks)] new-account (assoc current-account :networks networks)]
{:db (assoc-in db [:accounts/accounts id] new-account) {:db (assoc-in db [:accounts/accounts id] new-account)
:data-store/save-account new-account}))) :data-store/save-account new-account})))
(defn update-settings [settings {{:keys [account/account] :as db} :db :as cofx}] (defn update-settings [settings {{:keys [account/account] :as db} :db :as cofx}]
(let [new-account (assoc account :settings settings)] (let [new-account (assoc account :settings settings)]
@ -112,47 +112,47 @@
:data-store/save-account new-account})) :data-store/save-account new-account}))
(handlers/register-handler-fx (handlers/register-handler-fx
:send-account-update-if-needed :send-account-update-if-needed
(fn [{:keys [db now] :as cofx} _] (fn [{:keys [db now] :as cofx} _]
(let [{:keys [last-updated]} (:account/account db) (let [{:keys [last-updated]} (:account/account db)
needs-update? (> (- now last-updated) time/week)] needs-update? (> (- now last-updated) time/week)]
(log/info "Need to send account-update: " needs-update?) (log/info "Need to send account-update: " needs-update?)
(when needs-update? (when needs-update?
;; TODO(janherich): this is very strange and misleading, need to figure out why it'd necessary to update ;; TODO(janherich): this is very strange and misleading, need to figure out why it'd necessary to update
;; account with network update when last update was more then week ago ;; account with network update when last update was more then week ago
(accounts.utils/account-update nil cofx))))) (accounts.utils/account-update nil cofx)))))
(handlers/register-handler-fx (handlers/register-handler-fx
:account-set-name :account-set-name
(fn [{{:accounts/keys [create] :as db} :db :as cofx} _] (fn [{{:accounts/keys [create] :as db} :db :as cofx} _]
(handlers-macro/merge-fx cofx (handlers-macro/merge-fx cofx
{:db db {:db db
:dispatch [:navigate-to-clean :usage-data [:account-finalized]]} :dispatch [:navigate-to-clean :usage-data [:account-finalized]]}
(accounts.utils/account-update {:name (:name create)})))) (accounts.utils/account-update {:name (:name create)}))))
(handlers/register-handler-fx (handlers/register-handler-fx
:account-finalized :account-finalized
(fn [{db :db} _] (fn [{db :db} _]
{:db (assoc db :accounts/create {:show-welcome? true}) {:db (assoc db :accounts/create {:show-welcome? true})
:dispatch-n [[:navigate-to-clean :home] :dispatch-n [[:navigate-to-clean :home]
[:request-notifications]]})) [:request-notifications]]}))
(handlers/register-handler-fx (handlers/register-handler-fx
:account-set-input-text :account-set-input-text
(fn [{db :db} [_ input-key text]] (fn [{db :db} [_ input-key text]]
{:db (update db :accounts/create merge {input-key text :error nil})})) {:db (update db :accounts/create merge {input-key text :error nil})}))
(handlers/register-handler-fx (handlers/register-handler-fx
:update-sign-in-time :update-sign-in-time
(fn [{db :db now :now :as cofx} _] (fn [{db :db now :now :as cofx} _]
(accounts.utils/account-update {:last-sign-in now} cofx))) (accounts.utils/account-update {:last-sign-in now} cofx)))
(handlers/register-handler-fx (handlers/register-handler-fx
:reset-account-creation :reset-account-creation
(fn [{db :db} _] (fn [{db :db} _]
{:db (update db :accounts/create assoc :step :enter-password :password nil :password-confirm nil :error nil)})) {:db (update db :accounts/create assoc :step :enter-password :password nil :password-confirm nil :error nil)}))
(handlers/register-handler-fx (handlers/register-handler-fx
:switch-dev-mode :switch-dev-mode
(fn [cofx [_ dev-mode]] (fn [cofx [_ dev-mode]]
(accounts.utils/account-update {:dev-mode? dev-mode} cofx))) (accounts.utils/account-update {:dev-mode? dev-mode} cofx)))

View File

@ -16,53 +16,53 @@
(reg-fx ::stop-node (fn [] (status/stop-node))) (reg-fx ::stop-node (fn [] (status/stop-node)))
(reg-fx (reg-fx
::login ::login
(fn [[address password]] (fn [[address password]]
(status/login address password #(dispatch [:login-handler % address])))) (status/login address password #(dispatch [:login-handler % address]))))
(reg-fx (reg-fx
::clear-web-data ::clear-web-data
(fn [] (fn []
(status/clear-web-data))) (status/clear-web-data)))
(reg-fx (reg-fx
::change-account ::change-account
(fn [[address]] (fn [[address]]
;; if we don't add delay when running app without status-go ;; if we don't add delay when running app without status-go
;; "null is not an object (evaluating 'realm.schema')" error appears ;; "null is not an object (evaluating 'realm.schema')" error appears
(keychain/get-encryption-key-then (keychain/get-encryption-key-then
(fn [encryption-key] (fn [encryption-key]
(let [change-account-fn (fn [] (data-store/change-account address (let [change-account-fn (fn [] (data-store/change-account address
false false
encryption-key encryption-key
#(dispatch [:change-account-handler % address])))] #(dispatch [:change-account-handler % address])))]
(if config/stub-status-go? (if config/stub-status-go?
(utils/set-timeout change-account-fn (utils/set-timeout change-account-fn
300) 300)
(change-account-fn))))))) (change-account-fn)))))))
;;;; Handlers ;;;; Handlers
(register-handler-fx (register-handler-fx
:open-login :open-login
(fn [{db :db} [_ address photo-path name]] (fn [{db :db} [_ address photo-path name]]
{:db (update db {:db (update db
:accounts/login assoc :accounts/login assoc
:address address :address address
:photo-path photo-path :photo-path photo-path
:name name) :name name)
:dispatch [:navigate-to :login]})) :dispatch [:navigate-to :login]}))
(defn wrap-with-login-account-fx [db address password] (defn wrap-with-login-account-fx [db address password]
{:db db {:db db
::login [address password]}) ::login [address password]})
(register-handler-fx (register-handler-fx
::login-account ::login-account
(fn [{db :db} [_ address password]] (fn [{db :db} [_ address password]]
(wrap-with-login-account-fx (wrap-with-login-account-fx
(assoc db :node/after-start nil) (assoc db :node/after-start nil)
address password))) address password)))
(defn get-network-by-address [db address] (defn get-network-by-address [db address]
(let [accounts (get db :accounts/accounts) (let [accounts (get db :accounts/accounts)
@ -78,55 +78,55 @@
:node/after-start [::login-account address password])})) :node/after-start [::login-account address password])}))
(register-handler-fx (register-handler-fx
::start-node ::start-node
(fn [{db :db} [_ address password]] (fn [{db :db} [_ address password]]
(wrap-with-initialize-geth-fx (wrap-with-initialize-geth-fx
(assoc db :node/after-stop nil) (assoc db :node/after-stop nil)
address password))) address password)))
(defn wrap-with-stop-node-fx [db address password] (defn wrap-with-stop-node-fx [db address password]
{:db (assoc db :node/after-stop [::start-node address password]) {:db (assoc db :node/after-stop [::start-node address password])
::stop-node nil}) ::stop-node nil})
(register-handler-fx (register-handler-fx
:login-account :login-account
(fn [{{:keys [network status-node-started?] :as db} :db} [_ address password]] (fn [{{:keys [network status-node-started?] :as db} :db} [_ address password]]
(let [{account-network :network} (get-network-by-address db address) (let [{account-network :network} (get-network-by-address db address)
db' (-> db db' (-> db
(assoc-in [:accounts/login :processing] true)) (assoc-in [:accounts/login :processing] true))
wrap-fn (cond (not status-node-started?) wrap-fn (cond (not status-node-started?)
wrap-with-initialize-geth-fx wrap-with-initialize-geth-fx
(= account-network network) (= account-network network)
wrap-with-login-account-fx wrap-with-login-account-fx
:else :else
wrap-with-stop-node-fx)] wrap-with-stop-node-fx)]
(wrap-fn db' address password)))) (wrap-fn db' address password))))
(register-handler-fx (register-handler-fx
:login-handler :login-handler
(fn [{db :db} [_ login-result address]] (fn [{db :db} [_ login-result address]]
(let [data (json->clj login-result) (let [data (json->clj login-result)
error (:error data) error (:error data)
success (zero? (count error)) success (zero? (count error))
db' (assoc-in db [:accounts/login :processing] false)] db' (assoc-in db [:accounts/login :processing] false)]
(if success (if success
{:db db' {:db db'
::clear-web-data nil ::clear-web-data nil
::change-account [address]} ::change-account [address]}
{:db (assoc-in db' [:accounts/login :error] error)})))) {:db (assoc-in db' [:accounts/login :error] error)}))))
(register-handler-fx (register-handler-fx
:change-account-handler :change-account-handler
(fn [{{:keys [accounts/accounts view-id] :as db} :db} [_ error address]] (fn [{{:keys [accounts/accounts view-id] :as db} :db} [_ error address]]
(if (nil? error) (if (nil? error)
{:db (cond-> (dissoc db :accounts/login) {:db (cond-> (dissoc db :accounts/login)
(= view-id :create-account) (= view-id :create-account)
(assoc-in [:accounts/create :step] :enter-name)) (assoc-in [:accounts/create :step] :enter-name))
:dispatch-n (concat :dispatch-n (concat
[[:stop-debugging] [[:stop-debugging]
[:initialize-account address [:initialize-account address
(when (not= view-id :create-account) (when (not= view-id :create-account)
[[:navigate-to-clean :home]])]])} [[:navigate-to-clean :home]])]])}
(log/debug "Error changing acount: " error)))) (log/debug "Error changing acount: " error))))

View File

@ -1,52 +1,52 @@
(ns status-im.ui.screens.accounts.recover.events (ns status-im.ui.screens.accounts.recover.events
(:require (:require
status-im.ui.screens.accounts.recover.navigation status-im.ui.screens.accounts.recover.navigation
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[status-im.native-module.core :as status] [status-im.native-module.core :as status]
[status-im.ui.screens.accounts.events :as accounts-events] [status-im.ui.screens.accounts.events :as accounts-events]
[status-im.utils.types :as types] [status-im.utils.types :as types]
[status-im.utils.identicon :as identicon] [status-im.utils.identicon :as identicon]
[clojure.string :as string] [clojure.string :as string]
[status-im.utils.handlers :as handlers] [status-im.utils.handlers :as handlers]
[status-im.utils.gfycat.core :as gfycat] [status-im.utils.gfycat.core :as gfycat]
[status-im.utils.signing-phrase.core :as signing-phrase] [status-im.utils.signing-phrase.core :as signing-phrase]
[status-im.utils.hex :as utils.hex] [status-im.utils.hex :as utils.hex]
[status-im.constants :as constants])) [status-im.constants :as constants]))
;;;; FX ;;;; FX
(re-frame/reg-fx (re-frame/reg-fx
::recover-account-fx ::recover-account-fx
(fn [[passphrase password]] (fn [[passphrase password]]
(status/recover-account (status/recover-account
(string/trim passphrase) (string/trim passphrase)
password password
#(re-frame/dispatch [:account-recovered % password])))) #(re-frame/dispatch [:account-recovered % password]))))
;;;; Handlers ;;;; Handlers
(handlers/register-handler-fx (handlers/register-handler-fx
:account-recovered :account-recovered
(fn [{:keys [db]} [_ result password]] (fn [{:keys [db]} [_ result password]]
(let [data (types/json->clj result) (let [data (types/json->clj result)
public-key (:pubkey data) public-key (:pubkey data)
address (-> data :address utils.hex/normalize-hex) address (-> data :address utils.hex/normalize-hex)
phrase (signing-phrase/generate) phrase (signing-phrase/generate)
account {:public-key public-key account {:public-key public-key
:address address :address address
:name (gfycat/generate-gfy public-key) :name (gfycat/generate-gfy public-key)
:photo-path (identicon/identicon public-key) :photo-path (identicon/identicon public-key)
:mnemonic "" :mnemonic ""
:signed-up? true :signed-up? true
:signing-phrase phrase :signing-phrase phrase
:settings constants/default-account-settings}] :settings constants/default-account-settings}]
(when-not (string/blank? public-key) (when-not (string/blank? public-key)
(-> db (-> db
(accounts-events/add-account account) (accounts-events/add-account account)
(assoc :dispatch [:login-account address password]) (assoc :dispatch [:login-account address password])
(assoc :dispatch-later [{:ms 2000 :dispatch [:navigate-to :usage-data]}])))))) (assoc :dispatch-later [{:ms 2000 :dispatch [:navigate-to :usage-data]}]))))))
(handlers/register-handler-fx (handlers/register-handler-fx
:recover-account :recover-account
(fn [_ [_ passphrase password]] (fn [_ [_ passphrase password]]
{::recover-account-fx [passphrase password]})) {::recover-account-fx [passphrase password]}))

View File

@ -48,8 +48,8 @@
(defview recover [] (defview recover []
(letsubs [{:keys [passphrase password]} [:get :accounts/recover]] (letsubs [{:keys [passphrase password]} [:get :accounts/recover]]
(let [valid-form? (and (let [valid-form? (and
(spec/valid? ::recover.db/passphrase passphrase) (spec/valid? ::recover.db/passphrase passphrase)
(spec/valid? ::db/password password))] (spec/valid? ::db/password password))]
[react/keyboard-avoiding-view {:style styles/screen-container} [react/keyboard-avoiding-view {:style styles/screen-container}
[status-bar/status-bar] [status-bar/status-bar]
[toolbar/toolbar nil toolbar/default-nav-back [toolbar/toolbar nil toolbar/default-nav-back

View File

@ -6,25 +6,25 @@
[cljs.spec.alpha :as spec])) [cljs.spec.alpha :as spec]))
(reg-sub :get-current-public-key (reg-sub :get-current-public-key
(fn [db] (fn [db]
(:current-public-key db))) (:current-public-key db)))
(reg-sub :get-accounts (reg-sub :get-accounts
(fn [db] (fn [db]
(:accounts/accounts db))) (:accounts/accounts db)))
(reg-sub :get-current-account (reg-sub :get-current-account
(fn [db] (fn [db]
(:account/account db))) (:account/account db)))
(reg-sub :get-current-account-hex (reg-sub :get-current-account-hex
:<- [:get-current-account] :<- [:get-current-account]
(fn [{:keys [address]}] (fn [{:keys [address]}]
(ethereum/normalized-address address))) (ethereum/normalized-address address)))
(reg-sub (reg-sub
:get-account-creation-next-enabled? :get-account-creation-next-enabled?
(fn [{:accounts/keys [create]}] (fn [{:accounts/keys [create]}]
(let [{:keys [step password password-confirm name]} create] (let [{:keys [step password password-confirm name]} create]
(or (and password (= :enter-password step) (spec/valid? ::db/password password)) (or (and password (= :enter-password step) (spec/valid? ::db/password password))
(and password-confirm (= :confirm-password step) (spec/valid? ::db/password password-confirm)) (and password-confirm (= :confirm-password step) (spec/valid? ::db/password password-confirm))

View File

@ -3,7 +3,6 @@
[status-im.utils.handlers-macro :as handlers-macro] [status-im.utils.handlers-macro :as handlers-macro]
[status-im.transport.message.v1.contact :as message.contact])) [status-im.transport.message.v1.contact :as message.contact]))
(defn account-update (defn account-update
"Takes effects (containing :db) + new account fields, adds all effects necessary for account update. "Takes effects (containing :db) + new account fields, adds all effects necessary for account update.
Optionally, one can specify event to be dispatched after fields are persisted." Optionally, one can specify event to be dispatched after fields are persisted."

View File

@ -8,7 +8,7 @@
(when (and whisper-identity (not (string/blank? whisper-identity))) (when (and whisper-identity (not (string/blank? whisper-identity)))
(cond (cond
(#{(hex/normalize-hex address) (hex/normalize-hex public-key)} (#{(hex/normalize-hex address) (hex/normalize-hex public-key)}
(hex/normalize-hex whisper-identity)) (hex/normalize-hex whisper-identity))
(i18n/label :t/can-not-add-yourself) (i18n/label :t/can-not-add-yourself)
(not (spec/valid? :global/public-key whisper-identity)) (not (spec/valid? :global/public-key whisper-identity))

View File

@ -3,8 +3,8 @@
[status-im.ui.screens.add-new.new-chat.db :as db])) [status-im.ui.screens.add-new.new-chat.db :as db]))
(re-frame/reg-sub (re-frame/reg-sub
:new-contact-error-message :new-contact-error-message
:<- [:get :contacts/new-identity] :<- [:get :contacts/new-identity]
:<- [:get-current-account] :<- [:get-current-account]
(fn [[new-identity account]] (fn [[new-identity account]]
(db/validate-pub-key new-identity account))) (db/validate-pub-key new-identity account)))

View File

@ -15,18 +15,18 @@
(spec/def :browser/options (spec/def :browser/options
(allowed-keys (allowed-keys
:opt-un [:browser/browser-id :opt-un [:browser/browser-id
:browser/can-go-back? :browser/can-go-back?
:browser/can-go-forward? :browser/can-go-forward?
:browser/fullscreen?])) :browser/fullscreen?]))
(spec/def :browser/browser (spec/def :browser/browser
(allowed-keys (allowed-keys
:req-un [:browser/browser-id :req-un [:browser/browser-id
:browser/timestamp] :browser/timestamp]
:opt-un [:browser/name :opt-un [:browser/name
:browser/dapp? :browser/dapp?
:browser/url :browser/url
:browser/contact])) :browser/contact]))
(spec/def :browser/browsers (spec/nilable (spec/map-of :global/not-empty-string :browser/browser))) (spec/def :browser/browsers (spec/nilable (spec/map-of :global/not-empty-string :browser/browser)))

View File

@ -6,25 +6,25 @@
[status-im.i18n :as i18n])) [status-im.i18n :as i18n]))
(handlers/register-handler-fx (handlers/register-handler-fx
:initialize-browsers :initialize-browsers
[(re-frame/inject-cofx :data-store/all-browsers)] [(re-frame/inject-cofx :data-store/all-browsers)]
(fn [{:keys [db all-stored-browsers]} _] (fn [{:keys [db all-stored-browsers]} _]
(let [browsers (into {} (map #(vector (:browser-id %) %) all-stored-browsers))] (let [browsers (into {} (map #(vector (:browser-id %) %) all-stored-browsers))]
{:db (assoc db :browser/browsers browsers)}))) {:db (assoc db :browser/browsers browsers)})))
(defn match-url [url] (defn match-url [url]
(str (when (and url (not (re-find #"^[a-zA-Z-_]+:/" url))) "http://") url)) (str (when (and url (not (re-find #"^[a-zA-Z-_]+:/" url))) "http://") url))
(defn get-new-browser [browser now] (defn get-new-browser [browser now]
(cond-> browser (cond-> browser
true true
(assoc :timestamp now) (assoc :timestamp now)
(not (:browser-id browser)) (not (:browser-id browser))
(assoc :browser-id (random/id)) (assoc :browser-id (random/id))
(not (:name browser)) (not (:name browser))
(assoc :name (i18n/label :t/browser)) (assoc :name (i18n/label :t/browser))
(:url browser) (:url browser)
(update :url match-url))) (update :url match-url)))
(defn add-browser-fx [{:keys [db now] :as cofx} browser] (defn add-browser-fx [{:keys [db now] :as cofx} browser]
(let [new-browser (get-new-browser browser now)] (let [new-browser (get-new-browser browser now)]
@ -32,42 +32,42 @@
:data-store/save-browser new-browser})) :data-store/save-browser new-browser}))
(handlers/register-handler-fx (handlers/register-handler-fx
:open-dapp-in-browser :open-dapp-in-browser
[re-frame/trim-v] [re-frame/trim-v]
(fn [cofx [{:keys [name dapp-url] :as contact}]] (fn [cofx [{:keys [name dapp-url] :as contact}]]
(let [browser {:browser-id (:whisper-identity contact) (let [browser {:browser-id (:whisper-identity contact)
:name name :name name
:dapp? true :dapp? true
:url dapp-url :url dapp-url
:contact (:whisper-identity contact)}] :contact (:whisper-identity contact)}]
(merge (add-browser-fx cofx browser) (merge (add-browser-fx cofx browser)
{:dispatch [:navigate-to :browser {:browser/browser-id (:browser-id browser)}]})))) {:dispatch [:navigate-to :browser {:browser/browser-id (:browser-id browser)}]}))))
(handlers/register-handler-fx (handlers/register-handler-fx
:open-browser :open-browser
[re-frame/trim-v] [re-frame/trim-v]
(fn [{:keys [now] :as cofx} [browser]] (fn [{:keys [now] :as cofx} [browser]]
(let [new-browser (get-new-browser browser now)] (let [new-browser (get-new-browser browser now)]
(merge (add-browser-fx cofx new-browser) (merge (add-browser-fx cofx new-browser)
{:dispatch [:navigate-to :browser {:browser/browser-id (:browser-id new-browser)}]})))) {:dispatch [:navigate-to :browser {:browser/browser-id (:browser-id new-browser)}]}))))
(handlers/register-handler-fx (handlers/register-handler-fx
:update-browser :update-browser
[re-frame/trim-v] [re-frame/trim-v]
(fn [{:keys [db now] :as cofx} [browser]] (fn [{:keys [db now] :as cofx} [browser]]
(let [new-browser (get-new-browser browser now)] (let [new-browser (get-new-browser browser now)]
(-> (add-browser-fx cofx new-browser) (-> (add-browser-fx cofx new-browser)
(update-in [:db :browser/options] #(assoc % :browser-id (:browser-id new-browser))))))) (update-in [:db :browser/options] #(assoc % :browser-id (:browser-id new-browser)))))))
(handlers/register-handler-fx (handlers/register-handler-fx
:update-browser-options :update-browser-options
[re-frame/trim-v] [re-frame/trim-v]
(fn [{:keys [db now] :as cofx} [options]] (fn [{:keys [db now] :as cofx} [options]]
{:db (update db :browser/options merge options)})) {:db (update db :browser/options merge options)}))
(handlers/register-handler-fx (handlers/register-handler-fx
:remove-browser :remove-browser
[re-frame/trim-v] [re-frame/trim-v]
(fn [{:keys [db]} [browser-id]] (fn [{:keys [db]} [browser-id]]
{:db (update-in db [:browser/browsers] dissoc browser-id) {:db (update-in db [:browser/browsers] dissoc browser-id)
:data-store/remove-browser browser-id})) :data-store/remove-browser browser-id}))

View File

@ -4,8 +4,8 @@
(re-frame/reg-sub :browsers :browser/browsers) (re-frame/reg-sub :browsers :browser/browsers)
(re-frame/reg-sub (re-frame/reg-sub
:get-current-browser :get-current-browser
:<- [:get :browser/options] :<- [:get :browser/options]
:<- [:browsers] :<- [:browsers]
(fn [[options browsers]] (fn [[options browsers]]
(get browsers (:browser-id options)))) (get browsers (:browser-id options))))

View File

@ -51,13 +51,13 @@
(defn web-view-error [] (defn web-view-error []
(reagent/as-element (reagent/as-element
[react/view styles/web-view-error [react/view styles/web-view-error
[react/text (i18n/label :t/web-view-error)]])) [react/text (i18n/label :t/web-view-error)]]))
(defn web-view-loading [] (defn web-view-loading []
(reagent/as-element (reagent/as-element
[react/view styles/web-view-loading [react/view styles/web-view-loading
[components/activity-indicator {:animating true}]])) [components/activity-indicator {:animating true}]]))
(defn on-navigation-change [event browser] (defn on-navigation-change [event browser]
(let [{:strs [url title canGoBack canGoForward]} (js->clj event)] (let [{:strs [url title canGoBack canGoForward]} (js->clj event)]

View File

@ -40,7 +40,6 @@
:on-press #(when click-handler :on-press #(when click-handler
(click-handler row action params))}])) (click-handler row action params))}]))
(defview contact-list-modal [] (defview contact-list-modal []
(letsubs [contacts [:all-added-people-contacts] (letsubs [contacts [:all-added-people-contacts]
click-handler [:get :contacts/click-handler] click-handler [:get :contacts/click-handler]

View File

@ -21,9 +21,9 @@
:chat-id public-key :chat-id public-key
:contact-info (prn-str contact-props)}] :contact-info (prn-str contact-props)}]
(handlers-macro/merge-fx cofx (handlers-macro/merge-fx cofx
{:db (update-in db [:contacts/contacts public-key] merge contact-props) {:db (update-in db [:contacts/contacts public-key] merge contact-props)
:data-store/save-contact contact-props} :data-store/save-contact contact-props}
(chat.models/upsert-chat chat-props))))) (chat.models/upsert-chat chat-props)))))
(defn receive-contact-request-confirmation (defn receive-contact-request-confirmation
[public-key {:keys [name profile-image address fcm-token]} [public-key {:keys [name profile-image address fcm-token]}
@ -38,10 +38,9 @@
chat-props {:name name chat-props {:name name
:chat-id public-key}] :chat-id public-key}]
(handlers-macro/merge-fx cofx (handlers-macro/merge-fx cofx
{:db (update-in db [:contacts/contacts public-key] merge contact-props) {:db (update-in db [:contacts/contacts public-key] merge contact-props)
:data-store/save-contact contact-props} :data-store/save-contact contact-props}
(chat.models/upsert-chat chat-props))))) (chat.models/upsert-chat chat-props)))))
(defn- update-contact [{:keys [whisper-identity] :as contact} {:keys [db]}] (defn- update-contact [{:keys [whisper-identity] :as contact} {:keys [db]}]
(when (get-in db [:contacts/contacts whisper-identity]) (when (get-in db [:contacts/contacts whisper-identity])
@ -59,7 +58,7 @@
:last-updated now}] :last-updated now}]
(if (chats public-key) (if (chats public-key)
(handlers-macro/merge-fx cofx (handlers-macro/merge-fx cofx
(update-contact contact) (update-contact contact)
(chat.models/upsert-chat {:chat-id chat-id (chat.models/upsert-chat {:chat-id chat-id
:name name})) :name name}))
(update-contact contact cofx)))))))) (update-contact contact cofx))))))))

View File

@ -38,29 +38,29 @@
(spec/def :contact/contact (spec/def :contact/contact
(allowed-keys (allowed-keys
:req-un [:contact/name] :req-un [:contact/name]
:opt-un [:contact/whisper-identity :opt-un [:contact/whisper-identity
:contact/address :contact/address
:contact/public-key :contact/public-key
:contact/photo-path :contact/photo-path
:contact/status :contact/status
:contact/last-updated :contact/last-updated
:contact/last-online :contact/last-online
:contact/pending? :contact/pending?
:contact/hide-contact? :contact/hide-contact?
:contact/unremovable? :contact/unremovable?
:contact/dapp? :contact/dapp?
:contact/dapp-url :contact/dapp-url
:contact/dapp-hash :contact/dapp-hash
:contact/bot-url :contact/bot-url
:contact/jail-loaded? :contact/jail-loaded?
:contact/jail-loaded-events :contact/jail-loaded-events
:contact/command :contact/command
:contact/response :contact/response
:contact/debug? :contact/debug?
:contact/subscriptions :contact/subscriptions
:contact/fcm-token :contact/fcm-token
:contact/description])) :contact/description]))
;;Contact list ui props ;;Contact list ui props
(spec/def :contact-list-ui/edit? boolean?) (spec/def :contact-list-ui/edit? boolean?)
@ -68,7 +68,6 @@
;;Contacts ui props ;;Contacts ui props
(spec/def :contacts-ui/edit? boolean?) (spec/def :contacts-ui/edit? boolean?)
(spec/def :contacts/contacts (spec/nilable (spec/map-of :global/not-empty-string :contact/contact))) (spec/def :contacts/contacts (spec/nilable (spec/map-of :global/not-empty-string :contact/contact)))
;public key of new contact during adding this new contact ;public key of new contact during adding this new contact
(spec/def :contacts/new-identity (spec/nilable string?)) (spec/def :contacts/new-identity (spec/nilable string?))

View File

@ -26,12 +26,12 @@
:data-store/save-contact contact})) :data-store/save-contact contact}))
(handlers/register-handler-fx (handlers/register-handler-fx
:load-contacts :load-contacts
[(re-frame/inject-cofx :data-store/get-all-contacts)] [(re-frame/inject-cofx :data-store/get-all-contacts)]
(fn [{:keys [db all-contacts]} _] (fn [{:keys [db all-contacts]} _]
(let [contacts-list (map #(vector (:whisper-identity %) %) all-contacts) (let [contacts-list (map #(vector (:whisper-identity %) %) all-contacts)
contacts (into {} contacts-list)] contacts (into {} contacts-list)]
{:db (update db :contacts/contacts #(merge contacts %))}))) {:db (update db :contacts/contacts #(merge contacts %))})))
(defn- add-new-contact [{:keys [whisper-identity] :as contact} {:keys [db]}] (defn- add-new-contact [{:keys [whisper-identity] :as contact} {:keys [db]}]
(let [new-contact (assoc contact :pending? false)] (let [new-contact (assoc contact :pending? false)]
@ -64,69 +64,69 @@
(defn add-contact [whisper-id {:keys [db] :as cofx}] (defn add-contact [whisper-id {:keys [db] :as cofx}]
(let [contact (build-contact whisper-id cofx)] (let [contact (build-contact whisper-id cofx)]
(handlers-macro/merge-fx cofx (handlers-macro/merge-fx cofx
(add-new-contact contact) (add-new-contact contact)
(send-contact-request contact)))) (send-contact-request contact))))
(defn add-contact-and-open-chat [whisper-id cofx] (defn add-contact-and-open-chat [whisper-id cofx]
(handlers-macro/merge-fx cofx (handlers-macro/merge-fx cofx
(navigation/navigate-to-clean :home) (navigation/navigate-to-clean :home)
(add-contact whisper-id) (add-contact whisper-id)
(chat.events/start-chat whisper-id {}))) (chat.events/start-chat whisper-id {})))
(handlers/register-handler-fx (handlers/register-handler-fx
:add-contact :add-contact
[(re-frame/inject-cofx :random-id)] [(re-frame/inject-cofx :random-id)]
(fn [cofx [_ whisper-id]] (fn [cofx [_ whisper-id]]
(add-contact whisper-id cofx))) (add-contact whisper-id cofx)))
(handlers/register-handler-fx (handlers/register-handler-fx
:set-contact-identity-from-qr :set-contact-identity-from-qr
[(re-frame/inject-cofx :random-id)] [(re-frame/inject-cofx :random-id)]
(fn [{:keys [db] :as cofx} [_ _ contact-identity]] (fn [{:keys [db] :as cofx} [_ _ contact-identity]]
(let [current-account (:account/account db) (let [current-account (:account/account db)
fx {:db (assoc db :contacts/new-identity contact-identity)}] fx {:db (assoc db :contacts/new-identity contact-identity)}]
(if (new-chat.db/validate-pub-key contact-identity current-account) (if (new-chat.db/validate-pub-key contact-identity current-account)
fx fx
(handlers-macro/merge-fx cofx (handlers-macro/merge-fx cofx
fx fx
(add-contact-and-open-chat contact-identity)))))) (add-contact-and-open-chat contact-identity))))))
(handlers/register-handler-fx (handlers/register-handler-fx
:hide-contact :hide-contact
(fn [cofx [_ {:keys [whisper-identity] :as contact}]] (fn [cofx [_ {:keys [whisper-identity] :as contact}]]
(update-contact {:whisper-identity whisper-identity (update-contact {:whisper-identity whisper-identity
:pending? true} :pending? true}
cofx))) cofx)))
;;used only by status-dev-cli ;;used only by status-dev-cli
(handlers/register-handler-fx (handlers/register-handler-fx
:remove-contact :remove-contact
(fn [{:keys [db]} [_ whisper-identity]] (fn [{:keys [db]} [_ whisper-identity]]
(when-let [contact (get-in db [:contacts/contacts whisper-identity])] (when-let [contact (get-in db [:contacts/contacts whisper-identity])]
{:db (update db :contacts/contacts dissoc whisper-identity) {:db (update db :contacts/contacts dissoc whisper-identity)
:data-store/delete-contact contact}))) :data-store/delete-contact contact})))
(handlers/register-handler-db (handlers/register-handler-db
:open-contact-toggle-list :open-contact-toggle-list
(fn [db [_ group-type]] (fn [db [_ group-type]]
(-> (assoc db (-> (assoc db
:group/group-type group-type :group/group-type group-type
:group/selected-contacts #{} :group/selected-contacts #{}
:new-chat-name "") :new-chat-name "")
(navigation/navigate-to :contact-toggle-list)))) (navigation/navigate-to :contact-toggle-list))))
(handlers/register-handler-fx (handlers/register-handler-fx
:open-chat-with-contact :open-chat-with-contact
[(re-frame/inject-cofx :random-id)] [(re-frame/inject-cofx :random-id)]
(fn [{:keys [db] :as cofx} [_ {:keys [whisper-identity] :as contact}]] (fn [{:keys [db] :as cofx} [_ {:keys [whisper-identity] :as contact}]]
(handlers-macro/merge-fx cofx (handlers-macro/merge-fx cofx
(navigation/navigate-to-clean :home) (navigation/navigate-to-clean :home)
(add-contact whisper-identity) (add-contact whisper-identity)
(chat.events/start-chat whisper-identity {})))) (chat.events/start-chat whisper-identity {}))))
(handlers/register-handler-fx (handlers/register-handler-fx
:add-contact-handler :add-contact-handler
[(re-frame/inject-cofx :random-id)] [(re-frame/inject-cofx :random-id)]
(fn [{{:contacts/keys [new-identity] :as db} :db :as cofx} _] (fn [{{:contacts/keys [new-identity] :as db} :db :as cofx} _]
(when (seq new-identity) (when (seq new-identity)
(add-contact-and-open-chat new-identity cofx)))) (add-contact-and-open-chat new-identity cofx))))

View File

@ -11,5 +11,5 @@
(defmethod nav/preload-data! :contact-list-modal (defmethod nav/preload-data! :contact-list-modal
[db [_ _ {:keys [handler action params]}]] [db [_ _ {:keys [handler action params]}]]
(assoc db :contacts/click-handler handler (assoc db :contacts/click-handler handler
:contacts/click-action action :contacts/click-action action
:contacts/click-params params)) :contacts/click-params params))

View File

@ -60,7 +60,7 @@
(def group-icon (def group-icon
(assoc option-inner-image (assoc option-inner-image
:tint-color common/color-gray)) :tint-color common/color-gray))
; New contact ; New contact

View File

@ -10,16 +10,16 @@
(reg-sub :get-contacts :contacts/contacts) (reg-sub :get-contacts :contacts/contacts)
(reg-sub :get-current-contact (reg-sub :get-current-contact
:<- [:get-contacts] :<- [:get-contacts]
:<- [:get-current-contact-identity] :<- [:get-current-contact-identity]
(fn [[contacts identity]] (fn [[contacts identity]]
(contacts identity))) (contacts identity)))
(reg-sub :get-current-chat-contact (reg-sub :get-current-chat-contact
:<- [:get-contacts] :<- [:get-contacts]
:<- [:get-current-chat-id] :<- [:get-current-chat-id]
(fn [[contacts chat-id]] (fn [[contacts chat-id]]
(get contacts chat-id))) (get contacts chat-id)))
(defn sort-contacts [contacts] (defn sort-contacts [contacts]
(sort (fn [c1 c2] (sort (fn [c1 c2]
@ -30,67 +30,67 @@
(vals contacts))) (vals contacts)))
(reg-sub :all-added-contacts (reg-sub :all-added-contacts
:<- [:get-contacts] :<- [:get-contacts]
(fn [contacts] (fn [contacts]
(->> contacts (->> contacts
(remove (fn [[_ {:keys [pending? hide-contact?]}]] (remove (fn [[_ {:keys [pending? hide-contact?]}]]
(or pending? hide-contact?))) (or pending? hide-contact?)))
(sort-contacts)))) (sort-contacts))))
(reg-sub :all-added-people-contacts (reg-sub :all-added-people-contacts
:<- [:all-added-contacts] :<- [:all-added-contacts]
(fn [contacts] (fn [contacts]
(remove :dapp? contacts))) (remove :dapp? contacts)))
(reg-sub :all-dapp-with-url-contacts (reg-sub :all-dapp-with-url-contacts
:<- [:all-added-contacts] :<- [:all-added-contacts]
:<- [:get-current-account] :<- [:get-current-account]
(fn [[contacts {:keys [dev-mode?]}]] (fn [[contacts {:keys [dev-mode?]}]]
(filter #(and (:dapp? %) (:dapp-url %) (or dev-mode? (filter #(and (:dapp? %) (:dapp-url %) (or dev-mode?
(not= "simple-dapp" (:whisper-identity %)))) (not= "simple-dapp" (:whisper-identity %))))
contacts))) contacts)))
(reg-sub :get-people-in-current-chat (reg-sub :get-people-in-current-chat
:<- [:get-current-chat-contacts] :<- [:get-current-chat-contacts]
(fn [contacts] (fn [contacts]
(remove #(true? (:dapp? %)) contacts))) (remove #(true? (:dapp? %)) contacts)))
(defn filter-group-contacts [group-contacts contacts] (defn filter-group-contacts [group-contacts contacts]
(let [group-contacts' (into #{} group-contacts)] (let [group-contacts' (into #{} group-contacts)]
(filter #(group-contacts' (:whisper-identity %)) contacts))) (filter #(group-contacts' (:whisper-identity %)) contacts)))
(reg-sub :get-all-added-group-contacts (reg-sub :get-all-added-group-contacts
:<- [:all-added-contacts] :<- [:all-added-contacts]
:<- [:get-contact-groups] :<- [:get-contact-groups]
(fn [[contacts contact-groups] [_ group-id]] (fn [[contacts contact-groups] [_ group-id]]
(filter-group-contacts (get-in contact-groups [group-id :contacts]) contacts))) (filter-group-contacts (get-in contact-groups [group-id :contacts]) contacts)))
(reg-sub :get-contact-by-identity (reg-sub :get-contact-by-identity
:<- [:get-contacts] :<- [:get-contacts]
(fn [contacts [_ identity]] (fn [contacts [_ identity]]
(get contacts identity))) (get contacts identity)))
(reg-sub :get-contact-name-by-identity (reg-sub :get-contact-name-by-identity
:<- [:get-contacts] :<- [:get-contacts]
:<- [:get-current-account] :<- [:get-current-account]
(fn [[contacts current-account] [_ identity]] (fn [[contacts current-account] [_ identity]]
(let [me? (= (:public-key current-account) identity)] (let [me? (= (:public-key current-account) identity)]
(if me? (if me?
(:name current-account) (:name current-account)
(:name (contacts identity)))))) (:name (contacts identity))))))
(defn query-chat-contacts [[{:keys [contacts group-admin]} all-contacts] [_ query-fn]] (defn query-chat-contacts [[{:keys [contacts group-admin]} all-contacts] [_ query-fn]]
(let [participant-set (into #{} (filter identity) (conj contacts group-admin))] (let [participant-set (into #{} (filter identity) (conj contacts group-admin))]
(query-fn (comp participant-set :whisper-identity) (vals all-contacts)))) (query-fn (comp participant-set :whisper-identity) (vals all-contacts))))
(reg-sub :query-current-chat-contacts (reg-sub :query-current-chat-contacts
:<- [:get-current-chat] :<- [:get-current-chat]
:<- [:get-contacts] :<- [:get-contacts]
query-chat-contacts) query-chat-contacts)
(reg-sub :get-all-contacts-not-in-current-chat (reg-sub :get-all-contacts-not-in-current-chat
:<- [:query-current-chat-contacts remove] :<- [:query-current-chat-contacts remove]
identity) identity)
(defn get-all-contacts-in-group-chat [chat-contact-ids group-admin-id contacts current-account] (defn get-all-contacts-in-group-chat [chat-contact-ids group-admin-id contacts current-account]
(let [participant-set (into #{} (filter identity) (conj chat-contact-ids group-admin-id)) (let [participant-set (into #{} (filter identity) (conj chat-contact-ids group-admin-id))
@ -103,33 +103,33 @@
participant-set))) participant-set)))
(reg-sub :get-current-chat-contacts (reg-sub :get-current-chat-contacts
:<- [:get-current-chat] :<- [:get-current-chat]
:<- [:get-contacts] :<- [:get-contacts]
:<- [:get-current-account] :<- [:get-current-account]
(fn [[{:keys [contacts group-admin]} all-contacts current-account]] (fn [[{:keys [contacts group-admin]} all-contacts current-account]]
(get-all-contacts-in-group-chat contacts group-admin all-contacts current-account))) (get-all-contacts-in-group-chat contacts group-admin all-contacts current-account)))
(reg-sub :get-contacts-by-chat (reg-sub :get-contacts-by-chat
(fn [[_ _ chat-id] _] (fn [[_ _ chat-id] _]
[(subscribe [:get-chat chat-id]) [(subscribe [:get-chat chat-id])
(subscribe [:get-contacts])]) (subscribe [:get-contacts])])
query-chat-contacts) query-chat-contacts)
(reg-sub :get-chat-photo (reg-sub :get-chat-photo
(fn [[_ chat-id] _] (fn [[_ chat-id] _]
[(subscribe [:get-chat chat-id]) [(subscribe [:get-chat chat-id])
(subscribe [:get-contacts-by-chat filter chat-id])]) (subscribe [:get-contacts-by-chat filter chat-id])])
(fn [[chat contacts] [_ chat-id]] (fn [[chat contacts] [_ chat-id]]
(when (and chat (not (:group-chat chat))) (when (and chat (not (:group-chat chat)))
(cond (cond
(:photo-path chat) (:photo-path chat)
(:photo-path chat) (:photo-path chat)
(pos? (count contacts)) (pos? (count contacts))
(:photo-path (first contacts)) (:photo-path (first contacts))
:else :else
(identicon/identicon chat-id))))) (identicon/identicon chat-id)))))
(defn- address= [{:keys [address] :as contact} s] (defn- address= [{:keys [address] :as contact} s]
(when (and address (= (ethereum/normalized-address s) (when (and address (= (ethereum/normalized-address s)
@ -141,16 +141,16 @@
contact)) contact))
(reg-sub :get-contact-by-address (reg-sub :get-contact-by-address
:<- [:get-contacts] :<- [:get-contacts]
(fn [contacts [_ address]] (fn [contacts [_ address]]
(some #(contact-by-address % address) contacts))) (some #(contact-by-address % address) contacts)))
(reg-sub :get-contacts-by-address (reg-sub :get-contacts-by-address
:<- [:get-contacts] :<- [:get-contacts]
(fn [contacts] (fn [contacts]
(reduce (fn [acc [_ {:keys [address] :as contact}]] (reduce (fn [acc [_ {:keys [address] :as contact}]]
(if address (if address
(assoc acc address contact) (assoc acc address contact)
acc)) acc))
{} {}
contacts))) contacts)))

View File

@ -137,107 +137,107 @@
(spec/def ::device-UUID (spec/nilable string?)) (spec/def ::device-UUID (spec/nilable string?))
(spec/def ::db (allowed-keys (spec/def ::db (allowed-keys
:opt :opt
[:contacts/contacts [:contacts/contacts
:contacts/new-identity :contacts/new-identity
:contacts/new-public-key-error :contacts/new-public-key-error
:contacts/identity :contacts/identity
:contacts/ui-props :contacts/ui-props
:contacts/list-ui-props :contacts/list-ui-props
:contacts/click-handler :contacts/click-handler
:contacts/click-action :contacts/click-action
:contacts/click-params :contacts/click-params
:group/contact-groups :group/contact-groups
:group/contact-group-id :group/contact-group-id
:group/group-type :group/group-type
:group/selected-contacts :group/selected-contacts
:group/groups-order :group/groups-order
:accounts/accounts :accounts/accounts
:accounts/create :accounts/create
:accounts/recover :accounts/recover
:accounts/login :accounts/login
:account/account :account/account
:my-profile/profile :my-profile/profile
:my-profile/default-name :my-profile/default-name
:my-profile/editing? :my-profile/editing?
:my-profile/advanced? :my-profile/advanced?
:my-profile/seed :my-profile/seed
:group-chat-profile/profile :group-chat-profile/profile
:group-chat-profile/editing? :group-chat-profile/editing?
:networks/selected-network :networks/selected-network
:networks/networks :networks/networks
:node/after-start :node/after-start
:node/after-stop :node/after-stop
:inbox/wnodes :inbox/wnodes
:inbox/password :inbox/password
:inbox/sym-key-id :inbox/sym-key-id
:inbox/last-request :inbox/last-request
:browser/browsers :browser/browsers
:browser/options :browser/options
:new/open-dapp :new/open-dapp
:navigation/screen-params :navigation/screen-params
:transport/message-envelopes :transport/message-envelopes
:transport/chats :transport/chats
:transport/discovery-filter :transport/discovery-filter
:desktop/desktop] :desktop/desktop]
:opt-un :opt-un
[::current-public-key [::current-public-key
::modal ::modal
::was-modal? ::was-modal?
::rpc-url ::rpc-url
::web3 ::web3
::webview-bridge ::webview-bridge
::status-module-initialized? ::status-module-initialized?
::status-node-started? ::status-node-started?
::keyboard-height ::keyboard-height
::keyboard-max-height ::keyboard-max-height
::tab-bar-visible? ::tab-bar-visible?
::network-status ::network-status
::mailserver-status ::mailserver-status
::peers-count ::peers-count
::sync-listening-started ::sync-listening-started
::sync-state ::sync-state
::sync-data ::sync-data
::network ::network
:navigation/view-id :navigation/view-id
:navigation/navigation-stack :navigation/navigation-stack
:navigation/prev-tab-view-id :navigation/prev-tab-view-id
:navigation/prev-view-id :navigation/prev-view-id
:qr/qr-codes :qr/qr-codes
:qr/qr-modal :qr/qr-modal
:qr/current-qr-context :qr/current-qr-context
:chat/chats :chat/chats
:chat/current-chat-id :chat/current-chat-id
:chat/chat-id :chat/chat-id
:chat/new-chat :chat/new-chat
:chat/new-chat-name :chat/new-chat-name
:chat/chat-animations :chat/chat-animations
:chat/chat-ui-props :chat/chat-ui-props
:chat/chat-list-ui-props :chat/chat-list-ui-props
:chat/layout-height :chat/layout-height
:chat/expandable-view-height-to-value :chat/expandable-view-height-to-value
:chat/message-data :chat/message-data
:chat/message-status :chat/message-status
:chat/selected-participants :chat/selected-participants
:chat/chat-loaded-callbacks :chat/chat-loaded-callbacks
:chat/public-group-topic :chat/public-group-topic
:chat/public-group-topic-error :chat/public-group-topic-error
:chat/messages :chat/messages
:chat/not-loaded-message-ids :chat/not-loaded-message-ids
:chat/last-clock-value :chat/last-clock-value
:chat/loaded-chats :chat/loaded-chats
:chat/bot-db :chat/bot-db
:commands/access-scope->commands-responses :commands/access-scope->commands-responses
:discoveries/discoveries :discoveries/discoveries
:discoveries/discover-search-tags :discoveries/discover-search-tags
:discoveries/discover-current-dapp :discoveries/discover-current-dapp
:discoveries/tags :discoveries/tags
:discoveries/current-tag :discoveries/current-tag
:discoveries/request-discoveries-timer :discoveries/request-discoveries-timer
:wallet/wallet :wallet/wallet
:wallet/wallet.transactions :wallet/wallet.transactions
:wallet/wallet-selected-asset :wallet/wallet-selected-asset
:prices/prices :prices/prices
:prices/prices-loading? :prices/prices-loading?
:notifications/notifications :notifications/notifications
::device-UUID])) ::device-UUID]))

View File

@ -16,11 +16,11 @@
(views/letsubs [{:keys [chat-id name public-key public? group-chat]} [:get-current-chat] (views/letsubs [{:keys [chat-id name public-key public? group-chat]} [:get-current-chat]
{:keys [pending?]} [:get-current-chat-contact]] {:keys [pending?]} [:get-current-chat-contact]]
(let [chat-name (str (let [chat-name (str
(if public? "#" "") (if public? "#" "")
(if (string/blank? name) (if (string/blank? name)
(gfycat.core/generate-gfy public-key) (gfycat.core/generate-gfy public-key)
(or name (or name
"Chat name")))] "Chat name")))]
[react/view {:style {:align-items :center :padding 11 :justify-content :center}} [react/view {:style {:align-items :center :padding 11 :justify-content :center}}
[react/view {:style {:flex-direction :row}} [react/view {:style {:flex-direction :row}}
(when public? (when public?
@ -77,31 +77,31 @@
[react/view {:style {:height 1 :background-color "#e8ebec"}}]] [react/view {:style {:height 1 :background-color "#e8ebec"}}]]
(when (= content-type constants/text-content-type) (when (= content-type constants/text-content-type)
(reagent.core/create-class (reagent.core/create-class
{:component-did-mount {:component-did-mount
#(when (and message-id #(when (and message-id
chat-id chat-id
(not outgoing) (not outgoing)
(not= :seen message-status) (not= :seen message-status)
(not= :seen (keyword (get-in user-statuses [current-public-key :status])))) (not= :seen (keyword (get-in user-statuses [current-public-key :status]))))
(re-frame/dispatch [:send-seen! {:chat-id chat-id (re-frame/dispatch [:send-seen! {:chat-id chat-id
:from from :from from
:message-id message-id}])) :message-id message-id}]))
:reagent-render :reagent-render
(fn [] (fn []
^{:key (str "message" message-id)} ^{:key (str "message" message-id)}
[react/view {:style {:flex-direction :row :flex 1 :margin-vertical 12}} [react/view {:style {:flex-direction :row :flex 1 :margin-vertical 12}}
(if outgoing (if outgoing
[my-photo from] [my-photo from]
[member-photo from]) [member-photo from])
[react/view {:style {:padding-horizontal 12 :background-color :white :border-radius 8 :flex 1}} [react/view {:style {:padding-horizontal 12 :background-color :white :border-radius 8 :flex 1}}
[react/view {:style {:flex-direction :row}} [react/view {:style {:flex-direction :row}}
[message-author-name message] [message-author-name message]
[react/view {:style {:flex 1}}] [react/view {:style {:flex 1}}]
[react/text {:style {:color styles/color-gray4 :font-size 12}} (time/timestamp->time timestamp)]] [react/text {:style {:color styles/color-gray4 :font-size 12}} (time/timestamp->time timestamp)]]
;;TODO use https://github.com/status-im/status-react/pull/3299 ;;TODO use https://github.com/status-im/status-react/pull/3299
;;[rn-hl/hyperlink {:linkStyle {:color "#2980b9"} :on-press #(re-frame/dispatch [:show-link-dialog %1])} ;;[rn-hl/hyperlink {:linkStyle {:color "#2980b9"} :on-press #(re-frame/dispatch [:show-link-dialog %1])}
[react/text [react/text
text]]])})))) text]]])}))))
(views/defview messages-view [{:keys [chat-id group-chat]}] (views/defview messages-view [{:keys [chat-id group-chat]}]
(views/letsubs [chat-id* (atom nil) (views/letsubs [chat-id* (atom nil)
@ -116,20 +116,20 @@
[react/view {:style {:flex 1 :background-color :white :margin-horizontal 16}} [react/view {:style {:flex 1 :background-color :white :margin-horizontal 16}}
[react/scroll-view {:scrollEventThrottle 16 [react/scroll-view {:scrollEventThrottle 16
:on-scroll (fn [e] :on-scroll (fn [e]
(let [ne (.-nativeEvent e) (let [ne (.-nativeEvent e)
y (.-y (.-contentOffset ne))] y (.-y (.-contentOffset ne))]
(when (zero? y) (when (zero? y)
(when @scroll-timer (js/clearTimeout @scroll-timer)) (when @scroll-timer (js/clearTimeout @scroll-timer))
(reset! scroll-timer (js/setTimeout #(re-frame/dispatch [:load-more-messages]) 300))) (reset! scroll-timer (js/setTimeout #(re-frame/dispatch [:load-more-messages]) 300)))
(reset! scroll-height (+ y (.-height (.-layoutMeasurement ne)))))) (reset! scroll-height (+ y (.-height (.-layoutMeasurement ne))))))
:on-content-size-change #(when (or (not @scroll-height) (< (- %2 @scroll-height) 500)) :on-content-size-change #(when (or (not @scroll-height) (< (- %2 @scroll-height) 500))
(.scrollToEnd @scroll-ref)) (.scrollToEnd @scroll-ref))
:ref #(reset! scroll-ref %)} :ref #(reset! scroll-ref %)}
[react/view {:style {:padding-vertical 60}} [react/view {:style {:padding-vertical 60}}
(doall (doall
(for [[index {:keys [from content message-id] :as message-obj}] (map-indexed vector (reverse @messages))] (for [[index {:keys [from content message-id] :as message-obj}] (map-indexed vector (reverse @messages))]
^{:key (str message index)} ^{:key (str message index)}
[message content (= from @current-public-key) (assoc message-obj :group-chat group-chat)]))]]]))) [message content (= from @current-public-key) (assoc message-obj :group-chat group-chat)]))]]])))
(views/defview chat-text-input [] (views/defview chat-text-input []
(views/letsubs [{:keys [input-text]} [:get-current-chat] (views/letsubs [{:keys [input-text]} [:get-current-chat]
@ -157,10 +157,10 @@
text (.-text native-event)] text (.-text native-event)]
(re-frame/dispatch [:set-chat-input-text text])))}]] (re-frame/dispatch [:set-chat-input-text text])))}]]
[react/touchable-highlight {:on-press (fn [] [react/touchable-highlight {:on-press (fn []
(js/setTimeout #(do (.clear @inp-ref)(.focus @inp-ref)) 200) (js/setTimeout #(do (.clear @inp-ref) (.focus @inp-ref)) 200)
(re-frame/dispatch [:send-current-message]))} (re-frame/dispatch [:send-current-message]))}
[react/view {:style {:margin-left 16 :width 30 :height 30 :border-radius 15 :background-color "#eef2f5" :align-items :center [react/view {:style {:margin-left 16 :width 30 :height 30 :border-radius 15 :background-color "#eef2f5" :align-items :center
:justify-content :center :transform [{ :rotate "90deg"}]}} :justify-content :center :transform [{:rotate "90deg"}]}}
[icons/icon :icons/arrow-left]]]]])) [icons/icon :icons/arrow-left]]]]]))
(views/defview chat-view [] (views/defview chat-view []

View File

@ -14,9 +14,9 @@
(views/defview chat-list-item-inner-view [{:keys [chat-id name group-chat public? public-key]}] (views/defview chat-list-item-inner-view [{:keys [chat-id name group-chat public? public-key]}]
(let [name (str (let [name (str
(if public? "#" "") (if public? "#" "")
(or name (or name
(gfycat/generate-gfy public-key)))] (gfycat/generate-gfy public-key)))]
[react/view {:style {:padding 12 :background-color :white :flex-direction :row :align-items :center}} [react/view {:style {:padding 12 :background-color :white :flex-direction :row :align-items :center}}
(when public? (when public?
[icons/icon :icons/public-chat]) [icons/icon :icons/public-chat])

View File

@ -37,8 +37,8 @@
[my-profile-info current-account]] [my-profile-info current-account]]
[react/view {:style {:height 1 :background-color "#e8ebec" :margin-horizontal 16}}] [react/view {:style {:height 1 :background-color "#e8ebec" :margin-horizontal 16}}]
[react/touchable-highlight {:on-press #(keychain/get-encryption-key-then [react/touchable-highlight {:on-press #(keychain/get-encryption-key-then
(fn [encryption-key] (fn [encryption-key]
(re-frame/dispatch [:logout encryption-key]))) (re-frame/dispatch [:logout encryption-key])))
:style {:margin-top 60}} :style {:margin-top 60}}
[react/view [react/view
[react/text {:style {:color :red}} "Log out"]]]])) [react/text {:style {:color :red}} "Log out"]]]]))

View File

@ -88,25 +88,25 @@
;;;; FX ;;;; FX
(re-frame/reg-fx (re-frame/reg-fx
:call-jail :call-jail
(fn [{:keys [callback-event-creator] :as opts}] (fn [{:keys [callback-event-creator] :as opts}]
(status/call-jail (status/call-jail
(-> opts (-> opts
(dissoc :callback-event-creator) (dissoc :callback-event-creator)
(assoc :callback (assoc :callback
(fn [jail-response] (fn [jail-response]
(when-let [event (callback-event-creator jail-response)] (when-let [event (callback-event-creator jail-response)]
(re-frame/dispatch event)))))))) (re-frame/dispatch event))))))))
(re-frame/reg-fx (re-frame/reg-fx
:call-jail-function :call-jail-function
call-jail-function) call-jail-function)
(re-frame/reg-fx (re-frame/reg-fx
:call-jail-function-n :call-jail-function-n
(fn [opts-seq] (fn [opts-seq]
(doseq [opts opts-seq] (doseq [opts opts-seq]
(call-jail-function opts)))) (call-jail-function opts))))
(defn- http-get [{:keys [url response-validator success-event-creator failure-event-creator timeout-ms]}] (defn- http-get [{:keys [url response-validator success-event-creator failure-event-creator timeout-ms]}]
(let [on-success #(re-frame/dispatch (success-event-creator %)) (let [on-success #(re-frame/dispatch (success-event-creator %))
@ -116,69 +116,69 @@
(http/get url on-success on-error opts))) (http/get url on-success on-error opts)))
(re-frame/reg-fx (re-frame/reg-fx
:http-get :http-get
http-get) http-get)
(re-frame/reg-fx (re-frame/reg-fx
:http-get-n :http-get-n
(fn [calls] (fn [calls]
(doseq [call calls] (doseq [call calls]
(http-get call)))) (http-get call))))
(re-frame/reg-fx (re-frame/reg-fx
::init-store ::init-store
(fn [encryption-key] (fn [encryption-key]
(data-store/init encryption-key))) (data-store/init encryption-key)))
(defn move-to-internal-storage [config] (defn move-to-internal-storage [config]
(status/move-to-internal-storage (status/move-to-internal-storage
#(status/start-node config))) #(status/start-node config)))
(re-frame/reg-fx (re-frame/reg-fx
::initialize-keychain-fx ::initialize-keychain-fx
(fn [] (fn []
(keychain/get-encryption-key-then (keychain/get-encryption-key-then
(fn [encryption-key] (fn [encryption-key]
(re-frame/dispatch [:initialize-app encryption-key]))))) (re-frame/dispatch [:initialize-app encryption-key])))))
(re-frame/reg-fx (re-frame/reg-fx
::got-encryption-key-fx ::got-encryption-key-fx
(fn [{:keys [encryption-key callback]}] (fn [{:keys [encryption-key callback]}]
(callback encryption-key))) (callback encryption-key)))
(re-frame/reg-fx (re-frame/reg-fx
:initialize-geth-fx :initialize-geth-fx
(fn [config] (fn [config]
;;TODO get rid of this, because we don't need this anymore ;;TODO get rid of this, because we don't need this anymore
(status/should-move-to-internal-storage? (status/should-move-to-internal-storage?
(fn [should-move?] (fn [should-move?]
(if should-move? (if should-move?
(re-frame/dispatch [:request-permissions {:permissions [:read-external-storage] (re-frame/dispatch [:request-permissions {:permissions [:read-external-storage]
:on-allowed #(move-to-internal-storage config)}]) :on-allowed #(move-to-internal-storage config)}])
(status/start-node config)))))) (status/start-node config))))))
(re-frame/reg-fx (re-frame/reg-fx
::status-module-initialized-fx ::status-module-initialized-fx
(fn [_] (fn [_]
(status/module-initialized!))) (status/module-initialized!)))
(re-frame/reg-fx (re-frame/reg-fx
:request-permissions-fx :request-permissions-fx
(fn [options] (fn [options]
(permissions/request-permissions options))) (permissions/request-permissions options)))
(re-frame/reg-fx (re-frame/reg-fx
::request-notifications-fx ::request-notifications-fx
(fn [_] (fn [_]
(notifications/request-permissions))) (notifications/request-permissions)))
(re-frame/reg-fx (re-frame/reg-fx
::testfairy-alert ::testfairy-alert
(fn [_] (fn [_]
(when config/testfairy-enabled? (when config/testfairy-enabled?
(utils/show-popup (utils/show-popup
(i18n/label :testfairy-title) (i18n/label :testfairy-title)
(i18n/label :testfairy-message))))) (i18n/label :testfairy-message)))))
(re-frame/reg-fx (re-frame/reg-fx
::init-device-UUID ::init-device-UUID
@ -186,47 +186,46 @@
(status/get-device-UUID #(re-frame/dispatch [:set :device-UUID %])))) (status/get-device-UUID #(re-frame/dispatch [:set :device-UUID %]))))
(re-frame/reg-fx (re-frame/reg-fx
::get-fcm-token-fx ::get-fcm-token-fx
(fn [_] (fn [_]
(notifications/get-fcm-token))) (notifications/get-fcm-token)))
(re-frame/reg-fx (re-frame/reg-fx
:show-error :show-error
(fn [content] (fn [content]
(utils/show-popup "Error" content))) (utils/show-popup "Error" content)))
(re-frame/reg-fx (re-frame/reg-fx
:show-confirmation :show-confirmation
(fn [{:keys [title content confirm-button-text on-accept on-cancel]}] (fn [{:keys [title content confirm-button-text on-accept on-cancel]}]
(utils/show-confirmation title content confirm-button-text on-accept on-cancel))) (utils/show-confirmation title content confirm-button-text on-accept on-cancel)))
(re-frame/reg-fx (re-frame/reg-fx
:close-application :close-application
(fn [_] (fn [_]
(status/close-application))) (status/close-application)))
;;;; Handlers ;;;; Handlers
(handlers/register-handler-db (handlers/register-handler-db
:set :set
(fn [db [_ k v]] (fn [db [_ k v]]
(assoc db k v))) (assoc db k v)))
(handlers/register-handler-db (handlers/register-handler-db
:set-in :set-in
(fn [db [_ path v]] (fn [db [_ path v]]
(assoc-in db path v))) (assoc-in db path v)))
(handlers/register-handler-fx (handlers/register-handler-fx
:initialize-keychain :initialize-keychain
(fn [_ _] (fn [_ _]
{::initialize-keychain-fx nil})) {::initialize-keychain-fx nil}))
(handlers/register-handler-fx (handlers/register-handler-fx
:got-encryption-key :got-encryption-key
(fn [_ [_ opts]] (fn [_ [_ opts]]
{::got-encryption-key-fx opts})) {::got-encryption-key-fx opts}))
(handlers/register-handler-fx (handlers/register-handler-fx
:initialize-app :initialize-app
@ -240,109 +239,109 @@
[:initialize-geth]]})) [:initialize-geth]]}))
(handlers/register-handler-fx (handlers/register-handler-fx
:logout :logout
(fn [{:keys [db] :as cofx} [_ encryption-key]] (fn [{:keys [db] :as cofx} [_ encryption-key]]
(let [{:transport/keys [chats]} db (let [{:transport/keys [chats]} db
sharing-usage-data? (get-in db [:account/account :sharing-usage-data?])] sharing-usage-data? (get-in db [:account/account :sharing-usage-data?])]
(handlers-macro/merge-fx cofx (handlers-macro/merge-fx cofx
{:dispatch-n (concat [[:initialize-db encryption-key] {:dispatch-n (concat [[:initialize-db encryption-key]
[:load-accounts] [:load-accounts]
[:listen-to-network-status] [:listen-to-network-status]
[:navigate-to :accounts]] [:navigate-to :accounts]]
(when sharing-usage-data? (when sharing-usage-data?
[[:unregister-mixpanel-tracking]]))} [[:unregister-mixpanel-tracking]]))}
(transport/stop-whisper))))) (transport/stop-whisper)))))
(handlers/register-handler-fx (handlers/register-handler-fx
:initialize-db :initialize-db
(fn [{{:keys [status-module-initialized? status-node-started? (fn [{{:keys [status-module-initialized? status-node-started?
network-status network] network-status network]
:or {network (get app-db :network)}} :db} :or {network (get app-db :network)}} :db}
[_ encryption-key]] [_ encryption-key]]
{::init-store encryption-key {::init-store encryption-key
:db (assoc app-db :db (assoc app-db
:contacts/contacts {} :contacts/contacts {}
:network-status network-status :network-status network-status
:status-module-initialized? (or platform/ios? js/goog.DEBUG status-module-initialized?) :status-module-initialized? (or platform/ios? js/goog.DEBUG status-module-initialized?)
:status-node-started? status-node-started? :status-node-started? status-node-started?
:network network)})) :network network)}))
(handlers/register-handler-db (handlers/register-handler-db
:initialize-account-db :initialize-account-db
(fn [{:keys [accounts/accounts accounts/create contacts/contacts networks/networks (fn [{:keys [accounts/accounts accounts/create contacts/contacts networks/networks
network network-status view-id navigation-stack network network-status view-id navigation-stack
access-scope->commands-responses access-scope->commands-responses
status-module-initialized? status-node-started?] status-module-initialized? status-node-started?]
:or [network (get app-db :network)]} [_ address]] :or [network (get app-db :network)]} [_ address]]
(let [console-contact (get contacts constants/console-chat-id) (let [console-contact (get contacts constants/console-chat-id)
current-account (accounts address)] current-account (accounts address)]
(cond-> (assoc app-db (cond-> (assoc app-db
:access-scope->commands-responses access-scope->commands-responses :access-scope->commands-responses access-scope->commands-responses
:current-public-key (:public-key current-account) :current-public-key (:public-key current-account)
:view-id view-id :view-id view-id
:navigation-stack navigation-stack :navigation-stack navigation-stack
:status-module-initialized? (or platform/ios? js/goog.DEBUG status-module-initialized?) :status-module-initialized? (or platform/ios? js/goog.DEBUG status-module-initialized?)
:status-node-started? status-node-started? :status-node-started? status-node-started?
:accounts/create create :accounts/create create
:networks/networks networks :networks/networks networks
:account/account current-account :account/account current-account
:network-status network-status :network-status network-status
:network network) :network network)
console-contact console-contact
(assoc :contacts/contacts {constants/console-chat-id console-contact}))))) (assoc :contacts/contacts {constants/console-chat-id console-contact})))))
(handlers/register-handler-fx (handlers/register-handler-fx
:initialize-account :initialize-account
(fn [_ [_ address events-after]] (fn [_ [_ address events-after]]
{:dispatch-n (cond-> [[:initialize-account-db address] {:dispatch-n (cond-> [[:initialize-account-db address]
[:initialize-protocol address] [:initialize-protocol address]
[:initialize-sync-listener] [:initialize-sync-listener]
[:load-contacts] [:load-contacts]
[:load-contact-groups] [:load-contact-groups]
[:initialize-chats] [:initialize-chats]
[:initialize-browsers] [:initialize-browsers]
[:initialize-debugging {:address address}] [:initialize-debugging {:address address}]
[:send-account-update-if-needed] [:send-account-update-if-needed]
[:process-pending-messages] [:process-pending-messages]
[:update-wallet] [:update-wallet]
[:update-transactions] [:update-transactions]
[:get-fcm-token] [:get-fcm-token]
[:update-sign-in-time]] [:update-sign-in-time]]
(seq events-after) (into events-after))})) (seq events-after) (into events-after))}))
(handlers/register-handler-fx (handlers/register-handler-fx
:initialize-views :initialize-views
(fn [{{:accounts/keys [accounts] :as db} :db} _] (fn [{{:accounts/keys [accounts] :as db} :db} _]
{:db (if (empty? accounts) {:db (if (empty? accounts)
(assoc db :view-id :intro :navigation-stack (list :intro)) (assoc db :view-id :intro :navigation-stack (list :intro))
(let [{:keys [address photo-path name]} (first (sort-by :last-sign-in > (vals accounts)))] (let [{:keys [address photo-path name]} (first (sort-by :last-sign-in > (vals accounts)))]
(-> db (-> db
(assoc :view-id :login (assoc :view-id :login
:navigation-stack (list :login)) :navigation-stack (list :login))
(update :accounts/login assoc (update :accounts/login assoc
:address address :address address
:photo-path photo-path :photo-path photo-path
:name name))))})) :name name))))}))
(handlers/register-handler-fx (handlers/register-handler-fx
:initialize-geth :initialize-geth
(fn [{db :db} _] (fn [{db :db} _]
(let [default-networks (:networks/networks db) (let [default-networks (:networks/networks db)
default-network (:network db) default-network (:network db)
{:keys [network networks]} (:account/account db) {:keys [network networks]} (:account/account db)
network-config (or (get-in networks [network :config]) network-config (or (get-in networks [network :config])
(get-in default-networks [default-network :config]))] (get-in default-networks [default-network :config]))]
{:initialize-geth-fx network-config}))) {:initialize-geth-fx network-config})))
(handlers/register-handler-fx (handlers/register-handler-fx
:webview-geo-permissions-granted :webview-geo-permissions-granted
(fn [{{:keys [webview-bridge]} :db} _] (fn [{{:keys [webview-bridge]} :db} _]
(.geoPermissionsGranted webview-bridge))) (.geoPermissionsGranted webview-bridge)))
(handlers/register-handler-fx (handlers/register-handler-fx
:get-fcm-token :get-fcm-token
(fn [_ _] (fn [_ _]
{::get-fcm-token-fx nil})) {::get-fcm-token-fx nil}))
;; Because we send command to jail in params and command `:ref` is a lookup vector with ;; Because we send command to jail in params and command `:ref` is a lookup vector with
;; keyword in it (for example `["transactor" :command 51 "send"]`), we lose that keyword ;; keyword in it (for example `["transactor" :command 51 "send"]`), we lose that keyword
@ -370,68 +369,68 @@
(log/debug "Unknown jail signal " event)))) (log/debug "Unknown jail signal " event))))
(handlers/register-handler-fx (handlers/register-handler-fx
:signal-event :signal-event
(fn [_ [_ event-str]] (fn [_ [_ event-str]]
(log/debug :event-str event-str) (log/debug :event-str event-str)
(instabug/log (str "Signal event: " event-str)) (instabug/log (str "Signal event: " event-str))
(let [{:keys [type event]} (types/json->clj event-str) (let [{:keys [type event]} (types/json->clj event-str)
to-dispatch (case type to-dispatch (case type
"sign-request.queued" [:sign-request-queued event] "sign-request.queued" [:sign-request-queued event]
"sign-request.failed" [:sign-request-failed event] "sign-request.failed" [:sign-request-failed event]
"node.started" [:status-node-started] "node.started" [:status-node-started]
"node.stopped" [:status-node-stopped] "node.stopped" [:status-node-stopped]
"module.initialized" [:status-module-initialized] "module.initialized" [:status-module-initialized]
"jail.signal" (handle-jail-signal event) "jail.signal" (handle-jail-signal event)
"envelope.sent" [:signals/envelope-status (:hash event) :sent] "envelope.sent" [:signals/envelope-status (:hash event) :sent]
"envelope.expired" [:signals/envelope-status (:hash event) :not-sent] "envelope.expired" [:signals/envelope-status (:hash event) :not-sent]
(log/debug "Event " type " not handled"))] (log/debug "Event " type " not handled"))]
(when to-dispatch (when to-dispatch
{:dispatch to-dispatch})))) {:dispatch to-dispatch}))))
(handlers/register-handler-fx (handlers/register-handler-fx
:status-module-initialized :status-module-initialized
(fn [{:keys [db]} _] (fn [{:keys [db]} _]
{:db (assoc db :status-module-initialized? true) {:db (assoc db :status-module-initialized? true)
::status-module-initialized-fx nil})) ::status-module-initialized-fx nil}))
(handlers/register-handler-fx (handlers/register-handler-fx
:status-node-started :status-node-started
(fn [{{:node/keys [after-start] :as db} :db} _] (fn [{{:node/keys [after-start] :as db} :db} _]
(merge {:db (assoc db :status-node-started? true)} (merge {:db (assoc db :status-node-started? true)}
(when after-start {:dispatch-n [after-start]})))) (when after-start {:dispatch-n [after-start]}))))
(handlers/register-handler-fx (handlers/register-handler-fx
:status-node-stopped :status-node-stopped
(fn [{{:node/keys [after-stop]} :db} _] (fn [{{:node/keys [after-stop]} :db} _]
(when after-stop {:dispatch-n [after-stop]}))) (when after-stop {:dispatch-n [after-stop]})))
(handlers/register-handler-fx (handlers/register-handler-fx
:app-state-change :app-state-change
(fn [_ [_ state]] (fn [_ [_ state]]
(status/app-state-change state))) (status/app-state-change state)))
(handlers/register-handler-fx (handlers/register-handler-fx
:request-permissions :request-permissions
(fn [_ [_ options]] (fn [_ [_ options]]
{:request-permissions-fx options})) {:request-permissions-fx options}))
(handlers/register-handler-fx (handlers/register-handler-fx
:request-notifications :request-notifications
(fn [_ _] (fn [_ _]
{::request-notifications-fx {}})) {::request-notifications-fx {}}))
(handlers/register-handler-db (handlers/register-handler-db
:set-swipe-position :set-swipe-position
[re-frame/trim-v] [re-frame/trim-v]
(fn [db [item-id value]] (fn [db [item-id value]]
(assoc-in db [:chat-animations item-id :delete-swiped] value))) (assoc-in db [:chat-animations item-id :delete-swiped] value)))
(handlers/register-handler-db (handlers/register-handler-db
:show-tab-bar :show-tab-bar
(fn [db _] (fn [db _]
(assoc db :tab-bar-visible? true))) (assoc db :tab-bar-visible? true)))
(handlers/register-handler-db (handlers/register-handler-db
:hide-tab-bar :hide-tab-bar
(fn [db _] (fn [db _]
(assoc db :tab-bar-visible? false))) (assoc db :tab-bar-visible? false)))

View File

@ -8,66 +8,65 @@
[status-im.utils.handlers :as handlers] [status-im.utils.handlers :as handlers]
[status-im.utils.handlers-macro :as handlers-macro])) [status-im.utils.handlers-macro :as handlers-macro]))
;;;; Handlers ;;;; Handlers
(handlers/register-handler-fx (handlers/register-handler-fx
:show-group-chat-profile :show-group-chat-profile
[re-frame/trim-v] [re-frame/trim-v]
(fn [{:keys [db] :as cofx} [chat-id]] (fn [{:keys [db] :as cofx} [chat-id]]
{:db (-> db {:db (-> db
(assoc :new-chat-name (get-in db [:chats chat-id :name]) (assoc :new-chat-name (get-in db [:chats chat-id :name])
:group/group-type :chat-group) :group/group-type :chat-group)
(navigation/navigate-to :group-chat-profile))})) (navigation/navigate-to :group-chat-profile))}))
(handlers/register-handler-fx (handlers/register-handler-fx
:add-new-group-chat-participants :add-new-group-chat-participants
[(re-frame/inject-cofx :random-id)] [(re-frame/inject-cofx :random-id)]
(fn [{{:keys [current-chat-id selected-participants] :as db} :db now :now message-id :random-id :as cofx} _] (fn [{{:keys [current-chat-id selected-participants] :as db} :db now :now message-id :random-id :as cofx} _]
(let [participants (concat (get-in db [:chats current-chat-id :contacts]) selected-participants) (let [participants (concat (get-in db [:chats current-chat-id :contacts]) selected-participants)
contacts (:contacts/contacts db) contacts (:contacts/contacts db)
added-participants-names (map #(get-in contacts [% :name]) selected-participants)] added-participants-names (map #(get-in contacts [% :name]) selected-participants)]
(handlers-macro/merge-fx cofx (handlers-macro/merge-fx cofx
{:db (-> db {:db (-> db
(assoc-in [:chats current-chat-id :contacts] participants) (assoc-in [:chats current-chat-id :contacts] participants)
(assoc :selected-participants #{})) (assoc :selected-participants #{}))
:data-store/add-chat-contacts (select-keys db [:current-chat-id :selected-participants])} :data-store/add-chat-contacts (select-keys db [:current-chat-id :selected-participants])}
(models.message/receive (models.message/receive
(models.message/system-message current-chat-id message-id now (models.message/system-message current-chat-id message-id now
(str "You've added " (apply str (interpose ", " added-participants-names))))) (str "You've added " (apply str (interpose ", " added-participants-names)))))
(transport/send (group-chat/GroupAdminUpdate. nil participants) current-chat-id))))) (transport/send (group-chat/GroupAdminUpdate. nil participants) current-chat-id)))))
(handlers/register-handler-fx (handlers/register-handler-fx
:remove-group-chat-participants :remove-group-chat-participants
[re-frame/trim-v (re-frame/inject-cofx :random-id)] [re-frame/trim-v (re-frame/inject-cofx :random-id)]
(fn [{{:keys [current-chat-id] :as db} :db now :now message-id :random-id :as cofx} [removed-participants]] (fn [{{:keys [current-chat-id] :as db} :db now :now message-id :random-id :as cofx} [removed-participants]]
(let [participants (remove removed-participants (get-in db [:chats current-chat-id :contacts])) (let [participants (remove removed-participants (get-in db [:chats current-chat-id :contacts]))
contacts (:contacts/contacts db) contacts (:contacts/contacts db)
removed-participants-names (map #(get-in contacts [% :name]) removed-participants)] removed-participants-names (map #(get-in contacts [% :name]) removed-participants)]
(handlers-macro/merge-fx cofx (handlers-macro/merge-fx cofx
{:db (assoc-in db [:chats current-chat-id :contacts] participants) {:db (assoc-in db [:chats current-chat-id :contacts] participants)
:data-store/remove-chat-contacts [current-chat-id removed-participants]} :data-store/remove-chat-contacts [current-chat-id removed-participants]}
(models.message/receive (models.message/receive
(models.message/system-message current-chat-id message-id now (models.message/system-message current-chat-id message-id now
(str "You've removed " (apply str (interpose ", " removed-participants-names))))) (str "You've removed " (apply str (interpose ", " removed-participants-names)))))
(transport/send (group-chat/GroupAdminUpdate. nil participants) current-chat-id))))) (transport/send (group-chat/GroupAdminUpdate. nil participants) current-chat-id)))))
(handlers/register-handler-fx (handlers/register-handler-fx
:set-group-chat-name :set-group-chat-name
(fn [{{:keys [current-chat-id] :as db} :db} [_ new-chat-name]] (fn [{{:keys [current-chat-id] :as db} :db} [_ new-chat-name]]
{:db (assoc-in db [:chats current-chat-id :name] new-chat-name) {:db (assoc-in db [:chats current-chat-id :name] new-chat-name)
:data-store/save-chat-property [current-chat-id :name new-chat-name]})) :data-store/save-chat-property [current-chat-id :name new-chat-name]}))
(handlers/register-handler-fx (handlers/register-handler-fx
:clear-history :clear-history
(fn [{{:keys [current-chat-id] :as db} :db} _] (fn [{{:keys [current-chat-id] :as db} :db} _]
{:db (assoc-in db [:chats current-chat-id :messages] {}) {:db (assoc-in db [:chats current-chat-id :messages] {})
:data-store/hide-messages current-chat-id})) :data-store/hide-messages current-chat-id}))
(handlers/register-handler-fx (handlers/register-handler-fx
:clear-history? :clear-history?
(fn [_ _] (fn [_ _]
{:show-confirmation {:title (i18n/label :t/clear-history-confirmation) {:show-confirmation {:title (i18n/label :t/clear-history-confirmation)
:content (i18n/label :t/clear-group-history-confirmation) :content (i18n/label :t/clear-group-history-confirmation)
:confirm-button-text (i18n/label :t/clear) :confirm-button-text (i18n/label :t/clear)
:on-accept #(re-frame/dispatch [:clear-history])}})) :on-accept #(re-frame/dispatch [:clear-history])}}))

View File

@ -3,10 +3,10 @@
[status-im.constants :refer [max-chat-name-length]])) [status-im.constants :refer [max-chat-name-length]]))
(reg-sub (reg-sub
:selected-participant :selected-participant
(fn [db] (fn [db]
(let [identity (first (:selected-participants db))] (let [identity (first (:selected-participants db))]
(get-in db [:contacts/contacts identity])))) (get-in db [:contacts/contacts identity]))))
(defn get-chat-name-validation-messages [chat-name] (defn get-chat-name-validation-messages [chat-name]
(filter some? (filter some?
@ -16,18 +16,18 @@
"Chat name is too long")))) "Chat name is too long"))))
(reg-sub (reg-sub
:new-chat-name :new-chat-name
(fn [db] (fn [db]
(:new-chat-name db))) (:new-chat-name db)))
(reg-sub (reg-sub
:new-chat-name-validation-messages :new-chat-name-validation-messages
:<- [:new-chat-name] :<- [:new-chat-name]
(fn [chat-name] (fn [chat-name]
(get-chat-name-validation-messages chat-name))) (get-chat-name-validation-messages chat-name)))
(reg-sub (reg-sub
:new-chat-name-valid? :new-chat-name-valid?
:<- [:new-chat-name] :<- [:new-chat-name]
(fn [chat-name] (fn [chat-name]
(zero? (count (get-chat-name-validation-messages chat-name))))) (zero? (count (get-chat-name-validation-messages chat-name)))))

View File

@ -20,9 +20,9 @@
(spec/def :group/contacts (spec/nilable (spec/* :group/contact))) (spec/def :group/contacts (spec/nilable (spec/* :group/contact)))
(spec/def :group/contact-group (allowed-keys (spec/def :group/contact-group (allowed-keys
:req-un [:group/group-id :group/name :group/timestamp :req-un [:group/group-id :group/name :group/timestamp
:group/order :group/contacts] :group/order :group/contacts]
:opt-un [:group/pending?])) :opt-un [:group/pending?]))
(spec/def :group/contact-groups (spec/nilable (spec/map-of :global/not-empty-string :group/contact-group))) (spec/def :group/contact-groups (spec/nilable (spec/map-of :global/not-empty-string :group/contact-group)))
;;used during editing contact group ;;used during editing contact group

View File

@ -8,45 +8,45 @@
;;;; COFX ;;;; COFX
(re-frame/reg-cofx (re-frame/reg-cofx
:get-default-contacts-and-groups :get-default-contacts-and-groups
(fn [coeffects _] (fn [coeffects _]
(assoc coeffects (assoc coeffects
:default-contacts js-res/default-contacts :default-contacts js-res/default-contacts
:default-groups js-res/default-contact-groups))) :default-groups js-res/default-contact-groups)))
;;;; Handlers ;;;; Handlers
(handlers/register-handler-db (handlers/register-handler-db
:deselect-contact :deselect-contact
(fn [db [_ id]] (fn [db [_ id]]
(update db :group/selected-contacts disj id))) (update db :group/selected-contacts disj id)))
(handlers/register-handler-db (handlers/register-handler-db
:select-contact :select-contact
(fn [db [_ id]] (fn [db [_ id]]
(update db :group/selected-contacts conj id))) (update db :group/selected-contacts conj id)))
(handlers/register-handler-db (handlers/register-handler-db
:deselect-participant :deselect-participant
(fn [db [_ id]] (fn [db [_ id]]
(update db :selected-participants disj id))) (update db :selected-participants disj id)))
(handlers/register-handler-db (handlers/register-handler-db
:select-participant :select-participant
(fn [db [_ id]] (fn [db [_ id]]
(update db :selected-participants conj id))) (update db :selected-participants conj id)))
(handlers/register-handler-fx (handlers/register-handler-fx
:create-new-contact-group :create-new-contact-group
[re-frame/trim-v (re-frame/inject-cofx :now) (re-frame/inject-cofx :random-id)] [re-frame/trim-v (re-frame/inject-cofx :now) (re-frame/inject-cofx :random-id)]
(fn [{{:group/keys [contact-groups selected-contacts] :as db} :db group-id :random-id now :now} [group-name]] (fn [{{:group/keys [contact-groups selected-contacts] :as db} :db group-id :random-id now :now} [group-name]]
(let [new-group {:group-id group-id (let [new-group {:group-id group-id
:name group-name :name group-name
:order (count contact-groups) :order (count contact-groups)
:timestamp now :timestamp now
:contacts selected-contacts}] :contacts selected-contacts}]
{:db (assoc-in db [:group/contact-groups group-id] new-group) {:db (assoc-in db [:group/contact-groups group-id] new-group)
:data-store/save-contact-group new-group}))) :data-store/save-contact-group new-group})))
(defn add-default-groups (defn add-default-groups
[{:keys [db now default-groups]}] [{:keys [db now default-groups]}]
@ -66,33 +66,33 @@
:data-store/save-contact-groups (vals groups-to-add)})) :data-store/save-contact-groups (vals groups-to-add)}))
(handlers/register-handler-fx (handlers/register-handler-fx
:load-contact-groups :load-contact-groups
[(re-frame/inject-cofx :data-store/get-all-contact-groups)] [(re-frame/inject-cofx :data-store/get-all-contact-groups)]
(fn [{:keys [db all-contact-groups]} _] (fn [{:keys [db all-contact-groups]} _]
{:db (assoc db :group/contact-groups all-contact-groups)})) {:db (assoc db :group/contact-groups all-contact-groups)}))
(handlers/register-handler-fx (handlers/register-handler-fx
:set-contact-group-name :set-contact-group-name
(fn [{{:keys [new-chat-name] :group/keys [contact-group-id] :as db} :db} _] (fn [{{:keys [new-chat-name] :group/keys [contact-group-id] :as db} :db} _]
{:db (assoc-in db {:db (assoc-in db
[:group/contact-groups contact-group-id :name] [:group/contact-groups contact-group-id :name]
new-chat-name) new-chat-name)
:data-store/save-contact-group-property [contact-group-id :name new-chat-name]})) :data-store/save-contact-group-property [contact-group-id :name new-chat-name]}))
(handlers/register-handler-fx (handlers/register-handler-fx
:add-selected-contacts-to-group :add-selected-contacts-to-group
(fn [{{:group/keys [contact-groups contact-group-id selected-contacts] :as db} :db} _] (fn [{{:group/keys [contact-groups contact-group-id selected-contacts] :as db} :db} _]
{:db (update-in db {:db (update-in db
[:group/contact-groups contact-group-id :contacts] [:group/contact-groups contact-group-id :contacts]
#(into [] (set (concat % selected-contacts)))) #(into [] (set (concat % selected-contacts))))
:data-store/add-contacts-to-contact-group [contact-group-id selected-contacts]})) :data-store/add-contacts-to-contact-group [contact-group-id selected-contacts]}))
(handlers/register-handler-fx (handlers/register-handler-fx
:remove-contact-from-group :remove-contact-from-group
[re-frame/trim-v] [re-frame/trim-v]
(fn [{:keys [db]} [whisper-identity group-id]] (fn [{:keys [db]} [whisper-identity group-id]]
(let [group (-> db (let [group (-> db
(get-in [:group/contact-groups group-id]) (get-in [:group/contact-groups group-id])
(update :contacts (partial remove #(= whisper-identity %))))] (update :contacts (partial remove #(= whisper-identity %))))]
{:db (assoc-in db [:group/contact-groups group-id] group) {:db (assoc-in db [:group/contact-groups group-id] group)
:data-store/save-contact-group group}))) :data-store/save-contact-group group})))

View File

@ -3,57 +3,57 @@
[status-im.utils.subs :as utils])) [status-im.utils.subs :as utils]))
(reg-sub (reg-sub
:is-contact-selected? :is-contact-selected?
(utils/contains-sub :group/selected-contacts)) (utils/contains-sub :group/selected-contacts))
(reg-sub (reg-sub
:is-participant-selected? :is-participant-selected?
(utils/contains-sub :selected-participants)) (utils/contains-sub :selected-participants))
(defn filter-selected-contacts [selected-contacts contacts] (defn filter-selected-contacts [selected-contacts contacts]
(remove #(true? (:pending? (contacts %))) selected-contacts)) (remove #(true? (:pending? (contacts %))) selected-contacts))
(reg-sub (reg-sub
:selected-contacts-count :selected-contacts-count
:<- [:get :group/selected-contacts] :<- [:get :group/selected-contacts]
:<- [:get-contacts] :<- [:get-contacts]
(fn [[selected-contacts contacts]] (fn [[selected-contacts contacts]]
(count (filter-selected-contacts selected-contacts contacts)))) (count (filter-selected-contacts selected-contacts contacts))))
(reg-sub (reg-sub
:selected-participants-count :selected-participants-count
:<- [:get :selected-participants] :<- [:get :selected-participants]
(fn [selected-participants] (fn [selected-participants]
(count selected-participants))) (count selected-participants)))
(defn filter-contacts [selected-contacts added-contacts] (defn filter-contacts [selected-contacts added-contacts]
(filter #(selected-contacts (:whisper-identity %)) added-contacts)) (filter #(selected-contacts (:whisper-identity %)) added-contacts))
(reg-sub (reg-sub
:selected-group-contacts :selected-group-contacts
:<- [:get :group/selected-contacts] :<- [:get :group/selected-contacts]
:<- [:all-added-contacts] :<- [:all-added-contacts]
(fn [[selected-contacts added-contacts]] (fn [[selected-contacts added-contacts]]
(filter-contacts selected-contacts added-contacts))) (filter-contacts selected-contacts added-contacts)))
(reg-sub (reg-sub
:get-contact-groups :get-contact-groups
(fn [db] (fn [db]
(:group/contact-groups db))) (:group/contact-groups db)))
(reg-sub (reg-sub
:get-contact-group-id :get-contact-group-id
(fn [db] (fn [db]
(:group/contact-group-id db))) (:group/contact-group-id db)))
(reg-sub (reg-sub
:get-contact-group :get-contact-group
:<- [:get-contact-groups] :<- [:get-contact-groups]
:<- [:get-contact-group-id] :<- [:get-contact-group-id]
(fn [[groups group-id]] (fn [[groups group-id]]
(get groups group-id))) (get groups group-id)))
(reg-sub (reg-sub
:get-group-type :get-group-type
(fn [db] (fn [db]
(:group/group-type db))) (:group/group-type db)))

View File

@ -30,6 +30,5 @@
:onPanResponderRelease (on-release animated-offset-x end-offset-x chat-id swiped?) :onPanResponderRelease (on-release animated-offset-x end-offset-x chat-id swiped?)
:onPanResponderTerminate (on-release animated-offset-x end-offset-x chat-id swiped?)}))) :onPanResponderTerminate (on-release animated-offset-x end-offset-x chat-id swiped?)})))
(defn pan-handlers [pan-responder] (defn pan-handlers [pan-responder]
(js->clj (.-panHandlers pan-responder))) (js->clj (.-panHandlers pan-responder)))

View File

@ -2,7 +2,7 @@
(:require [re-frame.core :as re-frame])) (:require [re-frame.core :as re-frame]))
(re-frame/reg-sub :home-items (re-frame/reg-sub :home-items
:<- [:get-active-chats] :<- [:get-active-chats]
:<- [:browsers] :<- [:browsers]
(fn [[chats browsers]] (fn [[chats browsers]]
(sort-by #(-> % second :timestamp) > (merge chats browsers)))) (sort-by #(-> % second :timestamp) > (merge chats browsers))))

View File

@ -52,8 +52,8 @@
(when is-deletable? (when is-deletable?
[react/touchable-highlight {:style styles/delete-icon-highlight [react/touchable-highlight {:style styles/delete-icon-highlight
:on-press #(do :on-press #(do
(re-frame/dispatch [:set-swipe-position home-item-id false]) (re-frame/dispatch [:set-swipe-position home-item-id false])
(re-frame/dispatch [delete-action home-item-id]))} (re-frame/dispatch [delete-action home-item-id]))}
[react/view {:style styles/delete-icon-container} [react/view {:style styles/delete-icon-container}
[vector-icons/icon :icons/delete {:color colors/red}]]])]]))) [vector-icons/icon :icons/delete {:color colors/red}]]])]])))

View File

@ -60,52 +60,52 @@
;; event handlers ;; event handlers
(handlers/register-handler-db (handlers/register-handler-db
:navigate-to :navigate-to
(re-frame/enrich preload-data!) (re-frame/enrich preload-data!)
(fn [db [_ & params]] (fn [db [_ & params]]
(apply navigate-to db params))) (apply navigate-to db params)))
(handlers/register-handler-db (handlers/register-handler-db
:navigate-to-modal :navigate-to-modal
(re-frame/enrich preload-data!) (re-frame/enrich preload-data!)
(fn [db [_ modal-view]] (fn [db [_ modal-view]]
(assoc db :modal modal-view))) (assoc db :modal modal-view)))
(handlers/register-handler-fx (handlers/register-handler-fx
:navigation-replace :navigation-replace
(re-frame/enrich preload-data!) (re-frame/enrich preload-data!)
(fn [cofx [_ view-id]] (fn [cofx [_ view-id]]
(replace-view view-id cofx))) (replace-view view-id cofx)))
(handlers/register-handler-db (handlers/register-handler-db
:navigate-back :navigate-back
(re-frame/enrich -preload-data!) (re-frame/enrich -preload-data!)
(fn [{:keys [navigation-stack view-id modal] :as db} _] (fn [{:keys [navigation-stack view-id modal] :as db} _]
(cond (cond
modal (assoc db :modal nil modal (assoc db :modal nil
:was-modal? true) :was-modal? true)
(>= 1 (count navigation-stack)) db (>= 1 (count navigation-stack)) db
:else :else
(let [[previous-view-id :as navigation-stack'] (pop navigation-stack) (let [[previous-view-id :as navigation-stack'] (pop navigation-stack)
first-in-stack (first navigation-stack)] first-in-stack (first navigation-stack)]
(if (= view-id first-in-stack) (if (= view-id first-in-stack)
(-> db (-> db
(assoc :view-id previous-view-id) (assoc :view-id previous-view-id)
(assoc :navigation-stack navigation-stack')) (assoc :navigation-stack navigation-stack'))
(assoc db :view-id first-in-stack)))))) (assoc db :view-id first-in-stack))))))
(handlers/register-handler-fx (handlers/register-handler-fx
:navigate-to-clean :navigate-to-clean
(fn [cofx [_ view-id params]] (fn [cofx [_ view-id params]]
(navigate-to-clean view-id cofx params))) (navigate-to-clean view-id cofx params)))
(handlers/register-handler-fx (handlers/register-handler-fx
:navigate-to-tab :navigate-to-tab
(re-frame/enrich preload-data!) (re-frame/enrich preload-data!)
(fn [{:keys [db] :as cofx} [_ view-id]] (fn [{:keys [db] :as cofx} [_ view-id]]
(handlers-macro/merge-fx cofx (handlers-macro/merge-fx cofx
{:db (-> db {:db (-> db
(assoc :prev-tab-view-id (:view-id db)) (assoc :prev-tab-view-id (:view-id db))
(assoc :prev-view-id (:view-id db)))} (assoc :prev-view-id (:view-id db)))}
(navigate-to-clean view-id)))) (navigate-to-clean view-id))))

View File

@ -10,46 +10,46 @@
;; handlers ;; handlers
(handlers/register-handler-fx (handlers/register-handler-fx
:add-networks :add-networks
(fn [{{:networks/keys [networks] :as db} :db} [_ new-networks]] (fn [{{:networks/keys [networks] :as db} :db} [_ new-networks]]
(let [identities (set (keys networks)) (let [identities (set (keys networks))
new-networks' (->> new-networks new-networks' (->> new-networks
(remove #(identities (:id %))) (remove #(identities (:id %)))
(map #(vector (:id %) %)) (map #(vector (:id %) %))
(into {}))] (into {}))]
{:db (-> db {:db (-> db
(update :networks merge new-networks') (update :networks merge new-networks')
(assoc :new-networks (vals new-networks'))) (assoc :new-networks (vals new-networks')))
:save-networks new-networks'}))) :save-networks new-networks'})))
(handlers/register-handler-fx (handlers/register-handler-fx
::close-application ::close-application
(fn [_ _] (fn [_ _]
{:close-application nil})) {:close-application nil}))
(handlers/register-handler-fx (handlers/register-handler-fx
::save-network ::save-network
(fn [{:keys [db now] :as cofx} [_ network]] (fn [{:keys [db now] :as cofx} [_ network]]
(handlers-macro/merge-fx cofx (handlers-macro/merge-fx cofx
(accounts.utils/account-update {:network network (accounts.utils/account-update {:network network
:last-updated now} :last-updated now}
[::close-application])))) [::close-application]))))
(handlers/register-handler-fx (handlers/register-handler-fx
:connect-network :connect-network
(fn [{:keys [db now] :as cofx} [_ network]] (fn [{:keys [db now] :as cofx} [_ network]]
(let [current-network (:network db) (let [current-network (:network db)
networks (:networks/networks db) networks (:networks/networks db)
chats (:transport/chats db)] chats (:transport/chats db)]
(if (utils/network-with-upstream-rpc? networks current-network) (if (utils/network-with-upstream-rpc? networks current-network)
(handlers-macro/merge-fx cofx (handlers-macro/merge-fx cofx
{:dispatch-n [[:load-accounts] {:dispatch-n [[:load-accounts]
[:navigate-to-clean :accounts]]} [:navigate-to-clean :accounts]]}
(transport/stop-whisper) (transport/stop-whisper)
(accounts.utils/account-update {:network network (accounts.utils/account-update {:network network
:last-updated now})) :last-updated now}))
{:show-confirmation {:title (i18n/label :t/close-app-title) {:show-confirmation {:title (i18n/label :t/close-app-title)
:content (i18n/label :t/close-app-content) :content (i18n/label :t/close-app-content)
:confirm-button-text (i18n/label :t/close-app-button) :confirm-button-text (i18n/label :t/close-app-button)
:on-accept #(dispatch [::save-network network]) :on-accept #(dispatch [::save-network network])
:on-cancel nil}})))) :on-cancel nil}}))))

View File

@ -1,13 +1,13 @@
(ns status-im.ui.screens.network-settings.network-details.views (ns status-im.ui.screens.network-settings.network-details.views
(:require-macros [status-im.utils.views :as views]) (:require-macros [status-im.utils.views :as views])
(:require (:require
[re-frame.core :as rf] [re-frame.core :as rf]
[status-im.ui.components.status-bar.view :as status-bar] [status-im.ui.components.status-bar.view :as status-bar]
[status-im.ui.components.toolbar.view :as toolbar] [status-im.ui.components.toolbar.view :as toolbar]
[status-im.ui.components.react :as react] [status-im.ui.components.react :as react]
[status-im.i18n :as i18n] [status-im.i18n :as i18n]
[status-im.ui.screens.network-settings.styles :as st] [status-im.ui.screens.network-settings.styles :as st]
[status-im.ui.screens.network-settings.views :as network-settings])) [status-im.ui.screens.network-settings.views :as network-settings]))
(views/defview network-details [] (views/defview network-details []
(views/letsubs [{:keys [networks/selected-network]} [:get-screen-params] (views/letsubs [{:keys [networks/selected-network]} [:get-screen-params]

View File

@ -2,11 +2,11 @@
(:require [re-frame.core :refer [reg-sub subscribe]])) (:require [re-frame.core :refer [reg-sub subscribe]]))
(reg-sub (reg-sub
:get-current-account-network :get-current-account-network
:<- [:get-current-account] :<- [:get-current-account]
:<- [:get :networks/networks] :<- [:get :networks/networks]
(fn [[current-account networks]] (fn [[current-account networks]]
(get networks (:network current-account)))) (get networks (:network current-account))))
(reg-sub (reg-sub
:get-network-id :get-network-id

View File

@ -8,21 +8,21 @@
[status-im.utils.ethereum.core :as ethereum])) [status-im.utils.ethereum.core :as ethereum]))
(handlers/register-handler-fx (handlers/register-handler-fx
::save-wnode ::save-wnode
(fn [{:keys [db now] :as cofx} [_ wnode]] (fn [{:keys [db now] :as cofx} [_ wnode]]
(let [network (ethereum/network->chain-keyword (:network db)) (let [network (ethereum/network->chain-keyword (:network db))
settings (get-in db [:account/account :settings])] settings (get-in db [:account/account :settings])]
(handlers-macro/merge-fx cofx (handlers-macro/merge-fx cofx
{:dispatch [:logout]} {:dispatch [:logout]}
(accounts-events/update-settings (assoc-in settings [:wnode network] wnode)))))) (accounts-events/update-settings (assoc-in settings [:wnode network] wnode))))))
(handlers/register-handler-fx (handlers/register-handler-fx
:connect-wnode :connect-wnode
(fn [{:keys [db]} [_ wnode]] (fn [{:keys [db]} [_ wnode]]
(let [network (ethereum/network->chain-keyword (:network db))] (let [network (ethereum/network->chain-keyword (:network db))]
{:show-confirmation {:title (i18n/label :t/close-app-title) {:show-confirmation {:title (i18n/label :t/close-app-title)
:content (i18n/label :t/connect-wnode-content :content (i18n/label :t/connect-wnode-content
{:name (get-in db [:inbox/wnodes network wnode :name])}) {:name (get-in db [:inbox/wnodes network wnode :name])})
:confirm-button-text (i18n/label :t/close-app-button) :confirm-button-text (i18n/label :t/close-app-button)
:on-accept #(dispatch [::save-wnode wnode]) :on-accept #(dispatch [::save-wnode wnode])
:on-cancel nil}}))) :on-cancel nil}})))

View File

@ -3,15 +3,15 @@
[status-im.utils.ethereum.core :as ethereum])) [status-im.utils.ethereum.core :as ethereum]))
(re-frame/reg-sub :settings/current-wnode (re-frame/reg-sub :settings/current-wnode
:<- [:network] :<- [:network]
:<- [:get-current-account] :<- [:get-current-account]
(fn [[network current-account]] (fn [[network current-account]]
(let [chain (ethereum/network->chain-keyword network)] (let [chain (ethereum/network->chain-keyword network)]
(get-in current-account [:settings :wnode chain])))) (get-in current-account [:settings :wnode chain]))))
(re-frame/reg-sub :settings/network-wnodes (re-frame/reg-sub :settings/network-wnodes
:<- [:network] :<- [:network]
:<- [:get :inbox/wnodes] :<- [:get :inbox/wnodes]
(fn [[network wnodes]] (fn [[network wnodes]]
(let [chain (ethereum/network->chain-keyword network)] (let [chain (ethereum/network->chain-keyword network)]
(chain wnodes)))) (chain wnodes))))

View File

@ -39,7 +39,7 @@
name]]]) name]]])
(defn- profile-header-edit [{:keys [name group-chat] :as contact} (defn- profile-header-edit [{:keys [name group-chat] :as contact}
icon-options on-change-text-event allow-icon-change?] icon-options on-change-text-event allow-icon-change?]
[react/view styles/profile-header-edit [react/view styles/profile-header-edit
[react/touchable-highlight {:on-press #(show-profile-icon-actions icon-options) [react/touchable-highlight {:on-press #(show-profile-icon-actions icon-options)
:accessibility-label :edit-profile-photo-button} :accessibility-label :edit-profile-photo-button}

View File

@ -13,27 +13,27 @@
[taoensso.timbre :as log])) [taoensso.timbre :as log]))
(re-frame/reg-fx (re-frame/reg-fx
:open-image-picker :open-image-picker
;; the image picker is only used here for now, this effect can be use in other scenarios as well ;; the image picker is only used here for now, this effect can be use in other scenarios as well
(fn [callback-event] (fn [callback-event]
(show-image-picker (show-image-picker
(fn [image] (fn [image]
(let [path (get (js->clj image) "path") (let [path (get (js->clj image) "path")
_ (log/debug path) _ (log/debug path)
on-success (fn [base64] on-success (fn [base64]
(re-frame/dispatch [callback-event base64])) (re-frame/dispatch [callback-event base64]))
on-error (fn [type error] on-error (fn [type error]
(.log js/console type error))] (.log js/console type error))]
(img->base64 path on-success on-error)))))) (img->base64 path on-success on-error))))))
(handlers/register-handler-fx (handlers/register-handler-fx
:profile/send-transaction :profile/send-transaction
[re-frame/trim-v] [re-frame/trim-v]
(fn [{{:contacts/keys [contacts]} :db :as cofx} [chat-id]] (fn [{{:contacts/keys [contacts]} :db :as cofx} [chat-id]]
(let [send-command (get-in contacts chat-const/send-command-ref)] (let [send-command (get-in contacts chat-const/send-command-ref)]
(handlers-macro/merge-fx cofx (handlers-macro/merge-fx cofx
(chat-events/start-chat chat-id {:navigation-replace? true}) (chat-events/start-chat chat-id {:navigation-replace? true})
(input-events/select-chat-input-command send-command nil true))))) (input-events/select-chat-input-command send-command nil true)))))
(defn get-current-account [db] (defn get-current-account [db]
(:account/account db)) (:account/account db))
@ -42,18 +42,18 @@
(spec/valid? :profile/name name)) (spec/valid? :profile/name name))
(handlers/register-handler-fx (handlers/register-handler-fx
:my-profile/update-name :my-profile/update-name
(fn [{:keys [db]} [_ name]] (fn [{:keys [db]} [_ name]]
{:db (-> db {:db (-> db
(assoc-in [:my-profile/profile :valid-name?] (valid-name? name)) (assoc-in [:my-profile/profile :valid-name?] (valid-name? name))
(assoc-in [:my-profile/profile :name] name))})) (assoc-in [:my-profile/profile :name] name))}))
(handlers/register-handler-fx (handlers/register-handler-fx
:my-profile/update-picture :my-profile/update-picture
(fn [{:keys [db]} [this-event base64-image]] (fn [{:keys [db]} [this-event base64-image]]
(if base64-image (if base64-image
{:db (assoc-in db [:my-profile/profile :photo-path] (str "data:image/jpeg;base64," base64-image))} {:db (assoc-in db [:my-profile/profile :photo-path] (str "data:image/jpeg;base64," base64-image))}
{:open-image-picker this-event}))) {:open-image-picker this-event})))
(defn clean-name [db edit-view] (defn clean-name [db edit-view]
(let [name (get-in db [edit-view :name])] (let [name (get-in db [edit-view :name])]
@ -65,51 +65,51 @@
{:db (dissoc db :my-profile/profile :my-profile/default-name :my-profile/editing?)}) {:db (dissoc db :my-profile/profile :my-profile/default-name :my-profile/editing?)})
(handlers/register-handler-fx (handlers/register-handler-fx
:my-profile/start-editing-profile :my-profile/start-editing-profile
(fn [{:keys [db]} []] (fn [{:keys [db]} []]
{:db (assoc db :my-profile/editing? true)})) {:db (assoc db :my-profile/editing? true)}))
(handlers/register-handler-fx (handlers/register-handler-fx
:my-profile/save-profile :my-profile/save-profile
(fn [{:keys [db now] :as cofx} _] (fn [{:keys [db now] :as cofx} _]
(let [{:keys [photo-path]} (:my-profile/profile db) (let [{:keys [photo-path]} (:my-profile/profile db)
cleaned-name (clean-name db :my-profile/profile) cleaned-name (clean-name db :my-profile/profile)
cleaned-edit (merge {:name cleaned-name cleaned-edit (merge {:name cleaned-name
:last-updated now} :last-updated now}
(if photo-path (if photo-path
{:photo-path photo-path}))] {:photo-path photo-path}))]
(handlers-macro/merge-fx cofx (handlers-macro/merge-fx cofx
(clear-profile) (clear-profile)
(accounts.utils/account-update cleaned-edit))))) (accounts.utils/account-update cleaned-edit)))))
(handlers/register-handler-fx (handlers/register-handler-fx
:group-chat-profile/start-editing :group-chat-profile/start-editing
(fn [{:keys [db]} _] (fn [{:keys [db]} _]
{:db (assoc db :group-chat-profile/editing? true)})) {:db (assoc db :group-chat-profile/editing? true)}))
(handlers/register-handler-fx (handlers/register-handler-fx
:group-chat-profile/save-profile :group-chat-profile/save-profile
(fn [{:keys [db]} _] (fn [{:keys [db]} _]
(-> {:db db} (-> {:db db}
(update :db dissoc :group-chat-profile/editing?)))) (update :db dissoc :group-chat-profile/editing?))))
(handlers/register-handler-fx (handlers/register-handler-fx
:my-profile/enter-two-random-words :my-profile/enter-two-random-words
(fn [{:keys [db]} []] (fn [{:keys [db]} []]
(let [{:keys [mnemonic]} (get-current-account db) (let [{:keys [mnemonic]} (get-current-account db)
shuffled-mnemonic (shuffle (map-indexed vector (clojure.string/split mnemonic #" ")))] shuffled-mnemonic (shuffle (map-indexed vector (clojure.string/split mnemonic #" ")))]
{:db (assoc db :my-profile/seed {:step :first-word {:db (assoc db :my-profile/seed {:step :first-word
:first-word (first shuffled-mnemonic) :first-word (first shuffled-mnemonic)
:second-word (second shuffled-mnemonic)})}))) :second-word (second shuffled-mnemonic)})})))
(handlers/register-handler-fx (handlers/register-handler-fx
:my-profile/set-step :my-profile/set-step
(fn [{:keys [db]} [_ step]] (fn [{:keys [db]} [_ step]]
{:db (update db :my-profile/seed assoc :step step :error nil :word nil)})) {:db (update db :my-profile/seed assoc :step step :error nil :word nil)}))
(handlers/register-handler-fx (handlers/register-handler-fx
:my-profile/finish :my-profile/finish
(fn [{:keys [db] :as cofx} _] (fn [{:keys [db] :as cofx} _]
(handlers-macro/merge-fx cofx (handlers-macro/merge-fx cofx
{:db (update db :my-profile/seed assoc :step :finish :error nil :word nil)} {:db (update db :my-profile/seed assoc :step :finish :error nil :word nil)}
(accounts.utils/account-update {:seed-backed-up? true})))) (accounts.utils/account-update {:seed-backed-up? true}))))

View File

@ -117,9 +117,9 @@
:else :else
(utils/show-question (utils/show-question
(i18n/label :t/are-you-sure?) (i18n/label :t/are-you-sure?)
(i18n/label :t/are-you-sure-description) (i18n/label :t/are-you-sure-description)
#(re-frame/dispatch [:my-profile/finish]))))}]]]) #(re-frame/dispatch [:my-profile/finish]))))}]]])
(defn finish [] (defn finish []
[react/view {:style styles/finish-container} [react/view {:style styles/finish-container}

View File

@ -3,7 +3,7 @@
[clojure.string :as string])) [clojure.string :as string]))
(reg-sub (reg-sub
:get-profile-unread-messages-number :get-profile-unread-messages-number
:<- [:get-current-account] :<- [:get-current-account]
(fn [{:keys [seed-backed-up? mnemonic]}] (fn [{:keys [seed-backed-up? mnemonic]}]
(if (or seed-backed-up? (string/blank? mnemonic)) 0 1))) (if (or seed-backed-up? (string/blank? mnemonic)) 0 1)))

View File

@ -92,8 +92,8 @@
(utils/show-confirmation (i18n/label :t/logout-title) (utils/show-confirmation (i18n/label :t/logout-title)
(i18n/label :t/logout-are-you-sure) (i18n/label :t/logout-are-you-sure)
(i18n/label :t/logout) #(keychain/get-encryption-key-then (i18n/label :t/logout) #(keychain/get-encryption-key-then
(fn [encryption-key] (fn [encryption-key]
(re-frame/dispatch [:logout encryption-key]))))) (re-frame/dispatch [:logout encryption-key])))))
(defn- my-profile-settings [{:keys [seed-backed-up? mnemonic]} sharing-usage-data?] (defn- my-profile-settings [{:keys [seed-backed-up? mnemonic]} sharing-usage-data?]
(let [show-backup-seed? (and (not seed-backed-up?) (not (string/blank? mnemonic)))] (let [show-backup-seed? (and (not seed-backed-up?) (not (string/blank? mnemonic)))]
@ -115,14 +115,14 @@
:icon-content [components.common/counter {:size 22} 1]}]) :icon-content [components.common/counter {:size 22} 1]}])
[profile.components/settings-item-separator] [profile.components/settings-item-separator]
[react/view styles/my-profile-settings-logout-wrapper [react/view styles/my-profile-settings-logout-wrapper
[react/view styles/my-profile-settings-logout [react/view styles/my-profile-settings-logout
[profile.components/settings-item {:label-kw :t/logout [profile.components/settings-item {:label-kw :t/logout
:accessibility-label :log-out-button :accessibility-label :log-out-button
:destructive? true :destructive? true
:hide-arrow? true :hide-arrow? true
:action-fn #(handle-logout)}]] :action-fn #(handle-logout)}]]
[react/view styles/my-profile-settings-logout-version [react/view styles/my-profile-settings-logout-version
[react/text build/version]]]])) [react/text build/version]]]]))
(defview advanced [{:keys [network networks dev-mode?]}] (defview advanced [{:keys [network networks dev-mode?]}]
(letsubs [advanced? [:get :my-profile/advanced?] (letsubs [advanced? [:get :my-profile/advanced?]

View File

@ -6,24 +6,24 @@
[status-im.i18n :as i18n])) [status-im.i18n :as i18n]))
(handlers/register-handler-fx (handlers/register-handler-fx
:scan-qr-code :scan-qr-code
(fn [{:keys [db]} [_ identifier handler]] (fn [{:keys [db]} [_ identifier handler]]
{:db (assoc-in db [:qr-codes identifier] handler) {:db (assoc-in db [:qr-codes identifier] handler)
:request-permissions-fx {:permissions [:camera] :request-permissions-fx {:permissions [:camera]
:on-allowed #(re-frame/dispatch [:navigate-to :qr-scanner {:current-qr-context identifier}]) :on-allowed #(re-frame/dispatch [:navigate-to :qr-scanner {:current-qr-context identifier}])
:on-denied #(utils/show-popup (i18n/label :t/error) :on-denied #(utils/show-popup (i18n/label :t/error)
(i18n/label :t/camera-access-error))}})) (i18n/label :t/camera-access-error))}}))
(handlers/register-handler-fx (handlers/register-handler-fx
:clear-qr-code :clear-qr-code
(fn [{:keys [db]} [_ identifier]] (fn [{:keys [db]} [_ identifier]]
{:db (update db :qr-codes dissoc identifier)})) {:db (update db :qr-codes dissoc identifier)}))
(handlers/register-handler-fx (handlers/register-handler-fx
:set-qr-code :set-qr-code
(fn [{:keys [db]} [_ context data]] (fn [{:keys [db]} [_ context data]]
(merge {:db (-> db (merge {:db (-> db
(update :qr-codes dissoc context) (update :qr-codes dissoc context)
(dissoc :current-qr-context))} (dissoc :current-qr-context))}
(when-let [handler (get-in db [:qr-codes context])] (when-let [handler (get-in db [:qr-codes context])]
{:dispatch [handler context data]})))) {:dispatch [handler context data]}))))

View File

@ -19,17 +19,17 @@
status-im.ui.screens.profile.subs)) status-im.ui.screens.profile.subs))
(reg-sub :get (reg-sub :get
(fn [db [_ k]] (fn [db [_ k]]
(get db k))) (get db k)))
(reg-sub :get-in (reg-sub :get-in
(fn [db [_ path]] (fn [db [_ path]]
(get-in db path))) (get-in db path)))
(reg-sub :signed-up? (reg-sub :signed-up?
:<- [:get-current-account] :<- [:get-current-account]
(fn [current-account] (fn [current-account]
(:signed-up? current-account))) (:signed-up? current-account)))
(reg-sub :network :network) (reg-sub :network :network)
@ -39,37 +39,37 @@
(reg-sub :mailserver-status :mailserver-status) (reg-sub :mailserver-status :mailserver-status)
(reg-sub :offline? (reg-sub :offline?
:<- [:network-status] :<- [:network-status]
:<- [:sync-state] :<- [:sync-state]
(fn [[network-status sync-state]] (fn [[network-status sync-state]]
(or (= network-status :offline) (or (= network-status :offline)
(= sync-state :offline)))) (= sync-state :offline))))
(reg-sub :connection-problem? (reg-sub :connection-problem?
:<- [:mailserver-status] :<- [:mailserver-status]
:<- [:peers-count] :<- [:peers-count]
(fn [[mailserver-status peers-count]] (fn [[mailserver-status peers-count]]
(or (= :disconnected mailserver-status) (or (= :disconnected mailserver-status)
(zero? peers-count)))) (zero? peers-count))))
(reg-sub :syncing? (reg-sub :syncing?
:<- [:sync-state] :<- [:sync-state]
(fn [sync-state] (fn [sync-state]
(#{:pending :in-progress} sync-state))) (#{:pending :in-progress} sync-state)))
(reg-sub :tab-bar-visible? (reg-sub :tab-bar-visible?
(fn [db _] (fn [db _]
(get db :tab-bar-visible?))) (get db :tab-bar-visible?)))
(reg-sub :get-screen-params (reg-sub :get-screen-params
(fn [db [_ view-id]] (fn [db [_ view-id]]
(get-in db [:navigation/screen-params (or view-id (:view-id db))]))) (get-in db [:navigation/screen-params (or view-id (:view-id db))])))
(reg-sub :can-navigate-back? (reg-sub :can-navigate-back?
(fn [db] (fn [db]
(> (count (:navigation-stack db)) 1))) (> (count (:navigation-stack db)) 1)))
(reg-sub :delete-swipe-position (reg-sub :delete-swipe-position
(fn [db [_ item-id]] (fn [db [_ item-id]]
(let [item-animation (get-in db [:chat-animations item-id])] (let [item-animation (get-in db [:chat-animations item-id])]
(if (some? item-animation) (:delete-swiped item-animation) nil)))) (if (some? item-animation) (:delete-swiped item-animation) nil))))

View File

@ -3,7 +3,7 @@
[status-im.ui.screens.accounts.utils :as accounts.utils])) [status-im.ui.screens.accounts.utils :as accounts.utils]))
(handlers/register-handler-fx (handlers/register-handler-fx
:help-improve-handler :help-improve-handler
(fn [{db :db} [_ yes? next]] (fn [{db :db} [_ yes? next]]
(merge (accounts.utils/account-update {:sharing-usage-data? yes?} {:db db}) (merge (accounts.utils/account-update {:sharing-usage-data? yes?} {:db db})
{:dispatch (or next [:navigate-to-clean :home])}))) {:dispatch (or next [:navigate-to-clean :home])})))

View File

@ -75,42 +75,42 @@
;;; | ;;; |
;;; - profile-photo-capture ;;; - profile-photo-capture
(views/compile-views root-view (views/compile-views root-view
[{:views #{:home :wallet :my-profile} [{:views #{:home :wallet :my-profile}
:component main-tabs} :component main-tabs}
{:view :chat {:view :chat
:hide? (not android?) :hide? (not android?)
:component chat} :component chat}
{:view :wallet-send-transaction {:view :wallet-send-transaction
:parent :wallet :parent :wallet
:hide? (not android?) :hide? (not android?)
:component send-transaction} :component send-transaction}
{:view :wallet-request-transaction {:view :wallet-request-transaction
:parent :wallet :parent :wallet
:component request-transaction} :component request-transaction}
{:view :wallet-request-assets {:view :wallet-request-assets
:parent :wallet-request-transaction :parent :wallet-request-transaction
:component wallet.components/request-assets} :component wallet.components/request-assets}
{:view :choose-recipient {:view :choose-recipient
:parent :wallet-send-transaction :parent :wallet-send-transaction
:hide? true :hide? true
:component choose-recipient} :component choose-recipient}
{:view :wallet-transaction-sent {:view :wallet-transaction-sent
:parent :wallet-send-transaction :parent :wallet-send-transaction
:component transaction-sent} :component transaction-sent}
{:views #{:transactions-history :unsigned-transactions} {:views #{:transactions-history :unsigned-transactions}
:parent :wallet :parent :wallet
:component wallet-transactions/transactions} :component wallet-transactions/transactions}
{:view :profile-photo-capture {:view :profile-photo-capture
:parent :my-profile :parent :my-profile
:component profile-photo-capture}]) :component profile-photo-capture}])
(defview main [] (defview main []
(letsubs [signed-up? [:signed-up?] (letsubs [signed-up? [:signed-up?]
@ -167,7 +167,7 @@
:choose-recipient :wallet-transaction-sent :transactions-history :choose-recipient :wallet-transaction-sent :transactions-history
:unsigned-transactions :wallet-request-transaction :edit-my-profile :unsigned-transactions :wallet-request-transaction :edit-my-profile
:profile-photo-capture :wallet-request-assets} :profile-photo-capture :wallet-request-assets}
view-id)) view-id))
[root-view] [root-view]
[component]) [component])
(when modal-view (when modal-view
@ -186,4 +186,4 @@
:wallet-transaction-fee wallet.send/transaction-fee :wallet-transaction-fee wallet.send/transaction-fee
[react/view [react/text (str "Unknown modal view: " modal-view)]])] [react/view [react/text (str "Unknown modal view: " modal-view)]])]
[react/main-screen-modal-view modal-view [react/main-screen-modal-view modal-view
[component]])]])])))) [component]])]])]))))

View File

@ -7,23 +7,23 @@
[status-im.utils.money :as money])) [status-im.utils.money :as money]))
(handlers/register-handler-db (handlers/register-handler-db
:wallet/toggle-flashlight :wallet/toggle-flashlight
(fn [db] (fn [db]
(let [flashlight-state (get-in db [:wallet :send-transaction :camera-flashlight]) (let [flashlight-state (get-in db [:wallet :send-transaction :camera-flashlight])
toggled-state (if (= :on flashlight-state) :off :on)] toggled-state (if (= :on flashlight-state) :off :on)]
(assoc-in db [:wallet :send-transaction :camera-flashlight] toggled-state)))) (assoc-in db [:wallet :send-transaction :camera-flashlight] toggled-state))))
(defn- fill-request-details [db {:keys [address name value symbol gas gasPrice whisper-identity]}] (defn- fill-request-details [db {:keys [address name value symbol gas gasPrice whisper-identity]}]
{:pre [(not (nil? address))]} {:pre [(not (nil? address))]}
(update-in (update-in
db [:wallet :send-transaction] db [:wallet :send-transaction]
#(cond-> (assoc % :to address :to-name name :whisper-identity whisper-identity) #(cond-> (assoc % :to address :to-name name :whisper-identity whisper-identity)
value (assoc :amount value) value (assoc :amount value)
symbol (assoc :symbol symbol) symbol (assoc :symbol symbol)
gas (assoc :gas (money/bignumber gas)) gas (assoc :gas (money/bignumber gas))
gasPrice (assoc :gas-price (money/bignumber gasPrice)) gasPrice (assoc :gas-price (money/bignumber gasPrice))
(and symbol (not gasPrice)) (and symbol (not gasPrice))
(assoc :gas-price (ethereum/estimate-gas symbol))))) (assoc :gas-price (ethereum/estimate-gas symbol)))))
(defn- extract-details (defn- extract-details
"First try to parse as EIP681 URI, if not assume this is an address directly. "First try to parse as EIP681 URI, if not assume this is an address directly.
@ -35,21 +35,21 @@
{:address s :chain-id chain-id}))) {:address s :chain-id chain-id})))
(handlers/register-handler-fx (handlers/register-handler-fx
:wallet/fill-request-from-url :wallet/fill-request-from-url
(fn [{{:keys [network] :as db} :db} [_ data]] (fn [{{:keys [network] :as db} :db} [_ data]]
(let [{:keys [view-id]} db (let [{:keys [view-id]} db
current-chain-id (get-in constants/default-networks [network :raw-config :NetworkId]) current-chain-id (get-in constants/default-networks [network :raw-config :NetworkId])
{:keys [address chain-id] :as details} (extract-details data current-chain-id) {:keys [address chain-id] :as details} (extract-details data current-chain-id)
valid-network? (boolean (= current-chain-id chain-id))] valid-network? (boolean (= current-chain-id chain-id))]
(cond-> {:db db (cond-> {:db db
:dispatch [:navigate-back]} :dispatch [:navigate-back]}
(and address (= :choose-recipient view-id)) (assoc :dispatch [:navigate-back]) (and address (= :choose-recipient view-id)) (assoc :dispatch [:navigate-back])
(and address valid-network?) (update :db #(fill-request-details % details)) (and address valid-network?) (update :db #(fill-request-details % details))
(not address) (assoc :show-error (i18n/label :t/wallet-invalid-address {:data data})) (not address) (assoc :show-error (i18n/label :t/wallet-invalid-address {:data data}))
(and address (not valid-network?)) (assoc :show-error (i18n/label :t/wallet-invalid-chain-id {:data data :chain current-chain-id})))))) (and address (not valid-network?)) (assoc :show-error (i18n/label :t/wallet-invalid-chain-id {:data data :chain current-chain-id}))))))
(handlers/register-handler-fx (handlers/register-handler-fx
:wallet/fill-request-from-contact :wallet/fill-request-from-contact
(fn [{db :db} [_ {:keys [address name whisper-identity]}]] (fn [{db :db} [_ {:keys [address name whisper-identity]}]]
{:db (fill-request-details db {:address address :name name :whisper-identity whisper-identity}) {:db (fill-request-details db {:address address :name name :whisper-identity whisper-identity})
:dispatch [:navigate-back]})) :dispatch [:navigate-back]}))

View File

@ -25,7 +25,7 @@
(defn- viewfinder [{:keys [height width]} size] (defn- viewfinder [{:keys [height width]} size]
(let [height (cond-> height (let [height (cond-> height
platform/iphone-x? (- 78))] platform/iphone-x? (- 78))]
[react/view {:style styles/viewfinder-port} [react/view {:style styles/viewfinder-port}
[react/view {:style (styles/viewfinder-translucent height width size :top)}] [react/view {:style (styles/viewfinder-translucent height width size :top)}]
[react/view {:style (styles/viewfinder-translucent height width size :right)}] [react/view {:style (styles/viewfinder-translucent height width size :right)}]

View File

@ -17,12 +17,12 @@
(def text-input (def text-input
(merge text-content (merge text-content
{:font-size 15 {:font-size 15
:flex 1 :flex 1
:padding-bottom 0 :padding-bottom 0
:padding-top 0 :padding-top 0
:height 52 :height 52
:letter-spacing -0.2})) :letter-spacing -0.2}))
(def contact-code-text-input (def contact-code-text-input
{:text-align-vertical :top {:text-align-vertical :top
@ -185,4 +185,3 @@
:font-size 15 :font-size 15
:letter-spacing -0.2}) :letter-spacing -0.2})

View File

@ -162,13 +162,13 @@
(defn- on-choose-recipient [contact-only?] (defn- on-choose-recipient [contact-only?]
(list-selection/show {:title (i18n/label :t/wallet-choose-recipient) (list-selection/show {:title (i18n/label :t/wallet-choose-recipient)
:options (concat :options (concat
[{:label (i18n/label :t/recent-recipients) [{:label (i18n/label :t/recent-recipients)
:action #(re-frame/dispatch [:navigate-to :recent-recipients])}] :action #(re-frame/dispatch [:navigate-to :recent-recipients])}]
(when-not contact-only? (when-not contact-only?
[{:label (i18n/label :t/scan-qr) [{:label (i18n/label :t/scan-qr)
:action request-camera-permissions} :action request-camera-permissions}
{:label (i18n/label :t/recipient-code) {:label (i18n/label :t/recipient-code)
:action #(re-frame/dispatch [:navigate-to :contact-code])}]))})) :action #(re-frame/dispatch [:navigate-to :contact-code])}]))}))
(defn recipient-selector [{:keys [name address disabled? contact-only? request?]}] (defn recipient-selector [{:keys [name address disabled? contact-only? request?]}]
[components/cartouche {:on-press #(on-choose-recipient contact-only?) [components/cartouche {:on-press #(on-choose-recipient contact-only?)
@ -186,13 +186,13 @@
:accessibility-label :specify-amount-button} :accessibility-label :specify-amount-button}
[components/text-input [components/text-input
(merge (merge
(if disabled? (if disabled?
{:editable false} {:editable false}
{:keyboard-type :numeric {:keyboard-type :numeric
:placeholder (i18n/label :t/amount-placeholder) :placeholder (i18n/label :t/amount-placeholder)
:style components.styles/flex :style components.styles/flex
:accessibility-label :amount-input}) :accessibility-label :amount-input})
input-options)]]) input-options)]])
(defn amount-selector [{:keys [error disabled?] :as m}] (defn amount-selector [{:keys [error disabled?] :as m}]
[react/view [react/view

View File

@ -26,13 +26,13 @@
(defn get-token-balance [{:keys [web3 contract account-id on-success on-error]}] (defn get-token-balance [{:keys [web3 contract account-id on-success on-error]}]
(if (and web3 contract account-id) (if (and web3 contract account-id)
(erc20/balance-of (erc20/balance-of
web3 web3
contract contract
(ethereum/normalized-address account-id) (ethereum/normalized-address account-id)
(fn [err resp] (fn [err resp]
(if-not err (if-not err
(on-success resp) (on-success resp)
(on-error err)))) (on-error err))))
(on-error "web3, contract or account-id not available"))) (on-error "web3, contract or account-id not available")))
(defn assoc-error-message [db error-type err] (defn assoc-error-message [db error-type err]
@ -45,203 +45,203 @@
;; FX ;; FX
(reg-fx (reg-fx
:get-balance :get-balance
(fn [{:keys [web3 account-id success-event error-event]}] (fn [{:keys [web3 account-id success-event error-event]}]
(get-balance {:web3 web3 (get-balance {:web3 web3
:account-id account-id :account-id account-id
:on-success #(re-frame/dispatch [success-event %]) :on-success #(re-frame/dispatch [success-event %])
:on-error #(re-frame/dispatch [error-event %])}))) :on-error #(re-frame/dispatch [error-event %])})))
(reg-fx (reg-fx
:get-tokens-balance :get-tokens-balance
(fn [{:keys [web3 symbols chain account-id success-event error-event]}] (fn [{:keys [web3 symbols chain account-id success-event error-event]}]
(doseq [symbol symbols] (doseq [symbol symbols]
(let [contract (:address (tokens/symbol->token chain symbol))] (let [contract (:address (tokens/symbol->token chain symbol))]
(get-token-balance {:web3 web3 (get-token-balance {:web3 web3
:contract contract :contract contract
:account-id account-id :account-id account-id
:on-success #(re-frame/dispatch [success-event symbol %]) :on-success #(re-frame/dispatch [success-event symbol %])
:on-error #(re-frame/dispatch [error-event %])}))))) :on-error #(re-frame/dispatch [error-event %])})))))
(reg-fx (reg-fx
:get-transactions :get-transactions
(fn [{:keys [network account-id success-event error-event]}] (fn [{:keys [network account-id success-event error-event]}]
(transactions/get-transactions network (transactions/get-transactions network
account-id account-id
#(re-frame/dispatch [success-event %]) #(re-frame/dispatch [success-event %])
#(re-frame/dispatch [error-event %])))) #(re-frame/dispatch [error-event %]))))
;; TODO(oskarth): At some point we want to get list of relevant assets to get prices for ;; TODO(oskarth): At some point we want to get list of relevant assets to get prices for
(reg-fx (reg-fx
:get-prices :get-prices
(fn [{:keys [from to success-event error-event]}] (fn [{:keys [from to success-event error-event]}]
(prices/get-prices from (prices/get-prices from
to to
#(re-frame/dispatch [success-event %]) #(re-frame/dispatch [success-event %])
#(re-frame/dispatch [error-event %])))) #(re-frame/dispatch [error-event %]))))
(reg-fx (reg-fx
:update-gas-price :update-gas-price
(fn [{:keys [web3 success-event edit?]}] (fn [{:keys [web3 success-event edit?]}]
(ethereum/gas-price web3 #(re-frame/dispatch [success-event %2 edit?])))) (ethereum/gas-price web3 #(re-frame/dispatch [success-event %2 edit?]))))
(reg-fx (reg-fx
:update-estimated-gas :update-estimated-gas
(fn [{:keys [web3 obj success-event]}] (fn [{:keys [web3 obj success-event]}]
(ethereum/estimate-gas-web3 web3 (clj->js obj) #(re-frame/dispatch [success-event %2])))) (ethereum/estimate-gas-web3 web3 (clj->js obj) #(re-frame/dispatch [success-event %2]))))
;; Handlers ;; Handlers
(handlers/register-handler-fx (handlers/register-handler-fx
:update-wallet :update-wallet
(fn [{{:keys [web3 account/account network network-status] :as db} :db} _] (fn [{{:keys [web3 account/account network network-status] :as db} :db} _]
(let [chain (ethereum/network->chain-keyword network) (let [chain (ethereum/network->chain-keyword network)
mainnet? (= :mainnet chain) mainnet? (= :mainnet chain)
address (:address account) address (:address account)
symbols (get-in account [:settings :wallet :visible-tokens chain])] symbols (get-in account [:settings :wallet :visible-tokens chain])]
(when (not= network-status :offline) (when (not= network-status :offline)
{:get-balance {:web3 web3 {:get-balance {:web3 web3
:account-id address :account-id address
:success-event :update-balance-success :success-event :update-balance-success
:error-event :update-balance-fail} :error-event :update-balance-fail}
:get-tokens-balance {:web3 web3 :get-tokens-balance {:web3 web3
:account-id address :account-id address
:symbols symbols :symbols symbols
:chain chain :chain chain
:success-event :update-token-balance-success :success-event :update-token-balance-success
:error-event :update-token-balance-fail} :error-event :update-token-balance-fail}
:get-prices {:from (if mainnet? (conj symbols "ETH") ["ETH"]) :get-prices {:from (if mainnet? (conj symbols "ETH") ["ETH"])
:to ["USD"] :to ["USD"]
:success-event :update-prices-success :success-event :update-prices-success
:error-event :update-prices-fail} :error-event :update-prices-fail}
:db (-> db :db (-> db
(clear-error-message :prices-update) (clear-error-message :prices-update)
(clear-error-message :balance-update) (clear-error-message :balance-update)
(assoc-in [:wallet :balance-loading?] true) (assoc-in [:wallet :balance-loading?] true)
(assoc :prices-loading? true))})))) (assoc :prices-loading? true))}))))
(handlers/register-handler-fx (handlers/register-handler-fx
:update-transactions :update-transactions
(fn [{{:keys [network network-status] :as db} :db} _] (fn [{{:keys [network network-status] :as db} :db} _]
(when (not= network-status :offline) (when (not= network-status :offline)
{:get-transactions {:account-id (get-in db [:account/account :address]) {:get-transactions {:account-id (get-in db [:account/account :address])
:network network :network network
:success-event :update-transactions-success :success-event :update-transactions-success
:error-event :update-transactions-fail} :error-event :update-transactions-fail}
:db (-> db :db (-> db
(clear-error-message :transactions-update) (clear-error-message :transactions-update)
(assoc-in [:wallet :transactions-loading?] true))}))) (assoc-in [:wallet :transactions-loading?] true))})))
(handlers/register-handler-db (handlers/register-handler-db
:update-transactions-success :update-transactions-success
(fn [db [_ transactions]] (fn [db [_ transactions]]
(-> db (-> db
(update-in [:wallet :transactions] merge transactions) (update-in [:wallet :transactions] merge transactions)
(assoc-in [:wallet :transactions-loading?] false)))) (assoc-in [:wallet :transactions-loading?] false))))
(handlers/register-handler-db (handlers/register-handler-db
:update-transactions-fail :update-transactions-fail
(fn [db [_ err]] (fn [db [_ err]]
(log/debug "Unable to get transactions: " err) (log/debug "Unable to get transactions: " err)
(-> db (-> db
(assoc-error-message :transactions-update err) (assoc-error-message :transactions-update err)
(assoc-in [:wallet :transactions-loading?] false)))) (assoc-in [:wallet :transactions-loading?] false))))
(handlers/register-handler-db (handlers/register-handler-db
:update-balance-success :update-balance-success
(fn [db [_ balance]] (fn [db [_ balance]]
(-> db (-> db
(assoc-in [:wallet :balance :ETH] balance) (assoc-in [:wallet :balance :ETH] balance)
(assoc-in [:wallet :balance-loading?] false)))) (assoc-in [:wallet :balance-loading?] false))))
(handlers/register-handler-db (handlers/register-handler-db
:update-balance-fail :update-balance-fail
(fn [db [_ err]] (fn [db [_ err]]
(log/debug "Unable to get balance: " err) (log/debug "Unable to get balance: " err)
(-> db (-> db
(assoc-error-message :balance-update err) (assoc-error-message :balance-update err)
(assoc-in [:wallet :balance-loading?] false)))) (assoc-in [:wallet :balance-loading?] false))))
(handlers/register-handler-db (handlers/register-handler-db
:update-token-balance-success :update-token-balance-success
(fn [db [_ symbol balance]] (fn [db [_ symbol balance]]
(-> db (-> db
(assoc-in [:wallet :balance symbol] balance) (assoc-in [:wallet :balance symbol] balance)
(assoc-in [:wallet :balance-loading?] false)))) (assoc-in [:wallet :balance-loading?] false))))
(handlers/register-handler-db (handlers/register-handler-db
:update-token-balance-fail :update-token-balance-fail
(fn [db [_ err]] (fn [db [_ err]]
(log/debug "Unable to get token balance: " err) (log/debug "Unable to get token balance: " err)
(-> db (-> db
(assoc-error-message :balance-update err) (assoc-error-message :balance-update err)
(assoc-in [:wallet :balance-loading?] false)))) (assoc-in [:wallet :balance-loading?] false))))
(handlers/register-handler-db (handlers/register-handler-db
:update-prices-success :update-prices-success
(fn [db [_ prices]] (fn [db [_ prices]]
(assoc db (assoc db
:prices prices :prices prices
:prices-loading? false))) :prices-loading? false)))
(handlers/register-handler-db (handlers/register-handler-db
:update-prices-fail :update-prices-fail
(fn [db [_ err]] (fn [db [_ err]]
(log/debug "Unable to get prices: " err) (log/debug "Unable to get prices: " err)
(-> db (-> db
(assoc-error-message :prices-update err) (assoc-error-message :prices-update err)
(assoc :prices-loading? false)))) (assoc :prices-loading? false))))
(handlers/register-handler-fx (handlers/register-handler-fx
:show-transaction-details :show-transaction-details
(fn [{:keys [db]} [_ hash]] (fn [{:keys [db]} [_ hash]]
{:db (assoc-in db [:wallet :current-transaction] hash) {:db (assoc-in db [:wallet :current-transaction] hash)
:dispatch [:navigate-to :wallet-transaction-details]})) :dispatch [:navigate-to :wallet-transaction-details]}))
(handlers/register-handler-fx (handlers/register-handler-fx
:wallet/show-sign-transaction :wallet/show-sign-transaction
(fn [{:keys [db]} [_ id from-chat?]] (fn [{:keys [db]} [_ id from-chat?]]
{:db (assoc-in db [:wallet :send-transaction] {:id id {:db (assoc-in db [:wallet :send-transaction] {:id id
:from-chat? from-chat?}) :from-chat? from-chat?})
:dispatch [:navigate-to-modal :wallet-send-transaction-modal]})) :dispatch [:navigate-to-modal :wallet-send-transaction-modal]}))
(handlers/register-handler-fx (handlers/register-handler-fx
:wallet/discard-unsigned-transaction :wallet/discard-unsigned-transaction
(fn [_ [_ transaction-id]] (fn [_ [_ transaction-id]]
{:discard-transaction transaction-id})) {:discard-transaction transaction-id}))
(handlers/register-handler-fx (handlers/register-handler-fx
:wallet/discard-unsigned-transaction-with-confirmation :wallet/discard-unsigned-transaction-with-confirmation
(fn [_ [_ transaction-id]] (fn [_ [_ transaction-id]]
{:show-confirmation {:title (i18n/label :t/transactions-delete) {:show-confirmation {:title (i18n/label :t/transactions-delete)
:content (i18n/label :t/transactions-delete-content) :content (i18n/label :t/transactions-delete-content)
:confirm-button-text (i18n/label :t/confirm) :confirm-button-text (i18n/label :t/confirm)
:on-accept #(re-frame/dispatch [:wallet/discard-unsigned-transaction transaction-id])}})) :on-accept #(re-frame/dispatch [:wallet/discard-unsigned-transaction transaction-id])}}))
(handlers/register-handler-fx (handlers/register-handler-fx
:wallet/update-gas-price :wallet/update-gas-price
(fn [{:keys [db]} [_ edit?]] (fn [{:keys [db]} [_ edit?]]
{:update-gas-price {:web3 (:web3 db) {:update-gas-price {:web3 (:web3 db)
:success-event :wallet/update-gas-price-success :success-event :wallet/update-gas-price-success
:edit? edit?}})) :edit? edit?}}))
(handlers/register-handler-db (handlers/register-handler-db
:wallet/update-gas-price-success :wallet/update-gas-price-success
(fn [db [_ price edit?]] (fn [db [_ price edit?]]
(assoc-in db [:wallet (if edit? :edit :send-transaction) :gas-price] price))) (assoc-in db [:wallet (if edit? :edit :send-transaction) :gas-price] price)))
(handlers/register-handler-fx (handlers/register-handler-fx
:wallet/update-estimated-gas :wallet/update-estimated-gas
(fn [{:keys [db]} [_ obj]] (fn [{:keys [db]} [_ obj]]
{:update-estimated-gas {:web3 (:web3 db) {:update-estimated-gas {:web3 (:web3 db)
:obj obj :obj obj
:success-event :wallet/update-estimated-gas-success}})) :success-event :wallet/update-estimated-gas-success}}))
(handlers/register-handler-db (handlers/register-handler-db
:wallet/update-estimated-gas-success :wallet/update-estimated-gas-success
(fn [db [_ gas]] (fn [db [_ gas]]
(assoc-in db [:wallet :send-transaction :gas] (money/bignumber gas)))) (assoc-in db [:wallet :send-transaction :gas] (money/bignumber gas))))
(handlers/register-handler-fx (handlers/register-handler-fx
:wallet/show-error :wallet/show-error
(fn [] (fn []
{:show-error (i18n/label :t/wallet-error)})) {:show-error (i18n/label :t/wallet-error)}))

View File

@ -19,7 +19,6 @@
{:gas (ethereum/estimate-gas symbol) {:gas (ethereum/estimate-gas symbol)
:symbol symbol})) :symbol symbol}))
(defmethod navigation/preload-data! :wallet-request-transaction (defmethod navigation/preload-data! :wallet-request-transaction
[db [event]] [db [event]]
(if (= event :navigate-back) (if (= event :navigate-back)

View File

@ -8,4 +8,4 @@
(spec/def ::symbol (spec/nilable keyword?)) (spec/def ::symbol (spec/nilable keyword?))
(spec/def :wallet/request-transaction (allowed-keys (spec/def :wallet/request-transaction (allowed-keys
:opt-un [::amount ::amount-error ::symbol])) :opt-un [::amount ::amount-error ::symbol]))

View File

@ -8,34 +8,34 @@
[status-im.utils.money :as money])) [status-im.utils.money :as money]))
(handlers/register-handler-fx (handlers/register-handler-fx
::wallet-send-chat-request ::wallet-send-chat-request
[re-frame/trim-v] [re-frame/trim-v]
(fn [{{:contacts/keys [contacts]} :db :as cofx} [amount]] (fn [{{:contacts/keys [contacts]} :db :as cofx} [amount]]
(handlers-macro/merge-fx cofx (handlers-macro/merge-fx cofx
{:dispatch [:send-current-message]} {:dispatch [:send-current-message]}
(input-events/select-chat-input-command (input-events/select-chat-input-command
(assoc (get-in contacts chat-const/request-command-ref) :prefill [amount]) nil true)))) (assoc (get-in contacts chat-const/request-command-ref) :prefill [amount]) nil true))))
(handlers/register-handler-fx (handlers/register-handler-fx
:wallet-send-request :wallet-send-request
[re-frame/trim-v] [re-frame/trim-v]
(fn [_ [whisper-identity amount]] (fn [_ [whisper-identity amount]]
(assert whisper-identity) (assert whisper-identity)
{:dispatch-n [[:navigate-back] {:dispatch-n [[:navigate-back]
[:navigate-to-clean :home] [:navigate-to-clean :home]
[:add-chat-loaded-event whisper-identity [:add-chat-loaded-event whisper-identity
[::wallet-send-chat-request (str (money/wei->ether amount))]] [::wallet-send-chat-request (str (money/wei->ether amount))]]
[:start-chat whisper-identity]]})) [:start-chat whisper-identity]]}))
(handlers/register-handler-fx (handlers/register-handler-fx
:wallet.request/set-recipient :wallet.request/set-recipient
(fn [{:keys [db]} [_ s]] (fn [{:keys [db]} [_ s]]
{:db (assoc-in db [:wallet :request-transaction :to] s)})) {:db (assoc-in db [:wallet :request-transaction :to] s)}))
(handlers/register-handler-fx (handlers/register-handler-fx
:wallet.request/set-and-validate-amount :wallet.request/set-and-validate-amount
(fn [{:keys [db]} [_ amount]] (fn [{:keys [db]} [_ amount]]
(let [{:keys [value error]} (wallet-db/parse-amount amount)] (let [{:keys [value error]} (wallet-db/parse-amount amount)]
{:db (-> db {:db (-> db
(assoc-in [:wallet :request-transaction :amount] (money/ether->wei value)) (assoc-in [:wallet :request-transaction :amount] (money/ether->wei value))
(assoc-in [:wallet :request-transaction :amount-error] error))}))) (assoc-in [:wallet :request-transaction :amount-error] error))})))

View File

@ -2,5 +2,5 @@
(:require [re-frame.core :as re-frame])) (:require [re-frame.core :as re-frame]))
(re-frame/reg-sub :wallet.request/transaction (re-frame/reg-sub :wallet.request/transaction
:<- [:wallet] :<- [:wallet]
:request-transaction) :request-transaction)

View File

@ -3,9 +3,9 @@
(defn animate-sign-panel [opacity-value bottom-value] (defn animate-sign-panel [opacity-value bottom-value]
(animation/start (animation/start
(animation/parallel (animation/parallel
[(animation/timing opacity-value {:toValue 1 [(animation/timing opacity-value {:toValue 1
:duration 500}) :duration 500})
(animation/timing bottom-value {:toValue 53 (animation/timing bottom-value {:toValue 53
:easing (.bezier (animation/easing) 0.685, 0.000, 0.025, 1.185) :easing (.bezier (animation/easing) 0.685, 0.000, 0.025, 1.185)
:duration 500})]))) :duration 500})])))

View File

@ -26,8 +26,8 @@
(spec/def ::method (spec/nilable string?)) (spec/def ::method (spec/nilable string?))
(spec/def :wallet/send-transaction (allowed-keys (spec/def :wallet/send-transaction (allowed-keys
:opt-un [::amount ::to ::to-name ::amount-error ::password :opt-un [::amount ::to ::to-name ::amount-error ::password
::waiting-signal? ::signing? ::id ::later? ::waiting-signal? ::signing? ::id ::later?
::camera-flashlight ::in-progress? ::camera-flashlight ::in-progress?
::wrong-password? ::from-chat? ::symbol ::advanced? ::wrong-password? ::from-chat? ::symbol ::advanced?
::gas ::gas-price ::whisper-identity ::method])) ::gas ::gas-price ::whisper-identity ::method]))

View File

@ -19,9 +19,9 @@
;;;; FX ;;;; FX
(re-frame/reg-fx (re-frame/reg-fx
::accept-transaction ::accept-transaction
(fn [{:keys [password id on-completed]}] (fn [{:keys [password id on-completed]}]
(status/approve-sign-requests (list id) password on-completed))) (status/approve-sign-requests (list id) password on-completed)))
(defn- send-ethers [{:keys [web3 from to value gas gas-price]}] (defn- send-ethers [{:keys [web3 from to value gas gas-price]}]
(.sendTransaction (.-eth web3) (.sendTransaction (.-eth web3)
@ -33,31 +33,31 @@
(erc20/transfer web3 contract from to value {:gas gas :gasPrice gas-price} #()))) (erc20/transfer web3 contract from to value {:gas gas :gasPrice gas-price} #())))
(re-frame/reg-fx (re-frame/reg-fx
::send-transaction ::send-transaction
(fn [{:keys [symbol] :as params}] (fn [{:keys [symbol] :as params}]
(case symbol (case symbol
:ETH (send-ethers params) :ETH (send-ethers params)
(send-tokens params)))) (send-tokens params))))
(re-frame/reg-fx (re-frame/reg-fx
::show-transaction-moved ::show-transaction-moved
(fn [modal?] (fn [modal?]
(utils/show-popup (utils/show-popup
(i18n/label :t/transaction-moved-title) (i18n/label :t/transaction-moved-title)
(i18n/label :t/transaction-moved-text) (i18n/label :t/transaction-moved-text)
(when modal? (when modal?
#(re-frame/dispatch [:navigate-back]))))) #(re-frame/dispatch [:navigate-back])))))
(re-frame/reg-fx (re-frame/reg-fx
::show-transaction-error ::show-transaction-error
(fn [message] (fn [message]
;; (andrey) we need this timeout because modal window conflicts with alert ;; (andrey) we need this timeout because modal window conflicts with alert
(utils/set-timeout #(utils/show-popup (i18n/label :t/transaction-failed) message) 1000))) (utils/set-timeout #(utils/show-popup (i18n/label :t/transaction-failed) message) 1000)))
(re-frame/reg-fx (re-frame/reg-fx
:discard-transaction :discard-transaction
(fn [id] (fn [id]
(status/discard-sign-request id))) (status/discard-sign-request id)))
;;Helper functions ;;Helper functions
@ -69,23 +69,23 @@
;;;; Handlers ;;;; Handlers
(handlers/register-handler-fx (handlers/register-handler-fx
:wallet.send/set-and-validate-amount :wallet.send/set-and-validate-amount
(fn [{:keys [db]} [_ amount]] (fn [{:keys [db]} [_ amount]]
(let [{:keys [value error]} (wallet.db/parse-amount amount)] (let [{:keys [value error]} (wallet.db/parse-amount amount)]
{:db (-> db {:db (-> db
(assoc-in [:wallet :send-transaction :amount] (money/ether->wei value)) (assoc-in [:wallet :send-transaction :amount] (money/ether->wei value))
(assoc-in [:wallet :send-transaction :amount-error] error))}))) (assoc-in [:wallet :send-transaction :amount-error] error))})))
(handlers/register-handler-fx (handlers/register-handler-fx
:wallet.send/set-symbol :wallet.send/set-symbol
(fn [{:keys [db]} [_ symbol]] (fn [{:keys [db]} [_ symbol]]
{:db (-> (assoc-in db [:wallet :send-transaction :symbol] symbol) {:db (-> (assoc-in db [:wallet :send-transaction :symbol] symbol)
(assoc-in [:wallet :send-transaction :gas] (ethereum/estimate-gas symbol)))})) (assoc-in [:wallet :send-transaction :gas] (ethereum/estimate-gas symbol)))}))
(handlers/register-handler-fx (handlers/register-handler-fx
:wallet.send/toggle-advanced :wallet.send/toggle-advanced
(fn [{:keys [db]} [_ advanced?]] (fn [{:keys [db]} [_ advanced?]]
{:db (assoc-in db [:wallet :send-transaction :advanced?] advanced?)})) {:db (assoc-in db [:wallet :send-transaction :advanced?] advanced?)}))
(def ^:private clear-send-properties {:id nil (def ^:private clear-send-properties {:id nil
:signing? false :signing? false
@ -100,9 +100,9 @@
(dispatch-transaction-completed result)))) (dispatch-transaction-completed result))))
(handlers/register-handler-fx (handlers/register-handler-fx
:sign-later-from-chat :sign-later-from-chat
(fn [_ _] (fn [_ _]
{::show-transaction-moved true})) {::show-transaction-moved true}))
(defn prepare-transaction [{:keys [id message_id args]} now] (defn prepare-transaction [{:keys [id message_id args]} now]
;;NOTE(goranjovic): the transactions started from chat using /send command ;;NOTE(goranjovic): the transactions started from chat using /send command
@ -125,63 +125,63 @@
;;TRANSACTION QUEUED signal from status-go ;;TRANSACTION QUEUED signal from status-go
(handlers/register-handler-fx (handlers/register-handler-fx
:sign-request-queued :sign-request-queued
(fn [{:keys [db]} [_ transaction]] (fn [{:keys [db]} [_ transaction]]
{:db (update-in db [:wallet :transactions-queue] conj transaction) {:db (update-in db [:wallet :transactions-queue] conj transaction)
:dispatch [:check-transactions-queue]})) :dispatch [:check-transactions-queue]}))
(handlers/register-handler-fx (handlers/register-handler-fx
:check-transactions-queue :check-transactions-queue
[(re-frame/inject-cofx :now)] [(re-frame/inject-cofx :now)]
(fn [{:keys [db now]} _] (fn [{:keys [db now]} _]
(let [{:keys [send-transaction transactions-queue]} (:wallet db) (let [{:keys [send-transaction transactions-queue]} (:wallet db)
{:keys [id method args] :as queued-transaction} (last transactions-queue) {:keys [id method args] :as queued-transaction} (last transactions-queue)
db' (update-in db [:wallet :transactions-queue] drop-last)] db' (update-in db [:wallet :transactions-queue] drop-last)]
(when (and (not (:id send-transaction)) queued-transaction) (when (and (not (:id send-transaction)) queued-transaction)
(cond (cond
;;SEND TRANSACTION ;;SEND TRANSACTION
(= method constants/web3-send-transaction) (= method constants/web3-send-transaction)
(let [{:keys [gas gasPrice]} args (let [{:keys [gas gasPrice]} args
transaction (prepare-transaction queued-transaction now) transaction (prepare-transaction queued-transaction now)
sending-from-bot-or-dapp? (not (get-in db [:wallet :send-transaction :waiting-signal?])) sending-from-bot-or-dapp? (not (get-in db [:wallet :send-transaction :waiting-signal?]))
new-db (assoc-in db' [:wallet :transactions-unsigned id] transaction) new-db (assoc-in db' [:wallet :transactions-unsigned id] transaction)
sending-db {:id id sending-db {:id id
:method method :method method
:from-chat? sending-from-bot-or-dapp?}] :from-chat? sending-from-bot-or-dapp?}]
(if sending-from-bot-or-dapp? (if sending-from-bot-or-dapp?
;;SENDING FROM BOT (CHAT) OR DAPP ;;SENDING FROM BOT (CHAT) OR DAPP
{:db (assoc-in new-db [:wallet :send-transaction] sending-db) ; we need to completely reset sending state here {:db (assoc-in new-db [:wallet :send-transaction] sending-db) ; we need to completely reset sending state here
:dispatch-n [[:update-wallet] :dispatch-n [[:update-wallet]
[:navigate-to-modal :wallet-send-transaction-modal] [:navigate-to-modal :wallet-send-transaction-modal]
(when-not (seq gas) (when-not (seq gas)
[:wallet/update-estimated-gas transaction]) [:wallet/update-estimated-gas transaction])
(when-not (seq gasPrice) (when-not (seq gasPrice)
[:wallet/update-gas-price])]} [:wallet/update-gas-price])]}
;;WALLET SEND SCREEN WAITING SIGNAL ;;WALLET SEND SCREEN WAITING SIGNAL
(let [{:keys [later? password]} (get-in db [:wallet :send-transaction]) (let [{:keys [later? password]} (get-in db [:wallet :send-transaction])
new-db' (update-in new-db [:wallet :send-transaction] merge sending-db)] ; just update sending state as we are in wallet flow new-db' (update-in new-db [:wallet :send-transaction] merge sending-db)] ; just update sending state as we are in wallet flow
(if later? (if later?
;;SIGN LATER ;;SIGN LATER
{:db (assoc-in new-db' [:wallet :send-transaction :waiting-signal?] false) {:db (assoc-in new-db' [:wallet :send-transaction :waiting-signal?] false)
:dispatch [:navigate-back] :dispatch [:navigate-back]
::show-transaction-moved false} ::show-transaction-moved false}
;;SIGN NOW ;;SIGN NOW
{:db new-db' {:db new-db'
::accept-transaction {:id id ::accept-transaction {:id id
:password password :password password
:on-completed on-transactions-completed}})))) :on-completed on-transactions-completed}}))))
;;SIGN MESSAGE ;;SIGN MESSAGE
(= method constants/web3-personal-sign) (= method constants/web3-personal-sign)
(let [{:keys [data]} args (let [{:keys [data]} args
data' (transport.utils/to-utf8 data)] data' (transport.utils/to-utf8 data)]
(if data' (if data'
{:db (-> db' {:db (-> db'
(assoc-in [:wallet :transactions-unsigned id] {:data data' :id id}) (assoc-in [:wallet :transactions-unsigned id] {:data data' :id id})
(assoc-in [:wallet :send-transaction] {:id id :method method})) (assoc-in [:wallet :send-transaction] {:id id :method method}))
:dispatch [:navigate-to-modal :wallet-sign-message-modal]} :dispatch [:navigate-to-modal :wallet-sign-message-modal]}
{:db db'}))))))) {:db db'})))))))
(defn this-transaction-signing? [id signing-id view-id modal] (defn this-transaction-signing? [id signing-id view-id modal]
(and (= signing-id id) (and (= signing-id id)
@ -191,25 +191,25 @@
;;TRANSACTION FAILED signal from status-go ;;TRANSACTION FAILED signal from status-go
(handlers/register-handler-fx (handlers/register-handler-fx
:sign-request-failed :sign-request-failed
(fn [{{:keys [view-id modal] :as db} :db} [_ {:keys [id method error_code error_message]}]] (fn [{{:keys [view-id modal] :as db} :db} [_ {:keys [id method error_code error_message]}]]
(let [send-transaction (get-in db [:wallet :send-transaction])] (let [send-transaction (get-in db [:wallet :send-transaction])]
(case error_code (case error_code
;;WRONG PASSWORD ;;WRONG PASSWORD
constants/send-transaction-password-error-code constants/send-transaction-password-error-code
{:db (assoc-in db [:wallet :send-transaction :wrong-password?] true)} {:db (assoc-in db [:wallet :send-transaction :wrong-password?] true)}
;;NO ERROR, DISCARDED, TIMEOUT or DEFAULT ERROR ;;NO ERROR, DISCARDED, TIMEOUT or DEFAULT ERROR
(if (this-transaction-signing? id (:id send-transaction) view-id modal) (if (this-transaction-signing? id (:id send-transaction) view-id modal)
(cond-> {:db (-> db (cond-> {:db (-> db
(assoc-in [:wallet :transactions-queue] nil) (assoc-in [:wallet :transactions-queue] nil)
(update-in [:wallet :transactions-unsigned] dissoc id) (update-in [:wallet :transactions-unsigned] dissoc id)
(update-in [:wallet :send-transaction] merge clear-send-properties)) (update-in [:wallet :send-transaction] merge clear-send-properties))
:dispatch [:navigate-back]} :dispatch [:navigate-back]}
(= method constants/web3-send-transaction) (= method constants/web3-send-transaction)
(assoc ::show-transaction-error error_message)) (assoc ::show-transaction-error error_message))
{:db (update-in db [:wallet :transactions-unsigned] dissoc id)}))))) {:db (update-in db [:wallet :transactions-unsigned] dissoc id)})))))
(defn prepare-unconfirmed-transaction [db now hash id] (defn prepare-unconfirmed-transaction [db now hash id]
(let [transaction (get-in db [:wallet :transactions-unsigned id])] (let [transaction (get-in db [:wallet :transactions-unsigned id])]
@ -224,26 +224,26 @@
(dissoc :message-id :id)))) (dissoc :message-id :id))))
(handlers/register-handler-fx (handlers/register-handler-fx
::transaction-completed ::transaction-completed
(fn [{db :db now :now} [_ {:keys [id response]} modal?]] (fn [{db :db now :now} [_ {:keys [id response]} modal?]]
(let [{:keys [hash error]} response (let [{:keys [hash error]} response
{:keys [method]} (get-in db [:wallet :send-transaction]) {:keys [method]} (get-in db [:wallet :send-transaction])
db' (assoc-in db [:wallet :send-transaction :in-progress?] false)] db' (assoc-in db [:wallet :send-transaction :in-progress?] false)]
(if (and error (string? error) (not (string/blank? error))) ;; ignore error here, error will be handled in :transaction-failed (if (and error (string? error) (not (string/blank? error))) ;; ignore error here, error will be handled in :transaction-failed
{:db db'} {:db db'}
(merge (merge
{:db (cond-> db' {:db (cond-> db'
(= method constants/web3-send-transaction) (= method constants/web3-send-transaction)
(assoc-in [:wallet :transactions hash] (prepare-unconfirmed-transaction db now hash id)) (assoc-in [:wallet :transactions hash] (prepare-unconfirmed-transaction db now hash id))
true true
(update-in [:wallet :transactions-unsigned] dissoc id) (update-in [:wallet :transactions-unsigned] dissoc id)
true true
(update-in [:wallet :send-transaction] merge clear-send-properties))} (update-in [:wallet :send-transaction] merge clear-send-properties))}
(if modal? (if modal?
(cond-> {:dispatch [:navigate-back]} (cond-> {:dispatch [:navigate-back]}
(= method constants/web3-send-transaction) (= method constants/web3-send-transaction)
(assoc :dispatch-later [{:ms 400 :dispatch [:navigate-to-modal :wallet-transaction-sent-modal]}])) (assoc :dispatch-later [{:ms 400 :dispatch [:navigate-to-modal :wallet-transaction-sent-modal]}]))
{:dispatch [:navigate-to :wallet-transaction-sent]})))))) {:dispatch [:navigate-to :wallet-transaction-sent]}))))))
(defn on-transactions-modal-completed [raw-results] (defn on-transactions-modal-completed [raw-results]
(let [results (:results (types/json->clj raw-results))] (let [results (:results (types/json->clj raw-results))]
@ -251,37 +251,37 @@
(dispatch-transaction-completed result true)))) (dispatch-transaction-completed result true))))
(handlers/register-handler-fx (handlers/register-handler-fx
:wallet/sign-transaction :wallet/sign-transaction
(fn [{{:keys [web3] :as db} :db} [_ later?]] (fn [{{:keys [web3] :as db} :db} [_ later?]]
(let [db' (assoc-in db [:wallet :send-transaction :wrong-password?] false) (let [db' (assoc-in db [:wallet :send-transaction :wrong-password?] false)
network (:network db) network (:network db)
{:keys [amount id password to symbol gas gas-price]} (get-in db [:wallet :send-transaction])] {:keys [amount id password to symbol gas gas-price]} (get-in db [:wallet :send-transaction])]
(if id (if id
{::accept-transaction {:id id {::accept-transaction {:id id
:password password :password password
:on-completed on-transactions-completed} :on-completed on-transactions-completed}
:db (assoc-in db' [:wallet :send-transaction :in-progress?] true)} :db (assoc-in db' [:wallet :send-transaction :in-progress?] true)}
{:db (update-in db' [:wallet :send-transaction] assoc {:db (update-in db' [:wallet :send-transaction] assoc
:waiting-signal? true :waiting-signal? true
:later? later? :later? later?
:in-progress? true) :in-progress? true)
::send-transaction {:web3 web3 ::send-transaction {:web3 web3
:from (get-in db [:account/account :address]) :from (get-in db [:account/account :address])
:to to :to to
:value amount :value amount
:gas gas :gas gas
:gas-price gas-price :gas-price gas-price
:symbol symbol :symbol symbol
:network network}})))) :network network}}))))
(handlers/register-handler-fx (handlers/register-handler-fx
:wallet/sign-transaction-modal :wallet/sign-transaction-modal
(fn [{db :db} _] (fn [{db :db} _]
(let [{:keys [id password]} (get-in db [:wallet :send-transaction])] (let [{:keys [id password]} (get-in db [:wallet :send-transaction])]
{:db (assoc-in db [:wallet :send-transaction :in-progress?] true) {:db (assoc-in db [:wallet :send-transaction :in-progress?] true)
::accept-transaction {:id id ::accept-transaction {:id id
:password password :password password
:on-completed on-transactions-modal-completed}}))) :on-completed on-transactions-modal-completed}})))
(defn discard-transaction (defn discard-transaction
[{:keys [db]}] [{:keys [db]}]
@ -291,69 +291,69 @@
{:discard-transaction id})))) {:discard-transaction id}))))
(handlers/register-handler-fx (handlers/register-handler-fx
:wallet/discard-transaction :wallet/discard-transaction
(fn [cofx _] (fn [cofx _]
(discard-transaction cofx))) (discard-transaction cofx)))
(handlers/register-handler-fx (handlers/register-handler-fx
:wallet/discard-transaction-navigate-back :wallet/discard-transaction-navigate-back
(fn [cofx _] (fn [cofx _]
(-> cofx (-> cofx
discard-transaction discard-transaction
(assoc :dispatch [:navigate-back])))) (assoc :dispatch [:navigate-back]))))
(handlers/register-handler-fx (handlers/register-handler-fx
:wallet/cancel-signing-modal :wallet/cancel-signing-modal
(fn [{:keys [db]} _] (fn [{:keys [db]} _]
{:db (update-in db [:wallet :send-transaction] assoc {:db (update-in db [:wallet :send-transaction] assoc
:signing? false :signing? false
:wrong-password? false :wrong-password? false
:password nil)})) :password nil)}))
(handlers/register-handler-fx (handlers/register-handler-fx
:wallet.send/set-password :wallet.send/set-password
(fn [{:keys [db]} [_ password]] (fn [{:keys [db]} [_ password]]
{:db (assoc-in db [:wallet :send-transaction :password] password)})) {:db (assoc-in db [:wallet :send-transaction :password] password)}))
(handlers/register-handler-fx (handlers/register-handler-fx
:wallet.send/set-signing? :wallet.send/set-signing?
(fn [{:keys [db]} [_ signing?]] (fn [{:keys [db]} [_ signing?]]
{:db (assoc-in db [:wallet :send-transaction :signing?] signing?)})) {:db (assoc-in db [:wallet :send-transaction :signing?] signing?)}))
(handlers/register-handler-fx (handlers/register-handler-fx
:wallet.send/edit-gas :wallet.send/edit-gas
(fn [{:keys [db]} [_ gas]] (fn [{:keys [db]} [_ gas]]
{:db (assoc-in db [:wallet :edit :gas] (money/bignumber gas))})) {:db (assoc-in db [:wallet :edit :gas] (money/bignumber gas))}))
(handlers/register-handler-fx (handlers/register-handler-fx
:wallet.send/edit-gas-price :wallet.send/edit-gas-price
(fn [{:keys [db]} [_ gas-price]] (fn [{:keys [db]} [_ gas-price]]
{:db (assoc-in db [:wallet :edit :gas-price] (money/bignumber gas-price))})) {:db (assoc-in db [:wallet :edit :gas-price] (money/bignumber gas-price))}))
(handlers/register-handler-fx (handlers/register-handler-fx
:wallet.send/set-gas-details :wallet.send/set-gas-details
(fn [{:keys [db]} [_ gas gas-price]] (fn [{:keys [db]} [_ gas gas-price]]
{:db (-> db {:db (-> db
(assoc-in [:wallet :send-transaction :gas] gas) (assoc-in [:wallet :send-transaction :gas] gas)
(assoc-in [:wallet :send-transaction :gas-price] gas-price))})) (assoc-in [:wallet :send-transaction :gas-price] gas-price))}))
(handlers/register-handler-fx (handlers/register-handler-fx
:wallet.send/clear-gas :wallet.send/clear-gas
(fn [{:keys [db]}] (fn [{:keys [db]}]
{:db (update db :wallet dissoc :edit)})) {:db (update db :wallet dissoc :edit)}))
(handlers/register-handler-fx (handlers/register-handler-fx
:wallet.send/reset-gas-default :wallet.send/reset-gas-default
(fn [{:keys [db]}] (fn [{:keys [db]}]
{:dispatch [:wallet/update-gas-price true] {:dispatch [:wallet/update-gas-price true]
:db (update-in db [:wallet :edit] :db (update-in db [:wallet :edit]
assoc assoc
:gas (ethereum/estimate-gas (get-in db [:wallet :send-transaction :symbol])))})) :gas (ethereum/estimate-gas (get-in db [:wallet :send-transaction :symbol])))}))
(handlers/register-handler-fx (handlers/register-handler-fx
:close-transaction-sent-screen :close-transaction-sent-screen
(fn [{:keys [db]} _] (fn [{:keys [db]} _]
{:dispatch (if (= :wallet-send-transaction (second (:navigation-stack db))) {:dispatch (if (= :wallet-send-transaction (second (:navigation-stack db)))
[:navigate-to-clean :wallet] [:navigate-to-clean :wallet]
[:navigate-back]) [:navigate-back])
:dispatch-later [{:ms 400 :dispatch [:check-transactions-queue]}]})) :dispatch-later [{:ms 400 :dispatch [:check-transactions-queue]}]}))

View File

@ -4,60 +4,59 @@
[status-im.utils.hex :as utils.hex])) [status-im.utils.hex :as utils.hex]))
(re-frame/reg-sub ::send-transaction (re-frame/reg-sub ::send-transaction
:<- [:wallet] :<- [:wallet]
(fn [wallet] (fn [wallet]
(let [transaction (:send-transaction wallet)] (let [transaction (:send-transaction wallet)]
;NOTE(goranjovic): the transactions started from chat using /send command ;NOTE(goranjovic): the transactions started from chat using /send command
; are only in ether, so this parameter defaults to ETH ; are only in ether, so this parameter defaults to ETH
(if (:symbol transaction) (if (:symbol transaction)
transaction transaction
(assoc transaction :symbol :ETH))))) (assoc transaction :symbol :ETH)))))
(re-frame/reg-sub :wallet.send/symbol (re-frame/reg-sub :wallet.send/symbol
:<- [::send-transaction] :<- [::send-transaction]
(fn [send-transaction] (fn [send-transaction]
(:symbol send-transaction))) (:symbol send-transaction)))
(re-frame/reg-sub :wallet.send/advanced? (re-frame/reg-sub :wallet.send/advanced?
:<- [::send-transaction] :<- [::send-transaction]
(fn [send-transaction] (fn [send-transaction]
(:advanced? send-transaction))) (:advanced? send-transaction)))
(re-frame/reg-sub :wallet.send/camera-flashlight (re-frame/reg-sub :wallet.send/camera-flashlight
:<- [::send-transaction] :<- [::send-transaction]
(fn [send-transaction] (fn [send-transaction]
(:camera-flashlight send-transaction))) (:camera-flashlight send-transaction)))
(re-frame/reg-sub :wallet.send/wrong-password? (re-frame/reg-sub :wallet.send/wrong-password?
:<- [::send-transaction] :<- [::send-transaction]
(fn [send-transaction] (fn [send-transaction]
(:wrong-password? send-transaction))) (:wrong-password? send-transaction)))
(re-frame/reg-sub :wallet.send/sign-password-enabled? (re-frame/reg-sub :wallet.send/sign-password-enabled?
:<- [::send-transaction] :<- [::send-transaction]
(fn [{:keys [password]}] (fn [{:keys [password]}]
(and (not (nil? password)) (not= password "")))) (and (not (nil? password)) (not= password ""))))
(re-frame/reg-sub ::unsigned-transactions (re-frame/reg-sub ::unsigned-transactions
:<- [:wallet] :<- [:wallet]
(fn [wallet] (fn [wallet]
(:transactions-unsigned wallet))) (:transactions-unsigned wallet)))
(re-frame/reg-sub ::unsigned-transaction (re-frame/reg-sub ::unsigned-transaction
:<- [::send-transaction] :<- [::send-transaction]
:<- [::unsigned-transactions] :<- [::unsigned-transactions]
(fn [[send-transaction unsigned-transactions]] (fn [[send-transaction unsigned-transactions]]
(when-let [unsigned-transaction (get unsigned-transactions (when-let [unsigned-transaction (get unsigned-transactions
(:id send-transaction))] (:id send-transaction))]
(merge send-transaction (merge send-transaction
unsigned-transaction unsigned-transaction
{:gas (or (:gas unsigned-transaction) (:gas send-transaction)) {:gas (or (:gas unsigned-transaction) (:gas send-transaction))
:gas-price (or (:gas-price unsigned-transaction) (:gas-price send-transaction))})))) :gas-price (or (:gas-price unsigned-transaction) (:gas-price send-transaction))}))))
(re-frame/reg-sub :wallet/edit (re-frame/reg-sub :wallet/edit
:<- [:wallet] :<- [:wallet]
:edit) :edit)
(defn sign-enabled? [amount-error to amount] (defn sign-enabled? [amount-error to amount]
(and (and
@ -66,21 +65,21 @@
(not (nil? amount)) (not= amount ""))) (not (nil? amount)) (not= amount "")))
(re-frame/reg-sub :wallet.send/transaction (re-frame/reg-sub :wallet.send/transaction
:<- [::send-transaction] :<- [::send-transaction]
:<- [:balance] :<- [:balance]
(fn [[{:keys [amount symbol] :as transaction} balance]] (fn [[{:keys [amount symbol] :as transaction} balance]]
(assoc transaction :sufficient-funds? (or (nil? amount) (assoc transaction :sufficient-funds? (or (nil? amount)
(money/sufficient-funds? amount (get balance symbol)))))) (money/sufficient-funds? amount (get balance symbol))))))
(re-frame/reg-sub :wallet.send/unsigned-transaction (re-frame/reg-sub :wallet.send/unsigned-transaction
:<- [::unsigned-transaction] :<- [::unsigned-transaction]
:<- [:get-contacts-by-address] :<- [:get-contacts-by-address]
:<- [:balance] :<- [:balance]
(fn [[{:keys [value to symbol] :as transaction} contacts balance]] (fn [[{:keys [value to symbol] :as transaction} contacts balance]]
(when transaction (when transaction
(let [contact (contacts (utils.hex/normalize-hex to)) (let [contact (contacts (utils.hex/normalize-hex to))
sufficient-funds? (money/sufficient-funds? value (get balance symbol))] sufficient-funds? (money/sufficient-funds? value (get balance symbol))]
(cond-> (assoc transaction (cond-> (assoc transaction
:amount value :amount value
:sufficient-funds? sufficient-funds?) :sufficient-funds? sufficient-funds?)
contact (assoc :to-name (:name contact))))))) contact (assoc :to-name (:name contact)))))))

View File

@ -26,11 +26,11 @@
(defn sign-later-popup (defn sign-later-popup
[from-chat?] [from-chat?]
(utils/show-question (utils/show-question
(i18n/label :t/sign-later-title) (i18n/label :t/sign-later-title)
(i18n/label :t/sign-later-text) (i18n/label :t/sign-later-text)
#(re-frame/dispatch (if from-chat? #(re-frame/dispatch (if from-chat?
[:sign-later-from-chat] [:sign-later-from-chat]
[:wallet/sign-transaction true])))) [:wallet/sign-transaction true]))))
(defview sign-panel [message?] (defview sign-panel [message?]
(letsubs [account [:get-current-account] (letsubs [account [:get-current-account]
@ -78,9 +78,9 @@
(defn- sign-enabled? [amount-error to amount] (defn- sign-enabled? [amount-error to amount]
(and (and
(nil? amount-error) (nil? amount-error)
(not (nil? to)) (not= to "") (not (nil? to)) (not= to "")
(not (nil? amount)))) (not (nil? amount))))
;; "Sign Later" and "Sign Transaction >" buttons ;; "Sign Later" and "Sign Transaction >" buttons
(defn- sign-buttons [amount-error to amount sufficient-funds? sign-later-handler modal?] (defn- sign-buttons [amount-error to amount sufficient-funds? sign-later-handler modal?]
@ -233,8 +233,8 @@
sufficient-funds? sufficient-funds?
(if modal? (if modal?
(if from-chat? (if from-chat?
#(sign-later-popup true) #(sign-later-popup true)
#(re-frame/dispatch [:navigate-back])) #(re-frame/dispatch [:navigate-back]))
#(sign-later-popup false)) #(sign-later-popup false))
modal?]) modal?])
(when signing? (when signing?

View File

@ -9,9 +9,9 @@
(disj ids id))) (disj ids id)))
(handlers/register-handler-fx (handlers/register-handler-fx
:wallet.settings/toggle-visible-token :wallet.settings/toggle-visible-token
(fn [{{:keys [network account/account] :as db} :db :as cofx} [_ symbol checked?]] (fn [{{:keys [network account/account] :as db} :db :as cofx} [_ symbol checked?]]
(let [chain (ethereum/network->chain-keyword network) (let [chain (ethereum/network->chain-keyword network)
settings (get account :settings) settings (get account :settings)
new-settings (update-in settings [:wallet :visible-tokens chain] #(toggle-checked % symbol checked?))] new-settings (update-in settings [:wallet :visible-tokens chain] #(toggle-checked % symbol checked?))]
(accounts/update-settings new-settings cofx)))) (accounts/update-settings new-settings cofx))))

View File

@ -35,15 +35,15 @@
(defn cartouche-content-wrapper [disabled?] (defn cartouche-content-wrapper [disabled?]
(merge (merge
{:flex-direction :row {:flex-direction :row
:margin-top 8 :margin-top 8
:border-radius styles/border-radius :border-radius styles/border-radius
:padding-left 14 :padding-left 14
:padding-right 8} :padding-right 8}
(if disabled? (if disabled?
{:border-color colors/white-light-transparent {:border-color colors/white-light-transparent
:border-width 1} :border-width 1}
{:background-color colors/white-transparent}))) {:background-color colors/white-transparent})))
(def cartouche-icon-wrapper (def cartouche-icon-wrapper
{:flex 1 {:flex 1

View File

@ -5,38 +5,38 @@
[status-im.utils.ethereum.tokens :as tokens])) [status-im.utils.ethereum.tokens :as tokens]))
(re-frame/reg-sub :wallet (re-frame/reg-sub :wallet
(fn [db] (fn [db]
(:wallet db))) (:wallet db)))
(re-frame/reg-sub :balance (re-frame/reg-sub :balance
:<- [:wallet] :<- [:wallet]
(fn [wallet] (fn [wallet]
(:balance wallet))) (:balance wallet)))
(re-frame/reg-sub :prices (re-frame/reg-sub :prices
(fn [db] (fn [db]
(:prices db))) (:prices db)))
(re-frame/reg-sub :price (re-frame/reg-sub :price
:<- [:prices] :<- [:prices]
(fn [prices [_ fsym tsym]] (fn [prices [_ fsym tsym]]
(get-in prices [fsym tsym :price]))) (get-in prices [fsym tsym :price])))
(re-frame/reg-sub :last-day (re-frame/reg-sub :last-day
:<- [:prices] :<- [:prices]
(fn [prices [_ fsym tsym]] (fn [prices [_ fsym tsym]]
(get-in prices [fsym tsym :last-day]))) (get-in prices [fsym tsym :last-day])))
(re-frame/reg-sub :asset-value (re-frame/reg-sub :asset-value
(fn [[_ fsym tsym]] (fn [[_ fsym tsym]]
[(re-frame/subscribe [:balance]) [(re-frame/subscribe [:balance])
(re-frame/subscribe [:price fsym tsym])]) (re-frame/subscribe [:price fsym tsym])])
(fn [[balance price] [_ fsym tsym]] (fn [[balance price] [_ fsym tsym]]
(when (and balance price) (when (and balance price)
(-> (money/wei->ether (get balance fsym)) (-> (money/wei->ether (get balance fsym))
(money/eth->fiat price) (money/eth->fiat price)
(money/with-precision 2) (money/with-precision 2)
str)))) str))))
(defn- get-balance-total-value [balance prices currency] (defn- get-balance-total-value [balance prices currency]
(->> balance (->> balance
@ -48,52 +48,52 @@
acc)) 0))) acc)) 0)))
(re-frame/reg-sub :portfolio-value (re-frame/reg-sub :portfolio-value
:<- [:balance] :<- [:balance]
:<- [:prices] :<- [:prices]
(fn [[balance prices] [_ currency]] (fn [[balance prices] [_ currency]]
(if (and balance prices) (if (and balance prices)
(let [balance-total-value (get-balance-total-value balance prices currency)] (let [balance-total-value (get-balance-total-value balance prices currency)]
(-> balance-total-value (-> balance-total-value
(money/with-precision 2) (money/with-precision 2)
str)) str))
"..."))) "...")))
(re-frame/reg-sub :prices-loading? (re-frame/reg-sub :prices-loading?
(fn [db] (fn [db]
(:prices-loading? db))) (:prices-loading? db)))
(re-frame/reg-sub :wallet/balance-loading? (re-frame/reg-sub :wallet/balance-loading?
:<- [:wallet] :<- [:wallet]
(fn [wallet] (fn [wallet]
(:balance-loading? wallet))) (:balance-loading? wallet)))
(re-frame/reg-sub :wallet/error-message? (re-frame/reg-sub :wallet/error-message?
:<- [:wallet] :<- [:wallet]
(fn [wallet] (fn [wallet]
(or (get-in wallet [:errors :balance-update]) (or (get-in wallet [:errors :balance-update])
(get-in wallet [:errors :prices-update])))) (get-in wallet [:errors :prices-update]))))
(re-frame/reg-sub :get-wallet-unread-messages-number (re-frame/reg-sub :get-wallet-unread-messages-number
(fn [db] (fn [db]
0)) 0))
(re-frame/reg-sub :wallet/visible-tokens-symbols (re-frame/reg-sub :wallet/visible-tokens-symbols
:<- [:network] :<- [:network]
:<- [:get-current-account] :<- [:get-current-account]
(fn [[network current-account]] (fn [[network current-account]]
(let [chain (ethereum/network->chain-keyword network)] (let [chain (ethereum/network->chain-keyword network)]
(get-in current-account [:settings :wallet :visible-tokens chain])))) (get-in current-account [:settings :wallet :visible-tokens chain]))))
(re-frame/reg-sub :wallet/visible-assets (re-frame/reg-sub :wallet/visible-assets
:<- [:network] :<- [:network]
:<- [:wallet/visible-tokens-symbols] :<- [:wallet/visible-tokens-symbols]
(fn [[network visible-tokens-symbols]] (fn [[network visible-tokens-symbols]]
(conj (filter #(contains? visible-tokens-symbols (:symbol %)) (conj (filter #(contains? visible-tokens-symbols (:symbol %))
(tokens/tokens-for (ethereum/network->chain-keyword network))) (tokens/tokens-for (ethereum/network->chain-keyword network)))
tokens/ethereum))) tokens/ethereum)))
(re-frame/reg-sub :wallet/visible-assets-with-amount (re-frame/reg-sub :wallet/visible-assets-with-amount
:<- [:balance] :<- [:balance]
:<- [:wallet/visible-assets] :<- [:wallet/visible-assets]
(fn [[balance visible-assets]] (fn [[balance visible-assets]]
(map #(assoc % :amount (get balance (:symbol %))) visible-assets))) (map #(assoc % :amount (get balance (:symbol %))) visible-assets)))

View File

@ -11,11 +11,11 @@
(update-in db [:wallet.transactions :filters] f)) (update-in db [:wallet.transactions :filters] f))
(handlers/register-handler-db (handlers/register-handler-db
:wallet.transactions/filter :wallet.transactions/filter
(fn [db [_ path checked?]] (fn [db [_ path checked?]]
(update-filters db #(mark-checked % path checked?)))) (update-filters db #(mark-checked % path checked?))))
(handlers/register-handler-db (handlers/register-handler-db
:wallet.transactions/filter-all :wallet.transactions/filter-all
(fn [db] (fn [db]
(update-filters db mark-all-checked))) (update-filters db mark-all-checked)))

View File

@ -7,14 +7,14 @@
[status-im.utils.transactions :as transactions])) [status-im.utils.transactions :as transactions]))
(reg-sub :wallet.transactions/transactions-loading? (reg-sub :wallet.transactions/transactions-loading?
:<- [:wallet] :<- [:wallet]
(fn [wallet] (fn [wallet]
(:transactions-loading? wallet))) (:transactions-loading? wallet)))
(reg-sub :wallet.transactions/current-tab (reg-sub :wallet.transactions/current-tab
:<- [:wallet] :<- [:wallet]
(fn [wallet] (fn [wallet]
(get wallet :current-tab 0))) (get wallet :current-tab 0)))
(defn enrich-transaction [{:keys [type to from timestamp] :as transaction} contacts] (defn enrich-transaction [{:keys [type to from timestamp] :as transaction} contacts]
(let [[contact-address key-contact key-wallet] (if (= type :inbound) (let [[contact-address key-contact key-wallet] (if (= type :inbound)
@ -28,18 +28,18 @@
:time-formatted (datetime/timestamp->time timestamp))))) :time-formatted (datetime/timestamp->time timestamp)))))
(reg-sub :wallet.transactions/transactions (reg-sub :wallet.transactions/transactions
:<- [:wallet] :<- [:wallet]
:<- [:get-contacts-by-address] :<- [:get-contacts-by-address]
(fn [[wallet contacts]] (fn [[wallet contacts]]
(reduce (fn [acc [hash transaction]] (reduce (fn [acc [hash transaction]]
(assoc acc hash (enrich-transaction transaction contacts))) (assoc acc hash (enrich-transaction transaction contacts)))
{} {}
(:transactions wallet)))) (:transactions wallet))))
(reg-sub :wallet.transactions/grouped-transactions (reg-sub :wallet.transactions/grouped-transactions
:<- [:wallet.transactions/transactions] :<- [:wallet.transactions/transactions]
(fn [transactions] (fn [transactions]
(group-by :type (vals transactions)))) (group-by :type (vals transactions))))
(defn- format-unsigned-transaction [{:keys [id] :as transaction}] (defn- format-unsigned-transaction [{:keys [id] :as transaction}]
(assoc transaction (assoc transaction
@ -49,44 +49,44 @@
:hash id)) :hash id))
(reg-sub :wallet/unsigned-transactions (reg-sub :wallet/unsigned-transactions
:<- [:wallet] :<- [:wallet]
:<- [:get-contacts-by-address] :<- [:get-contacts-by-address]
(fn [[wallet contacts]] (fn [[wallet contacts]]
(map #(enrich-transaction % contacts) (vals (:transactions-unsigned wallet))))) (map #(enrich-transaction % contacts) (vals (:transactions-unsigned wallet)))))
(reg-sub :wallet.transactions/unsigned-transactions (reg-sub :wallet.transactions/unsigned-transactions
:<- [:wallet/unsigned-transactions] :<- [:wallet/unsigned-transactions]
(fn [transactions] (fn [transactions]
(reduce (fn [acc {:keys [id] :as transaction}] (reduce (fn [acc {:keys [id] :as transaction}]
(assoc acc id (format-unsigned-transaction transaction))) (assoc acc id (format-unsigned-transaction transaction)))
{} {}
transactions))) transactions)))
(reg-sub :wallet.transactions/unsigned-transactions-count (reg-sub :wallet.transactions/unsigned-transactions-count
:<- [:wallet.transactions/unsigned-transactions] :<- [:wallet.transactions/unsigned-transactions]
(fn [unsigned-transactions] (fn [unsigned-transactions]
(count unsigned-transactions))) (count unsigned-transactions)))
(reg-sub :wallet.transactions/unsigned-transactions-list (reg-sub :wallet.transactions/unsigned-transactions-list
:<- [:wallet.transactions/unsigned-transactions] :<- [:wallet.transactions/unsigned-transactions]
(fn [unsigned-transactions] (fn [unsigned-transactions]
(vals unsigned-transactions))) (vals unsigned-transactions)))
(reg-sub :wallet.transactions/postponed-transactions-list (reg-sub :wallet.transactions/postponed-transactions-list
:<- [:wallet.transactions/grouped-transactions] :<- [:wallet.transactions/grouped-transactions]
(fn [{:keys [postponed]}] (fn [{:keys [postponed]}]
(when postponed (when postponed
{:title "Postponed" {:title "Postponed"
:key :postponed :key :postponed
:data postponed}))) :data postponed})))
(reg-sub :wallet.transactions/pending-transactions-list (reg-sub :wallet.transactions/pending-transactions-list
:<- [:wallet.transactions/grouped-transactions] :<- [:wallet.transactions/grouped-transactions]
(fn [{:keys [pending]}] (fn [{:keys [pending]}]
(when pending (when pending
{:title "Pending" {:title "Pending"
:key :pending :key :pending
:data pending}))) :data pending})))
(defn group-transactions-by-date [transactions] (defn group-transactions-by-date [transactions]
(->> transactions (->> transactions
@ -99,68 +99,68 @@
:data (sort-by :timestamp > transactions)})))) :data (sort-by :timestamp > transactions)}))))
(reg-sub :wallet.transactions/completed-transactions-list (reg-sub :wallet.transactions/completed-transactions-list
:<- [:wallet.transactions/grouped-transactions] :<- [:wallet.transactions/grouped-transactions]
(fn [{:keys [inbound outbound]}] (fn [{:keys [inbound outbound]}]
(group-transactions-by-date (into inbound outbound)))) (group-transactions-by-date (into inbound outbound))))
(reg-sub :wallet.transactions/transactions-history-list (reg-sub :wallet.transactions/transactions-history-list
:<- [:wallet.transactions/postponed-transactions-list] :<- [:wallet.transactions/postponed-transactions-list]
:<- [:wallet.transactions/pending-transactions-list] :<- [:wallet.transactions/pending-transactions-list]
:<- [:wallet.transactions/completed-transactions-list] :<- [:wallet.transactions/completed-transactions-list]
(fn [[postponed pending completed]] (fn [[postponed pending completed]]
(cond-> [] (cond-> []
postponed (into postponed) postponed (into postponed)
pending (into pending) pending (into pending)
completed (into completed)))) completed (into completed))))
(reg-sub :wallet.transactions/current-transaction (reg-sub :wallet.transactions/current-transaction
:<- [:wallet] :<- [:wallet]
(fn [wallet] (fn [wallet]
(:current-transaction wallet))) (:current-transaction wallet)))
(reg-sub :wallet.transactions/transaction-details (reg-sub :wallet.transactions/transaction-details
:<- [:wallet.transactions/unsigned-transactions] :<- [:wallet.transactions/unsigned-transactions]
:<- [:wallet.transactions/transactions] :<- [:wallet.transactions/transactions]
:<- [:wallet.transactions/current-transaction] :<- [:wallet.transactions/current-transaction]
:<- [:network] :<- [:network]
(fn [[unsigned-transactions transactions current-transaction network]] (fn [[unsigned-transactions transactions current-transaction network]]
(let [transactions (merge transactions unsigned-transactions) (let [transactions (merge transactions unsigned-transactions)
{:keys [gas-used gas-price hash timestamp type] :as transaction} (get transactions current-transaction)] {:keys [gas-used gas-price hash timestamp type] :as transaction} (get transactions current-transaction)]
(when transaction (when transaction
(merge transaction (merge transaction
{:gas-price-eth (money/wei->str :eth gas-price) {:gas-price-eth (money/wei->str :eth gas-price)
:gas-price-gwei (money/wei->str :gwei gas-price) :gas-price-gwei (money/wei->str :gwei gas-price)
:date (datetime/timestamp->long-date timestamp)} :date (datetime/timestamp->long-date timestamp)}
(if (= type :unsigned) (if (= type :unsigned)
{:block (i18n/label :not-applicable) {:block (i18n/label :not-applicable)
:cost (i18n/label :not-applicable) :cost (i18n/label :not-applicable)
:gas-limit (i18n/label :not-applicable) :gas-limit (i18n/label :not-applicable)
:gas-used (i18n/label :not-applicable) :gas-used (i18n/label :not-applicable)
:nonce (i18n/label :not-applicable) :nonce (i18n/label :not-applicable)
:hash (i18n/label :not-applicable)} :hash (i18n/label :not-applicable)}
{:cost (when gas-used {:cost (when gas-used
(money/wei->str :eth (money/fee-value gas-used gas-price))) (money/wei->str :eth (money/fee-value gas-used gas-price)))
:url (transactions/get-transaction-details-url network hash)})))))) :url (transactions/get-transaction-details-url network hash)}))))))
(reg-sub :wallet.transactions.details/confirmations (reg-sub :wallet.transactions.details/confirmations
:<- [:wallet.transactions/transaction-details] :<- [:wallet.transactions/transaction-details]
(fn [transaction-details] (fn [transaction-details]
;;TODO (yenda) this field should be calculated based on the current-block and the block of the transaction ;;TODO (yenda) this field should be calculated based on the current-block and the block of the transaction
(:confirmations transaction-details))) (:confirmations transaction-details)))
(reg-sub :wallet.transactions.details/confirmations-progress (reg-sub :wallet.transactions.details/confirmations-progress
:<- [:wallet.transactions.details/confirmations] :<- [:wallet.transactions.details/confirmations]
(fn [confirmations] (fn [confirmations]
(let [max-confirmations 10] (let [max-confirmations 10]
(if (>= confirmations max-confirmations) (if (>= confirmations max-confirmations)
100 100
(* 100 (/ confirmations max-confirmations)))))) (* 100 (/ confirmations max-confirmations))))))
(reg-sub :wallet.transactions/filters (reg-sub :wallet.transactions/filters
(fn [db] (fn [db]
(get-in db [:wallet.transactions :filters]))) (get-in db [:wallet.transactions :filters])))
(reg-sub :wallet.transactions/error-message? (reg-sub :wallet.transactions/error-message?
:<- [:wallet] :<- [:wallet]
(fn [wallet] (fn [wallet]
(get-in wallet [:errors :transactions-update]))) (get-in wallet [:errors :transactions-update])))

View File

@ -19,9 +19,9 @@
(defn history-action [filter?] (defn history-action [filter?]
(cond-> (cond->
{:icon :icons/filter {:icon :icons/filter
:icon-opts {:accessibility-label :filters-button} :icon-opts {:accessibility-label :filters-button}
:handler #(re-frame/dispatch [:navigate-to-modal :wallet-transactions-filter])} :handler #(re-frame/dispatch [:navigate-to-modal :wallet-transactions-filter])}
filter? (assoc-in [:icon-opts :overlay-style] styles/corner-dot))) filter? (assoc-in [:icon-opts :overlay-style] styles/corner-dot)))
(defn- all-checked? [filter-data] (defn- all-checked? [filter-data]