Skip to content

Commit

Permalink
feat: implement new design for the ENS registration
Browse files Browse the repository at this point in the history
  • Loading branch information
jrainville committed Jun 2, 2020
1 parent e4f5f22 commit 7eb2245
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 42 deletions.
40 changes: 21 additions & 19 deletions src/status_im/ens/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
(:refer-clojure :exclude [name])
(:require [clojure.string :as string]
[re-frame.core :as re-frame]
[status-im.utils.handlers :as handlers]
[status-im.ethereum.abi-spec :as abi-spec]
[status-im.ethereum.contracts :as contracts]
[status-im.ethereum.core :as ethereum]
Expand All @@ -17,7 +16,6 @@
[status-im.utils.fx :as fx]
[status-im.utils.money :as money]
[status-im.utils.random :as random]))
[status-im.utils.types]

(defn fullname [custom-domain? username]
(if custom-domain?
Expand All @@ -31,11 +29,23 @@
:username username
:custom-domain? custom-domain?})})

(fx/defn redirect-to-ens-summary
{:events [::redirect-to-ens-summary]}
[cofx]
;; we reset navigation so that navigate back doesn't return
;; into the registration flow
(navigation/navigate-reset cofx
{:index 1
:key :profile-stack
:routes [{:name :my-profile}
{:name :ens-confirmation}]}))

(fx/defn update-ens-tx-state-and-redirect
{:events [:update-ens-tx-state-and-redirect]}
[_ new-state username custom-domain? tx-hash]
{:dispatch-n [[:update-ens-tx-state new-state username custom-domain? tx-hash]
[::redirect-to-ens-summary]]})
[cofx new-state username custom-domain? tx-hash]
(fx/merge cofx
(update-ens-tx-state new-state username custom-domain? tx-hash)
(redirect-to-ens-summary)))

(fx/defn clear-ens-registration
{:events [:clear-ens-registration]}
Expand Down Expand Up @@ -82,19 +92,20 @@
{:contract resolver-contract
:method "setPubkey(bytes32,bytes32,bytes32)"
:params [namehash x y]
:on-result [::save-username custom-domain? username]
:on-result [::save-username custom-domain? username true]
:on-error [::on-registration-failure]})))

(fx/defn save-username
{:events [::save-username]}
[{:keys [db] :as cofx} custom-domain? username]
[{:keys [db] :as cofx} custom-domain? username redirectToSummary]
(let [name (fullname custom-domain? username)
names (get-in db [:multiaccount :usernames] [])
new-names (conj names name)]
(fx/merge cofx
(multiaccounts.update/multiaccount-update
:usernames new-names
{})
(when redirectToSummary
{:on-success #(re-frame/dispatch [::redirect-to-ens-summary])}))
(when (empty? names)
(multiaccounts.update/multiaccount-update
:preferred-name name {})))))
Expand All @@ -112,20 +123,11 @@
:connected-with-different-key
(ens/resolver registry-contract ens-name
#(re-frame/dispatch [::resolver-found %]))
:connected
(save-username cofx custom-domain? username true)
;; for other states, we do nothing
nil)))

(fx/defn redirect-to-ens-summary
{:events [::redirect-to-ens-summary]}
[cofx]
;; we reset navigation so that navigate back doesn't return
;; into the registration flow
(navigation/navigate-reset cofx
{:index 1
:key :profile-stack
:routes [{:name :my-profile}
{:name :ens-confirmation}]}))

(defn- on-resolve-owner
[registry custom-domain? username address public-key response resolve-last-id* resolve-last-id]
(when (= @resolve-last-id* resolve-last-id)
Expand Down
23 changes: 11 additions & 12 deletions src/status_im/ethereum/transactions/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@
[{:keys [db]} address]
{:db (assoc-in db [:wallet :fetching address :all-fetched?] true)})

(fx/defn handle-mew-transfer
(fx/defn handle-new-transfer
[{:keys [db] :as cofx} transfers {:keys [address limit]}]
(log/debug "[transfers] new-transfers"
"address" address
Expand Down Expand Up @@ -238,33 +238,32 @@
[{:keys [db] :as cofx} transfers]
(let [set-of-transactions-hash (reduce (fn [acc {:keys [hash]}] (conj acc hash)) #{} transfers)
registrations (filter
(fn [[hash {:keys [state]}]]
(and
(or (= state :dismissed) (= state :submitted))
(contains? set-of-transactions-hash hash)))
(get db :ens/registrations))
(fn [[hash {:keys [state]}]]
(and
(or (= state :dismissed) (= state :submitted))
(contains? set-of-transactions-hash hash)))
(get db :ens/registrations))
fxs (map (fn [[hash {:keys [username custom-domain?]}]]
(let [transfer (first (filter (fn [transfer] (let [transfer-hash (get transfer :hash)] (= transfer-hash hash))) transfers))
type (get transfer :type)
transaction-success (get transfer :transfer)]
(cond
(= transaction-success true)
(fx/merge cofx
(status-im.ens.core/update-ens-tx-state :success username custom-domain? hash)
(status-im.ens.core/save-username custom-domain? username))
(ens/clear-ens-registration hash)
(ens/save-username custom-domain? username false))
(= type :failed)
(status-im.ens.core/update-ens-tx-state :failure username custom-domain? hash)
(ens/update-ens-tx-state :failure username custom-domain? hash)
:else
nil)))
registrations)
]
registrations)]
(apply fx/merge cofx fxs)))

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

