Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement "Account origin" Component #17147

Merged
merged 11 commits into from
Sep 1, 2023
Merged

Implement "Account origin" Component #17147

merged 11 commits into from
Sep 1, 2023

Conversation

mmilad75
Copy link
Contributor

@mmilad75 mmilad75 commented Aug 30, 2023

fixes #16951

Android iOS
Screen.Recording.2023-08-30.at.15.22.12.mov
Screen.Recording.2023-08-30.at.14.57.00.mov

Platforms

  • Android
  • iOS

@mmilad75 mmilad75 changed the title Milad/16951 Implement "Account origin" Component Aug 30, 2023
@mmilad75 mmilad75 self-assigned this Aug 30, 2023
@status-im-auto
Copy link
Member

status-im-auto commented Aug 30, 2023

Jenkins Builds

Click to see older builds (40)
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ 22ac1f2 #1 2023-08-30 12:00:35 ~6 min android 🤖apk 📲
✔️ 22ac1f2 #1 2023-08-30 12:00:36 ~6 min android-e2e 🤖apk 📲
✔️ 22ac1f2 #1 2023-08-30 12:02:04 ~7 min ios 📱ipa 📲
✔️ 22ac1f2 #1 2023-08-30 12:04:04 ~9 min tests 📄log
✔️ 67b5ea4 #2 2023-08-30 13:00:15 ~6 min android-e2e 🤖apk 📲
✔️ 67b5ea4 #2 2023-08-30 13:01:32 ~7 min ios 📱ipa 📲
✔️ 67b5ea4 #2 2023-08-30 13:03:31 ~9 min android 🤖apk 📲
✔️ 67b5ea4 #2 2023-08-30 13:04:12 ~10 min tests 📄log
✔️ ea06b4a #3 2023-08-30 17:08:11 ~6 min ios 📱ipa 📲
✔️ ea06b4a #3 2023-08-30 17:08:11 ~6 min android-e2e 🤖apk 📲
✔️ ea06b4a #3 2023-08-30 17:09:23 ~7 min android 🤖apk 📲
ea06b4a #3 2023-08-30 17:09:52 ~8 min tests 📄log
b76faf8 #4 2023-08-31 10:31:18 ~31 sec android-e2e 📄log
b76faf8 #4 2023-08-31 10:31:25 ~37 sec android 📄log
b76faf8 #4 2023-08-31 10:31:33 ~42 sec ios 📄log
b76faf8 #4 2023-08-31 10:32:24 ~1 min tests 📄log
9b862a5 #5 2023-08-31 10:37:37 ~25 sec ios 📄log
9b862a5 #5 2023-08-31 10:37:40 ~26 sec android 📄log
9b862a5 #5 2023-08-31 10:38:03 ~51 sec android-e2e 📄log
9b862a5 #5 2023-08-31 10:39:16 ~2 min tests 📄log
✔️ 5aeb682 #6 2023-08-31 11:03:37 ~6 min android-e2e 🤖apk 📲
✔️ 5aeb682 #6 2023-08-31 11:03:41 ~6 min android 🤖apk 📲
✔️ 5aeb682 #6 2023-08-31 11:04:31 ~7 min ios 📱ipa 📲
5aeb682 #6 2023-08-31 11:06:53 ~9 min tests 📄log
✔️ 7b0f8a2 #7 2023-08-31 11:15:21 ~5 min android-e2e 🤖apk 📲
✔️ 7b0f8a2 #7 2023-08-31 11:17:42 ~8 min android 🤖apk 📲
✔️ 7b0f8a2 #7 2023-08-31 11:17:59 ~8 min ios 📱ipa 📲
7b0f8a2 #7 2023-08-31 11:19:26 ~10 min tests 📄log
✔️ 5ca3df8 #8 2023-08-31 12:16:39 ~5 min android-e2e 🤖apk 📲
✔️ 5ca3df8 #8 2023-08-31 12:19:07 ~8 min android 🤖apk 📲
✔️ 5ca3df8 #8 2023-08-31 12:19:22 ~8 min ios 📱ipa 📲
5ca3df8 #8 2023-08-31 12:20:16 ~9 min tests 📄log
✔️ 7e217c6 #9 2023-08-31 16:16:31 ~6 min ios 📱ipa 📲
✔️ 7e217c6 #9 2023-08-31 16:17:05 ~7 min android-e2e 🤖apk 📲
✔️ 7e217c6 #9 2023-08-31 16:17:07 ~7 min android 🤖apk 📲
7e217c6 #9 2023-08-31 16:18:57 ~8 min tests 📄log
✔️ 24df68c #10 2023-09-01 09:55:28 ~5 min android 🤖apk 📲
✔️ 24df68c #10 2023-09-01 09:55:46 ~6 min android-e2e 🤖apk 📲
✔️ 24df68c #10 2023-09-01 09:58:28 ~8 min ios 📱ipa 📲
24df68c #10 2023-09-01 09:59:03 ~9 min tests 📄log
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ 265c537 #11 2023-09-01 14:10:31 ~5 min android-e2e 🤖apk 📲
✔️ 265c537 #11 2023-09-01 14:12:14 ~7 min ios 📱ipa 📲
✔️ 265c537 #11 2023-09-01 14:12:32 ~7 min android 🤖apk 📲
✔️ 265c537 #11 2023-09-01 14:13:42 ~9 min tests 📄log
✔️ cdda4f6 #12 2023-09-01 17:05:23 ~6 min android-e2e 🤖apk 📲
✔️ cdda4f6 #12 2023-09-01 17:05:30 ~6 min android 🤖apk 📲
✔️ cdda4f6 #12 2023-09-01 17:05:42 ~6 min ios 📱ipa 📲
✔️ cdda4f6 #12 2023-09-01 17:07:39 ~8 min tests 📄log

