Show ENS name only when confirmed
fix: only save the ENS username when the TX is confirmed feat: show when ens registration are in progress, done or errored feat: implement new design for the ENS registration Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
This commit is contained in:
parent
e743cbacd0
commit
08ff2edb0b
|
@ -22,6 +22,36 @@
|
||||||
username
|
username
|
||||||
(stateofus/subdomain username)))
|
(stateofus/subdomain username)))
|
||||||
|
|
||||||
|
(fx/defn update-ens-tx-state
|
||||||
|
{:events [:update-ens-tx-state]}
|
||||||
|
[{:keys [db]} new-state username custom-domain? tx-hash]
|
||||||
|
{:db (assoc-in db [:ens/registrations tx-hash] {:state new-state
|
||||||
|
: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]}
|
||||||
|
[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]}
|
||||||
|
[{:keys [db]} tx-hash]
|
||||||
|
{:db (update db :ens/registrations dissoc tx-hash)})
|
||||||
|
|
||||||
(re-frame/reg-fx
|
(re-frame/reg-fx
|
||||||
::resolve-address
|
::resolve-address
|
||||||
(fn [[registry name cb]]
|
(fn [[registry name cb]]
|
||||||
|
@ -62,19 +92,20 @@
|
||||||
{:contract resolver-contract
|
{:contract resolver-contract
|
||||||
:method "setPubkey(bytes32,bytes32,bytes32)"
|
:method "setPubkey(bytes32,bytes32,bytes32)"
|
||||||
:params [namehash x y]
|
:params [namehash x y]
|
||||||
:on-result [::save-username custom-domain? username]
|
:on-result [::save-username custom-domain? username true]
|
||||||
:on-error [::on-registration-failure]})))
|
:on-error [::on-registration-failure]})))
|
||||||
|
|
||||||
(fx/defn save-username
|
(fx/defn save-username
|
||||||
{:events [::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)
|
(let [name (fullname custom-domain? username)
|
||||||
names (get-in db [:multiaccount :usernames] [])
|
names (get-in db [:multiaccount :usernames] [])
|
||||||
new-names (conj names name)]
|
new-names (conj names name)]
|
||||||
(fx/merge cofx
|
(fx/merge cofx
|
||||||
(multiaccounts.update/multiaccount-update
|
(multiaccounts.update/multiaccount-update
|
||||||
:usernames new-names
|
:usernames new-names
|
||||||
{:on-success #(re-frame/dispatch [::username-saved])})
|
(when redirectToSummary
|
||||||
|
{:on-success #(re-frame/dispatch [::redirect-to-ens-summary])}))
|
||||||
(when (empty? names)
|
(when (empty? names)
|
||||||
(multiaccounts.update/multiaccount-update
|
(multiaccounts.update/multiaccount-update
|
||||||
:preferred-name name {})))))
|
:preferred-name name {})))))
|
||||||
|
@ -93,21 +124,10 @@
|
||||||
(ens/resolver registry-contract ens-name
|
(ens/resolver registry-contract ens-name
|
||||||
#(re-frame/dispatch [::resolver-found %]))
|
#(re-frame/dispatch [::resolver-found %]))
|
||||||
:connected
|
:connected
|
||||||
(save-username cofx custom-domain? username)
|
(save-username cofx custom-domain? username true)
|
||||||
;; for other states, we do nothing
|
;; for other states, we do nothing
|
||||||
nil)))
|
nil)))
|
||||||
|
|
||||||
(fx/defn username-saved
|
|
||||||
{:events [::username-saved]}
|
|
||||||
[{:keys [db] :as 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
|
(defn- on-resolve-owner
|
||||||
[registry custom-domain? username address public-key response resolve-last-id* resolve-last-id]
|
[registry custom-domain? username address public-key response resolve-last-id* resolve-last-id]
|
||||||
(when (= @resolve-last-id* resolve-last-id)
|
(when (= @resolve-last-id* resolve-last-id)
|
||||||
|
@ -157,7 +177,7 @@
|
||||||
(money/unit->token amount 18)
|
(money/unit->token amount 18)
|
||||||
(abi-spec/encode "register(bytes32,address,bytes32,bytes32)"
|
(abi-spec/encode "register(bytes32,address,bytes32,bytes32)"
|
||||||
[(ethereum/sha3 username) address x y])]
|
[(ethereum/sha3 username) address x y])]
|
||||||
:on-result [::save-username custom-domain? username]
|
:on-result [:update-ens-tx-state-and-redirect :submitted username custom-domain?]
|
||||||
:on-error [::on-registration-failure]})))
|
:on-error [::on-registration-failure]})))
|
||||||
|
|
||||||
(defn- valid-custom-domain? [username]
|
(defn- valid-custom-domain? [username]
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
[status-im.ethereum.eip55 :as eip55]
|
[status-im.ethereum.eip55 :as eip55]
|
||||||
[status-im.ethereum.encode :as encode]
|
[status-im.ethereum.encode :as encode]
|
||||||
[status-im.ethereum.json-rpc :as json-rpc]
|
[status-im.ethereum.json-rpc :as json-rpc]
|
||||||
|
[status-im.ens.core :as ens]
|
||||||
[status-im.utils.fx :as fx]
|
[status-im.utils.fx :as fx]
|
||||||
[status-im.wallet.core :as wallet]
|
[status-im.wallet.core :as wallet]
|
||||||
[taoensso.timbre :as log]
|
[taoensso.timbre :as log]
|
||||||
|
@ -205,8 +206,7 @@
|
||||||
[{:keys [db]} address]
|
[{:keys [db]} address]
|
||||||
{:db (assoc-in db [:wallet :fetching address :all-fetched?] true)})
|
{:db (assoc-in db [:wallet :fetching address :all-fetched?] true)})
|
||||||
|
|
||||||
(fx/defn new-transfers
|
(fx/defn handle-new-transfer
|
||||||
{:events [::new-transfers]}
|
|
||||||
[{:keys [db] :as cofx} transfers {:keys [address limit]}]
|
[{:keys [db] :as cofx} transfers {:keys [address limit]}]
|
||||||
(log/debug "[transfers] new-transfers"
|
(log/debug "[transfers] new-transfers"
|
||||||
"address" address
|
"address" address
|
||||||
|
@ -234,6 +234,38 @@
|
||||||
(conj (tx-history-end-reached checksum)))]
|
(conj (tx-history-end-reached checksum)))]
|
||||||
(apply fx/merge cofx (tx-fetching-ended [checksum]) effects)))
|
(apply fx/merge cofx (tx-fetching-ended [checksum]) effects)))
|
||||||
|
|
||||||
|
(fx/defn check-ens-transactions
|
||||||
|
[{: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))
|
||||||
|
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
|
||||||
|
(ens/clear-ens-registration hash)
|
||||||
|
(ens/save-username custom-domain? username false))
|
||||||
|
(= type :failed)
|
||||||
|
(ens/update-ens-tx-state :failure username custom-domain? hash)
|
||||||
|
:else
|
||||||
|
nil)))
|
||||||
|
registrations)]
|
||||||
|
(apply fx/merge cofx fxs)))
|
||||||
|
|
||||||
|
(fx/defn new-transfers
|
||||||
|
{:events [::new-transfers]}
|
||||||
|
[cofx transfers params]
|
||||||
|
(fx/merge cofx
|
||||||
|
(handle-new-transfer transfers params)
|
||||||
|
(check-ens-transactions transfers)))
|
||||||
|
|
||||||
(fx/defn tx-fetching-failed
|
(fx/defn tx-fetching-failed
|
||||||
{:events [::tx-fetching-failed]}
|
{:events [::tx-fetching-failed]}
|
||||||
[cofx error address]
|
[cofx error address]
|
||||||
|
|
|
@ -166,6 +166,7 @@
|
||||||
|
|
||||||
;;ens
|
;;ens
|
||||||
(reg-root-key-sub :ens/registration :ens/registration)
|
(reg-root-key-sub :ens/registration :ens/registration)
|
||||||
|
(reg-root-key-sub :ens/registrations :ens/registrations)
|
||||||
(reg-root-key-sub :ens/names :ens/names)
|
(reg-root-key-sub :ens/names :ens/names)
|
||||||
|
|
||||||
;;signing
|
;;signing
|
||||||
|
@ -2024,10 +2025,12 @@
|
||||||
:<- [:multiaccount/usernames]
|
:<- [:multiaccount/usernames]
|
||||||
:<- [:multiaccount]
|
:<- [:multiaccount]
|
||||||
:<- [:ens/preferred-name]
|
:<- [:ens/preferred-name]
|
||||||
(fn [[names multiaccount preferred-name]]
|
:<- [:ens/registrations]
|
||||||
{:names names
|
(fn [[names multiaccount preferred-name registrations]]
|
||||||
:multiaccount multiaccount
|
{:names names
|
||||||
:preferred-name preferred-name}))
|
:multiaccount multiaccount
|
||||||
|
:preferred-name preferred-name
|
||||||
|
:registrations registrations}))
|
||||||
|
|
||||||
;;SIGNING =============================================================================================================
|
;;SIGNING =============================================================================================================
|
||||||
|
|
||||||
|
|
|
@ -597,12 +597,14 @@
|
||||||
[button {:on-press #(re-frame/dispatch [::ens/get-started-pressed])
|
[button {:on-press #(re-frame/dispatch [::ens/get-started-pressed])
|
||||||
:label (i18n/label :t/get-started)}]]]))
|
: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)
|
(let [stateofus-username (stateofus/username name)
|
||||||
s (or stateofus-username name)]
|
s (or stateofus-username name)]
|
||||||
[list-item/list-item
|
[list-item/list-item
|
||||||
{:title s
|
{:title s
|
||||||
:subtitle (when stateofus-username stateofus/domain)
|
:subtitle (if subtitle
|
||||||
|
subtitle
|
||||||
|
(when stateofus-username stateofus/domain))
|
||||||
:on-press action
|
:on-press action
|
||||||
:icon :main-icons/username}]))
|
:icon :main-icons/username}]))
|
||||||
|
|
||||||
|
@ -627,12 +629,25 @@
|
||||||
[name-item {:name name :hide-chevron? true :action action}]]
|
[name-item {:name name :hide-chevron? true :action action}]]
|
||||||
[radio/radio (= name preferred-name)]]]))]]]])
|
[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/defview my-name []
|
||||||
(views/letsubs [contact-name [:multiaccount/preferred-name]]
|
(views/letsubs [contact-name [:multiaccount/preferred-name]]
|
||||||
(when-not (string/blank? contact-name)
|
(when-not (string/blank? contact-name)
|
||||||
(chat.utils/format-author (str "@" contact-name) message.style/message-author-name-container))))
|
(chat.utils/format-author (str "@" 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/view {:style {:flex 1}}
|
||||||
[react/scroll-view
|
[react/scroll-view
|
||||||
[react/view {:style {:margin-top 8}}
|
[react/view {:style {:margin-top 8}}
|
||||||
|
@ -644,12 +659,15 @@
|
||||||
[react/view {:style {:margin-top 22 :margin-bottom 8}}
|
[react/view {:style {:margin-top 22 :margin-bottom 8}}
|
||||||
[react/text {:style {:color colors/gray :margin-horizontal 16}}
|
[react/text {:style {:color colors/gray :margin-horizontal 16}}
|
||||||
(i18n/label :t/ens-your-usernames)]
|
(i18n/label :t/ens-your-usernames)]
|
||||||
|
(when registrations
|
||||||
|
[in-progress-registrations registrations])
|
||||||
(if (seq names)
|
(if (seq names)
|
||||||
[react/view {:style {:margin-top 8}}
|
[react/view {:style {:margin-top 8}}
|
||||||
(for [name names]
|
(for [name names]
|
||||||
^{:key name}
|
^{:key name}
|
||||||
[name-item {:name name :action #(re-frame/dispatch [::ens/navigate-to-name name])}])]
|
[name-item {:name name :action #(re-frame/dispatch [::ens/navigate-to-name name])}])]
|
||||||
[react/text {:style {:color colors/gray :font-size 15}}
|
[react/text {:style {:color colors/gray :font-size 15
|
||||||
|
:margin-horizontal 16}}
|
||||||
(i18n/label :t/ens-no-usernames)])]
|
(i18n/label :t/ens-no-usernames)])]
|
||||||
[react/view {:style {:padding-vertical 22 :border-color colors/gray-lighter :border-top-width 1}}
|
[react/view {:style {:padding-vertical 22 :border-color colors/gray-lighter :border-top-width 1}}
|
||||||
(when (> (count names) 1)
|
(when (> (count names) 1)
|
||||||
|
@ -678,9 +696,9 @@
|
||||||
[message/text-message message]]])]])
|
[message/text-message message]]])]])
|
||||||
|
|
||||||
(views/defview main []
|
(views/defview main []
|
||||||
(views/letsubs [{:keys [names multiaccount show?]} [:ens.main/screen]]
|
(views/letsubs [{:keys [names multiaccount show? registrations]} [:ens.main/screen]]
|
||||||
[react/keyboard-avoiding-view {:style {:flex 1}}
|
[react/keyboard-avoiding-view {:style {:flex 1}}
|
||||||
[topbar/topbar {:title :t/ens-usernames}]
|
[topbar/topbar {:title :t/ens-usernames}]
|
||||||
(if (seq names)
|
(if (or (seq names) registrations)
|
||||||
[registered names multiaccount show?]
|
[registered names multiaccount show? registrations]
|
||||||
[welcome])]))
|
[welcome])]))
|
||||||
|
|
|
@ -349,6 +349,9 @@
|
||||||
"ens-powered-by": "Powered by Ethereum Name Services",
|
"ens-powered-by": "Powered by Ethereum Name Services",
|
||||||
"ens-primary-username": "Primary username",
|
"ens-primary-username": "Primary username",
|
||||||
"ens-register": "Register",
|
"ens-register": "Register",
|
||||||
|
"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": "To register the username, please try again.",
|
||||||
"ens-registration-failed-title": "Transaction failed",
|
"ens-registration-failed-title": "Transaction failed",
|
||||||
"ens-release-username": "Release username",
|
"ens-release-username": "Release username",
|
||||||
|
|
Loading…
Reference in New Issue