diff --git a/project.clj b/project.clj index 75fc06b..751dd64 100644 --- a/project.clj +++ b/project.clj @@ -4,7 +4,8 @@ [reagent "0.7.0" :exclusions [cljsjs/react cljsjs/react-dom]] [re-frame "0.10.2"] [cljs-web3 "0.19.0-0-9"] - [day8.re-frame/http-fx "0.1.5"]] + [day8.re-frame/http-fx "0.1.5"] + [javax.xml.bind/jaxb-api "2.3.1"]] :plugins [[lein-cljsbuild "1.1.7"]] :min-lein-version "2.5.3" diff --git a/src/cljs/status_dapp/db.cljs b/src/cljs/status_dapp/db.cljs index 9e41475..10073bc 100644 --- a/src/cljs/status_dapp/db.cljs +++ b/src/cljs/status_dapp/db.cljs @@ -3,17 +3,35 @@ (def dapp-store? (re-find #"#dapp-store" (-> js/window .-location .-href))) -(def web3 (or dapp-store? (when (exists? js/web3) - js/web3) - (when (exists? js/ethereum) - (js/setTimeout (fn [] - (.then (.enable js/ethereum) - #(re-frame/dispatch [:set-default-account (first %1)])) - (when js/ethereum.status - (.then (.getContactCode js/ethereum.status) #(re-frame/dispatch [:on-status-api :contact %])))) - 100) - (js/Web3. js/ethereum)))) +(defn get-web3 [] + (or dapp-store? (if (exists? js/web3) + js/web3 + (do (re-frame/dispatch [:set-in [:foo] "w3 doesn't exist"]) + nil)) + (if (exists? js/ethereum) + (do + (js/setTimeout (fn [] + (.then (.enable js/ethereum) + #(re-frame/dispatch [:set-default-account (first %1)])) + (when js/ethereum.status + (.then (.getContactCode js/ethereum.status) #(re-frame/dispatch [:on-status-api :contact %])))) + 100) + (js/Web3. js/ethereum)) + (re-frame/dispatch [:set-in [:foo] "ethereum doesn exists"])))) +(def web3 (get-web3)) + +;; NOTE(rasom): injection of js code into Android's webview might take some time +;; and if js/web3 or js/ethereum are not available rignt away it makes sense to +;; retry a bit later +(when (nil? web3) + (js/setTimeout + (fn [] + (when-let [web3 (get-web3)] + (re-frame/dispatch [:set-in [:web3] web3]) + (when-not dapp-store? + (re-frame/dispatch [:set-in [:view-id] :web3])))) + 300)) (def all [{:title "Exchanges"