Skip to content

Commit

Permalink
Merge branch 'develop' into qr-scanner
Browse files Browse the repository at this point in the history
  • Loading branch information
alwx authored Feb 16, 2024
2 parents d0e81a8 + 2e23dc7 commit b7f4cb9
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
(ns status-im.contexts.wallet.add-address-to-watch.confirm-address.component-spec
(:require
[status-im.contexts.wallet.add-address-to-watch.confirm-address.view :as confirm-address]
[test-helpers.component :as h]
[utils.re-frame :as rf]))
[test-helpers.component :as h]))

(h/describe "Add Watch Only Account Page"
(h/setup-restorable-re-frame)

(h/test "Create Account button is disabled while no account name exists"
(let [callback (h/mock-fn)]
(with-redefs [rf/dispatch #(callback)]
(h/setup-subs {:profile/wallet-accounts []
:get-screen-params {:address "0xmock-address"}})
(h/render [confirm-address/view {}])
(h/is-truthy (h/get-by-text "0xmock-address"))
(h/was-not-called callback)
(h/fire-event :change-text (h/get-by-label-text :profile-title-input) "NAME")
(h/fire-event :press (h/get-by-translation-text :t/add-watched-address))
(h/was-called callback)))))
(h/setup-subs {:wallet/watch-only-accounts []
:get-screen-params {:address "0xmock-address"}})
(h/render [confirm-address/view])
(h/is-truthy (h/get-by-text "0xmock-address"))
(h/is-disabled (h/get-by-label-text :confirm-button-label))))
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
(defn view
[]
(let [{:keys [address]} (rf/sub [:get-screen-params])
number-of-accounts (count (rf/sub [:profile/wallet-accounts]))
account-name (reagent/atom (i18n/label :t/default-account-name
{:number (inc number-of-accounts)}))
number-of-accounts (count (rf/sub [:wallet/watch-only-accounts]))
account-name (reagent/atom "")
placeholder (i18n/label :t/default-watched-address-placeholder
{:number (inc number-of-accounts)})
account-color (reagent/atom (rand-nth colors/account-colors))
account-emoji (reagent/atom (emoji-picker.utils/random-emoji))
on-change-name #(reset! account-name %)
Expand All @@ -31,6 +32,7 @@
#(js/alert
"Get info (to be
implemented)")}]
:placeholder placeholder
:account-name @account-name
:account-emoji @account-emoji
:account-color @account-color
Expand All @@ -42,6 +44,7 @@
:bottom-action-label :t/add-watched-address
:bottom-action-props {:customization-color @account-color
:disabled? (string/blank? @account-name)
:accessibility-label :confirm-button-label
:on-press #(rf/dispatch [:wallet/add-account
{:sha3-pwd nil
:type :watch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
[utils.re-frame :as rf]))

(defn view
[{:keys [margin-top? page-nav-right-side account-name account-color account-emoji on-change-name
[{:keys [margin-top? page-nav-right-side placeholder account-name account-color account-emoji
on-change-name
on-change-color
on-change-emoji on-focus on-blur section-label bottom-action?
bottom-action-label bottom-action-props
Expand Down Expand Up @@ -45,10 +46,11 @@
:container-style style/reaction-button-container}
:i/reaction]]
[quo/title-input
{:placeholder (i18n/label :t/account-name-input-placeholder)
{:placeholder placeholder
:max-length constants/wallet-account-name-max-length
:blur? true
:default-value account-name
:auto-focus true
:on-change-text on-change-name
:container-style style/title-input-container
:on-focus on-focus
Expand Down
13 changes: 9 additions & 4 deletions src/status_im/contexts/wallet/create_account/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@
bottom (safe-area/get-bottom)
account-color (reagent/atom (rand-nth colors/account-colors))
emoji (reagent/atom (emoji-picker.utils/random-emoji))
number-of-accounts (count (rf/sub [:wallet/accounts]))
account-name (reagent/atom (i18n/label :t/default-account-name
{:number (inc number-of-accounts)}))
number-of-accounts (count (rf/sub [:wallet/accounts-without-watched-accounts]))
account-name (reagent/atom "")
placeholder (i18n/label :t/default-account-placeholder
{:number (inc number-of-accounts)})
derivation-path (reagent/atom (utils/get-derivation-path number-of-accounts))
{:keys [public-key]} (rf/sub [:profile/profile])
on-change-text #(reset! account-name %)
Expand Down Expand Up @@ -96,11 +97,12 @@
:container-style style/reaction-button-container} :i/reaction]]
[quo/title-input
{:customization-color @account-color
:placeholder "Type something here"
:placeholder placeholder
:on-change-text on-change-text
:max-length constants/wallet-account-name-max-length
:blur? true
:disabled? false
:auto-focus true
:default-value @account-name
:container-style style/title-input-container}]
[quo/divider-line]
Expand Down Expand Up @@ -133,6 +135,9 @@
:path @derivation-path
:account-name @account-name}]))
:auth-button-label (i18n/label :t/confirm)
;; TODO (@rende11) Add this property when sliding button issue will fixed
;; https://github.com/status-im/status-mobile/pull/18683#issuecomment-1941564785
;; :disabled? (empty? @account-name)
:container-style (style/slide-button-container bottom)}]])))

(def view (quo.theme/with-theme view-internal))
6 changes: 6 additions & 0 deletions src/status_im/subs/wallet/wallet.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@
(map #(assoc-network-preferences-names network-details % test-networks-enabled?))
(sort-by :position))))

(rf/reg-sub
:wallet/watch-only-accounts
:<- [:wallet/accounts]
(fn [accounts]
(filter :watch-only? accounts)))

(rf/reg-sub
:wallet/addresses
:<- [:wallet]
Expand Down
13 changes: 13 additions & 0 deletions src/status_im/subs/wallet/wallet_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -484,3 +484,16 @@
(assoc :customization-color :magenta)
(assoc :network-preferences-names #{}))]
(rf/sub [sub-name])))))

(h/deftest-sub :wallet/watch-only-accounts
[sub-name]
(testing "returns only active (not watch-only?) accounts"
(swap! rf-db/app-db
#(-> %
(assoc-in [:wallet :accounts] accounts)
(assoc-in [:wallet :networks] network-data)))
(is
(= [(-> accounts
(get "0x3")
(assoc :network-preferences-names #{}))]
(rf/sub [sub-name])))))
4 changes: 2 additions & 2 deletions translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,8 @@
"decline": "Decline",
"decryption-failed-content": "An error occured decrypting your data. You might need to erase your old data and generate a new account. Tap “Apply” to erase or “Cancel” to try again",
"default": "Default",
"default-account-name": "Account {{number}}",
"default-account-placeholder": "Account {{number}}",
"default-watched-address-placeholder": "Watched address {{number}}",
"delete": "Delete",
"delete-and-leave-group": "Delete and leave group",
"delete-bootnode": "Delete bootnode",
Expand Down Expand Up @@ -2404,7 +2405,6 @@
"moonpay-description": "The new standard for fiat to crypto, supports Apple Pay.",
"latamex-description": "Easily buy crypto in Argentina, Mexico and Brazil.",
"account-info": "Account info",
"account-name-input-placeholder": "Account name",
"network-preferences": "Network preferences",
"network-preferences-desc-1": "Select which networks this address is happy to receive funds on",
"network-preferences-desc-2": "Select which networks to receive funds on",
Expand Down

0 comments on commit b7f4cb9

Please sign in to comment.