Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9fbf140da0 | ||
|
|
e9b8118c0d | ||
|
|
80c15bd8d0 |
@@ -88,6 +88,15 @@
|
||||
{:chainId :chain-id
|
||||
:removed :removed?})
|
||||
name-details)]
|
||||
(let [new-db (reduce (fn [db {:keys [username removed? chain-id] :as name-detail}]
|
||||
(if removed?
|
||||
(update-in db [:ens/names chain-id] dissoc username)
|
||||
(let [old (get-in db [:ens/names chain-id username])]
|
||||
(assoc-in db [:ens/names chain-id username] (merge old name-detail)))))
|
||||
db
|
||||
name-details)]
|
||||
(prn "new db" new-db)
|
||||
)
|
||||
{:db (reduce (fn [db {:keys [username removed? chain-id] :as name-detail}]
|
||||
(if removed?
|
||||
(update-in db [:ens/names chain-id] dissoc username)
|
||||
|
||||
+64
-24
@@ -4,6 +4,8 @@
|
||||
[clojure.string :as string]
|
||||
[native-module.utils :as native-utils]
|
||||
[react-native.platform :as platform]
|
||||
[status-backend.core :as status-backend]
|
||||
[status-backend.config :as status-backend.config]
|
||||
[taoensso.timbre :as log]
|
||||
[utils.transforms :as types]))
|
||||
|
||||
@@ -14,18 +16,24 @@
|
||||
|
||||
(defn account-manager
|
||||
[]
|
||||
(when (exists? (.-NativeModules react-native))
|
||||
(.-AccountManager ^js (.-NativeModules react-native))))
|
||||
(if false
|
||||
(when (exists? (.-NativeModules react-native))
|
||||
(.-AccountManager ^js (.-NativeModules react-native)))
|
||||
status-backend/fetch-js-obj))
|
||||
|
||||
(defn encryption
|
||||
[]
|
||||
(when (exists? (.-NativeModules react-native))
|
||||
(.-EncryptionUtils ^js (.-NativeModules react-native))))
|
||||
(if false
|
||||
(when (exists? (.-NativeModules react-native))
|
||||
(.-EncryptionUtils ^js (.-NativeModules react-native)))
|
||||
status-backend/fetch-js-obj))
|
||||
|
||||
(defn database
|
||||
[]
|
||||
(when (exists? (.-NativeModules react-native))
|
||||
(.-DatabaseManager ^js (.-NativeModules react-native))))
|
||||
(if false
|
||||
(when (exists? (.-NativeModules react-native))
|
||||
(.-DatabaseManager ^js (.-NativeModules react-native)))
|
||||
status-backend/fetch-js-obj))
|
||||
|
||||
(defn ui-helper
|
||||
[]
|
||||
@@ -34,23 +42,31 @@
|
||||
|
||||
(defn log-manager
|
||||
[]
|
||||
(when (exists? (.-NativeModules react-native))
|
||||
(.-LogManager ^js (.-NativeModules react-native))))
|
||||
(if false
|
||||
(when (exists? (.-NativeModules react-native))
|
||||
(.-LogManager ^js (.-NativeModules react-native)))
|
||||
status-backend/fetch-js-obj))
|
||||
|
||||
(defn utils
|
||||
[]
|
||||
(when (exists? (.-NativeModules react-native))
|
||||
(.-Utils ^js (.-NativeModules react-native))))
|
||||
(if false
|
||||
(when (exists? (.-NativeModules react-native))
|
||||
(.-Utils ^js (.-NativeModules react-native)))
|
||||
status-backend/fetch-js-obj))
|
||||
|
||||
(defn network
|
||||
[]
|
||||
(when (exists? (.-NativeModules react-native))
|
||||
(.-NetworkManager ^js (.-NativeModules react-native))))
|
||||
(if false
|
||||
(when (exists? (.-NativeModules react-native))
|
||||
(.-NetworkManager ^js (.-NativeModules react-native)))
|
||||
status-backend/fetch-js-obj))
|
||||
|
||||
(defn mail-manager
|
||||
[]
|
||||
(when (exists? (.-NativeModules react-native))
|
||||
(.-MailManager ^js (.-NativeModules react-native))))
|
||||
(if false
|
||||
(when (exists? (.-NativeModules react-native))
|
||||
(.-MailManager ^js (.-NativeModules react-native)))
|
||||
status-backend/fetch-js-obj))
|
||||
|
||||
(defn mail
|
||||
[opts callback]
|
||||
@@ -58,7 +74,9 @@
|
||||
|
||||
(defn init
|
||||
[handler]
|
||||
(.addListener ^js (.-DeviceEventEmitter ^js react-native) "gethEvent" #(handler (.-jsonEvent ^js %))))
|
||||
(if false
|
||||
(.addListener ^js (.-DeviceEventEmitter ^js react-native) "gethEvent" #(handler (.-jsonEvent ^js %)))
|
||||
(status-backend/init-web-socket handler)))
|
||||
|
||||
(defn clear-web-data
|
||||
[]
|
||||
@@ -340,7 +358,9 @@
|
||||
(log/debug "[native-module] set-blank-preview-flag")
|
||||
;; Sometimes the app crashes during logout because `flag` is nil.
|
||||
(when-not (nil? flag)
|
||||
(.setBlankPreviewFlag ^js (encryption) flag)))
|
||||
(.setBlankPreviewFlag ^js (when (exists? (.-NativeModules react-native))
|
||||
(.-EncryptionUtils ^js (.-NativeModules react-native)))
|
||||
flag)))
|
||||
|
||||
(defn get-device-model-info
|
||||
[]
|
||||
@@ -419,8 +439,11 @@
|
||||
(defn sha3
|
||||
[s]
|
||||
(log/debug "[native-module] sha3")
|
||||
(when s
|
||||
(.sha3 ^js (encryption) (str s))))
|
||||
(time
|
||||
(let [temp-encryption (when (exists? (.-NativeModules react-native))
|
||||
(.-EncryptionUtils ^js (.-NativeModules react-native)))]
|
||||
(when s
|
||||
(.sha3 ^js temp-encryption (str s))))))
|
||||
|
||||
(defn utf8-to-hex
|
||||
[s]
|
||||
@@ -444,7 +467,8 @@
|
||||
|
||||
(defn add-centralized-metric
|
||||
[metric]
|
||||
(.addCentralizedMetric ^js (status) (types/clj->json metric) #(log/debug "pushed metric" % metric)))
|
||||
(.addCentralizedMetric ^js (status) (types/clj->json metric)
|
||||
(fn []) #_(log/debug "pushed metric" % metric)))
|
||||
|
||||
(defn address?
|
||||
[address]
|
||||
@@ -456,7 +480,9 @@
|
||||
(defn to-checksum-address
|
||||
[address]
|
||||
(log/debug "[native-module] to-checksum-address")
|
||||
(.toChecksumAddress ^js (utils) address))
|
||||
(.toChecksumAddress ^js (when (exists? (.-NativeModules react-native))
|
||||
(.-Utils ^js (.-NativeModules react-native)))
|
||||
address))
|
||||
|
||||
(defn validate-mnemonic
|
||||
"Validate that a mnemonic conforms to BIP39 dictionary/checksum standards"
|
||||
@@ -522,7 +548,9 @@
|
||||
|
||||
(defn backup-disabled-data-dir
|
||||
[]
|
||||
(.backupDisabledDataDir ^js (utils)))
|
||||
(if false ;; Check for not use of status-backend
|
||||
(.backupDisabledDataDir ^js (utils))
|
||||
status-backend.config/data-dir-path))
|
||||
|
||||
(defn fleets
|
||||
[]
|
||||
@@ -530,15 +558,27 @@
|
||||
|
||||
(defn keystore-dir
|
||||
[]
|
||||
(.keystoreDir ^js (utils)))
|
||||
(if false
|
||||
(.keystoreDir ^js (utils))
|
||||
status-backend.config/keystore-dir-path))
|
||||
|
||||
(defn log-file-directory
|
||||
[]
|
||||
(.logFileDirectory ^js (log-manager)))
|
||||
(if false
|
||||
(.logFileDirectory ^js (log-manager))
|
||||
status-backend.config/log-dir-path))
|
||||
|
||||
(defn init-status-go-logging
|
||||
[{:keys [enable? mobile-system? log-level log-request-go? callback]}]
|
||||
(.initLogging ^js (log-manager) enable? mobile-system? log-level log-request-go? callback))
|
||||
(if false
|
||||
(.initLogging ^js (log-manager) enable? mobile-system? log-level log-request-go? callback)
|
||||
(.initLogging ^js (log-manager)
|
||||
{:Enabled enable?
|
||||
:MobileSystem mobile-system?
|
||||
:Level log-level
|
||||
:LogRequestGo log-request-go?
|
||||
:LogRequestFile status-backend.config/log-request-file-path}
|
||||
callback)))
|
||||
|
||||
(defn get-random-mnemonic
|
||||
[callback]
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
(ns status-backend.config)
|
||||
|
||||
;; Before run:
|
||||
;; adb reverse tcp:9050 tcp:9050
|
||||
|
||||
;; TODO: these should be read from env vars
|
||||
(def ^:private address "localhost")
|
||||
(def ^:private port 9050)
|
||||
(def ^:private url (str "http://" address ":" port))
|
||||
|
||||
(def status-go-url (str url "/statusgo/"))
|
||||
(def signals-url (str url "/signals"))
|
||||
|
||||
(def fetch-default-params
|
||||
{:method :POST
|
||||
:headers {"Accept" "application/json"
|
||||
"Content-Type" "application/json"}})
|
||||
|
||||
;; This dir musts exist before running the app
|
||||
(def data-dir-path "/home/ulises/p/status-go/1_test-db")
|
||||
|
||||
(def keystore-dir-path "/home/ulises/p/status-go/1_test-db/1_keystore")
|
||||
(def log-dir-path "/home/ulises/p/status-go/requests.log")
|
||||
(def log-request-file-path (str data-dir-path "/requests.log"))
|
||||
@@ -0,0 +1,86 @@
|
||||
(ns status-backend.core
|
||||
(:require
|
||||
[status-backend.config :as config]
|
||||
[utils.network.core :as network]
|
||||
[clojure.string :as string]
|
||||
[oops.core :as oops]
|
||||
[taoensso.timbre :as log]))
|
||||
|
||||
(defn fetch
|
||||
([endpoint]
|
||||
(println (str ".......................... 1-----: " endpoint))
|
||||
(fetch endpoint nil (fn [])))
|
||||
([endpoint body-params]
|
||||
(println (str ".......................... 2-----: " endpoint))
|
||||
(fetch endpoint body-params (fn [])))
|
||||
([endpoint body-params callback]
|
||||
(println (str "========================== > INVOKE: " endpoint "::" (prn-str body-params)))
|
||||
(let [url (str config/status-go-url endpoint)
|
||||
params (assoc config/fetch-default-params :body body-params)]
|
||||
(network/fetch url params callback))))
|
||||
|
||||
(defn- method-name->endpoint [s]
|
||||
(let [first-letter-capitalized (string/capitalize (first s))]
|
||||
(str first-letter-capitalized (subs s 1))))
|
||||
|
||||
(def fetch-js-obj
|
||||
"Performs a request to the status-backend (by using `status-backend.core/fetch`) using
|
||||
the method invoked as endpoint name. E.g
|
||||
This call: (.myMethod fetch-js-obj params)
|
||||
Is the same as: (fetch \"MyMethod\" params)
|
||||
"
|
||||
(js/Proxy. #js{}
|
||||
#js{:get (fn [_target native-module-method-name]
|
||||
(let [endpoint (method-name->endpoint native-module-method-name)]
|
||||
(partial fetch endpoint)))}))
|
||||
|
||||
(declare web-socket)
|
||||
|
||||
(defn init-web-socket [on-message]
|
||||
(defonce web-socket (js/WebSocket. config/signals-url))
|
||||
(oops/oset! web-socket "onopen" #(log/debug "[backend] Web Socket connected"))
|
||||
(oops/oset! web-socket "onmessage" (fn [e]
|
||||
(println " NEW WEBSOCKET MESSAGE! -- START")
|
||||
(-> e (oops/oget "data") (on-message))
|
||||
(println " NEW WEBSOCKET MESSAGE! -- END")))
|
||||
(oops/oset! web-socket "onerror" #(log/error "[backend] Web Socket error" %))
|
||||
(oops/oset! web-socket "onclose" #(log/error "[backend] Web Socket closed" %)))
|
||||
|
||||
|
||||
;(defn call-private-rpc [payload callback]
|
||||
; ;; NOTE: according to the status-backend readme, we call RPCs using the `CallRPC`
|
||||
; ;; endpoint, instead of using `CallPrivateRPC` as in mobile.
|
||||
; (fetch "CallRPC" payload callback))
|
||||
|
||||
|
||||
(comment ;; Useful REPL commands (will be removed)
|
||||
;; STEP 1: Initialize the app
|
||||
;; Option 1: Method call
|
||||
(.initializeApplication ^js fetch-js-obj
|
||||
(utils.transforms/clj->json {:dataDir "/home/ulises/p/status-go/test-db" ;; Put your dir
|
||||
:mixpanelAppId status-im.config/mixpanel-app-id
|
||||
:mixpanelToken status-im.config/mixpanel-token})
|
||||
(fn [raw-response]
|
||||
(let [result (utils.transforms/json->clj raw-response)]
|
||||
(js/alert (prn-str result)))))
|
||||
|
||||
;; Option 2: calling fetch
|
||||
(fetch "InitializeApplication"
|
||||
{:dataDir "/home/ulises/p/status-go/test-db"
|
||||
:mixpanelAppId status-im.config/mixpanel-app-id
|
||||
:mixpanelToken status-im.config/mixpanel-token}
|
||||
(fn [response]
|
||||
(js/alert (prn-str response))))
|
||||
|
||||
|
||||
;; STEP 2 "Create a Profile and Log in
|
||||
(let [body (-> (status-im.contexts.profile.config/create)
|
||||
(assoc :displayName "Sonic"
|
||||
:password (native-module.core/sha3 "Hola1234.,")
|
||||
:imagePath nil
|
||||
:customizationColor :army))]
|
||||
(fetch "CreateAccountAndLogin"
|
||||
body
|
||||
(fn [response]
|
||||
(def --r response)
|
||||
(js/alert (str "HTTP-RESPONSE:\n" (js/JSON.stringify response)))))))
|
||||
@@ -25,6 +25,7 @@
|
||||
(rf/defn process
|
||||
{:events [:signals/signal-received]}
|
||||
[{:keys [db] :as cofx} event-str]
|
||||
(println (str "<<<<<<<<<<<<<<<<<<<<<<<<<< SIGNAL: " (prn-str event-str)))
|
||||
;; We only convert to clojure when strictly necessary or we know it
|
||||
;; won't impact performance, as it is a fairly costly operation on large-ish
|
||||
;; data structures
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
[context]
|
||||
(when (push-event? (interceptor/get-coeffect context :db))
|
||||
(when-let [event (tracking/metrics-event (interceptor/get-coeffect context :event))]
|
||||
(log/debug "tracking event" event)
|
||||
#_(log/debug "tracking event" event)
|
||||
(if (or (seq? event) (vector? event))
|
||||
(doseq [e event]
|
||||
(native-module/add-centralized-metric e))
|
||||
|
||||
@@ -87,7 +87,7 @@
|
||||
:screen/onboarding.new-to-status)]]]
|
||||
(when-not syncing-account-recovered?
|
||||
[:dispatch [:syncing/clear-syncing-installation-id]])]
|
||||
:dispatch-later [{:ms constants/onboarding-generating-keys-animation-duration-ms
|
||||
:dispatch-later [#_{:ms constants/onboarding-generating-keys-animation-duration-ms
|
||||
:dispatch [:navigate-to-within-stack
|
||||
[:screen/onboarding.enable-notifications
|
||||
loading-screen]]}]
|
||||
|
||||
@@ -65,7 +65,7 @@
|
||||
|
||||
(defn title
|
||||
[]
|
||||
(let [generate-keys-opacity (reanimated/use-shared-value 1)
|
||||
#_(let [generate-keys-opacity (reanimated/use-shared-value 1)
|
||||
saving-keys-opacity (reanimated/use-shared-value 0)
|
||||
keys-saved-opacity (reanimated/use-shared-value 0)]
|
||||
(sequence-animation generate-keys-opacity saving-keys-opacity keys-saved-opacity)
|
||||
@@ -86,7 +86,8 @@
|
||||
{:style (reanimated/apply-animations-to-style
|
||||
{:opacity keys-saved-opacity}
|
||||
style/title-style)}
|
||||
[keys-saved-title]]]))
|
||||
[keys-saved-title]]])
|
||||
)
|
||||
|
||||
(defn content
|
||||
[]
|
||||
|
||||
@@ -156,7 +156,9 @@
|
||||
{:db (update db :profile/login #(-> % (dissoc :processing) (assoc :error error)))}
|
||||
{:db (dissoc db :profile/login)
|
||||
:fx [(when (and new-account? (not recovered-account?))
|
||||
[:dispatch-later [{:ms 1000 :dispatch [:wallet-legacy/set-initial-blocks-range]}]])
|
||||
;; INVALID EVENT:
|
||||
;[:dispatch-later [{:ms 1000 :dispatch [:wallet-legacy/set-initial-blocks-range]}]]
|
||||
)
|
||||
[:dispatch-later [{:ms 2000 :dispatch [:ens/update-usernames ensUsernames]}]]
|
||||
[:dispatch [:profile.login/login-existing-profile settings account]]]})))
|
||||
|
||||
|
||||
@@ -89,7 +89,7 @@
|
||||
;; RN to dispatch the network status update, otherwise when going
|
||||
;; offline the user will immediately see a toast saying "provider
|
||||
;; X is down".
|
||||
[{:ms 500
|
||||
[{:ms 50000
|
||||
:dispatch [:wallet/blockchain-status-changed
|
||||
(transforms/js->clj event-js)]}]]]}
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
|
||||
(def adjust-resize 16)
|
||||
|
||||
(defn is-hermes
|
||||
(defn hermes?
|
||||
[]
|
||||
(boolean (.-HermesInternal js/global)))
|
||||
|
||||
@@ -68,7 +68,7 @@
|
||||
(ff/load-flags))
|
||||
|
||||
(dev/setup)
|
||||
(log/info "hermesEnabled ->" (is-hermes))
|
||||
(log/info "hermesEnabled ->" (hermes?))
|
||||
|
||||
(re-frame/dispatch-sync [:app-started])
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
(ns utils.network.core
|
||||
(:require
|
||||
[clojure.string :as string]))
|
||||
(:require [clojure.string :as string]
|
||||
[taoensso.timbre :as log]))
|
||||
|
||||
(def url-regex
|
||||
#"https?://(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}(\.[a-z]{2,6})?\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)")
|
||||
@@ -41,7 +41,12 @@
|
||||
(map :error)
|
||||
(not-any? identity)))
|
||||
|
||||
(defn chain-id-available?
|
||||
[current-networks network]
|
||||
(let [chain-id (get-in network [:config :NetworkId])]
|
||||
(every? #(not= chain-id (get-in % [1 :config :NetworkId])) current-networks)))
|
||||
(defn fetch [url {:keys [body] :as params} callback]
|
||||
(let [js-params (cond-> params
|
||||
(map? body) (update :body (comp js/JSON.stringify clj->js))
|
||||
:always clj->js)]
|
||||
(-> (js/fetch url js-params)
|
||||
(.then (fn [response]
|
||||
(.text response)))
|
||||
(.then callback)
|
||||
(.catch #(log/error (str "Error while fetching: " url) %)))))
|
||||
|
||||
@@ -21,8 +21,10 @@
|
||||
(when js/goog.DEBUG
|
||||
(reset! handler-nesting-level 0))
|
||||
(when rf.interop/debug-enabled?
|
||||
(log/debug "Handling re-frame event: "
|
||||
(first (interceptor/get-coeffect context :event))))
|
||||
(do
|
||||
(log/debug "Handling re-frame event: "
|
||||
(first (interceptor/get-coeffect context :event)))
|
||||
nil))
|
||||
context)))
|
||||
|
||||
(defn- update-db
|
||||
|
||||
Reference in New Issue
Block a user