:derivation-path "m / 44’ / 60’ / 0’ / 0’ / 2"
:user-name "Alisher Yakupov"
:on-press (h/mock-fn)}])
(h/is-truthy (h/get-by-text (i18n/label "origin"))))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use h/get-by-translation-text instead of i18n/label

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 👍 . Done

:derivation-path "m / 44’ / 60’ / 0’ / 0’ / 2"
:user-name "Alisher Yakupov"
:on-press (h/mock-fn)}])
(h/is-truthy (h/get-by-text (i18n/label "on-device"))))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

h/get-by-translation-text

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

:derivation-path "m / 44’ / 60’ / 0’ / 0’ / 2"
:user-name "Alisher Yakupov"
:on-press (h/mock-fn)}])
(h/is-truthy (h/get-by-text (i18n/label "on-keycard"))))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

h/get-by-translation-text

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

[text/text
{:weight :medium
:size :paragraph-1}
(case type
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: I'd rename type since it shadows a Clojure core function.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recently opened a PR #17138 to unshadow all core vars & non-core vars, but kept cljs.core/type and cljs.core/name as exceptions in the linter configuration.

I think unshadowing type is difficult in status-mobile, because it's used hundreds of times and it's hard to find a replacement word. I can think of kind, but it's meh IMO. The word type is so ubiquitous in the data structures that we use that I'm not sure it's worth the trouble.

Other words have nice replacements, for example, in the PRs I opened to unshadow:

  • hash -> tx-hash (usually related to the transaction hash)
  • range (as a time period) becomes period
  • meta -> metadata
  • count -> amount
  • subs -> subscriptions
  • And so on

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -323,6 +324,7 @@

;;;; Wallet
(def account-card quo2.components.wallet.account-card.view/view)
(def account-origin quo2.components.wallet.account-origin.view/view)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should swap lines with account-overview to be alpha sorted.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But or should be before ov

[text/text
{:weight :medium
:size :paragraph-1}
(case type
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recently opened a PR #17138 to unshadow all core vars & non-core vars, but kept cljs.core/type and cljs.core/name as exceptions in the linter configuration.

I think unshadowing type is difficult in status-mobile, because it's used hundreds of times and it's hard to find a replacement word. I can think of kind, but it's meh IMO. The word type is so ubiquitous in the data structures that we use that I'm not sure it's worth the trouble.

Other words have nice replacements, for example, in the PRs I opened to unshadow:

  • hash -> tx-hash (usually related to the transaction hash)
  • range (as a time period) becomes period
  • meta -> metadata
  • count -> amount
  • subs -> subscriptions
  • And so on

[theme]
{:border-radius 16
:border-width 1
:border-color (colors/theme-colors colors/neutral-10
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The line breaks in theme-colors are unnecessary. Though I understand it's an stylistic/personal choice.

(defn container
  [theme]
  {:border-radius 16
   :border-width  1
   :border-color  (colors/theme-colors colors/neutral-10 colors/neutral-80 theme)})

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

:theme theme
:secondary-color secondary-color}]))

(defn- card-view
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general it's fine to name components without the suffix view (or whatever other suffix). I use this convention myself when I have a binding with a name that conflicts (shadows) the component name, but that's not the case here. Just card seems to be enough because I don't see any binding or var named card.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, but the reason I used card-view was to match other names in the file. There word list is a reserved-word in clojure, so I had to change it to list-view, therefore, I changed card to card-view

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would do the same and name it list-view. For the card component I see you wanted to have a consistent naming scheme. Fair enough :)

:margin-horizontal 20}}
[quo/account-origin @state]]])))

