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

[#18817] Import private key: UI for key pair name #18817 #19747

Merged
merged 3 commits into from May 13, 2024

Conversation

Rende11
Copy link
Collaborator

@Rende11 Rende11 commented Apr 20, 2024

Fixes #18817

Summary

UI for adding key pair name, re-frame subs and events

Testing notes

Example of private key - 0xcaed41dd92c1548cf7536c290e6a1871757fb5fea5721dea3a08c6d4abcd16cf,
result of account activity (no activity/has activity) is random now.
Public address of private key is hardcoded now.

!!! Important
It reuses status-im.contexts.wallet.add-account.create-account.key-pair-name.view screen in this import private key workflow and in new key pair (check video)

Before and after screenshots comparison

Design

!!! After updates

Simulator.Screen.Recording.-.iPhone.13.-.2024-05-03.at.03.04.03.mp4

|Simulator Screenshot - iPhone 13 - 2024-04-25 at 23 52 42|Simulator Screenshot - iPhone 13 - 2024-04-25 at 23 52 53|

|Simulator Screenshot - iPhone 13 - 2024-04-25 at 23 53 34|Simulator Screenshot - iPhone 13 - 2024-04-25 at 23 53 19|

|Simulator Screenshot - iPhone 13 - 2024-04-25 at 23 53 09|Simulator Screenshot - iPhone 13 - 2024-04-25 at 23 53 03|

status: ready

@status-github-bot status-github-bot bot added this to REVIEW in Pipeline for QA Apr 20, 2024
@status-im-auto
Copy link
Member

status-im-auto commented Apr 20, 2024

Jenkins Builds

Click to see older builds (64)
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ 5508ca4 #1 2024-04-20 21:04:28 ~4 min tests 📄log
✔️ 5508ca4 #1 2024-04-20 21:08:04 ~8 min android-e2e 🤖apk 📲
✔️ 5508ca4 #1 2024-04-20 21:08:08 ~8 min android 🤖apk 📲
✔️ 5508ca4 #1 2024-04-20 21:08:36 ~8 min ios 📱ipa 📲
✔️ 583b450 #2 2024-04-23 17:20:32 ~4 min tests 📄log
✔️ 583b450 #2 2024-04-23 17:23:56 ~7 min android-e2e 🤖apk 📲
✔️ 583b450 #2 2024-04-23 17:24:06 ~8 min android 🤖apk 📲
✔️ 583b450 #2 2024-04-23 17:24:30 ~8 min ios 📱ipa 📲
✔️ daa5b59 #3 2024-04-24 16:35:39 ~4 min tests 📄log
✔️ daa5b59 #3 2024-04-24 16:39:14 ~8 min android-e2e 🤖apk 📲
✔️ daa5b59 #3 2024-04-24 16:39:15 ~8 min android 🤖apk 📲
✔️ daa5b59 #3 2024-04-24 16:39:29 ~8 min ios 📱ipa 📲
✔️ 6e88be8 #4 2024-04-25 11:53:27 ~4 min tests 📄log
✔️ 6e88be8 #4 2024-04-25 11:56:56 ~8 min android-e2e 🤖apk 📲
✔️ 6e88be8 #4 2024-04-25 11:57:00 ~8 min android 🤖apk 📲
✔️ 6e88be8 #4 2024-04-25 11:58:43 ~9 min ios 📱ipa 📲
✔️ bf387c3 #6 2024-04-25 20:52:40 ~4 min tests 📄log
✔️ bf387c3 #6 2024-04-25 20:55:56 ~7 min android-e2e 🤖apk 📲
✔️ bf387c3 #6 2024-04-25 20:56:01 ~7 min android 🤖apk 📲
✔️ bf387c3 #6 2024-04-25 20:58:09 ~9 min ios 📱ipa 📲
✔️ cfef154 #7 2024-04-30 11:25:45 ~4 min tests 📄log
✔️ cfef154 #7 2024-04-30 11:29:18 ~7 min android-e2e 🤖apk 📲
✔️ cfef154 #7 2024-04-30 11:29:23 ~8 min android 🤖apk 📲
✔️ cfef154 #7 2024-04-30 11:29:48 ~8 min ios 📱ipa 📲
✔️ 77a5fa0 #8 2024-04-30 13:48:25 ~4 min tests 📄log
✔️ 77a5fa0 #8 2024-04-30 13:51:55 ~7 min android-e2e 🤖apk 📲
✔️ 77a5fa0 #8 2024-04-30 13:52:01 ~8 min android 🤖apk 📲
✔️ 77a5fa0 #8 2024-04-30 13:52:50 ~8 min ios 📱ipa 📲
✔️ e7fa186 #9 2024-05-01 15:36:35 ~4 min tests 📄log
✔️ e7fa186 #9 2024-05-01 15:39:16 ~6 min android-e2e 🤖apk 📲
✔️ e7fa186 #9 2024-05-01 15:39:19 ~6 min android 🤖apk 📲
✔️ e7fa186 #9 2024-05-01 15:42:30 ~10 min ios 📱ipa 📲
✔️ 2d36fd1 #10 2024-05-01 20:00:21 ~4 min tests 📄log
✔️ 2d36fd1 #10 2024-05-01 20:03:48 ~7 min android-e2e 🤖apk 📲
✔️ 2d36fd1 #10 2024-05-01 20:03:55 ~7 min android 🤖apk 📲
✔️ 2d36fd1 #10 2024-05-01 20:06:18 ~10 min ios 📱ipa 📲
✔️ 538fffc #11 2024-05-02 23:01:11 ~4 min tests 📄log
✔️ 538fffc #11 2024-05-02 23:04:46 ~8 min android-e2e 🤖apk 📲
✔️ 538fffc #11 2024-05-02 23:04:50 ~8 min android 🤖apk 📲
✔️ 538fffc #11 2024-05-02 23:05:15 ~8 min ios 📱ipa 📲
0d22806 #13 2024-05-03 00:10:17 ~2 min tests 📄log
✔️ 0d22806 #13 2024-05-03 00:13:37 ~5 min android-e2e 🤖apk 📲
✔️ 0d22806 #13 2024-05-03 00:14:34 ~6 min android 🤖apk 📲
✔️ 0d22806 #13 2024-05-03 00:16:17 ~8 min ios 📱ipa 📲
✔️ 5de289d #14 2024-05-07 08:51:14 ~5 min android-e2e 🤖apk 📲
✔️ 5de289d #14 2024-05-07 10:11:13 ~8 min ios 📱ipa 📲
✔️ 5de289d #14 2024-05-07 10:48:16 ~5 min android 🤖apk 📲
✔️ 5de289d #14 2024-05-07 11:05:24 ~3 min tests 📄log
✔️ 399a44e #15 2024-05-07 22:08:46 ~4 min tests 📄log
✔️ 399a44e #15 2024-05-07 22:12:16 ~8 min android-e2e 🤖apk 📲
✔️ 399a44e #15 2024-05-07 22:12:22 ~8 min android 🤖apk 📲
✔️ 399a44e #15 2024-05-07 22:12:38 ~8 min ios 📱ipa 📲
✔️ 76e3ffa #16 2024-05-08 10:20:56 ~3 min tests 📄log
✔️ 76e3ffa #16 2024-05-08 10:26:11 ~9 min ios 📱ipa 📲
76e3ffa #16 2024-05-08 10:27:21 ~10 min android 📄log
76e3ffa #16 2024-05-08 10:27:30 ~10 min android-e2e 📄log
✔️ 0d332e6 #17 2024-05-08 10:39:59 ~5 min tests 📄log
✔️ 0d332e6 #17 2024-05-08 10:43:34 ~9 min android-e2e 🤖apk 📲
✔️ 0d332e6 #17 2024-05-08 10:43:39 ~9 min android 🤖apk 📲
✔️ 0d332e6 #17 2024-05-08 10:44:21 ~9 min ios 📱ipa 📲
✔️ a82a2b3 #18 2024-05-08 13:04:14 ~4 min tests 📄log
✔️ a82a2b3 #18 2024-05-08 13:07:43 ~8 min android-e2e 🤖apk 📲
✔️ a82a2b3 #18 2024-05-08 13:07:50 ~8 min android 🤖apk 📲
✔️ a82a2b3 #18 2024-05-08 13:10:34 ~10 min ios 📱ipa 📲
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ 067ae6f #19 2024-05-08 18:38:51 ~4 min tests 📄log
✔️ 067ae6f #19 2024-05-08 18:40:14 ~5 min android-e2e 🤖apk 📲
✔️ 067ae6f #19 2024-05-08 18:41:52 ~7 min android 🤖apk 📲
✔️ 067ae6f #19 2024-05-08 18:42:57 ~8 min ios 📱ipa 📲
✔️ 54f1b50 #20 2024-05-13 09:37:46 ~5 min tests 📄log
✔️ 54f1b50 #20 2024-05-13 09:39:17 ~7 min android-e2e 🤖apk 📲
✔️ 54f1b50 #20 2024-05-13 09:39:25 ~7 min android 🤖apk 📲
✔️ 54f1b50 #20 2024-05-13 09:41:31 ~9 min ios 📱ipa 📲

@Rende11 Rende11 force-pushed the 18817-ui-key-pair-name branch 4 times, most recently from e88bc35 to bf387c3 Compare April 25, 2024 20:48
@Rende11 Rende11 changed the title [WIP][#18817] Import private key: UI for key pair name [#18817] Import private key: UI for key pair name Apr 25, 2024
@Rende11 Rende11 changed the title [#18817] Import private key: UI for key pair name [#18817] Import private key: UI for key pair name #18817 Apr 27, 2024
Copy link
Member

@OmarBasem OmarBasem left a comment

Choose a reason for hiding this comment

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

The keypair name screen is duplicated. Please use the existing screen.

(rf/reg-event-fx
:wallet/set-private-key
(fn [{:keys [db]} [value]]
{:db (assoc-in db [:wallet :ui :import-private-key :private-key] value)}))
Copy link
Member

Choose a reason for hiding this comment

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

probably we need to use security/mask-data for the private-key

@OmarBasem
Copy link
Member

Thanks @Rende11 for addressing the comments. There is currently a conflict in the keypair_name screen, please resolve that conflict and make sure to copy the new changes

@Rende11 Rende11 force-pushed the 18817-ui-key-pair-name branch 2 times, most recently from c09c632 to 0d22806 Compare May 3, 2024 00:07
@Rende11 Rende11 force-pushed the 18817-ui-key-pair-name branch 2 times, most recently from bd5e16a to 5de289d Compare May 6, 2024 18:36
@Rende11 Rende11 requested a review from ilmotta May 6, 2024 18:36
Copy link
Member

@seanstrom seanstrom left a comment

Choose a reason for hiding this comment

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

Nice stuff 🙌
Thanks for doing this 🙏
Left some small comments 👍

Comment on lines +16 to +45
[{:keys [input-value set-flow-state error?]}]
(let [check-address
(rn/use-callback
(debounce/debounce
(fn [v]
(if (empty? v)
(set-flow-state nil)
;; TODO check for validation
(if-not (v/private-key? v)
(set-flow-state :invalid-private-key)
;; TODO add real requests
(do
(set-flow-state :scanning)
;; TODO get real address
;; Should be fixed in #18819
(rf/dispatch [:wallet/set-public-address
"0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"])
(js/setTimeout set-flow-state 400 (rand-nth [:active-address :inactive-address]))))))
500))

on-change (rn/use-callback
(fn [v]
(rf/dispatch [:wallet/set-private-key v])
(check-address v)))
on-paste (rn/use-callback
(fn []
(clipboard/get-string
(fn [clipboard]
(when-not (empty? clipboard)
(on-change clipboard))))))]
Copy link
Member

Choose a reason for hiding this comment

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

Small tweak 🔧

We may want to update these use-callback usages and provide them with their dependency arrays (?). For example: check-address depends on set-flow-state, on-change depends on check-address, and on-paste depends on on-change.

Copy link
Collaborator Author

@Rende11 Rende11 May 7, 2024

Choose a reason for hiding this comment

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

As I understand, set-flow-state provided from use-state hook never changes

Copy link
Member

Choose a reason for hiding this comment

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

adding use-callback in this way is questionable enough already, I think there is even further questions to adding state setters in the dependency array as I can only assume React has already considered this to some extent and as @Rende11 pointed out this method never changes so there is most likely no value in doing so 👍
If anything we are just making the code really hard to read 🦀

@J-Son89
Copy link
Member

J-Son89 commented May 8, 2024

@status-im/mobile-qa - this pr will skip manual QA as it is all behind a feature flag 👍

Move files

Fix label

Enable feature and fix auto-focus

Add events and subs

Some fixes

Merge screens

Fixes

Minor fixes

Some tweaks

Fix feature flag
@J-Son89 J-Son89 moved this from REVIEW to E2E Tests in Pipeline for QA May 8, 2024
@status-im-auto
Copy link
Member

85% of end-end tests have passed

Total executed tests: 52
Failed tests: 6
Expected to fail tests: 2
Passed tests: 44
IDs of failed tests: 727230,704613,727229,702807,727232,702775 
IDs of expected to fail tests: 703495,703503 

Failed tests (6)

Click to expand
  • Rerun failed tests

  • Class TestGroupChatMultipleDeviceMergedNewUI:

    1. test_group_chat_join_send_text_messages_push, id: 702807

    Device 2: Find `Text` by `xpath`: `//*[starts-with(@text,'Hey, admin!')]/ancestor::android.view.ViewGroup[@content-desc='chat-item']//*[@content-desc='message-status']/android.widget.TextView`
    Device 2: `Text` is `Sent`

    critical/chats/test_group_chat.py:95: in test_group_chat_join_send_text_messages_push
        self.chats[1].chat_element_by_text(message_to_admin).wait_for_status_to_be('Delivered', timeout=120)
    ../views/chat_view.py:225: in wait_for_status_to_be
        raise TimeoutException("Message status was not changed to %s, it's %s" % (expected_status, current_status))
     Message status was not changed to Delivered, it's Sent
    



    Device sessions

    Class TestWalletMultipleDevice:

    1. test_wallet_send_asset_from_drawer, id: 727230

    # STEP: Getting ETH amount in the wallet of the sender before transaction
    Device 1: Find WalletTab by accessibility id: wallet-stack-tab

    critical/test_wallet.py:117: in test_wallet_send_asset_from_drawer
        sender_balance, receiver_balance, eth_amount_sender, eth_amount_receiver = self._get_balances_before_tx()
    critical/test_wallet.py:39: in _get_balances_before_tx
        self.wallet_1.wallet_tab.click()
    ../views/base_element.py:90: in click
        element = self.find_element()
    ../views/base_element.py:79: in find_element
        raise NoSuchElementException(
     Device 1: WalletTab by accessibility id: `wallet-stack-tab` is not found on the screen; For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors#no-such-element-exception
    



    2. test_wallet_send_eth, id: 727229

    Device 1: Swiping right on element SlideButton
    Device 1: Find SlideButton by xpath: //*[@resource-id='slide-button-track']

    critical/test_wallet.py:109: in test_wallet_send_eth
        self.wallet_1.send_asset(address=self.receiver['address'], asset_name='Ether', amount=amount_to_send)
    ../views/wallet_view.py:99: in send_asset
        self.confirm_transaction()
    ../views/wallet_view.py:86: in confirm_transaction
        self.slide_and_confirm_with_password()
    ../views/wallet_view.py:80: in slide_and_confirm_with_password
        self.slide_button_track.slide()
    ../views/base_view.py:257: in slide
        self.swipe_right_on_element(width_percentage=1.3, start_x=100)
    ../views/base_element.py:308: in swipe_right_on_element
        location, size = self.get_element_coordinates()
    ../views/base_element.py:294: in get_element_coordinates
        element = self.find_element()
    ../views/base_element.py:79: in find_element
        raise NoSuchElementException(
     Device 1: SlideButton by xpath: `//*[@resource-id='slide-button-track']` is not found on the screen; For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors#no-such-element-exception
    



    Class TestDeepLinksOneDevice:

    1. test_links_open_universal_links_from_chat, id: 704613

    Device 1: Find Button by xpath: //*[@text="open community"]
    Device 1: Tap on found: Button

    critical/test_deep_and_universal_links.py:70: in test_links_open_universal_links_from_chat
        self.errors.verify_no_errors()
    base_test_case.py:190: in verify_no_errors
        pytest.fail('\n '.join([self.errors.pop(0) for _ in range(len(self.errors))]))
     Community 'Open community for e2e' was not requested to join by the url https://status.app/c/G1AAAGR0G-IRb2YJD4lRXwLusAFnGrDHGNl6Wt55MIARwVYvarnO873011-fdVSz1kHSan-qq0G96vOaMqyTRhJnQV74KCUr#zQ3shb9irJR66rhG1E8sQZX8pDU3dpGm4daYSmPVDd2e73ewE
    



    Device sessions

    2. test_links_deep_links, id: 702775

    Device 1: Find BrowserTab by accessibility id: browser-stack-tab
    Device 1: Tap on found: BrowserTab

    critical/test_deep_and_universal_links.py:114: in test_links_deep_links
        self.errors.verify_no_errors()
    base_test_case.py:190: in verify_no_errors
        pytest.fail('\n '.join([self.errors.pop(0) for _ in range(len(self.errors))]))
     Community 'Open community for e2e' was not requested to join by the deep link status.app://c/G1AAAGR0G-IRb2YJD4lRXwLusAFnGrDHGNl6Wt55MIARwVYvarnO873011-fdVSz1kHSan-qq0G96vOaMqyTRhJnQV74KCUr#zQ3shb9irJR66rhG1E8sQZX8pDU3dpGm4daYSmPVDd2e73ewE
    



    Device sessions

    Class TestWalletOneDevice:

    1. test_wallet_add_remove_watch_only_account, id: 727232

    Device 1: Find EditBox by accessibility id: add-address-to-watch
    Device 1: Type 0x8d2413447ff297d30bdc475f6d5cb00254685aae to EditBox

    critical/test_wallet.py:190: in test_wallet_add_remove_watch_only_account
        self.wallet_view.add_watch_only_account(address=address_to_watch, account_name=new_account_name)
    ../views/wallet_view.py:120: in add_watch_only_account
        self.account_has_activity_label.wait_for_visibility_of_element()
    ../views/base_element.py:147: in wait_for_visibility_of_element
        raise TimeoutException(
     Device 1: Text by accessibility id:`account-has-activity` is not found on the screen after wait_for_visibility_of_element
    



    Device sessions

    Expected to fail tests (2)

    Click to expand

    Class TestCommunityOneDeviceMerged:

    1. test_community_discovery, id: 703503

    Test is not run, e2e blocker  
    

    [[reason: [NOTRUN] Curated communities not loading, https://github.com//issues/17852]]

    Class TestGroupChatMultipleDeviceMergedNewUI:

    1. test_group_chat_mute_chat, id: 703495

    # STEP: Change device time so chat will be unmuted by timer
    Device 2: Long press on ChatElement

    critical/chats/test_group_chat.py:464: in test_group_chat_mute_chat
        self.errors.verify_no_errors()
    base_test_case.py:190: in verify_no_errors
        pytest.fail('\n '.join([self.errors.pop(0) for _ in range(len(self.errors))]))
     Chat is still muted after timeout 
    

    [[Chat is not unmuted after expected time: https://github.com//issues/19627]]

    Device sessions

    Passed tests (44)

    Click to expand

    Class TestCommunityOneDeviceMerged:

    1. test_restore_multiaccount_with_waku_backup_remove_switch, id: 703133
    Device sessions

    2. test_community_copy_and_paste_message_in_chat_input, id: 702742
    Device sessions

    3. test_community_undo_delete_message, id: 702869
    Device sessions

    4. test_community_navigate_to_channel_when_relaunch, id: 702846
    Device sessions

    5. test_community_mute_community_and_channel, id: 703382
    Device sessions

    Class TestActivityMultipleDevicePR:

    1. test_navigation_jump_to, id: 702936
    Device sessions

    2. test_activity_center_reply_read_unread_delete_filter_swipe, id: 702947
    Device sessions

    Class TestCommunityMultipleDeviceMerged:

    1. test_community_several_images_send_reply, id: 703194
    Device sessions

    2. test_community_one_image_send_reply, id: 702859
    Device sessions

    3. test_community_emoji_send_copy_paste_reply, id: 702840
    Device sessions

    4. test_community_mark_all_messages_as_read, id: 703086
    Device sessions

    5. test_community_contact_block_unblock_offline, id: 702894
    Device sessions

    6. test_community_edit_delete_message_when_offline, id: 704615
    Device sessions

    7. test_community_message_delete, id: 702839
    Device sessions

    8. test_community_message_send_check_timestamps_sender_username, id: 702838
    Device sessions

    9. test_community_links_with_previews_github_youtube_twitter_gif_send_enable, id: 702844
    Device sessions

    10. test_community_message_edit, id: 702843
    Device sessions

    11. test_community_unread_messages_badge, id: 702841
    Device sessions

    Class TestWalletOneDevice:

    1. test_wallet_add_remove_regular_account, id: 727231
    Device sessions

    Class TestOneToOneChatMultipleSharedDevicesNewUi:

    1. test_1_1_chat_emoji_send_reply_and_open_link, id: 702782
    Device sessions

    2. test_1_1_chat_text_message_delete_push_disappear, id: 702733
    Device sessions

    3. test_1_1_chat_push_emoji, id: 702813
    Device sessions

    4. test_1_1_chat_non_latin_messages_stack_update_profile_photo, id: 702745
    Device sessions

    5. test_1_1_chat_edit_message, id: 702855
    Device sessions

    6. test_1_1_chat_send_image_save_and_share, id: 703391
    Device sessions

    7. test_1_1_chat_pin_messages, id: 702731
    Device sessions

    8. test_1_1_chat_message_reaction, id: 702730
    Device sessions

    Class TestActivityCenterContactRequestMultipleDevicePR:

    1. test_add_contact_field_validation, id: 702777
    Device sessions

    2. test_activity_center_contact_request_accept_swipe_mark_all_as_read, id: 702851
    Device sessions

    3. test_activity_center_contact_request_decline, id: 702850
    Device sessions

    Class TestGroupChatMultipleDeviceMergedNewUI:

    1. test_group_chat_pin_messages, id: 702732
    Device sessions

    2. test_group_chat_send_image_save_and_share, id: 703297
    Device sessions

    3. test_group_chat_reactions, id: 703202
    Device sessions

    4. test_group_chat_offline_pn, id: 702808
    Device sessions

    Class TestActivityMultipleDevicePRTwo:

    1. test_activity_center_mentions, id: 702957
    Device sessions

    2. test_activity_center_admin_notification_accept_swipe, id: 702958
    Device sessions

    Class TestOneToOneChatMultipleSharedDevicesNewUiTwo:

    1. test_1_1_chat_delete_via_long_press_relogin, id: 702784
    Device sessions

    2. test_1_1_chat_is_shown_message_sent_delivered_from_offline, id: 702783
    Device sessions

    3. test_1_1_chat_mute_chat, id: 703496
    Device sessions

    Class TestCommunityMultipleDeviceMergedTwo:

    1. test_community_markdown_support, id: 702809
    Device sessions

    2. test_community_hashtag_links_to_community_channels, id: 702948
    Device sessions

    3. test_community_mentions_push_notification, id: 702786
    Device sessions

    4. test_community_leave, id: 702845
    Device sessions

    5. test_community_join_when_node_owner_offline, id: 703629
    Device sessions

    Copy link
    Contributor

    @ilmotta ilmotta left a comment

    Choose a reason for hiding this comment

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

    @Rende11 Thank you for working in this PR. None of my comments are blockers given the context of this PR.

    customization-color (rf/sub [:profile/customization-color])
    private-key (rf/sub [:wallet/import-private-key])
    public-address (rf/sub [:wallet/public-address])
    [flow-state set-flow-state] (rn/use-state nil)
    Copy link
    Contributor

    Choose a reason for hiding this comment

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

    It's not clear what a nil flow-state means. Nil is generally overloaded in meaning. What do you think about using an explicit value that's self-explanatory?

    [rn/view {:style (style/public-address flow-state theme)}
    [quo/text "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"]]])
    (when (seq input-value)
    (when (seq public-address)
    Copy link
    Contributor

    Choose a reason for hiding this comment

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

    (seq some-string) is slower than using (not string/blank? some-string). We can always say this is unimportant, but it's a better default in our slow mobile universe. In Clojure on the JVM the drop in performance is even more pronounced.

    I'd say string/blank? is also generally clearer in intention. There's no guessing about the type of argument passed to it. Here I guess it's fine because we can guess public-address is a string.

    Side note: historically in PRs, I've also seen the result of (seq some-string) be passed over to components as if it's a boolean, but this is also costly and will cause Reagent to spend more time figuring out if component args are different.

    :new-key-pair
    (rf/dispatch [:wallet/new-keypair-continue
    {:keypair-name key-pair-name}])
    (js/alert "Unknown workflow")))
    Copy link
    Contributor

    Choose a reason for hiding this comment

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

    Why would we alert the user of an unknown workflow? What will they do with the popup? In theory, I imagine in production an unhandled workflow would be considered a bug? @J-Son89

    (def ^:private key-pair-name-max-length 15)
    (def ^:private key-pair-name-min-length 5)

    (def error-messages
    Copy link
    Contributor

    Choose a reason for hiding this comment

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

    Can be private.

    on-continue (rn/use-callback
    (fn [_]
    (case workflow
    ;; TODO issue #19759. Implement creation account from
    Copy link
    Contributor

    Choose a reason for hiding this comment

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

    (when-not (empty? clipboard)
    (on-change clipboard))))))]
    [{:keys [input-value set-flow-state error?]}]
    (let [check-address
    Copy link
    Contributor

    Choose a reason for hiding this comment

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

    This check-address function is quite confusing to me with the TODO comments and hardcoded values. It's something we would not usually approve for merge in the past.

    We've done this before, I mean, when we need to implement client features before the backend supports them, we can write re-frame subs/events/etc as if the backend is ready even though it isn't. Then, in the near future, it'll be cheaper to plug in the real data. The re-frame architecture is perfect for that. IMO it's also a better practice because it leads to higher quality client code.

    I guess this strategy should've been aligned before any implementation was done. Anyway, just a light suggestion for refactor because I know you inherited the implementation like this before working on this PR, so you're just following the flow.

    (fn [v]
    (if (empty? v)
    (set-flow-state nil)
    ;; TODO check for validation
    Copy link
    Contributor

    Choose a reason for hiding this comment

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

    Following our guidelines for TODOs, I think these TODOs should be deleted and instead, whatever is left to do after this PR should be explained in a new or existing issue.

    {:keypair-name key-pair-name}])
    (js/alert "Unknown workflow")))
    [workflow key-pair-name])
    disabled? (or (some? error) (string/blank? key-pair-name))]
    Copy link
    Contributor

    Choose a reason for hiding this comment

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

    A light suggestion: disabled? is a name coupled with what the footer expects, but this is not necessarily obvious because it requires the dev to jump down a few lines. If we name the binding invalid-key-name? then I think we decouple them more and the binding has meaning on its own, which helps read the code line by line.

    (set-key-pair-name value)
    (cond
    (> (count value) key-pair-name-max-length)
    (set-error :too-long)
    Copy link
    Contributor

    Choose a reason for hiding this comment

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

    Hum, I think we can separate side-effectful code from pure code.

    My suggestion here is to define a pure function validate-key-pair-name as a separate var that returns the type of error or nil. Then, your on-change-text will be just two nice lines:

    (rn/use-callback
     (fn [value]
       (set-key-pair-name value)
       (set-error (validate-key-pair-name value))))

    After this new function is defined, I would unit test it in a file named view_test.cljs.

    Another interesting option is to completely extract the validation part from the view namespace and move them to a validation.cljs file inside key_pair_name/. That way the design sort of forces developers to keep pure code more separated from side-effects and also creates a stronger incentive to unit test the behavior because in view namespaces there's a strong tendency to not unit test anything there.

    @mariia-skrypnyk
    Copy link

    Hey @Rende11 🙌!

    Thanks for your PR!
    All failed e2e tests are known and not related to your PR.

    @churik churik moved this from E2E Tests to MERGE in Pipeline for QA May 9, 2024
    @flexsurfer
    Copy link
    Member

    hey @J-Son89 should we merge this?

    @J-Son89
    Copy link
    Member

    J-Son89 commented May 13, 2024

    @flexsurfer - yes let's merge and I can address @ilmotta's comments in a follow up pr 👍

    @flexsurfer flexsurfer merged commit 2618a55 into status-im:develop May 13, 2024
    4 of 5 checks passed
    Pipeline for QA automation moved this from MERGE to DONE May 13, 2024
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    Development

    Successfully merging this pull request may close these issues.

    Wallet - Import private key flow - Add UI for Key Pair Name
    10 participants