|
2 | 2 | (:require [clojure.string :as string] |
3 | 3 | [quo.core :as quo] |
4 | 4 | [react-native.core :as rn] |
5 | | - [status-im.common.not-implemented :as not-implemented] |
6 | 5 | [status-im.constants :as constants] |
7 | 6 | [status-im.contexts.profile.contact.add-nickname.view :as add-nickname] |
8 | 7 | [status-im.contexts.profile.contact.block-contact.view :as block-contact] |
9 | 8 | [status-im.contexts.profile.utils :as profile.utils] |
10 | 9 | [utils.i18n :as i18n] |
11 | 10 | [utils.re-frame :as rf])) |
12 | 11 |
|
| 12 | +(defn hide-sheet-and-dispatch |
| 13 | + [event] |
| 14 | + (rf/dispatch [:hide-bottom-sheet]) |
| 15 | + (rf/dispatch event)) |
| 16 | + |
13 | 17 | (defn on-add-nickname |
14 | 18 | [] |
15 | 19 | (rf/dispatch [:show-bottom-sheet |
|
25 | 29 | (defn view |
26 | 30 | [] |
27 | 31 | (let [{:keys [nickname public-key contact-request-state blocked? trust-status] |
28 | | - :as contact} (rf/sub [:contacts/current-contact]) |
29 | | - full-name (profile.utils/displayed-name contact) |
30 | | - on-remove-nickname (rn/use-callback |
31 | | - (fn [] |
32 | | - (rf/dispatch [:hide-bottom-sheet]) |
33 | | - (rf/dispatch [:toasts/upsert |
34 | | - {:id :remove-nickname |
35 | | - :type :positive |
36 | | - :text (i18n/label :t/nickname-removed)}]) |
37 | | - (rf/dispatch [:contacts/update-nickname public-key ""])) |
38 | | - [public-key]) |
39 | | - on-show-qr (rn/use-callback |
40 | | - (fn [] |
41 | | - (rf/dispatch [:universal-links/generate-profile-url |
42 | | - {:public-key public-key |
43 | | - :on-success #(rf/dispatch [:open-modal |
44 | | - :screen/share-contact])}])) |
45 | | - [public-key]) |
46 | | - has-nickname? (rn/use-memo (fn [] (not (string/blank? nickname))) [nickname]) |
47 | | - on-share-profile (rn/use-callback |
48 | | - (fn [] |
49 | | - (rf/dispatch [:universal-links/generate-profile-url |
50 | | - {:public-key public-key |
51 | | - :on-success #(rf/dispatch [:open-share |
52 | | - {:options {:message %}}])}])) |
53 | | - [public-key]) |
54 | | - on-remove-contact (rn/use-callback |
55 | | - (fn [] |
56 | | - (rf/dispatch [:hide-bottom-sheet]) |
57 | | - (rf/dispatch [:toasts/upsert |
58 | | - {:id :remove-contact |
59 | | - :type :positive |
60 | | - :text (->> (i18n/label :t/removed-from-contacts) |
61 | | - (string/lower-case) |
62 | | - (str full-name " "))}]) |
63 | | - (rf/dispatch [:contact.ui/remove-contact-pressed contact])) |
64 | | - [public-key full-name])] |
| 32 | + :as contact} (rf/sub [:contacts/current-contact]) |
| 33 | + full-name (profile.utils/displayed-name contact) |
| 34 | + on-remove-nickname (rn/use-callback |
| 35 | + (fn [] |
| 36 | + (rf/dispatch [:hide-bottom-sheet]) |
| 37 | + (rf/dispatch [:toasts/upsert |
| 38 | + {:id :remove-nickname |
| 39 | + :type :positive |
| 40 | + :text (i18n/label :t/nickname-removed)}]) |
| 41 | + (rf/dispatch [:contacts/update-nickname public-key ""])) |
| 42 | + [public-key]) |
| 43 | + on-show-qr (rn/use-callback |
| 44 | + (fn [] |
| 45 | + (rf/dispatch [:universal-links/generate-profile-url |
| 46 | + {:public-key public-key |
| 47 | + :on-success #(rf/dispatch [:open-modal |
| 48 | + :screen/share-contact])}])) |
| 49 | + [public-key]) |
| 50 | + has-nickname? (rn/use-memo (fn [] (not (string/blank? nickname))) [nickname]) |
| 51 | + on-share-profile (rn/use-callback |
| 52 | + (fn [] |
| 53 | + (rf/dispatch [:universal-links/generate-profile-url |
| 54 | + {:public-key public-key |
| 55 | + :on-success #(rf/dispatch [:open-share |
| 56 | + {:options {:message %}}])}])) |
| 57 | + [public-key]) |
| 58 | + untrustworthy? (rn/use-memo (fn [] |
| 59 | + (= trust-status |
| 60 | + constants/contact-trust-status-untrustworthy)) |
| 61 | + [trust-status]) |
| 62 | + on-trust-mark-press (rn/use-callback |
| 63 | + (fn [] |
| 64 | + (hide-sheet-and-dispatch |
| 65 | + (if untrustworthy? |
| 66 | + [:contact/remove-trust-status public-key full-name] |
| 67 | + [:contact/mark-as-untrusted-sheet contact]))) |
| 68 | + [untrustworthy? contact]) |
| 69 | + on-remove-contact (rn/use-callback |
| 70 | + (fn [] |
| 71 | + (rf/dispatch [:hide-bottom-sheet]) |
| 72 | + (rf/dispatch [:toasts/upsert |
| 73 | + {:id :remove-contact |
| 74 | + :type :positive |
| 75 | + :text (->> (i18n/label :t/removed-from-contacts) |
| 76 | + (string/lower-case) |
| 77 | + (str full-name " "))}]) |
| 78 | + (rf/dispatch [:contact.ui/remove-contact-pressed contact])) |
| 79 | + [public-key full-name])] |
65 | 80 | [quo/action-drawer |
66 | 81 | [(concat |
67 | 82 | [{:icon :i/edit |
|
87 | 102 | :accessibility-label :remove-nickname |
88 | 103 | :danger? true}) |
89 | 104 | {:icon :i/untrustworthy |
90 | | - :label (i18n/label (if (= trust-status |
91 | | - constants/contact-trust-status-untrustworthy) |
| 105 | + :label (i18n/label (if untrustworthy? |
92 | 106 | :t/remove-untrusted-mark |
93 | 107 | :t/mark-as-untrusted)) |
94 | | - :on-press not-implemented/alert |
| 108 | + :on-press on-trust-mark-press |
95 | 109 | :accessibility-label :mark-as-untrusted |
96 | 110 | :add-divider? (when-not has-nickname? true) |
97 | 111 | :danger? true} |
|
0 commit comments