Skip to content

Commit

Permalink
remove firebase and notifications clojure side
Browse files Browse the repository at this point in the history
  • Loading branch information
yenda committed Oct 28, 2019
1 parent d3bc951 commit e486506
Show file tree
Hide file tree
Showing 32 changed files with 172 additions and 536 deletions.
15 changes: 7 additions & 8 deletions fiddle/src/fiddle/views/screens.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
[status-im.ui.screens.wallet.add-new.views :as add-new]
[fiddle.frame :as frame]))

;:generate-key
;:choose-key
;:select-key-storage
;:create-code
;:confirm-code
;:enable-fingerprint
;:enable-notifications
;;:generate-key
;;:choose-key
;;:select-key-storage
;;:create-code
;;:confirm-code
;;:enable-fingerprint
(re-frame/reg-sub :intro-wizard (fn [_] {:step :generate-key :generating-keys? false}))

(defn screens []
Expand All @@ -21,4 +20,4 @@
[frame/frame
[intro/wizard]]
[frame/frame
[add-new/add-account]]])
[add-new/add-account]]])
1 change: 0 additions & 1 deletion src/status_im/chat/models/message.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
[status-im.ethereum.core :as ethereum]
[status-im.mailserver.core :as mailserver]
[status-im.native-module.core :as status]
[status-im.notifications.core :as notifications]
[status-im.transport.message.group-chat :as message.group-chat]
[status-im.transport.message.protocol :as protocol]
[status-im.transport.message.transit :as transit]
Expand Down
21 changes: 6 additions & 15 deletions src/status_im/contact/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[status-im.multiaccounts.model :as multiaccounts.model]
[status-im.transport.filters.core :as transport.filters]
[status-im.contact.db :as contact.db]
[status-im.contact.device-info :as device-info]

[status-im.ethereum.core :as ethereum]
[status-im.data-store.contacts :as contacts-store]
[status-im.mailserver.core :as mailserver]
Expand Down Expand Up @@ -43,13 +43,10 @@

(defn- own-info
[db]
(let [{:keys [name preferred-name photo-path address]} (:multiaccount db)
fcm-token (get-in db [:notifications :fcm-token])]
(let [{:keys [name preferred-name photo-path address]} (:multiaccount db)]
{:name (or preferred-name name)
:profile-image photo-path
:address address
:device-info (device-info/all {:db db})
:fcm-token fcm-token}))
:address address}))

(fx/defn upsert-contact
[{:keys [db] :as cofx}
Expand Down Expand Up @@ -105,7 +102,7 @@
[{{:contacts/keys [contacts] :as db} :db :as cofx}
public-key
timestamp
{:keys [name profile-image address fcm-token device-info] :as m}]
{:keys [name profile-image address] :as m}]
;; We need to convert to timestamp ms as before we were using now in ms to
;; set last updated
;; Using whisper timestamp mostly works but breaks in a few scenarios:
Expand All @@ -121,22 +118,17 @@
(let [contact (get contacts public-key)

;; Backward compatibility with <= 0.9.21, as they don't send
;; fcm-token & address in contact updates
;; address in contact updates
contact-props
(cond-> {:public-key public-key
:photo-path profile-image
:name name
:address (or address
(:address contact)
(ethereum/public-key->address public-key))
:device-info (device-info/merge-info
timestamp
(:device-info contact)
device-info)
:last-updated timestamp-ms
:system-tags (conj (get contact :system-tags #{})
:contact/request-received)}
fcm-token (assoc :fcm-token fcm-token))]
:contact/request-received)})]
(upsert-contact cofx contact-props)))))

(fx/defn initialize-contacts [cofx]
Expand Down Expand Up @@ -182,4 +174,3 @@
{:events [:contacts/ens-names-verified]}
[{:keys [db]} names]
{:db (update db :contacts/contacts add-ens-names names)})

4 changes: 1 addition & 3 deletions src/status_im/contact/db.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
;;Contact