(defn preview
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, update this preview namespace to use the new API that helps us keep these screens DRY(ish). You can find a few dozen examples in the codebase already. For example: status-im2.contexts.quo-preview.dropdowns.dropdown

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mmilad75, the namespace is not yet using the new code. If you take a look at status-im2.contexts.quo-preview.dropdowns.dropdown (or many others, like status-im2.contexts.quo-preview.list-items.dapp) you will see there's less boilerplate.

We can use the component preview/preview-container. Here's how it should probably be:

(ns status-im2.contexts.quo-preview.wallet.account-origin
  (:require [quo2.core :as quo]
            [reagent.core :as reagent]
            [status-im2.common.resources :as resources]
            [status-im2.contexts.quo-preview.preview :as preview]))

(def descriptor
  [{:type    :select
    :key     :type
    :options [{:key :default-keypair}
              {:key :recovery-phrase}
              {:key :private-key}]}
   {:type    :select
    :key     :stored
    :options [{:key :on-device}
              {:key :on-keycard}]}])

(defn view
  []
  (let [state (reagent/atom {:type            :default-keypair
                             :stored          :on-keycard
                             :profile-picture (resources/get-mock-image :user-picture-male5)
                             :derivation-path "m / 44’ / 60’ / 0’ / 0’ / 2"
                             :user-name       "Alisher Yakupov"
                             :on-press        #(js/alert "pressed")})]
    (fn []
      [preview/preview-container {:state state :descriptor descriptor}
       [quo/account-origin @state]])))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

:type :select
:key :type
:options [{:key :default-keypair
:value "Default Keypair"}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to explicitly pass :value if you think the humanized text deduced from :default-keypair is good enough. In this case it is, :default-keypair will be automatically transformed to "Default keypair". You can also remove redundant :label values.

For reference: here's the function that does this work for us

This is how the descriptor should look like:

(def descriptor
  [{:type    :select
    :key     :type
    :options [{:key :default-keypair}
              {:key :recovery-phrase}
              {:key :private-key}]}
   {:type    :select
    :key     :stored
    :options [{:key :on-device}
              {:key :on-keycard}]}])

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very smaller and cleaner. Done

(defn- list-view
[{:keys [type stored profile-picture user-name theme secondary-color]}]
(let [stored-name (if (= :on-device stored)
(i18n/label "on-device")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know I'm just repeating something you already know :), but translation keys should be keywords and qualified with :t

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, thanks for reminding it. Done

[utils.i18n :as i18n]))

(h/describe
"account origin tests"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Code style] The describe text arg almost always go on the same line as describe.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

(defn- list-view
[{:keys [type stored profile-picture user-name theme secondary-color]}]
(let [stored-name (if (= :on-device stored)
(i18n/label "on-device")
Copy link
Contributor

@vkjr vkjr Aug 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the keyword with i18n/label is the default approach in a codebase, so we can stick to it. Like (i18n/label :t/on-device), (i18n/label :t/on-keycard)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -0,0 +1,53 @@
(ns status-im2.contexts.quo-preview.wallet.account-origin
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quo preview can be simplified by using improvements added in this PR. That will make the file shorter and less boilerplate :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can go further @mmilad75. See comment #17147 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@vkjr
Copy link
Contributor

vkjr commented Aug 30, 2023

Wow, I shouldn't have made a break during the PR review) All my comments became a duplicate 😁

:stored :on-keycard
:derivation-path "m / 44’ / 60’ / 0’ / 0’ / 2"
:user-name "Alisher Yakupov"
:on-press (h/mock-fn)}])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think passing a mock function to on-press is unnecessary in the tests, unless we are explicitly asserting something about it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, tests should use the minimum amount of data needed for the test to work imo

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

:secondary-color secondary-color}])

(def view-internal
(fn [{:keys [type theme derivation-path on-press] :as props}]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This anonymous function is unnecessary, or in other words, view-internal doesn't need to be a form-2 component.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

:margin-horizontal 20}}
[quo/account-origin @state]]])))

(defn preview
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mmilad75, the namespace is not yet using the new code. If you take a look at status-im2.contexts.quo-preview.dropdowns.dropdown (or many others, like status-im2.contexts.quo-preview.list-items.dapp) you will see there's less boilerplate.

We can use the component preview/preview-container. Here's how it should probably be:

(ns status-im2.contexts.quo-preview.wallet.account-origin
  (:require [quo2.core :as quo]
            [reagent.core :as reagent]
            [status-im2.common.resources :as resources]
            [status-im2.contexts.quo-preview.preview :as preview]))

(def descriptor
  [{:type    :select
    :key     :type
    :options [{:key :default-keypair}
              {:key :recovery-phrase}
              {:key :private-key}]}
   {:type    :select
    :key     :stored
    :options [{:key :on-device}
              {:key :on-keycard}]}])

(defn view
  []
  (let [state (reagent/atom {:type            :default-keypair
                             :stored          :on-keycard
                             :profile-picture (resources/get-mock-image :user-picture-male5)
                             :derivation-path "m / 44’ / 60’ / 0’ / 0’ / 2"
                             :user-name       "Alisher Yakupov"
                             :on-press        #(js/alert "pressed")})]
    (fn []
      [preview/preview-container {:state state :descriptor descriptor}
       [quo/account-origin @state]])))

[card-view theme derivation-path secondary-color on-press])])))

