From a573ae70e52e3c764b7a79a346c6114d01de458e Mon Sep 17 00:00:00 2001 From: andrey Date: Wed, 10 Nov 2021 13:20:54 +0100 Subject: [PATCH] [#12760] Add Binance Smart chain as main network Signed-off-by: andrey --- resources/images/tokens/bsc/0-native.png | Bin 0 -> 3247 bytes src/status_im/ethereum/core.cljs | 6 ++++-- src/status_im/ethereum/macros.clj | 7 ++++--- src/status_im/ethereum/tokens.cljs | 12 ++++++++---- src/status_im/multiaccounts/login/core.cljs | 15 +++++++++------ .../ui/screens/wallet/account/views.cljs | 12 ++++++++---- .../ui/screens/wallet/accounts/views.cljs | 6 ++++-- src/status_im/utils/config.cljs | 8 +++++++- 8 files changed, 44 insertions(+), 22 deletions(-) create mode 100644 resources/images/tokens/bsc/0-native.png diff --git a/resources/images/tokens/bsc/0-native.png b/resources/images/tokens/bsc/0-native.png new file mode 100644 index 0000000000000000000000000000000000000000..e715b87e05e41ada539a88efc97d102038ae67b3 GIT binary patch literal 3247 zcmXYzc~n!^7Kd+=3nmDX5D^uG%M>9H2$D!tB$vpj2oVvfRf!;4r;@f<5iGf3Fe*ZV zAW()!up)y3qGBx$iP|EgfC?gDnG^(MkVyzh?u&1|wa(i6+k5}^+3T!x{x}!8{@!{z zYjpqs(DU{22m}C(1~C90r*S84g#>9Fc+`ETI{;LPmn#oxeXITw=*gbEeWZ zP#qX{H0J-81JlNyVducKcVJLy8|@qzHa2uBjY)ObXzSo&Ph(K2^#4_v8mr0B>6&n( zMr=#lNTq(0+0hvG_6!=$*;ccIgGQ#YnkfvbBh#9$Y5AtHp|k89zm3rJQXLug4$k%t zOo$HKJ2I$rO^aqOv%O?ZVZ6mam64}AUHLazlc`9C($89DoV7a7r+C6n70G7OcneQ= zCzgxzXYKf9n$x*N1^Vv>h;%Lw5f{jM;g-otKExA5R?@|hlYC;RfJ;YYFqbcBkyIAY zrMIC1q_IP3rx)AZiv_bSnHk?Dllz1)OO{hPOHd7a}A^MV~|d~OUy%TaXK^Zotoy(iT%e-277vM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9{CvNqz`6VN$Ga-XY@Yv$x zdty_cFEq7l-#h1yY6`~@Td2P~Hv$0J{w**x`cq77wWpoDz$L(ePMM~D>W5NA|4J+>85#_@h@)Y_YlmOJRBf$N>F6(QtS~77XhQSaF`3w;ZOiR2 z+2}u#F|%q)NZA$OCHiLk&+EJ4n3Lr?SQeVK7YoP_$^C%g0yc0f(T7+O0U`@#`>B!3cPpe4Tr{ zL$3!NSRabE*7H4qkx(KgODj(|3zVq0Qsg}Fc%Ru0z=nx3t)-u2nP8CWtpvG)c9FPW z#Z74#tAjvy)QZcOPBRN2W%ypNoEjx=Q04%hdn?$Ok9D@%7c*F`K0{rs2k6S-(;2f| zmPi*pTjWZF9-{um4|39qZ*)$`UeoJ;r0=bdYt0CAi8j8z7z6`x{WHM|?f8*D^7TmbuoZ<`Rg5qcu&-LQ?Z{;k! z1J3?josJl?UD}c4Dalh6rNWN;GOqgdIvzJT9C&Wy#qrnI-VuAqLzUqzOaA$TIZs{R z-7k2n>%8`|s2*L|(tN%_w|2xub#1om>7!uTZ^3(qCm)F?CIi+pPs=(!pQE1VJDqCp zR(kDC?e1ghmyY-*s$`_1b$hJvg>&op?z#UaCHWnus61 g{&mdt(F}?Sc=}~k+Jo{Bny)qB>*?=N!QsXK7u2B4+yDRo literal 0 HcmV?d00001 diff --git a/src/status_im/ethereum/core.cljs b/src/status_im/ethereum/core.cljs index 739d7df0d1..bfe7d71d61 100644 --- a/src/status_im/ethereum/core.cljs +++ b/src/status_im/ethereum/core.cljs @@ -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) @@ -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])) diff --git a/src/status_im/ethereum/macros.clj b/src/status_im/ethereum/macros.clj index f492b6bb0d..7dce3f213f 100644 --- a/src/status_im/ethereum/macros.clj +++ b/src/status_im/ethereum/macros.clj @@ -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. diff --git a/src/status_im/ethereum/tokens.cljs b/src/status_im/ethereum/tokens.cljs index a8685fbae3..0ec2150c11 100644 --- a/src/status_im/ethereum/tokens.cljs +++ b/src/status_im/ethereum/tokens.cljs @@ -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")) @@ -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 diff --git a/src/status_im/multiaccounts/login/core.cljs b/src/status_im/multiaccounts/login/core.cljs index 6a5195b6eb..79d2a07549 100644 --- a/src/status_im/multiaccounts/login/core.cljs +++ b/src/status_im/multiaccounts/login/core.cljs @@ -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) @@ -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 diff --git a/src/status_im/ui/screens/wallet/account/views.cljs b/src/status_im/ui/screens/wallet/account/views.cljs index 2068769a4d..d70d4ef132 100644 --- a/src/status_im/ui/screens/wallet/account/views.cljs +++ b/src/status_im/ui/screens/wallet/account/views.cljs @@ -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)])] diff --git a/src/status_im/ui/screens/wallet/accounts/views.cljs b/src/status_im/ui/screens/wallet/accounts/views.cljs index a496afd85b..cd7bd146c0 100644 --- a/src/status_im/ui/screens/wallet/accounts/views.cljs +++ b/src/status_im/ui/screens/wallet/accounts/views.cljs @@ -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 @@ -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]])) diff --git a/src/status_im/utils/config.cljs b/src/status_im/utils/config.cljs index 1c4a269d68..608efecab6 100644 --- a/src/status_im/utils/config.cljs +++ b/src/status_im/utils/config.cljs @@ -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",