Use promise resolve value instead of global var

This commit is contained in:
Vitaliy Vlasov 2020-03-20 21:56:33 +02:00 committed by flexsurfer
parent 3210411a4c
commit 0dd2ecbf7a
2 changed files with 8 additions and 13 deletions

View File

@ -3,17 +3,12 @@
(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/ethereumBeta)
(js/setTimeout (fn []
(.then (.send js/ethereumBeta "eth_requestAccounts") #(re-frame/dispatch [:set-default-account]))
(when js/ethereumBeta
(.then (.getContactCode js/ethereumBeta.status) #(re-frame/dispatch [:on-status-api :contact %]))))
100)
(js/Web3. js/ethereumBeta))
(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]))
(.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)

View File

@ -292,6 +292,6 @@
(re-frame/reg-event-fx
:set-default-account
(fn [{db :db} _]
(set! (.-defaultAccount (.-eth (:web3 db))) js/currentAccountAddress)
(fn [{db :db} [_ current-account-address]]
(set! (.-defaultAccount (.-eth (:web3 db))) current-account-address)
{:dispatch [:request-web3-async-data]}))