File tree 20 files changed +123
-38
lines changed
test/cljs/status_im/test/utils
20 files changed +123
-38
lines changed Original file line number Diff line number Diff line change 88
88
(defn personal-send-request-short-preview
89
89
[label-key {:keys [content]}]
90
90
(let [{:keys [amount asset network]} (:params content)
91
- token (tokens/asset-for (keyword network) (keyword asset))]
91
+ token (when (and network asset)
92
+ (tokens/asset-for (keyword network) (keyword asset)))]
92
93
[chat-preview/text {}
93
94
(i18n/label label-key {:amount (i18n/label-number amount)
94
95
:asset (wallet.utils/display-symbol token)})]))
227
228
:font :default }
228
229
(wallet.utils/display-symbol token)]]]]
229
230
(when (and fiat-amount
230
- platform/mobile?)
231
+ platform/mobile?
232
+ ; ;NOTE(goranjovic) - have to hide cross network asset fiat value until we can support
233
+ ; ; multiple chain prices simultaneously
234
+ (not network-mismatch?))
231
235
[react/view transactions-styles/command-send-fiat-amount
232
236
[react/text {:style (transactions-styles/command-send-fiat-amount-text outgoing)}
233
237
(str " ~ " fiat-amount " " (or currency (i18n/label :usd-currency )))]])
412
416
[react/text {:style (transactions-styles/command-request-currency-text outgoing)
413
417
:font :default }
414
418
asset]]]
415
- (when platform/mobile?
419
+ (when (and platform/mobile?
420
+ ; ;NOTE(goranjovic) - have to hide cross network asset fiat value until we can support
421
+ ; ; multiple chain prices simultaneously
422
+ (not network-mismatch?))
416
423
[react/view transactions-styles/command-request-fiat-amount-row
417
424
[react/text {:style (transactions-styles/command-request-fiat-amount-text outgoing)}
418
425
(str " ~ " fiat-amount " " (or currency (i18n/label :usd-currency )))]])
Original file line number Diff line number Diff line change 47
47
:UpstreamConfig {:Enabled true
48
48
:URL " https://mainnet.infura.io/z6GCTmjdP3FETEJmMBI4" }}}})
49
49
50
+ (def sidechain-networks
51
+ {" xdai_rpc" {:id " xdai_rpc" ,
52
+ :name " xDai Chain" ,
53
+ :config {:NetworkId (ethereum/chain-keyword->chain-id :xdai )
54
+ :DataDir " /ethereum/xdai_rpc"
55
+ :UpstreamConfig {:Enabled true
56
+ :URL " https://dai.poa.network" }}}
57
+ " poa_rpc" {:id " poa_rpc" ,
58
+ :name " POA Network" ,
59
+ :config {:NetworkId (ethereum/chain-keyword->chain-id :poa )
60
+ :DataDir " /ethereum/poa_rpc"
61
+ :UpstreamConfig {:Enabled true
62
+ :URL " https://poa.infura.io" }}}})
63
+
50
64
(def testnet-networks
51
65
{" testnet" {:id " testnet" ,
52
66
:name " Ropsten" ,
83
97
84
98
(def default-networks
85
99
(into {} (filter network-enabled?
86
- (merge testnet-networks mainnet-networks))))
100
+ (merge testnet-networks mainnet-networks sidechain-networks ))))
87
101
88
102
(defn default-account-settings []
89
103
{:wallet {:visible-tokens {:testnet #{:STT :HND }
90
104
:mainnet #{:SNT }
91
- :rinkeby #{:MOKSHA :KDO }}}})
105
+ :rinkeby #{:MOKSHA :KDO }
106
+ :xdai #{}
107
+ :poa #{}}}})
92
108
93
109
(def currencies
94
110
{:aed {:id :aed :code " AED" :display-name (i18n/label :t/currency-display-name-aed ) :symbol " د.إ" }
Original file line number Diff line number Diff line change 8
8
[status-im.utils.ethereum.tokens :as tokens]
9
9
[status-im.utils.hex :as utils.hex]
10
10
[status-im.utils.money :as money]
11
- [status-im.utils.fx :as fx]))
11
+ [status-im.utils.fx :as fx]
12
+ [status-im.ui.screens.wallet.utils :as wallet.utils]))
12
13
13
14
(def min-gas-price-wei (money/bignumber 1 ))
14
15
233
234
:chain chain
234
235
:success-event :update-token-balance-success
235
236
:error-event :update-token-balance-fail }
236
- :get-prices {:from (if mainnet? (conj tokens " ETH" ) [" ETH" ])
237
+ :get-prices {:from (if mainnet?
238
+ (conj tokens " ETH" )
239
+ [(-> (tokens/native-currency chain)
240
+ (wallet.utils/exchange-symbol ))])
237
241
:to [(:code currency)]
242
+ :mainnet? mainnet?
238
243
:success-event :update-prices-success
239
244
:error-event :update-prices-fail }
240
245
:db (-> db
Original file line number Diff line number Diff line change 6
6
[status-im.utils.ethereum.core :as ethereum]
7
7
[status-im.utils.fx :as fx]
8
8
[status-im.utils.semaphores :as semaphores]
9
- [status-im.utils.utils :as utils]))
9
+ [status-im.utils.utils :as utils]
10
+ [status-im.i18n :as i18n]))
10
11
11
12
(fx/defn update-sync-state
12
13
[{{:keys [sync-state sync-data] :as db} :db } error sync]
73
74
(when (and (not error) ; error most probably means we are offline
74
75
(not= network-id fetched-network-id))
75
76
(utils/show-popup
76
- " Ethereum node started incorrectly"
77
- " Ethereum node was started with incorrect configuration, application will be stopped to recover from that condition."
77
+ (i18n/label :t/ethereum-node-started-incorrectly-title )
78
+ (i18n/label :t/ethereum-node-started-incorrectly-description
79
+ {:network-id network-id
80
+ :fetched-network-id fetched-network-id})
78
81
#(re-frame/dispatch [:protocol.ui/close-app-confirmed ]))))))))
Original file line number Diff line number Diff line change 53
53
[react/view styles/network-icon
54
54
[vector-icons/icon :icons/network {:color :white }]]
55
55
[react/text {:style (styles/network-text text-color)}
56
- (if (ethereum/testnet? network-id)
57
- (i18n/label :t/testnet-text {:testnet (get-in ethereum/chains [(ethereum/chain-id->chain-keyword network-id) :name ] " Unknown" )})
58
- (i18n/label :t/mainnet-text ))]]]))
56
+ (cond (ethereum/testnet? network-id)
57
+ (i18n/label :t/testnet-text {:testnet (get-in ethereum/chains [(ethereum/chain-id->chain-keyword network-id) :name ] " Unknown" )})
58
+
59
+ (ethereum/sidechain? network-id)
60
+ (i18n/label :t/sidechain-text {:sidechain (get-in ethereum/chains [(ethereum/chain-id->chain-keyword network-id) :name ] " Unknown" )})
61
+
62
+ :else
63
+ (i18n/label :t/mainnet-text ))]]]))
59
64
60
65
(defn logo
61
66
([] (logo nil ))
Original file line number Diff line number Diff line change 79
79
; ; TODO(oskarth): At some point we want to get list of relevant assets to get prices for
80
80
(re-frame/reg-fx
81
81
:get-prices
82
- (fn [{:keys [from to success-event error-event]}]
82
+ (fn [{:keys [from to mainnet? success-event error-event]}]
83
83
(prices/get-prices from
84
84
to
85
+ mainnet?
85
86
#(re-frame/dispatch [success-event %])
86
87
#(re-frame/dispatch [error-event %]))))
87
88
Original file line number Diff line number Diff line change 7
7
(money/token->unit decimals)
8
8
money/to-fixed))
9
9
10
- (defn display-symbol [{:keys [symbol-display symbol]}]
11
- (clojure.core/name (or symbol-display symbol)))
10
+ ; ;NOTE(goranjovic) - we are internally using symbol ETH for native currencies of any ethereum network
11
+ ; ; some sidechains have different names for this native currency, which we handle with `symbol-display` override.
12
+ (defn display-symbol [{:keys [symbol-display symbol] :as token}]
13
+ (when token
14
+ (clojure.core/name (or symbol-display symbol))))
15
+
16
+ ; ;NOTE(goranjovic) - in addition to custom symbol display, some sidechain native currencies are listed under a different
17
+ ; ; ticker on exchange networks. We handle that with `symbol-exchange` override.
18
+ (defn exchange-symbol [{:keys [symbol-exchange symbol-display symbol]}]
19
+ (clojure.core/name (or symbol-exchange symbol-display symbol)))
Original file line number Diff line number Diff line change 10
10
(def chains
11
11
{:mainnet {:id 1 :name " Mainnet" }
12
12
:testnet {:id 3 :name " Ropsten" }
13
- :rinkeby {:id 4 :name " Rinkeby" }})
13
+ :rinkeby {:id 4 :name " Rinkeby" }
14
+ :xdai {:id 100 :name " xDai" }
15
+ :poa {:id 99 :name " POA" }})
14
16
15
17
(defn chain-id->chain-keyword [i]
16
18
(or (some #(when (= i (:id (val %))) (key %)) chains)
20
22
(get-in chains [k :id ]))
21
23
22
24
(defn testnet? [id]
23
- (contains? #{(chain-keyword->chain-id :testnet ) (chain-keyword->chain-id :rinkeby )} id))
25
+ (contains? #{(chain-keyword->chain-id :testnet )
26
+ (chain-keyword->chain-id :rinkeby )} id))
27
+
28
+ (defn sidechain? [id]
29
+ (contains? #{(chain-keyword->chain-id :xdai )
30
+ (chain-keyword->chain-id :poa )} id))
24
31
25
32
(defn network-with-upstream-rpc? [network]
26
33
(get-in network [:config :UpstreamConfig :Enabled ]))
Original file line number Diff line number Diff line change 18
18
(def parameter-separator " &" )
19
19
(def key-value-separator " =" )
20
20
21
+ ; ;TODO(goranjovic) - rewrite all of these with something more readable than regex
21
22
(def uri-pattern (re-pattern (str scheme scheme-separator " ([^" query-separator " ]*)(?:\\ " query-separator " (.*))?" )))
22
- (def authority-path-pattern (re-pattern (str " ^([^" chain-id-separator function-name-separator " ]*)(?:" chain-id-separator " (\\ d))?(?:" function-name-separator " (\\ w*))?" )))
23
+ (def authority-path-pattern (re-pattern (str " ^([^" chain-id-separator function-name-separator " ]*)(?:" chain-id-separator " (\\ d+ ))?(?:" function-name-separator " (\\ w*))?" )))
23
24
(def key-value-format (str " ([^" parameter-separator key-value-separator " ]+)" ))
24
25
(def query-pattern (re-pattern (str key-value-format key-value-separator key-value-format)))
25
26
Original file line number Diff line number Diff line change 25
25
:rinkeby {:name " Rinkeby Ether"
26
26
:symbol :ETH
27
27
:symbol-display :ETHri
28
- :decimals 18 }}))
28
+ :decimals 18 }
29
+ :poa {:name " POA"
30
+ :symbol :ETH
31
+ :symbol-display :POA
32
+ :decimals 18 }
33
+ :xdai {:name " xDAI"
34
+ :symbol :ETH
35
+ :symbol-display :xDAI
36
+ :symbol-exchange :DAI
37
+ :decimals 18 }}))
29
38
30
39
(def native-currency-symbols
31
40
(set (map #(-> % val :symbol ) all-native-currencies)))
Original file line number Diff line number Diff line change 19
19
(defn- gen-price-url [fsyms tsyms]
20
20
(str api-url " /pricemultifull?fsyms=" (->url-param-syms fsyms) " &tsyms=" (->url-param-syms tsyms) " &" status-identifier))
21
21
22
- (defn- format-price-resp [resp]
23
- (into {} (for [[from entries] (:RAW (types/json->clj resp))]
24
- {from (into {} (for [[to entry] entries]
25
- {to {:from (name from)
26
- :to (name to)
27
- :price (:PRICE entry)
28
- :last-day (:OPEN24HOUR entry)}}))})))
22
+ (defn- format-price-resp [resp mainnet?]
23
+ ; ;NOTE(this check is to allow value conversion for sidechains with native currencies listed on cryptocompare
24
+ ; ; under a symbol different than display symbol. Specific use case xDAI and POA.
25
+ (if mainnet?
26
+ (into {} (for [[from entries] (:RAW (types/json->clj resp))]
27
+ {from (into {} (for [[to entry] entries]
28
+ {to {:from (name from)
29
+ :to (name to)
30
+ :price (:PRICE entry)
31
+ :last-day (:OPEN24HOUR entry)}}))}))
32
+ (into {} (for [[_ entries] (:RAW (types/json->clj resp))]
33
+ {:ETH (into {} (for [[to entry] entries]
34
+ {to {:from " ETH"
35
+ :to (name to)
36
+ :price (:PRICE entry)
37
+ :last-day (:OPEN24HOUR entry)}}))}))))
29
38
30
- (defn get-prices [from to on-success on-error]
39
+ (defn get-prices [from to mainnet? on-success on-error]
31
40
(http/get
32
41
(gen-price-url from to)
33
- (fn [resp] (on-success (format-price-resp resp)))
42
+ (fn [resp] (on-success (format-price-resp resp mainnet? )))
34
43
on-error))
Original file line number Diff line number Diff line change 3
3
[status-im.utils.types :as types]
4
4
[taoensso.timbre :as log]))
5
5
6
+ (def etherscan-supported?
7
+ #{:testnet :mainnet :rinkeby })
8
+
6
9
(defn- get-network-subdomain [chain]
7
10
(case chain
8
11
(:testnet ) " ropsten"
9
12
(:mainnet ) nil
10
13
(:rinkeby ) " rinkeby" ))
11
14
12
15
(defn get-transaction-details-url [chain hash]
13
- (let [network-subdomain (get-network-subdomain chain)]
14
- (str " https://" (when network-subdomain (str network-subdomain " ." )) " etherscan.io/tx/" hash)))
16
+ (when (etherscan-supported? chain)
17
+ (let [network-subdomain (get-network-subdomain chain)]
18
+ (str " https://" (when network-subdomain (str network-subdomain " ." )) " etherscan.io/tx/" hash))))
15
19
16
20
(def etherscan-api-key " DMSI4UAAKUBVGCDMVP3H2STAMSAUV7BYFI" )
17
21
56
60
{})))
57
61
58
62
(defn get-transactions [chain account on-success on-error]
59
- (let [url (get-transaction-url chain account)]
60
- (log/debug " HTTP GET" url)
61
- (http/get url
62
- #(on-success (format-transactions-response % account))
63
- on-error)))
63
+ (if (etherscan-supported? chain)
64
+ (let [url (get-transaction-url chain account)]
65
+ (log/debug " HTTP GET" url)
66
+ (http/get url
67
+ #(on-success (format-transactions-response % account))
68
+ on-error))
69
+ (log/info " Etherscan not supported for " chain)))
You can’t perform that action at this time.
0 commit comments