Skip to content

Commit

Permalink
move registration logic to tarnsactions/core and use new-transfers event
Browse files Browse the repository at this point in the history
  • Loading branch information
jrainville committed May 7, 2020
1 parent 5c7a435 commit 12f6428
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 37 deletions.
28 changes: 26 additions & 2 deletions src/status_im/ethereum/transactions/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
[status-im.ethereum.eip55 :as eip55]
[status-im.ethereum.encode :as encode]
[status-im.ethereum.json-rpc :as json-rpc]
[status-im.ens.core :as ens]
[status-im.utils.fx :as fx]
[status-im.wallet.core :as wallet]
[taoensso.timbre :as log]
Expand Down Expand Up @@ -205,8 +206,7 @@
[{:keys [db]} address]
{:db (assoc-in db [:wallet :fetching address :all-fetched?] true)})

(fx/defn new-transfers
{:events [::new-transfers]}
(fx/defn handle-mew-transfer
[{:keys [db] :as cofx} transfers {:keys [address limit]}]
(log/debug "[transfers] new-transfers"
"address" address
Expand Down Expand Up @@ -234,6 +234,30 @@
(conj (tx-history-end-reached checksum)))]
(apply fx/merge cofx (tx-fetching-ended [checksum]) effects)))

(fx/defn check-ens-transactions
[{:keys [db]} transfers]
(let [registrations (get db :ens/registrations)]
(doseq [[hash {:keys [state username custom-domain?]}] registrations]
(when (or (= state :dismissed) (= state :submitted))
(doseq [transaction transfers]
(let [transaction-hash (get transaction :hash)
type (get transaction :type)
transaction-success (get transaction :transfer)]
(when (= hash transaction-hash)
; TODO Return from the loop once we find a match
(when (= transaction-success true)
(re-frame/dispatch [:update-ens-tx-state :success username custom-domain? hash])
(re-frame/dispatch [::status-im.ens.core/save-username custom-domain? username]))
(when (= type :failed)
(re-frame/dispatch [:update-ens-tx-state :failure username custom-domain? hash])))))))))

(fx/defn new-transfers
{:events [::new-transfers]}
[cofx transfers params]
(fx/merge cofx
(handle-mew-transfer transfers params)
(check-ens-transactions transfers)))

(fx/defn tx-fetching-failed
{:events [::tx-fetching-failed]}
[cofx error address]
Expand Down
55 changes: 20 additions & 35 deletions src/status_im/ui/screens/ens/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -626,41 +626,26 @@
[radio/radio (= name preferred-name)]]]))]]]])

(views/defview in-progress-registrations [registrations address]
(views/letsubs [transactions [:wallet/transactions address]]
[react/view {:style {:margin-top 8}}
;; Loop registrations to see if some of them were updated
(doseq [[hash {:keys [state username custom-domain?]}] registrations]
(when (or (= state :dismissed) (= state :submitted))
(doseq [[transaction-hash transaction] transactions]
(let [type (get transaction :type)
transaction-success (get transaction :transfer)]
(when (= hash transaction-hash)
; TODO Return from the loop once we find a match
(when (= transaction-success true)
(re-frame/dispatch [:update-ens-tx-state :success username custom-domain? hash])
(re-frame/dispatch [::status-im.ens.core/save-username custom-domain? username]))
(when (= type :failed)
(re-frame/dispatch [:update-ens-tx-state :failure username custom-domain? hash])))))))

(for [[hash {:keys [state username custom-domain?]}] registrations]
(when-not (= state :dismissed)
^{:key hash}
[list-item/list-item
{:title (let [progress-msg (str username (i18n/label :t/ens-registration-in-progress))]
(case state
:submitted progress-msg
:success (str username (i18n/label :t/ens-registration-complete))
:failure (str username (i18n/label :t/ens-registration-failure))
progress-msg))
:subtitle (i18n/label :t/ens-dismiss-message)
:on-press #(re-frame/dispatch (if (= state :submitted)
[:update-ens-tx-state :dismissed username custom-domain? hash]
[:clear-ens-registration hash]))
:icon (case state
:submitted :main-icons/change
:success :main-icons/check
:failure :main-icons/close
:main-icons/change)}]))]))
[react/view {:style {:margin-top 8}}
(for [[hash {:keys [state username custom-domain?]}] registrations]
(when-not (= state :dismissed)
^{:key hash}
[list-item/list-item
{:title (let [progress-msg (str username (i18n/label :t/ens-registration-in-progress))]
(case state
:submitted progress-msg
:success (str username (i18n/label :t/ens-registration-complete))
:failure (str username (i18n/label :t/ens-registration-failure))
progress-msg))
:subtitle (i18n/label :t/ens-dismiss-message)
:on-press #(re-frame/dispatch (if (= state :submitted)
[:update-ens-tx-state :dismissed username custom-domain? hash]
[:clear-ens-registration hash]))
:icon (case state
:submitted :main-icons/change
:success :main-icons/check
:failure :main-icons/close
:main-icons/change)}]))])

(views/defview registered [names {:keys [preferred-name public-key name] :as account} _ registrations address]
[react/view {:style {:flex 1}}
Expand Down

0 comments on commit 12f6428

Please sign in to comment.