[#11263] Entering "0x" in the Recipient throws an error

[#11262] Wallet "Done" and "Add to favorites" only appears when the input box is focused

Signed-off-by: andrey <motor4ik@gmail.com>
This commit is contained in:
andrey 2020-10-05 12:50:41 +02:00
parent 2e7c377343
commit b198084b78
No known key found for this signature in database
GPG Key ID: 89B67245FD2F0272
3 changed files with 27 additions and 60 deletions

View File

@ -89,7 +89,6 @@
:subtitle second-name
:on-press #(do
(some-> ^js @scroll-view-ref (.scrollTo #js {:x 0 :animated true}))
(re-frame/dispatch [:wallet.recipient/focus-input])
(re-frame/dispatch [:wallet.recipient/address-changed name]))
:icon [chat-icon/contact-icon-contacts-tab
(multiaccounts/displayed-photo contact)]}]))
@ -119,9 +118,7 @@
[quo/list-item
{:title [quo/text {:monospace true}
(utils/get-shortened-checksum-address address)]
:on-press #(do
(re-frame/dispatch [:wallet.recipient/focus-input])
(re-frame/dispatch [:wallet.recipient/address-changed address]))
:on-press #(re-frame/dispatch [:wallet.recipient/address-changed address])
:size :small
:accessory [react/text {:style {:flex-shrink 1
:color colors/gray}}
@ -248,9 +245,8 @@
(i18n/label :t/add)]}]]]))
(views/defview recipient []
(views/letsubs [{:keys [address resolved-address searching] :as recip} [:wallet/recipient]
search-filter [:search/recipient-filter]
input-focused? (reagent/atom false)]
(views/letsubs [{:keys [address resolved-address searching]} [:wallet/recipient]
search-filter [:search/recipient-filter]]
(let [disabled? (or searching (not resolved-address))]
[kb-presentation/keyboard-avoiding-view {:style {:flex 1}}
[react/view {:flex 1}
@ -270,10 +266,6 @@
(i18n/label :t/paste)]]
[quo/text-input
{:multiline true
:get-ref #(when (and recip %)
(re-frame/dispatch [:set-in [:wallet/recipient :inp-ref] %]))
:on-focus #(reset! input-focused? true)
:on-blur #(reset! input-focused? false)
:default-value address
:height 70
:placeholder (i18n/label :t/recipient-code-placeholder)
@ -297,21 +289,20 @@
:color :inherit}
(utils/get-shortened-address resolved-address)]]))]
[accordion search-filter]]]
(when @input-focused?
[toolbar/toolbar
{:show-border? true
:left
[quo/button
{:accessibility-label :participant-add-to-favs
:type :secondary
:disabled disabled?
:on-press #(re-frame/dispatch [:navigate-to :new-favourite])}
(i18n/label :t/add-to-favourites)]
:right
[quo/button
{:accessibility-label :participant-done
:type :secondary
:after :main-icons/next
:disabled disabled?
:on-press #(re-frame/dispatch [:wallet.send/set-recipient resolved-address])}
(i18n/label :t/done)]}])]])))
[toolbar/toolbar
{:show-border? true
:left
[quo/button
{:accessibility-label :participant-add-to-favs
:type :secondary
:disabled disabled?
:on-press #(re-frame/dispatch [:navigate-to :new-favourite])}
(i18n/label :t/add-to-favourites)]
:right
[quo/button
{:accessibility-label :participant-done
:type :secondary
:after :main-icons/next
:disabled disabled?
:on-press #(re-frame/dispatch [:wallet.send/set-recipient resolved-address])}
(i18n/label :t/done)]}]]])))

View File

@ -81,9 +81,7 @@
(if address
(if (:wallet/recipient db)
{:db (update db :wallet/recipient assoc :resolved-address address
:address address)
;;android
:dispatch-later [{:ms 1000 :dispatch [:wallet.recipient/focus-input]}]}
:address address)}
(if (:wallet/prepare-transaction db)
{:db (update db :wallet/prepare-transaction assoc
:to address :to-name (find-address-name db address))}

View File

@ -23,35 +23,14 @@
(re-frame/reg-fx
:wallet.recipient/address-paste
(fn [inp-ref]
(fn []
(react/get-from-clipboard
#(do
(when inp-ref (.focus inp-ref))
(re-frame/dispatch [:wallet.recipient/address-changed (string/trim %)])))))
(re-frame/reg-fx
:wallet.recipient/address-paste
(fn [inp-ref]
(react/get-from-clipboard
#(do
(when inp-ref (.focus inp-ref))
(re-frame/dispatch [:wallet.recipient/address-changed (string/trim %)])))))
(re-frame/reg-fx
::focus-input
(fn [inp-ref]
(when inp-ref
(.focus inp-ref))))
(fx/defn focus-input
{:events [:wallet.recipient/focus-input]}
[{:keys [db]}]
{::focus-input (get-in db [:wallet/recipient :inp-ref])})
#(re-frame/dispatch [:wallet.recipient/address-changed (string/trim %)]))))
(fx/defn address-paste-pressed
{:events [:wallet.recipient/address-paste-pressed]}
[{:keys [db]}]
{:wallet.recipient/address-paste (get-in db [:wallet/recipient :inp-ref])})
[_]
{:wallet.recipient/address-paste nil})
(fx/defn set-recipient
{:events [::recipient-address-resolved]}
@ -77,7 +56,8 @@
:number-of-retries 3}))
{:ui/show-error (i18n/label :t/wallet-invalid-address-checksum {:data recipient})
:db (assoc-in db [:wallet/recipient :searching] false)}))
(and (not (string/blank? recipient)) (ens/valid-eth-name-prefix? recipient))
(and (not (string/blank? recipient)) (not (string/starts-with? recipient "0x"))
(ens/valid-eth-name-prefix? recipient))
(let [ens-name (if (= (.indexOf ^js recipient ".") -1)
(stateofus/subdomain recipient)
recipient)]
@ -112,8 +92,6 @@
:name (or name "")}]
(fx/merge cofx
{:db (assoc-in db [:wallet/favourites address] new-favourite)
;;android
:dispatch-later [{:ms 1000 :dispatch [:wallet.recipient/focus-input]}]
::json-rpc/call [{:method "wallet_addFavourite"
:params [new-favourite]
:on-success #()}]}