Skip to content

Commit

Permalink
[#12760] Add Binance Smart chain as main network
Browse files Browse the repository at this point in the history
Signed-off-by: andrey <[email protected]>
  • Loading branch information
flexsurfer committed Nov 12, 2021
1 parent 345ae29 commit a573ae7
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 22 deletions.
Binary file added resources/images/tokens/bsc/0-native.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 4 additions & 2 deletions src/status_im/ethereum/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
:rinkeby {:id 4 :name "Rinkeby"}
:xdai {:id 100 :name "xDai"}
:poa {:id 99 :name "POA"}
:goerli {:id 5 :name "Goerli"}})
:goerli {:id 5 :name "Goerli"}
:bsc {:id 56 :name "BSC"}})

(defn chain-id->chain-keyword [i]
(or (some #(when (= i (:id (val %))) (key %)) chains)
Expand All @@ -50,7 +51,8 @@

(defn sidechain? [id]
(contains? #{(chain-keyword->chain-id :xdai)
(chain-keyword->chain-id :poa)} id))
(chain-keyword->chain-id :poa)
(chain-keyword->chain-id :bsc)} id))

(defn network-with-upstream-rpc? [network]
(get-in network [:config :UpstreamConfig :Enabled]))
Expand Down
7 changes: 4 additions & 3 deletions src/status_im/ethereum/macros.clj
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,20 @@
tokens))

(defn network->icon [network]
(let [s (str "../resources/images/tokens/" (name network) "/0-native.png")
(let [s (str "./resources/images/tokens/" (name network) "/0-native.png")
s-js (str "." s)
image (gensym)]
(if (.exists (io/file s))
`(let [~image (atom nil)]
(fn []
(or @~image
(reset! ~image (js/require ~s)))))
(reset! ~image (js/require ~s-js)))))
`(let [~image (atom nil)]
(fn []
(or
@~image
(reset! ~image
(js/require "../resources/images/tokens/default-native.png"))))))))
(js/require "../resources/images/tokens/default-token.png"))))))))

(defmacro resolve-native-currency-icons
"In react-native arguments to require must be static strings.
Expand Down
12 changes: 8 additions & 4 deletions src/status_im/ethereum/tokens.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
(def default-native-currency
(memoize
(fn []
{:name "Native"
:symbol :ETH
:decimals 18
:icon {:source (js/require "../resources/images/tokens/default-native.png")}})))
{:name "Native"
:symbol :ETH
:decimals 18
:icon {:source (js/require "../resources/images/tokens/default-token.png")}})))

(def snt-icon-source (js/require "../resources/images/tokens/mainnet/SNT.png"))

Expand All @@ -34,6 +34,10 @@
:symbol :ETH
:symbol-display :xDAI
:symbol-exchange :DAI
:decimals 18}
:bsc {:name "BSC"
:symbol :ETH
:symbol-display :BNB
:decimals 18}}))

(def native-currency-symbols
Expand Down
15 changes: 9 additions & 6 deletions src/status_im/multiaccounts/login/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -300,17 +300,20 @@
(let [{:networks/keys [current-network networks]
:as settings}
(data-store.settings/rpc->settings settings)
multiaccount (dissoc settings :networks/current-network :networks/networks)]
multiaccount (dissoc settings :networks/current-network :networks/networks)
;;for some reason we save default networks in db, in case when we want to modify default-networks for
;; existing accounts we have to merge them again into networks
merged-networks (merge networks config/default-networks-by-id)]
(fx/merge cofx
{:db (-> db
(dissoc :multiaccounts/login)
(assoc :networks/current-network current-network
:networks/networks networks
:networks/networks merged-networks
:multiaccount multiaccount))}
(data-store.chats/fetch-chats-rpc
{:on-success
#(do (re-frame/dispatch [:chats-list/load-success %])
(re-frame/dispatch [::get-chats-callback settings]))})
(re-frame/dispatch [::get-chats-callback]))})
(acquisition/login)
(initialize-appearance)
(initialize-communities-enabled)
Expand All @@ -321,9 +324,9 @@

(fx/defn get-chats-callback
{:events [::get-chats-callback]}
[{:keys [db] :as cofx} settings]
(let [{:keys [notifications-enabled?]
:networks/keys [current-network networks]} settings
[{:keys [db] :as cofx}]
(let [{:networks/keys [current-network networks]} db
notifications-enabled? (get-in db [:multiaccount :notifications-enabled?])
network-id (str (get-in networks [current-network :config :NetworkId]))]
(fx/merge cofx
(cond-> {::eip1559/check-eip1559-activation
Expand Down
12 changes: 8 additions & 4 deletions src/status_im/ui/screens/wallet/account/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,21 @@
(views/letsubs [{:keys [tokens]} [:wallet/visible-assets-with-values address]
currency [:wallet/currency]
opensea-enabled? [:opensea-enabled?]
collectible-collection [:wallet/collectible-collection address]]
collectible-collection [:wallet/collectible-collection address]
mainnet? [:mainnet?]]
(let [{:keys [tab]} @state]
[react/view {:flex 1}
[react/view {:flex-direction :row :margin-bottom 8 :padding-horizontal 4}
[tabs/tab-title state :assets (i18n/label :t/wallet-assets) (= tab :assets)]
[tabs/tab-title state :nft (i18n/label :t/wallet-collectibles) (= tab :nft)]
[tabs/tab-title state :history (i18n/label :t/history) (= tab :history)]]
(when mainnet?
[tabs/tab-title state :nft (i18n/label :t/wallet-collectibles) (= tab :nft)])
(when mainnet?
[tabs/tab-title state :history (i18n/label :t/history) (= tab :history)])]
(cond
(= tab :assets)
[:<>
[buy-crypto/banner]
(when mainnet?
[buy-crypto/banner])
(for [item tokens]
^{:key (:name item)}
[accounts/render-asset item nil nil (:code currency)])]
Expand Down
6 changes: 4 additions & 2 deletions src/status_im/ui/screens/wallet/accounts/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@
:onRefresh refresh-action}]))

(defn accounts-overview []
(let [mnemonic @(re-frame/subscribe [:mnemonic])]
(let [mnemonic @(re-frame/subscribe [:mnemonic])
mainnet? @(re-frame/subscribe [:mainnet?])]
[react/view
{:style {:flex 1}}
[quo/animated-header
Expand All @@ -235,7 +236,8 @@
:icon :main-icons/more
:accessibility-label :accounts-more-options}]}
[accounts]
[buy-crypto/banner]
(when mainnet?
[buy-crypto/banner])
[assets]
[react/view {:height 68}]]
[send-button]]))
8 changes: 7 additions & 1 deletion src/status_im/utils/config.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,13 @@
:config {:NetworkId (ethereum/chain-keyword->chain-id :poa)
:DataDir "/ethereum/poa_rpc"
:UpstreamConfig {:Enabled true
:URL "https://core.poa.network"}}}])
:URL "https://core.poa.network"}}}
{:id "bsc_rpc",
:name "BSC Network",
:config {:NetworkId (ethereum/chain-keyword->chain-id :bsc)
:DataDir "/ethereum/bsc_rpc"
:UpstreamConfig {:Enabled true
:URL "https://bsc-dataseed.binance.org"}}}])

(def testnet-networks
[{:id "testnet_rpc",
Expand Down

0 comments on commit a573ae7

Please sign in to comment.