[fix 8796] big number error when adding owned ens name

fix #8796

Signed-off-by: yenda <eric@status.im>
This commit is contained in:
yenda 2019-08-22 11:41:20 +02:00
parent 697c767a8b
commit f14fd19f2c
No known key found for this signature in database
GPG Key ID: 0095623C0069DCE6
4 changed files with 44 additions and 39 deletions

View File

@ -30,8 +30,12 @@
(fn [[registry name cb]]
(resolver/pubkey registry name cb)))
(defn- final-state? [state]
(#{:saved :registered :registration-failed} 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]
(assoc-in db [:ens/names :details username k] v))
@ -122,36 +126,28 @@
(fx/defn save-preferred-name
{:events [:ens/save-preferred-name]}
[{:keys [db] :as cofx} name]
(fx/merge (assoc-in cofx [:db :multiaccount :preferred-name] name)
(multiaccounts.update/multiaccount-update cofx
{: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)))
{:preferred-name name}
{}))
(fx/defn save-username
{:events [:ens/save-username]}
[{:keys [db] :as cofx} custom-domain? username]
(let [name (fullname custom-domain? username)
new-db (update-in db [:multiaccount :usernames] #((fnil conj []) %1 %2) name)
names (get-in new-db [:multiaccount :usernames])]
(fx/merge {:db new-db}
names (get-in db [:multiaccount :usernames] [])
new-names (conj names name)]
(multiaccounts.update/multiaccount-update cofx
{:usernames names}
{:success-event [:ens/set-state username :saved]})
(save-preferred-name-when-first names name))))
(cond-> {:usernames new-names}
(empty? names) (assoc :preferred-name name))
{:on-success #(re-frame/dispatch [:ens/set-state username :saved])})))
(fx/defn switch-show-username
{:events [:ens/switch-show-username]}
[{:keys [db] :as cofx} _]
(let [new-db (update-in db [:multiaccount :show-name?] not)]
(fx/merge {:db new-db}
(let [show-name? (not (get-in db [:multiaccount :show-name?]))]
(multiaccounts.update/multiaccount-update cofx
{:show-name? (get-in new-db [:multiaccount :show-name?])}))))
{:show-name? show-name?}
{})))
(fx/defn 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-pubkey [registry name #(re-frame/dispatch [:ens/store-name-detail name :public-key %])]}
(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 {})))

View File

@ -52,8 +52,8 @@
[{:method "settings_saveConfig"
:params ["multiaccount" (types/serialize new-multiaccount)]
:on-success on-success}]}
{:keys [name photo-path]} new-multiaccount-fields]
(if (or name photo-path)
{:keys [name photo-path prefered-name]} new-multiaccount-fields]
(if (or name photo-path prefered-name)
(fx/merge cofx
fx
(send-multiaccount-update))

View File

@ -1807,8 +1807,9 @@
:<- [:ens/registration]
:<- [:ens.stateofus/registrar]
:<- [:multiaccount]
(fn [[{:keys [custom-domain? username-candidate] :as ens} registrar {:keys [accounts public-key]}] _]
{:state (or (get-in ens [:states username-candidate]) :initial)
(fn [[{:keys [custom-domain? username-candidate registering?] :as ens} registrar {:keys [accounts public-key]}]]
{:state (get-in ens [:states username-candidate])
:registering? registering?
:username username-candidate
:custom-domain? (or custom-domain? false)
:contract registrar
@ -1819,7 +1820,7 @@
:ens.name/screen
:<- [:get-screen-params :ens-name-details]
:<- [:ens/names]
(fn [[name ens] _]
(fn [[name ens]]
(let [{:keys [address public-key]} (get-in ens [:details name])]
{:name name
:address address
@ -1831,7 +1832,7 @@
:<- [:multiaccount]
:<- [:ens/preferred-name]
:<- [:ens/show?]
(fn [[names multiaccount preferred-name show?] _]
(fn [[names multiaccount preferred-name show?]]
{:names names
:multiaccount multiaccount
:preferred-name preferred-name

View File

@ -132,7 +132,6 @@
:text-color colors/gray
:text-style {:font-weight "500"}
:subtext (i18n/label :t/ens-locked)
:action-fn #(re-frame/dispatch [:navigate-to :ens-register])
:icon :main-icons/delete
:icon-color colors/gray
:active? false
@ -193,9 +192,6 @@
(defn- valid-domain? [state]
(#{:registrable :owned :connected} state))
(defn- final-state? [state]
(#{:saved :registered :registration-failed} state))
(defn- main-icon [state]
(cond
(valid-domain? state) :main-icons/check
@ -433,15 +429,20 @@
[toolbar/content-title (i18n/label :t/ens-your-username)]])
(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)
props (merge props {:checked checked :address (ethereum/normalized-address address)})]
[react/keyboard-avoiding-view {:flex 1}
[status-bar/status-bar {:type :main}]
[toolbar]
(if (final-state? state)
[registration-finalized props]
[registration-pending props])])))
;; NOTE: this view is used both for finalized and pending registration
;; and when the registration data is cleared for a brief moment state
;; 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
@ -487,7 +488,7 @@
[react/view {:align-items :center :background-color colors/white
:position :absolute :left 0 :right 0 :bottom 0
: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)}]]])
(defn- name-item [{:keys [name action hide-chevron?]}]
@ -525,7 +526,7 @@
[react/scroll-view
[react/view {:style {:margin-top 8}}
[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}]]
[react/view {:style {:margin-top 22 :margin-bottom 8}}
[react/text {:style {:color colors/gray :margin-horizontal 16}}
@ -558,7 +559,7 @@
(views/defview main []
(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}]
[toolbar/simple-toolbar
(i18n/label :t/ens-usernames)]