(fx/defn tx-fetching-failed
Expand Down
30 changes: 22 additions & 8 deletions src/status_im/ui/screens/ens/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -596,12 +596,14 @@
[button {:on-press #(re-frame/dispatch [::ens/get-started-pressed])
:label (i18n/label :t/get-started)}]]]))

(defn- name-item [{:keys [name action]}]
(defn- name-item [{:keys [name action subtitle]}]
(let [stateofus-username (stateofus/username name)
s (or stateofus-username name)]
[list-item/list-item
{:title s
:subtitle (when stateofus-username stateofus/domain)
:subtitle (if subtitle
subtitle
(when stateofus-username stateofus/domain))
:on-press action
:icon :main-icons/username}]))

Expand All @@ -626,15 +628,26 @@
[name-item {:name name :hide-chevron? true :action action}]]
[radio/radio (= name preferred-name)]]]))]]]])

(views/defview in-progress-registrations [registrations]
[react/view {:style {:margin-top 8}}
(for [[hash {:keys [state username]}] registrations
:when (or (= state :submitted) (= state :failure))]
^{:key hash}
[name-item {:name username
:action (when-not (= state :submitted)
#(re-frame/dispatch [:clear-ens-registration hash]))
:subtitle (case state
:submitted (i18n/label :t/ens-registration-in-progress)
:failure (i18n/label :t/ens-registration-failure)
nil)}])])

(views/defview my-name []
(views/letsubs [contact-name [:multiaccount/my-name]]
(chat.utils/format-author contact-name message.style/message-author-name-container)))

(defn- registered [names {:keys [preferred-name] :as account} _]
(views/defview registered [names {:keys [preferred-name] :as account} _ registrations]
[react/view {:style {:flex 1}}
[react/scroll-view
(when registrations
[in-progress-registrations registrations address])
[react/view {:style {:margin-top 8}}
[list-item/list-item
{:title (i18n/label :t/ens-add-username)
Expand All @@ -644,6 +657,8 @@
[react/view {:style {:margin-top 22 :margin-bottom 8}}
[react/text {:style {:color colors/gray :margin-horizontal 16}}
(i18n/label :t/ens-your-usernames)]
(when registrations
[in-progress-registrations registrations])
(if (seq names)
[react/view {:style {:margin-top 8}}
(for [name names]
Expand Down Expand Up @@ -679,10 +694,9 @@
[message/text-message message]]])]])

(views/defview main []
(views/letsubs [{:keys [names multiaccount show? registrations]} [:ens.main/screen]
{:keys [address]} [:multiaccount/current-account]]
(views/letsubs [{:keys [names multiaccount show? registrations]} [:ens.main/screen]]
[react/keyboard-avoiding-view {:style {:flex 1}}
[topbar/topbar {:title :t/ens-usernames}]
(if (or (seq names) registrations)
[registered names multiaccount show? registrations address]
[registered names multiaccount show? registrations]
[welcome])]))
5 changes: 2 additions & 3 deletions translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -349,9 +349,8 @@
"ens-powered-by": "Powered by Ethereum Name Services",
"ens-primary-username": "Primary username",
"ens-register": "Register",
"ens-registration-in-progress": ": Registration in progress",
"ens-registration-complete": ": Registration complete",
"ens-registration-failure": ": Registration failed",
"ens-registration-in-progress": "Registration in progress...",
"ens-registration-failure": "Registration failed",
"ens-dismiss-message": "Click here to dismiss",
"ens-registration-failed": "To register the username, please try again.",
"ens-registration-failed-title": "Transaction failed",
Expand Down

0 comments on commit 7eb2245

Please sign in to comment.