(spec/def :contact/address (spec/nilable :global/address))
(spec/def :contact/fcm-token (spec/nilable string?))
(spec/def :contact/last-online (spec/nilable int?))
(spec/def :contact/last-updated (spec/nilable int?))
(spec/def :contact/name (spec/nilable string?))
Expand All @@ -31,8 +30,7 @@
(spec/def :contact/contact (spec/keys :req-un [:contact/address
:contact/public-key
:contact/system-tags]
:opt-un [:contact/fcm-token
:contact/name
:opt-un [:contact/name
:contact/photo-path
:contact/last-online
:contact/last-updated
Expand Down
26 changes: 0 additions & 26 deletions src/status_im/contact/device_info.cljs

This file was deleted.

1 change: 0 additions & 1 deletion src/status_im/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
[status-im.utils.error-handler :as error-handler]
[status-im.utils.platform :as platform]
[status-im.ui.components.react :as react]
[status-im.notifications.background :as background-messaging]
[reagent.core :as reagent]
status-im.transport.impl.receive
status-im.transport.impl.send
Expand Down
19 changes: 0 additions & 19 deletions src/status_im/data_store/contacts.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,15 @@
[taoensso.timbre :as log]
[status-im.utils.types :as types]))

(defn deserialize-device-info [contact]
(update contact :deviceInfo (fn [device-info]
(reduce (fn [acc info]
(assoc acc
(:installationId info)
(clojure.set/rename-keys info {:fcmToken :fcm-token :installationId :id})))
{}
device-info))))

(defn serialize-device-info [contact]
(update contact :device-info (fn [device-info]
(map
#(clojure.set/rename-keys % {:fcm-token :fcmToken :id :installationId})
(vals device-info)))))

(defn <-rpc [contact]
(-> contact
deserialize-device-info
(update :tributeToTalk types/deserialize)
(update :systemTags
#(reduce (fn [acc s]
(conj acc (keyword (subs s 1))))
#{}
%)) (clojure.set/rename-keys {:id :public-key
:photoPath :photo-path
:deviceInfo :device-info
:tributeToTalk :tribute-to-talk
:ensVerifiedAt :ens-verified-at
:ensVerified :ens-verified
Expand All @@ -40,14 +23,12 @@

(defn ->rpc [contact]
(-> contact
serialize-device-info
(update :tribute-to-talk types/serialize)
(update :system-tags #(mapv str %))
(clojure.set/rename-keys {:public-key :id
:ens-verified :ensVerified
:ens-verified-at :ensVerifiedAt
:photo-path :photoPath
:device-info :deviceInfo
:tribute-to-talk :tributeToTalk
:system-tags :systemTags
:last-updated :lastUpdated})))
Expand Down
1 change: 0 additions & 1 deletion src/status_im/desktop/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
status-im.subs
[status-im.ui.screens.views :as views]
[status-im.ui.components.react :as react]
[status-im.notifications.core :as notifications]
[status-im.core :as core]
[status-im.utils.snoopy :as snoopy]
[status-im.ui.components.desktop.shortcuts :as shortcuts]
Expand Down
18 changes: 0 additions & 18 deletions src/status_im/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
[status-im.mailserver.constants :as mailserver.constants]
[status-im.mailserver.topics :as mailserver.topics]
[status-im.node.core :as node]
[status-im.notifications.core :as notifications]
[status-im.pairing.core :as pairing]
[status-im.privacy-policy.core :as privacy-policy]
[status-im.protocol.core :as protocol]
Expand Down Expand Up @@ -660,23 +659,6 @@
(log/debug :event-str event-str)
(signals/process cofx event-str)))

;; notifications module

(handlers/register-handler-fx
:notifications/notification-open-event-received
(fn [cofx [_ decoded-payload ctx]]
(notifications/handle-push-notification-open cofx decoded-payload ctx)))

(handlers/register-handler-fx
:notifications.callback/get-fcm-token-success
(fn [{:keys [db]} [_ fcm-token]]
{:db (assoc-in db [:notifications :fcm-token] fcm-token)}))

(handlers/register-handler-fx
:notifications.callback/on-message
(fn [cofx [_ decoded-payload opts]]
(notifications/handle-on-message cofx decoded-payload opts)))

;; hardwallet module

(handlers/register-handler-fx
Expand Down
23 changes: 4 additions & 19 deletions src/status_im/init/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
[status-im.multiaccounts.login.core :as multiaccounts.login]
[status-im.native-module.core :as status]
[status-im.network.net-info :as network]
[status-im.notifications.core :as notifications]
[status-im.react-native.js-dependencies :as rn-dependencies]
[status-im.ui.screens.db :refer [app-db]]
[status-im.ui.screens.navigation :as navigation]
Expand All @@ -22,34 +21,21 @@
(fx/defn initialize-app-db
"Initialize db to initial state"
[{{:keys [view-id hardwallet initial-props desktop/desktop
supported-biometric-auth push-notifications/stored network/type]} :db}]
supported-biometric-auth network/type]} :db}]
{:db (assoc app-db
:initial-props initial-props
:desktop/desktop (merge desktop (:desktop/desktop app-db))
:network/type type
:hardwallet (dissoc hardwallet :secrets)
:supported-biometric-auth supported-biometric-auth
:view-id view-id
:push-notifications/stored stored)})
:view-id view-id)})

