Skip to content

Commit 46d2658

Browse files
committed
feature status-im#6250 - added xdai and poa sidechains
Signed-off-by: Goran Jovic <goranjovic@gmail.com>
1 parent 6d0c6a8 commit 46d2658

File tree

20 files changed

+123
-38
lines changed

20 files changed

+123
-38
lines changed
17 KB
Loading
17.8 KB
Loading
18.4 KB
Loading
18.8 KB
Loading
19.8 KB
Loading
20.8 KB
Loading

src/status_im/chat/commands/impl/transactions.cljs

+10-3
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@
8888
(defn personal-send-request-short-preview
8989
[label-key {:keys [content]}]
9090
(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)))]
9293
[chat-preview/text {}
9394
(i18n/label label-key {:amount (i18n/label-number amount)
9495
:asset (wallet.utils/display-symbol token)})]))
@@ -227,7 +228,10 @@
227228
:font :default}
228229
(wallet.utils/display-symbol token)]]]]
229230
(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?))
231235
[react/view transactions-styles/command-send-fiat-amount
232236
[react/text {:style (transactions-styles/command-send-fiat-amount-text outgoing)}
233237
(str "~ " fiat-amount " " (or currency (i18n/label :usd-currency)))]])
@@ -412,7 +416,10 @@
412416
[react/text {:style (transactions-styles/command-request-currency-text outgoing)
413417
:font :default}
414418
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?))
416423
[react/view transactions-styles/command-request-fiat-amount-row
417424
[react/text {:style (transactions-styles/command-request-fiat-amount-text outgoing)}
418425
(str "~ " fiat-amount " " (or currency (i18n/label :usd-currency)))]])

src/status_im/constants.cljs

+18-2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,20 @@
4747
:UpstreamConfig {:Enabled true
4848
:URL "https://mainnet.infura.io/z6GCTmjdP3FETEJmMBI4"}}}})
4949

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+
5064
(def testnet-networks
5165
{"testnet" {:id "testnet",
5266
:name "Ropsten",
@@ -83,12 +97,14 @@
8397

8498
(def default-networks
8599
(into {} (filter network-enabled?
86-
(merge testnet-networks mainnet-networks))))
100+
(merge testnet-networks mainnet-networks sidechain-networks))))
87101

88102
(defn default-account-settings []
89103
{:wallet {:visible-tokens {:testnet #{:STT :HND}
90104
:mainnet #{:SNT}
91-
:rinkeby #{:MOKSHA :KDO}}}})
105+
:rinkeby #{:MOKSHA :KDO}
106+
:xdai #{}
107+
:poa #{}}}})
92108

93109
(def currencies
94110
{:aed {:id :aed :code "AED" :display-name (i18n/label :t/currency-display-name-aed) :symbol "د.إ"}

src/status_im/models/wallet.cljs

+7-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
[status-im.utils.ethereum.tokens :as tokens]
99
[status-im.utils.hex :as utils.hex]
1010
[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]))
1213

1314
(def min-gas-price-wei (money/bignumber 1))
1415

@@ -233,8 +234,12 @@
233234
:chain chain
234235
:success-event :update-token-balance-success
235236
: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))])
237241
:to [(:code currency)]
242+
:mainnet? mainnet?
238243
:success-event :update-prices-success
239244
:error-event :update-prices-fail}
240245
:db (-> db

src/status_im/protocol/core.cljs

+6-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
[status-im.utils.ethereum.core :as ethereum]
77
[status-im.utils.fx :as fx]
88
[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]))
1011

1112
(fx/defn update-sync-state
1213
[{{:keys [sync-state sync-data] :as db} :db} error sync]
@@ -73,6 +74,8 @@
7374
(when (and (not error) ; error most probably means we are offline
7475
(not= network-id fetched-network-id))
7576
(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})
7881
#(re-frame/dispatch [:protocol.ui/close-app-confirmed]))))))))

src/status_im/ui/components/common/common.cljs

+8-3
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,14 @@
5353
[react/view styles/network-icon
5454
[vector-icons/icon :icons/network {:color :white}]]
5555
[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))]]]))
5964

6065
(defn logo
6166
([] (logo nil))

src/status_im/ui/screens/wallet/events.cljs

+2-1
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,10 @@
7979
;; TODO(oskarth): At some point we want to get list of relevant assets to get prices for
8080
(re-frame/reg-fx
8181
:get-prices
82-
(fn [{:keys [from to success-event error-event]}]
82+
(fn [{:keys [from to mainnet? success-event error-event]}]
8383
(prices/get-prices from
8484
to
85+
mainnet?
8586
#(re-frame/dispatch [success-event %])
8687
#(re-frame/dispatch [error-event %]))))
8788

src/status_im/ui/screens/wallet/utils.cljs

+10-2
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,13 @@
77
(money/token->unit decimals)
88
money/to-fixed))
99

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)))

src/status_im/utils/ethereum/core.cljs

+9-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
(def chains
1111
{:mainnet {:id 1 :name "Mainnet"}
1212
: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"}})
1416

1517
(defn chain-id->chain-keyword [i]
1618
(or (some #(when (= i (:id (val %))) (key %)) chains)
@@ -20,7 +22,12 @@
2022
(get-in chains [k :id]))
2123

2224
(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))
2431

2532
(defn network-with-upstream-rpc? [network]
2633
(get-in network [:config :UpstreamConfig :Enabled]))

src/status_im/utils/ethereum/eip681.cljs

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818
(def parameter-separator "&")
1919
(def key-value-separator "=")
2020

21+
;;TODO(goranjovic) - rewrite all of these with something more readable than regex
2122
(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*))?")))
2324
(def key-value-format (str "([^" parameter-separator key-value-separator "]+)"))
2425
(def query-pattern (re-pattern (str key-value-format key-value-separator key-value-format)))
2526

src/status_im/utils/ethereum/tokens.cljs

+10-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,16 @@
2525
:rinkeby {:name "Rinkeby Ether"
2626
:symbol :ETH
2727
: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}}))
2938

3039
(def native-currency-symbols
3140
(set (map #(-> % val :symbol) all-native-currencies)))

src/status_im/utils/prices.cljs

+18-9
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,25 @@
1919
(defn- gen-price-url [fsyms tsyms]
2020
(str api-url "/pricemultifull?fsyms=" (->url-param-syms fsyms) "&tsyms=" (->url-param-syms tsyms) "&" status-identifier))
2121

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)}}))}))))
2938

30-
(defn get-prices [from to on-success on-error]
39+
(defn get-prices [from to mainnet? on-success on-error]
3140
(http/get
3241
(gen-price-url from to)
33-
(fn [resp] (on-success (format-price-resp resp)))
42+
(fn [resp] (on-success (format-price-resp resp mainnet?)))
3443
on-error))

src/status_im/utils/transactions.cljs

+13-7
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,19 @@
33
[status-im.utils.types :as types]
44
[taoensso.timbre :as log]))
55

6+
(def etherscan-supported?
7+
#{:testnet :mainnet :rinkeby})
8+
69
(defn- get-network-subdomain [chain]
710
(case chain
811
(:testnet) "ropsten"
912
(:mainnet) nil
1013
(:rinkeby) "rinkeby"))
1114

1215
(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))))
1519

1620
(def etherscan-api-key "DMSI4UAAKUBVGCDMVP3H2STAMSAUV7BYFI")
1721

@@ -56,8 +60,10 @@
5660
{})))
5761

5862
(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)))

0 commit comments

Comments
 (0)