mirror of
https://github.com/status-im/status-mobile.git
synced 2025-02-10 07:36:46 +00:00
[fix 8796] big number error when adding owned ens name
fix #8796 Signed-off-by: yenda <eric@status.im>
This commit is contained in:
parent
697c767a8b
commit
f14fd19f2c
@ -30,8 +30,12 @@
|
|||||||
(fn [[registry name cb]]
|
(fn [[registry name cb]]
|
||||||
(resolver/pubkey registry name cb)))
|
(resolver/pubkey registry name cb)))
|
||||||
|
|
||||||
|
(defn- final-state? [state]
|
||||||
|
(#{:saved :registered :registration-failed} state))
|
||||||
|
|
||||||
(defn assoc-state-for [db username state]
|
(defn assoc-state-for [db username state]
|
||||||
(assoc-in db [:ens/registration :states username] state))
|
(cond-> (assoc-in db [:ens/registration :states username] state)
|
||||||
|
(final-state? state) (update :ens/registration dissoc :registering?)))
|
||||||
|
|
||||||
(defn assoc-details-for [db username k v]
|
(defn assoc-details-for [db username k v]
|
||||||
(assoc-in db [:ens/names :details username k] v))
|
(assoc-in db [:ens/names :details username k] v))
|
||||||
@ -122,36 +126,28 @@
|
|||||||
(fx/defn save-preferred-name
|
(fx/defn save-preferred-name
|
||||||
{:events [:ens/save-preferred-name]}
|
{:events [:ens/save-preferred-name]}
|
||||||
[{:keys [db] :as cofx} name]
|
[{:keys [db] :as cofx} name]
|
||||||
(fx/merge (assoc-in cofx [:db :multiaccount :preferred-name] name)
|
|
||||||
(multiaccounts.update/multiaccount-update cofx
|
(multiaccounts.update/multiaccount-update cofx
|
||||||
{:preferred-name name})
|
{:preferred-name name}
|
||||||
(multiaccounts.update/send-multiaccount-update)))
|
{}))
|
||||||
|
|
||||||
(fx/defn save-preferred-name-when-first
|
|
||||||
[cofx names name]
|
|
||||||
(when (= 1 (count names))
|
|
||||||
;; First name, save it as default
|
|
||||||
(save-preferred-name cofx name)))
|
|
||||||
|
|
||||||
(fx/defn save-username
|
(fx/defn save-username
|
||||||
{:events [:ens/save-username]}
|
{:events [:ens/save-username]}
|
||||||
[{:keys [db] :as cofx} custom-domain? username]
|
[{:keys [db] :as cofx} custom-domain? username]
|
||||||
(let [name (fullname custom-domain? username)
|
(let [name (fullname custom-domain? username)
|
||||||
new-db (update-in db [:multiaccount :usernames] #((fnil conj []) %1 %2) name)
|
names (get-in db [:multiaccount :usernames] [])
|
||||||
names (get-in new-db [:multiaccount :usernames])]
|
new-names (conj names name)]
|
||||||
(fx/merge {:db new-db}
|
|
||||||
(multiaccounts.update/multiaccount-update cofx
|
(multiaccounts.update/multiaccount-update cofx
|
||||||
{:usernames names}
|
(cond-> {:usernames new-names}
|
||||||
{:success-event [:ens/set-state username :saved]})
|
(empty? names) (assoc :preferred-name name))
|
||||||
(save-preferred-name-when-first names name))))
|
{:on-success #(re-frame/dispatch [:ens/set-state username :saved])})))
|
||||||
|
|
||||||
(fx/defn switch-show-username
|
(fx/defn switch-show-username
|
||||||
{:events [:ens/switch-show-username]}
|
{:events [:ens/switch-show-username]}
|
||||||
[{:keys [db] :as cofx} _]
|
[{:keys [db] :as cofx} _]
|
||||||
(let [new-db (update-in db [:multiaccount :show-name?] not)]
|
(let [show-name? (not (get-in db [:multiaccount :show-name?]))]
|
||||||
(fx/merge {:db new-db}
|
|
||||||
(multiaccounts.update/multiaccount-update cofx
|
(multiaccounts.update/multiaccount-update cofx
|
||||||
{:show-name? (get-in new-db [:multiaccount :show-name?])}))))
|
{:show-name? show-name?}
|
||||||
|
{})))
|
||||||
|
|
||||||
(fx/defn on-registration-failure
|
(fx/defn on-registration-failure
|
||||||
{:events [:ens/on-registration-failure]}
|
{:events [:ens/on-registration-failure]}
|
||||||
@ -171,3 +167,10 @@
|
|||||||
{:ens/resolve-address [registry name #(re-frame/dispatch [:ens/store-name-detail name :address %])]
|
{:ens/resolve-address [registry name #(re-frame/dispatch [:ens/store-name-detail name :address %])]
|
||||||
:ens/resolve-pubkey [registry name #(re-frame/dispatch [:ens/store-name-detail name :public-key %])]}
|
:ens/resolve-pubkey [registry name #(re-frame/dispatch [:ens/store-name-detail name :public-key %])]}
|
||||||
(navigation/navigate-to-cofx :ens-name-details name))))
|
(navigation/navigate-to-cofx :ens-name-details name))))
|
||||||
|
|
||||||
|
(fx/defn start-registration
|
||||||
|
{:events [::add-username-pressed ::get-started-pressed]}
|
||||||
|
[{:keys [db] :as cofx}]
|
||||||
|
(fx/merge cofx
|
||||||
|
{:db (assoc-in db [:ens/registration :registering?] true)}
|
||||||
|
(navigation/navigate-to-cofx :ens-register {})))
|
||||||
|
@ -52,8 +52,8 @@
|
|||||||
[{:method "settings_saveConfig"
|
[{:method "settings_saveConfig"
|
||||||
:params ["multiaccount" (types/serialize new-multiaccount)]
|
:params ["multiaccount" (types/serialize new-multiaccount)]
|
||||||
:on-success on-success}]}
|
:on-success on-success}]}
|
||||||
{:keys [name photo-path]} new-multiaccount-fields]
|
{:keys [name photo-path prefered-name]} new-multiaccount-fields]
|
||||||
(if (or name photo-path)
|
(if (or name photo-path prefered-name)
|
||||||
(fx/merge cofx
|
(fx/merge cofx
|
||||||
fx
|
fx
|
||||||
(send-multiaccount-update))
|
(send-multiaccount-update))
|
||||||
|
@ -1807,8 +1807,9 @@
|
|||||||
:<- [:ens/registration]
|
:<- [:ens/registration]
|
||||||
:<- [:ens.stateofus/registrar]
|
:<- [:ens.stateofus/registrar]
|
||||||
:<- [:multiaccount]
|
:<- [:multiaccount]
|
||||||
(fn [[{:keys [custom-domain? username-candidate] :as ens} registrar {:keys [accounts public-key]}] _]
|
(fn [[{:keys [custom-domain? username-candidate registering?] :as ens} registrar {:keys [accounts public-key]}]]
|
||||||
{:state (or (get-in ens [:states username-candidate]) :initial)
|
{:state (get-in ens [:states username-candidate])
|
||||||
|
:registering? registering?
|
||||||
:username username-candidate
|
:username username-candidate
|
||||||
:custom-domain? (or custom-domain? false)
|
:custom-domain? (or custom-domain? false)
|
||||||
:contract registrar
|
:contract registrar
|
||||||
@ -1819,7 +1820,7 @@
|
|||||||
:ens.name/screen
|
:ens.name/screen
|
||||||
:<- [:get-screen-params :ens-name-details]
|
:<- [:get-screen-params :ens-name-details]
|
||||||
:<- [:ens/names]
|
:<- [:ens/names]
|
||||||
(fn [[name ens] _]
|
(fn [[name ens]]
|
||||||
(let [{:keys [address public-key]} (get-in ens [:details name])]
|
(let [{:keys [address public-key]} (get-in ens [:details name])]
|
||||||
{:name name
|
{:name name
|
||||||
:address address
|
:address address
|
||||||
@ -1831,7 +1832,7 @@
|
|||||||
:<- [:multiaccount]
|
:<- [:multiaccount]
|
||||||
:<- [:ens/preferred-name]
|
:<- [:ens/preferred-name]
|
||||||
:<- [:ens/show?]
|
:<- [:ens/show?]
|
||||||
(fn [[names multiaccount preferred-name show?] _]
|
(fn [[names multiaccount preferred-name show?]]
|
||||||
{:names names
|
{:names names
|
||||||
:multiaccount multiaccount
|
:multiaccount multiaccount
|
||||||
:preferred-name preferred-name
|
:preferred-name preferred-name
|
||||||
|
@ -132,7 +132,6 @@
|
|||||||
:text-color colors/gray
|
:text-color colors/gray
|
||||||
:text-style {:font-weight "500"}
|
:text-style {:font-weight "500"}
|
||||||
:subtext (i18n/label :t/ens-locked)
|
:subtext (i18n/label :t/ens-locked)
|
||||||
:action-fn #(re-frame/dispatch [:navigate-to :ens-register])
|
|
||||||
:icon :main-icons/delete
|
:icon :main-icons/delete
|
||||||
:icon-color colors/gray
|
:icon-color colors/gray
|
||||||
:active? false
|
:active? false
|
||||||
@ -193,9 +192,6 @@
|
|||||||
(defn- valid-domain? [state]
|
(defn- valid-domain? [state]
|
||||||
(#{:registrable :owned :connected} state))
|
(#{:registrable :owned :connected} state))
|
||||||
|
|
||||||
(defn- final-state? [state]
|
|
||||||
(#{:saved :registered :registration-failed} state))
|
|
||||||
|
|
||||||
(defn- main-icon [state]
|
(defn- main-icon [state]
|
||||||
(cond
|
(cond
|
||||||
(valid-domain? state) :main-icons/check
|
(valid-domain? state) :main-icons/check
|
||||||
@ -433,15 +429,20 @@
|
|||||||
[toolbar/content-title (i18n/label :t/ens-your-username)]])
|
[toolbar/content-title (i18n/label :t/ens-your-username)]])
|
||||||
|
|
||||||
(views/defview register []
|
(views/defview register []
|
||||||
(views/letsubs [{:keys [address state] :as props} [:ens.registration/screen]]
|
(views/letsubs [{:keys [address state registering?] :as props} [:ens.registration/screen]]
|
||||||
(let [checked (reagent/atom false)
|
(let [checked (reagent/atom false)
|
||||||
props (merge props {:checked checked :address (ethereum/normalized-address address)})]
|
props (merge props {:checked checked :address (ethereum/normalized-address address)})]
|
||||||
[react/keyboard-avoiding-view {:flex 1}
|
[react/keyboard-avoiding-view {:flex 1}
|
||||||
[status-bar/status-bar {:type :main}]
|
[status-bar/status-bar {:type :main}]
|
||||||
[toolbar]
|
[toolbar]
|
||||||
(if (final-state? state)
|
;; NOTE: this view is used both for finalized and pending registration
|
||||||
[registration-finalized props]
|
;; and when the registration data is cleared for a brief moment state
|
||||||
[registration-pending props])])))
|
;; is nil and registration-pending show which triggers the keyboard
|
||||||
|
;; and it's ugly
|
||||||
|
;; TODO: something less crazy with proper separated views and routes
|
||||||
|
(if registering?
|
||||||
|
[registration-pending props]
|
||||||
|
[registration-finalized props])])))
|
||||||
|
|
||||||
;; Welcome
|
;; Welcome
|
||||||
|
|
||||||
@ -487,7 +488,7 @@
|
|||||||
[react/view {:align-items :center :background-color colors/white
|
[react/view {:align-items :center :background-color colors/white
|
||||||
:position :absolute :left 0 :right 0 :bottom 0
|
:position :absolute :left 0 :right 0 :bottom 0
|
||||||
:border-top-width 1 :border-top-color colors/gray-lighter}
|
:border-top-width 1 :border-top-color colors/gray-lighter}
|
||||||
[button {:on-press #(re-frame/dispatch [:navigate-to :ens-register])
|
[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 hide-chevron?]}]
|
(defn- name-item [{:keys [name action hide-chevron?]}]
|
||||||
@ -525,7 +526,7 @@
|
|||||||
[react/scroll-view
|
[react/scroll-view
|
||||||
[react/view {:style {:margin-top 8}}
|
[react/view {:style {:margin-top 8}}
|
||||||
[list/big-list-item {:text (i18n/label :t/ens-add-username)
|
[list/big-list-item {:text (i18n/label :t/ens-add-username)
|
||||||
:action-fn #(re-frame/dispatch [:navigate-to :ens-register])
|
:action-fn #(re-frame/dispatch [::ens/add-username-pressed])
|
||||||
:icon :main-icons/add}]]
|
:icon :main-icons/add}]]
|
||||||
[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}}
|
||||||
@ -558,7 +559,7 @@
|
|||||||
|
|
||||||
(views/defview main []
|
(views/defview main []
|
||||||
(views/letsubs [{:keys [names multiaccount preferred-name show?]} [:ens.main/screen]]
|
(views/letsubs [{:keys [names multiaccount preferred-name show?]} [:ens.main/screen]]
|
||||||
[react/view {:style {:flex 1}}
|
[react/keyboard-avoiding-view {:style {:flex 1}}
|
||||||
[status-bar/status-bar {:type :main}]
|
[status-bar/status-bar {:type :main}]
|
||||||
[toolbar/simple-toolbar
|
[toolbar/simple-toolbar
|
||||||
(i18n/label :t/ens-usernames)]
|
(i18n/label :t/ens-usernames)]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user