(fx/defn initialize-views
[cofx]
(let [{{:multiaccounts/keys [multiaccounts] :as db} :db} cofx]
(if (empty? multiaccounts)
(navigation/navigate-to-cofx cofx :intro nil)
(let [multiaccount-with-notification
(when-not platform/desktop?
(notifications/lookup-contact-pubkey-from-hash
cofx
(first (keys (:push-notifications/stored db)))))
selection-fn
(if (not-empty multiaccount-with-notification)
#(filter (fn [multiaccount]
(= multiaccount-with-notification
(:public-key multiaccount)))
%)
#(sort-by :last-sign-in > %))
{:keys [address public-key photo-path name]} (first (selection-fn (vals multiaccounts)))]
(let [{:keys [address public-key photo-path name]} (first (#(sort-by :last-sign-in > %) (vals multiaccounts)))]
(multiaccounts.login/open-login cofx address photo-path name public-key)))))

(fx/defn initialize-multiaccounts
Expand All @@ -74,7 +60,6 @@
::restore-native-settings nil
::open-multiaccounts #(re-frame/dispatch [::initialize-multiaccounts %])
:ui/listen-to-window-dimensions-change nil
:notifications/init nil
::network/listen-to-network-info nil
:hardwallet/register-card-events nil
:hardwallet/check-nfc-support nil
Expand All @@ -94,4 +79,4 @@
(re-frame/reg-fx
::init-keystore
(fn []
(status/init-keystore)))
(status/init-keystore)))
46 changes: 18 additions & 28 deletions src/status_im/multiaccounts/create/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
:choose-key 2
:select-key-storage 3
:create-code 4
:confirm-code 5
:enable-notifications 6})
:confirm-code 5})

(defn decrement-step [step]
(let [inverted (map-invert step-kw-to-num)]
Expand Down Expand Up @@ -84,22 +83,21 @@
{:events [:intro-wizard/navigate-back]}
[{:keys [db] :as cofx} skip-alert?]
(let [step (get-in db [:intro-wizard :step])]
;; Cannot go back after account has been created
;; and we're on "Enable notifications" step
(when-not (= :enable-notifications step)
(if (and (= step :choose-key) (not skip-alert?))
(utils/show-question
(i18n/label :t/are-you-sure-to-cancel)
(i18n/label :t/you-will-start-from-scratch)
#(re-frame/dispatch [:intro-wizard/navigate-back true]))
(fx/merge cofx
dec-step
navigation/navigate-back)))))

(fx/defn exit-wizard [{:keys [db] :as cofx}]
(if (and (= step :choose-key) (not skip-alert?))
(utils/show-question
(i18n/label :t/are-you-sure-to-cancel)
(i18n/label :t/you-will-start-from-scratch)
#(re-frame/dispatch [:intro-wizard/navigate-back true]))
(fx/merge cofx
dec-step
navigation/navigate-back))))

(fx/defn exit-wizard
[{:keys [db] :as cofx}]
(fx/merge cofx
{:db (dissoc db :intro-wizard)}
(navigation/navigate-to-cofx :home nil)))
(navigation/navigate-reset {:index 0
:actions [{:routeName :home}]})))

(fx/defn init-key-generation
[{:keys [db] :as cofx}]
Expand Down Expand Up @@ -131,13 +129,9 @@
(cond (confirm-failure? db)
(on-confirm-failure cofx)

(or (= step :enable-notifications)
(and (not first-time-setup?) (= step :confirm-code)
(:multiaccounts/login db)))
(fx/merge cofx
(when (and (= step :enable-notifications) (not skip?))
{:notifications/request-notifications-permissions nil})
exit-wizard)
(and (= step :confirm-code)
(:multiaccounts/login db))
(exit-wizard cofx)

(= step :generate-key)
(init-key-generation cofx)
Expand All @@ -160,11 +154,7 @@
:step next-step)}
(when (= step :create-code)
store-key-code)
(when (= next-step :enable-notifications)
(navigation/navigate-reset {:index 0
:actions [{:routeName :create-multiaccount-enable-notifications}]}))
(when (not= next-step :enable-notifications)
(navigation/navigate-to-cofx (->> next-step name (str "create-multiaccount-") keyword) nil)))))))
(navigation/navigate-to-cofx (->> next-step name (str "create-multiaccount-") keyword) nil))))))

(defn prepare-accounts-data
[multiaccount]
Expand Down
Loading

0 comments on commit e486506

Please sign in to comment.