(def view
"Create an accont-origin UI component.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo -> account

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw I like this format for the docstrings much easier to read 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, Thank you 😊

Copy link
Contributor

@J-Son89 J-Son89 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice work @mmilad75! :)

@@ -8,71 +8,63 @@
{:type :recovery-phrase
:stored :on-keycard
:derivation-path "m / 44’ / 60’ / 0’ / 0’ / 2"
:user-name "Alisher Yakupov"
:on-press (h/mock-fn)}])
:user-name "Alisher Yakupov"}])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: maybe let's use a test name, e.g "Test Name"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link

@Francesca-G Francesca-G left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me :)

Minor fix about the icon size here

@mmilad75 mmilad75 merged commit 6809311 into develop Sep 1, 2023
2 checks passed
@mmilad75 mmilad75 deleted the milad/16951 branch September 1, 2023 17:11
alwx pushed a commit that referenced this pull request Sep 6, 2023
Implement "Account origin" Component
@churik
Copy link
Member

churik commented Sep 18, 2023

@mmilad75
did you create an issue follow-up based on the design review?

Based on https://github.com/status-im/status-mobile/blob/develop/doc/pipeline_process.md > Design review, all follow-up issues have to be created when PR is merged and linked to the original PR.

@mmilad75
Copy link
Contributor Author

@mmilad75 did you create an issue follow-up based on the design review?

Based on https://github.com/status-im/status-mobile/blob/develop/doc/pipeline_process.md > Design review, all follow-up issues have to be created when PR is merged and linked to the original PR.

No, I didn't. I wasn't aware of this concept. Thanks for letting me know

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Archived in project
Development

Successfully merging this pull request may close these issues.

Implement "Account origin" Component
8 participants