Compare commits

..
Author SHA1 Message Date
Dario Gabriel Lipicar 78767a764e update go version 2024-10-23 16:34:46 -03:00
26 changed files with 285 additions and 519 deletions
-9
View File
@@ -88,15 +88,6 @@
{: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)
+24 -64
View File
@@ -4,8 +4,6 @@
[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]))
@@ -16,24 +14,18 @@
(defn account-manager
[]
(if false
(when (exists? (.-NativeModules react-native))
(.-AccountManager ^js (.-NativeModules react-native)))
status-backend/fetch-js-obj))
(when (exists? (.-NativeModules react-native))
(.-AccountManager ^js (.-NativeModules react-native))))
(defn encryption
[]
(if false
(when (exists? (.-NativeModules react-native))
(.-EncryptionUtils ^js (.-NativeModules react-native)))
status-backend/fetch-js-obj))
(when (exists? (.-NativeModules react-native))
(.-EncryptionUtils ^js (.-NativeModules react-native))))
(defn database
[]
(if false
(when (exists? (.-NativeModules react-native))
(.-DatabaseManager ^js (.-NativeModules react-native)))
status-backend/fetch-js-obj))
(when (exists? (.-NativeModules react-native))
(.-DatabaseManager ^js (.-NativeModules react-native))))
(defn ui-helper
[]
@@ -42,31 +34,23 @@
(defn log-manager
[]
(if false
(when (exists? (.-NativeModules react-native))
(.-LogManager ^js (.-NativeModules react-native)))
status-backend/fetch-js-obj))
(when (exists? (.-NativeModules react-native))
(.-LogManager ^js (.-NativeModules react-native))))
(defn utils
[]
(if false
(when (exists? (.-NativeModules react-native))
(.-Utils ^js (.-NativeModules react-native)))
status-backend/fetch-js-obj))
(when (exists? (.-NativeModules react-native))
(.-Utils ^js (.-NativeModules react-native))))
(defn network
[]
(if false
(when (exists? (.-NativeModules react-native))
(.-NetworkManager ^js (.-NativeModules react-native)))
status-backend/fetch-js-obj))
(when (exists? (.-NativeModules react-native))
(.-NetworkManager ^js (.-NativeModules react-native))))
(defn mail-manager
[]
(if false
(when (exists? (.-NativeModules react-native))
(.-MailManager ^js (.-NativeModules react-native)))
status-backend/fetch-js-obj))
(when (exists? (.-NativeModules react-native))
(.-MailManager ^js (.-NativeModules react-native))))
(defn mail
[opts callback]
@@ -74,9 +58,7 @@
(defn init
[handler]
(if false
(.addListener ^js (.-DeviceEventEmitter ^js react-native) "gethEvent" #(handler (.-jsonEvent ^js %)))
(status-backend/init-web-socket handler)))
(.addListener ^js (.-DeviceEventEmitter ^js react-native) "gethEvent" #(handler (.-jsonEvent ^js %))))
(defn clear-web-data
[]
@@ -358,9 +340,7 @@
(log/debug "[native-module] set-blank-preview-flag")
;; Sometimes the app crashes during logout because `flag` is nil.
(when-not (nil? flag)
(.setBlankPreviewFlag ^js (when (exists? (.-NativeModules react-native))
(.-EncryptionUtils ^js (.-NativeModules react-native)))
flag)))
(.setBlankPreviewFlag ^js (encryption) flag)))
(defn get-device-model-info
[]
@@ -439,11 +419,8 @@
(defn sha3
[s]
(log/debug "[native-module] sha3")
(time
(let [temp-encryption (when (exists? (.-NativeModules react-native))
(.-EncryptionUtils ^js (.-NativeModules react-native)))]
(when s
(.sha3 ^js temp-encryption (str s))))))
(when s
(.sha3 ^js (encryption) (str s))))
(defn utf8-to-hex
[s]
@@ -467,8 +444,7 @@
(defn add-centralized-metric
[metric]
(.addCentralizedMetric ^js (status) (types/clj->json metric)
(fn []) #_(log/debug "pushed metric" % metric)))
(.addCentralizedMetric ^js (status) (types/clj->json metric) #(log/debug "pushed metric" % metric)))
(defn address?
[address]
@@ -480,9 +456,7 @@
(defn to-checksum-address
[address]
(log/debug "[native-module] to-checksum-address")
(.toChecksumAddress ^js (when (exists? (.-NativeModules react-native))
(.-Utils ^js (.-NativeModules react-native)))
address))
(.toChecksumAddress ^js (utils) address))
(defn validate-mnemonic
"Validate that a mnemonic conforms to BIP39 dictionary/checksum standards"
@@ -548,9 +522,7 @@
(defn backup-disabled-data-dir
[]
(if false ;; Check for not use of status-backend
(.backupDisabledDataDir ^js (utils))
status-backend.config/data-dir-path))
(.backupDisabledDataDir ^js (utils)))
(defn fleets
[]
@@ -558,27 +530,15 @@
(defn keystore-dir
[]
(if false
(.keystoreDir ^js (utils))
status-backend.config/keystore-dir-path))
(.keystoreDir ^js (utils)))
(defn log-file-directory
[]
(if false
(.logFileDirectory ^js (log-manager))
status-backend.config/log-dir-path))
(.logFileDirectory ^js (log-manager)))
(defn init-status-go-logging
[{:keys [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)))
(.initLogging ^js (log-manager) enable? mobile-system? log-level log-request-go? callback))
(defn get-random-mnemonic
[callback]
@@ -28,6 +28,7 @@
:seed :i/seed
:key :i/password
nil)
:color :neutral
:blur? true
:border? true}]
[rn/view
-24
View File
@@ -1,24 +0,0 @@
(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"))
-86
View File
@@ -1,86 +0,0 @@
(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)))))))
-1
View File
@@ -25,7 +25,6 @@
(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,8 +86,7 @@
{:style (reanimated/apply-animations-to-style
{:opacity keys-saved-opacity}
style/title-style)}
[keys-saved-title]]])
)
[keys-saved-title]]]))
(defn content
[]
@@ -156,9 +156,7 @@
{:db (update db :profile/login #(-> % (dissoc :processing) (assoc :error error)))}
{:db (dissoc db :profile/login)
:fx [(when (and new-account? (not recovered-account?))
;; INVALID EVENT:
;[:dispatch-later [{:ms 1000 :dispatch [:wallet-legacy/set-initial-blocks-range]}]]
)
[: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]]]})))
@@ -15,7 +15,7 @@
(defn- bridge-token-component
[]
(fn [{:keys [chain-id network-name]} {:keys [supported-networks] :as token}]
(fn [{:keys [chain-id network-name]} {:keys [networks] :as token}]
(let [network (rf/sub [:wallet/network-details-by-chain-id chain-id])
currency (rf/sub [:profile/currency])
currency-symbol (rf/sub [:profile/currency-symbol])
@@ -28,8 +28,7 @@
fiat-formatted (utils/get-standard-fiat-format crypto-value
currency-symbol
fiat-value)
token-available-on-network? (network-utils/token-available-on-network? supported-networks
chain-id)]
token-available-on-network? (network-utils/token-available-on-network? networks chain-id)]
[quo/network-list
{:label (name network-name)
:network-image (quo.resources/get-network (:network-name network))
@@ -50,10 +49,7 @@
mainnet (first network-details)
layer-2-networks (rest network-details)
account-token (some #(when (= token-symbol (:symbol %)) %) tokens)
account-token (when account-token
(assoc account-token
:networks (:networks token)
:supported-networks (:supported-networks token)))
account-token (when account-token (assoc account-token :networks (:networks token)))
bridge-to-title (i18n/label :t/bridge-to
{:name (string/upper-case (str token-symbol))})]
@@ -522,10 +522,9 @@
[tokens networks chain-ids]
(map (fn [token]
(assoc token
:networks (network-utils/network-list-with-positive-balance token networks)
:supported-networks (network-utils/network-list token networks)
:available-balance (calculate-total-token-balance token)
:total-balance (calculate-total-token-balance token chain-ids)))
:networks (network-utils/network-list token networks)
:available-balance (calculate-total-token-balance token)
:total-balance (calculate-total-token-balance token chain-ids)))
tokens))
(defn estimated-time-format
+4 -25
View File
@@ -72,32 +72,11 @@
(update :testPreferredChainIds chain-ids-set->string)
(dissoc :watch-only? :default-account? :operable? :tokens :collectibles)))
(defn add-missing-balance-per-chain-values
"Adds any missing chain balance (0) to the balance-per-chain map based on token supported chains as
status-go returns balance for that chain only if the balance is positive."
[balances-per-chain supported-chains]
(let [zero-balance-per-chain (fn [chain-id]
{:chain-id chain-id
:raw-balance (money/->bignumber 0)
:balance "0"})]
(reduce
(fn [result chain-id]
(if (contains? result chain-id)
result
(assoc result chain-id (zero-balance-per-chain chain-id))))
balances-per-chain
supported-chains)))
(defn- rpc->balances-per-chain
[token supported-chains]
[token]
(-> token
(update :balances-per-chain update-vals #(update % :raw-balance money/bignumber))
(update :balances-per-chain update-keys (comp utils.number/parse-int name))
(update :balances-per-chain #(add-missing-balance-per-chain-values % supported-chains))))
(defn- update-balances-per-chain
[tokens supported-chains-by-token-symbol]
(mapv #(rpc->balances-per-chain % (get supported-chains-by-token-symbol (:symbol %))) tokens))
(update :balances-per-chain update-keys (comp utils.number/parse-int name))))
(defn- remove-tokens-with-empty-values
[tokens]
@@ -106,12 +85,12 @@
tokens))
(defn rpc->tokens
[tokens supported-chains-by-token-symbol]
[tokens]
(-> tokens
(update-keys name)
(update-vals #(cske/transform-keys transforms/->kebab-case-keyword %))
(update-vals remove-tokens-with-empty-values)
(update-vals #(update-balances-per-chain % supported-chains-by-token-symbol))))
(update-vals #(mapv rpc->balances-per-chain %))))
(defn rpc->network
[network]
+8 -11
View File
@@ -229,17 +229,14 @@
(rf/reg-event-fx
:wallet/store-wallet-token
(fn [{:keys [db]} [address raw-tokens-data]]
(let [supported-chains-by-token-symbol (get-in db [:wallet :tokens :supported-chains-by-symbol])
tokens (data-store/rpc->tokens raw-tokens-data
supported-chains-by-token-symbol)
add-tokens (fn [stored-accounts tokens-per-account]
(reduce-kv
(fn [accounts address tokens-data]
(if (contains? accounts address)
(update accounts address assoc :tokens tokens-data)
accounts))
stored-accounts
tokens-per-account))]
(let [tokens (data-store/rpc->tokens raw-tokens-data)
add-tokens (fn [stored-accounts tokens-per-account]
(reduce-kv (fn [accounts address tokens-data]
(if (contains? accounts address)
(update accounts address assoc :tokens tokens-data)
accounts))
stored-accounts
tokens-per-account))]
{:db (-> db
(update-in [:wallet :accounts] add-tokens tokens)
(assoc-in [:wallet :ui :tokens-loading address] false))})))
+16 -28
View File
@@ -53,7 +53,7 @@
token-decimals (if collectible 0 (:decimals token))
native-token? (and token (= token-display-name "ETH"))
routes-available? (pos? (count chosen-route))
token-networks (:supported-networks token)
token-networks (:networks token)
token-networks-ids (when token-networks
(map #(:chain-id %) token-networks))
from-network-amounts-by-chain (send-utils/network-amounts-by-chain
@@ -190,21 +190,17 @@
;; `token` is a map extracted from the sender, but in the wallet home page we don't know the
;; sender yet, so we only provide the `token-symbol`, later in
;; `:wallet/select-from-account` the `token` key will be set.
(let [{:keys [networks]} token
receiver-networks (get-in db [:wallet :ui :send :receiver-networks])
token-networks-ids (map :chain-id networks)
unsupported-token? (not-any? (set receiver-networks) token-networks-ids)
unique-owner (when (= (count owners) 1)
(first owners))
unique-owner-tokens (get-in db [:wallet :accounts unique-owner :tokens])
token-data (or token
(when (and token-symbol unique-owner)
(some #(when (= (:symbol %) token-symbol) %)
unique-owner-tokens)))
test-networks-enabled? (get-in db [:profile/profile :test-networks-enabled?])
network-details (-> (get-in db
[:wallet :networks (if test-networks-enabled? :test :prod)])
(network-utils/sorted-networks-with-details))]
(let [{:keys [networks]} token
receiver-networks (get-in db [:wallet :ui :send :receiver-networks])
token-networks-ids (map :chain-id networks)
unsupported-token? (not-any? (set receiver-networks) token-networks-ids)
unique-owner (when (= (count owners) 1)
(first owners))
unique-owner-tokens (get-in db [:wallet :accounts unique-owner :tokens])
token-data (or token
(when (and token-symbol unique-owner)
(some #(when (= (:symbol %) token-symbol) %)
unique-owner-tokens)))]
(when (or token-data token-symbol)
{:db (cond-> db
:always (update-in [:wallet :ui :send]
@@ -215,11 +211,7 @@
token-symbol (assoc-in [:wallet :ui :send :token-symbol] token-symbol)
token-data (update-in [:wallet :ui :send]
#(assoc %
:token (assoc token-data
:supported-networks
(network-utils/network-list
token-data
network-details))
:token token-data
:token-display-name (:symbol token-data)))
unique-owner (assoc-in [:wallet :current-viewing-account-address] unique-owner)
entry-point (assoc-in [:wallet :ui :send :entry-point] entry-point))
@@ -238,7 +230,7 @@
(rf/reg-event-fx
:wallet/edit-token-to-send
(fn [{:keys [db]} [token]]
(let [{token-networks :supported-networks
(let [{token-networks :networks
token-symbol :symbol} token
receiver-networks (get-in db [:wallet :ui :send :receiver-networks])
token-networks-ids (map :chain-id token-networks)
@@ -434,7 +426,7 @@
{:balances-per-chain balances-per-chain
:disabled-chain-ids disabled-from-chain-ids
:only-with-balance? false}))
token-networks-ids (when token (map #(:chain-id %) (:supported-networks token)))
token-networks-ids (when token (map #(:chain-id %) (:networks token)))
sender-network-values (when sender-token-available-networks-for-suggested-routes
(send-utils/loading-network-amounts
{:valid-networks
@@ -716,11 +708,7 @@
;; account, so we extract the token data from the picked account.
(let [token (utils/get-token-from-account db token-symbol address)]
(assoc token
:networks (network-utils/network-list-with-positive-balance
token
network-details)
:supported-networks (network-utils/network-list token
network-details)
:networks (network-utils/network-list token network-details)
:total-balance (utils/calculate-total-token-balance token))))
bridge-tx? (= tx-type :tx/bridge)
flow-id (if bridge-tx?
@@ -79,14 +79,11 @@
(h/deftest-event :wallet/edit-token-to-send
[event-id dispatch]
(let [token-symbol "ETH"
token {:symbol "ETH"
:name "Ether"
:networks #{{:chain-id 421614}
{:chain-id 11155420}
{:chain-id 11155111}}
:supported-networks #{{:chain-id 421614}
{:chain-id 11155420}
{:chain-id 11155111}}}
token {:symbol "ETH"
:name "Ether"
:networks #{{:chain-id 421614}
{:chain-id 11155420}
{:chain-id 11155111}}}
receiver-networks [421614 11155420]]
(testing "can be called with :token"
(let [initial-db {:wallet {:ui {:send {:receiver-networks receiver-networks
@@ -27,7 +27,7 @@
receiver-preferred-networks (rf/sub
[:wallet/wallet-send-receiver-preferred-networks])
{token-symbol :symbol
token-networks :supported-networks} (rf/sub [:wallet/wallet-send-token])
token-networks :networks} (rf/sub [:wallet/wallet-send-token])
token-chain-ids-set (set (mapv #(:chain-id %) token-networks))
[selected-receiver-networks
set-selected-receiver-networks] (rn/use-state receiver-networks)
+1 -1
View File
@@ -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 50000
[{:ms 500
:dispatch [:wallet/blockchain-status-changed
(transforms/js->clj event-js)]}]]]}
@@ -65,11 +65,7 @@
:tokens
(filter #(= token-symbol (:symbol %)))
first)]
(assoc token
:networks
(network-utils/network-list-with-positive-balance
token
networks))))
(assoc token :networks (network-utils/network-list token networks))))
(defn select-default-asset-to-receive
"Selects an asset to receive if it was not provided explicitly.
@@ -20,50 +20,40 @@
(defn store-token-list
[{:keys [db]} [{:keys [data]}]]
(let [chain-ids (chain/chain-ids db)
tokens (reduce (fn [{:keys [by-address by-symbol] :as data}
{:keys [name source version tokens]}]
(-> data
(update :sources
conj
{:name name
:source source
:version version
:tokens-count (count tokens)})
(update :by-address
merge
(tokens-data/tokens-by-address
{:added-tokens by-address
:source-name name
:tokens tokens
:chain-ids chain-ids}))
(update :by-symbol
merge
(tokens-data/tokens-by-symbol
{:added-tokens by-symbol
:source-name name
:tokens tokens
:chain-ids chain-ids}))))
{:sources []
:by-address {}
:by-symbol {}}
data)
symbols (->> tokens
:by-symbol
vals
(map :symbol)
set
vec)
by-symbol-vals (-> tokens :by-symbol vals)
supported-chains-by-symbol (reduce
(fn [result
{token-symbol :symbol
:keys [chain-id]}]
(if (contains? result token-symbol)
(update result token-symbol conj chain-id)
(assoc result token-symbol #{chain-id})))
{}
by-symbol-vals)]
(let [chain-ids (chain/chain-ids db)
tokens (reduce (fn [{:keys [by-address by-symbol] :as data}
{:keys [name source version tokens]}]
(-> data
(update :sources
conj
{:name name
:source source
:version version
:tokens-count (count tokens)})
(update :by-address
merge
(tokens-data/tokens-by-address
{:added-tokens by-address
:source-name name
:tokens tokens
:chain-ids chain-ids}))
(update :by-symbol
merge
(tokens-data/tokens-by-symbol
{:added-tokens by-symbol
:source-name name
:tokens tokens
:chain-ids chain-ids}))))
{:sources []
:by-address {}
:by-symbol {}}
data)
symbols (->> tokens
:by-symbol
vals
(map :symbol)
set
vec)]
{:fx [[:effects.wallet.tokens/fetch-market-values
{:symbols symbols
:currency constants/profile-default-currency
@@ -80,10 +70,9 @@
:on-error [:wallet.tokens/fetch-prices-failed]}]]
:db (-> db
(assoc-in [:wallet :tokens]
{:sources (:sources tokens)
:supported-chains-by-symbol supported-chains-by-symbol
:by-address (-> tokens :by-address vals)
:by-symbol by-symbol-vals})
{:sources (:sources tokens)
:by-address (-> tokens :by-address vals)
:by-symbol (-> tokens :by-symbol vals)})
(assoc-in [:wallet :ui :loading]
{:token-list false
:market-values true
@@ -47,10 +47,10 @@
(match?
(:db (tokens.events/store-token-list cofx [{:data data}]))
{:wallet {:networks {:prod [{:chain-id 1}]}
:tokens {:sources [{:name "native"
:source "native"
:version "1.0.0"
:tokens-count 2}]
:tokens {:sources [{:name "native"
:source "native"
:version "1.0.0"
:tokens-count 2}]
:by-address '({:address "0x0000000000000000000000000000000000000000"
:decimals 18
:key "1-0x0000000000000000000000000000000000000000"
@@ -73,29 +73,28 @@
:verified? true
:chain-id 1
:image nil})
:by-symbol '({:address "0x0000000000000000000000000000000000000000"
:decimals 18
:key "1-ETH"
:community-id nil
:symbol "ETH"
:sources ["native"]
:name "Ether"
:type :erc20
:verified? true
:chain-id 1
:image nil}
{:address "0x0000000000000000000000000000000000000001"
:decimals 18
:key "1-SNT"
:community-id nil
:symbol "SNT"
:sources ["native"]
:name "Status Network Token"
:type :erc20
:verified? true
:chain-id 1
:image nil})
:supported-chains-by-symbol {"ETH" #{1} "SNT" #{1}}}
:by-symbol '({:address "0x0000000000000000000000000000000000000000"
:decimals 18
:key "1-ETH"
:community-id nil
:symbol "ETH"
:sources ["native"]
:name "Ether"
:type :erc20
:verified? true
:chain-id 1
:image nil}
{:address "0x0000000000000000000000000000000000000001"
:decimals 18
:key "1-SNT"
:community-id nil
:symbol "SNT"
:sources ["native"]
:name "Status Network Token"
:type :erc20
:verified? true
:chain-id 1
:image nil})}
:ui {:loading {:token-list false
:market-values true
:details true
@@ -110,13 +109,12 @@
:db
:wallet
:tokens)
{:sources [{:name "native"
:source "native"
:version "1.0.0"
:tokens-count 2}]
:by-address nil
:by-symbol nil
:supported-chains-by-symbol {}}))))
{:sources [{:name "native"
:source "native"
:version "1.0.0"
:tokens-count 2}]
:by-address nil
:by-symbol nil}))))
(testing "response contains two lists"
(let [cofx {:db {:wallet {:networks {:prod [{:chain-id 1}]}}}}
data [{:name "native"
@@ -133,81 +131,80 @@
:db
:wallet
:tokens)
{:sources [{:name "native"
:source "native"
:version "1.0.0"
:tokens-count 2}
{:name "second"
:source "second"
:version "1.0.0"
:tokens-count 2}]
:by-address '({:address "0x0000000000000000000000000000000000000000"
:decimals 18
:key "1-0x0000000000000000000000000000000000000000"
:community-id nil
:symbol "ETH"
:sources ["native"]
:name "Ether"
:type :erc20
:verified? true
:chain-id 1
:image nil}
{:address "0x0000000000000000000000000000000000000001"
:decimals 18
:key "1-0x0000000000000000000000000000000000000001"
:community-id nil
:symbol "SNT"
:sources ["native" "second"]
:name "Status Network Token"
:type :erc20
:verified? true
:chain-id 1
:image nil}
{:address "0x0000000000000000000000000000000000000002"
:decimals 18
:key "1-0x0000000000000000000000000000000000000002"
:community-id nil
:symbol "ANOTHER1"
:sources ["second"]
:name "Another Token 1"
:type :erc20
:verified? false
:chain-id 1
:image nil})
:by-symbol '({:address "0x0000000000000000000000000000000000000000"
:decimals 18
:key "1-ETH"
:community-id nil
:symbol "ETH"
:sources ["native"]
:name "Ether"
:type :erc20
:verified? true
:chain-id 1
:image nil}
{:address "0x0000000000000000000000000000000000000001"
:decimals 18
:key "1-SNT"
:community-id nil
:symbol "SNT"
:sources ["native" "second"]
:name "Status Network Token"
:type :erc20
:verified? true
:chain-id 1
:image nil}
{:address "0x0000000000000000000000000000000000000002"
:decimals 18
:key "1-ANOTHER1"
:community-id nil
:symbol "ANOTHER1"
:sources ["second"]
:name "Another Token 1"
:type :erc20
:verified? false
:chain-id 1
:image nil})
:supported-chains-by-symbol {"ETH" #{1} "SNT" #{1} "ANOTHER1" #{1}}}))))
{:sources [{:name "native"
:source "native"
:version "1.0.0"
:tokens-count 2}
{:name "second"
:source "second"
:version "1.0.0"
:tokens-count 2}]
:by-address '({:address "0x0000000000000000000000000000000000000000"
:decimals 18
:key "1-0x0000000000000000000000000000000000000000"
:community-id nil
:symbol "ETH"
:sources ["native"]
:name "Ether"
:type :erc20
:verified? true
:chain-id 1
:image nil}
{:address "0x0000000000000000000000000000000000000001"
:decimals 18
:key "1-0x0000000000000000000000000000000000000001"
:community-id nil
:symbol "SNT"
:sources ["native" "second"]
:name "Status Network Token"
:type :erc20
:verified? true
:chain-id 1
:image nil}
{:address "0x0000000000000000000000000000000000000002"
:decimals 18
:key "1-0x0000000000000000000000000000000000000002"
:community-id nil
:symbol "ANOTHER1"
:sources ["second"]
:name "Another Token 1"
:type :erc20
:verified? false
:chain-id 1
:image nil})
:by-symbol '({:address "0x0000000000000000000000000000000000000000"
:decimals 18
:key "1-ETH"
:community-id nil
:symbol "ETH"
:sources ["native"]
:name "Ether"
:type :erc20
:verified? true
:chain-id 1
:image nil}
{:address "0x0000000000000000000000000000000000000001"
:decimals 18
:key "1-SNT"
:community-id nil
:symbol "SNT"
:sources ["native" "second"]
:name "Status Network Token"
:type :erc20
:verified? true
:chain-id 1
:image nil}
{:address "0x0000000000000000000000000000000000000002"
:decimals 18
:key "1-ANOTHER1"
:community-id nil
:symbol "ANOTHER1"
:sources ["second"]
:name "Another Token 1"
:type :erc20
:verified? false
:chain-id 1
:image nil})}))))
(testing "second list contains a token that replaces the one that was added before"
(let [cofx {:db {:wallet {:networks {:prod [{:chain-id 1}]}}}}
data [{:name "native"
@@ -224,56 +221,55 @@
:db
:wallet
:tokens)
{:sources [{:name "native"
:source "native"
:version "1.0.0"
:tokens-count 2}
{:name "second"
:source "second"
:version "1.0.0"
:tokens-count 1}]
:by-address '({:address "0x0000000000000000000000000000000000000000"
:decimals 18
:key "1-0x0000000000000000000000000000000000000000"
:community-id nil
:symbol "ANOTHER1"
:sources ["native" "second"]
:name "Another Token 2"
:type :erc20
:verified? false
:chain-id 1
:image nil}
{:address "0x0000000000000000000000000000000000000002"
:decimals 18
:key "1-0x0000000000000000000000000000000000000002"
:community-id nil
:symbol "ANOTHER1"
:sources ["native"]
:name "Another Token 1"
:type :erc20
:verified? false
:chain-id 1
:image nil})
:by-symbol '({:address "0x0000000000000000000000000000000000000000"
:decimals 18
:key "1-ETH"
:community-id nil
:symbol "ETH"
:sources ["native"]
:name "Ether"
:type :erc20
:verified? true
:chain-id 1
:image nil}
{:address "0x0000000000000000000000000000000000000000"
:decimals 18
:key "1-ANOTHER1"
:community-id nil
:symbol "ANOTHER1"
:sources ["native" "second"]
:name "Another Token 2"
:type :erc20
:verified? false
:chain-id 1
:image nil})
:supported-chains-by-symbol {"ETH" #{1} "ANOTHER1" #{1}}})))))
{:sources [{:name "native"
:source "native"
:version "1.0.0"
:tokens-count 2}
{:name "second"
:source "second"
:version "1.0.0"
:tokens-count 1}]
:by-address '({:address "0x0000000000000000000000000000000000000000"
:decimals 18
:key "1-0x0000000000000000000000000000000000000000"
:community-id nil
:symbol "ANOTHER1"
:sources ["native" "second"]
:name "Another Token 2"
:type :erc20
:verified? false
:chain-id 1
:image nil}
{:address "0x0000000000000000000000000000000000000002"
:decimals 18
:key "1-0x0000000000000000000000000000000000000002"
:community-id nil
:symbol "ANOTHER1"
:sources ["native"]
:name "Another Token 1"
:type :erc20
:verified? false
:chain-id 1
:image nil})
:by-symbol '({:address "0x0000000000000000000000000000000000000000"
:decimals 18
:key "1-ETH"
:community-id nil
:symbol "ETH"
:sources ["native"]
:name "Ether"
:type :erc20
:verified? true
:chain-id 1
:image nil}
{:address "0x0000000000000000000000000000000000000000"
:decimals 18
:key "1-ANOTHER1"
:community-id nil
:symbol "ANOTHER1"
:sources ["native" "second"]
:name "Another Token 2"
:type :erc20
:verified? false
:chain-id 1
:image nil})})))))
+2 -2
View File
@@ -40,7 +40,7 @@
(def adjust-resize 16)
(defn hermes?
(defn is-hermes
[]
(boolean (.-HermesInternal js/global)))
@@ -68,7 +68,7 @@
(ff/load-flags))
(dev/setup)
(log/info "hermesEnabled ->" (hermes?))
(log/info "hermesEnabled ->" (is-hermes))
(re-frame/dispatch-sync [:app-started])
+5 -7
View File
@@ -144,12 +144,11 @@
(remove disabled-from-chain-ids?)
set)]
(some-> token
(assoc :networks (network-utils/network-list-with-positive-balance token networks)
:supported-networks (network-utils/network-list token networks)
:available-balance (utils/calculate-total-token-balance token)
:total-balance (utils/calculate-total-token-balance
token
enabled-from-chain-ids))))))
(assoc :networks (network-utils/network-list token networks)
:available-balance (utils/calculate-total-token-balance token)
:total-balance (utils/calculate-total-token-balance
token
enabled-from-chain-ids))))))
(rf/reg-sub
:wallet/wallet-send-token-symbol
@@ -460,7 +459,6 @@
networks)
chain-ids
(filter #(some #{(:chain-id %)} chain-ids)))
:supported-networks (network-utils/network-list token networks)
:available-balance (utils/calculate-total-token-balance token)
:total-balance (utils/calculate-total-token-balance
token
+6 -11
View File
@@ -1,6 +1,6 @@
(ns utils.network.core
(:require [clojure.string :as string]
[taoensso.timbre :as log]))
(:require
[clojure.string :as string]))
(def url-regex
#"https?://(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}(\.[a-z]{2,6})?\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)")
@@ -41,12 +41,7 @@
(map :error)
(not-any? identity)))
(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) %)))))
(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)))
+2 -4
View File
@@ -21,10 +21,8 @@
(when js/goog.DEBUG
(reset! handler-nesting-level 0))
(when rf.interop/debug-enabled?
(do
(log/debug "Handling re-frame event: "
(first (interceptor/get-coeffect context :event)))
nil))
(log/debug "Handling re-frame event: "
(first (interceptor/get-coeffect context :event))))
context)))
(defn- update-db
+3 -3
View File
@@ -3,7 +3,7 @@
"_comment": "Instead use: scripts/update-status-go.sh <rev>",
"owner": "status-im",
"repo": "status-go",
"version": "v3.5.0",
"commit-sha1": "39511298cdc8f50e7659ac8079d5bc8a4763ddc7",
"src-sha256": "1nn8gq9d91ix5mzndr306rq3n68rzj4drym3pfaxzaa73k4v9r07"
"version": "feat/cached-eth-client",
"commit-sha1": "1ff81a2f757eb981e234201e4e5028b7933eaa2a",
"src-sha256": "0hqyhddh08mhz9z8y3s17wgvzc7yfafydj60sjsfxb364ajhhb2q"
}