From 7eb22458ca9699ea99cfb73714e3112f5de216f9 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Tue, 2 Jun 2020 11:33:56 -0400 Subject: [PATCH] feat: implement new design for the ENS registration --- src/status_im/ens/core.cljs | 40 ++++++++++--------- src/status_im/ethereum/transactions/core.cljs | 23 +++++------ src/status_im/ui/screens/ens/views.cljs | 30 ++++++++++---- translations/en.json | 5 +-- 4 files changed, 56 insertions(+), 42 deletions(-) diff --git a/src/status_im/ens/core.cljs b/src/status_im/ens/core.cljs index 3be69afaa4cd..21d2485454bf 100644 --- a/src/status_im/ens/core.cljs +++ b/src/status_im/ens/core.cljs @@ -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] @@ -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? @@ -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]} @@ -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 {}))))) @@ -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) diff --git a/src/status_im/ethereum/transactions/core.cljs b/src/status_im/ethereum/transactions/core.cljs index 01e1cb16e532..42740389cd2e 100644 --- a/src/status_im/ethereum/transactions/core.cljs +++ b/src/status_im/ethereum/transactions/core.cljs @@ -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 @@ -238,11 +238,11 @@ [{: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) @@ -250,21 +250,20 @@ (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 diff --git a/src/status_im/ui/screens/ens/views.cljs b/src/status_im/ui/screens/ens/views.cljs index 4e3bc7034232..a2306fc82cfc 100644 --- a/src/status_im/ui/screens/ens/views.cljs +++ b/src/status_im/ui/screens/ens/views.cljs @@ -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}])) @@ -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) @@ -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] @@ -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])])) diff --git a/translations/en.json b/translations/en.json index 2ae4da713d9a..357101470908 100644 --- a/translations/en.json +++ b/translations/en.json @@ -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",