Skip to content

Commit 2eee4fe

Browse files
committed
Implement trust status actions
1 parent 11b89cc commit 2eee4fe

File tree

6 files changed

+78
-14
lines changed

6 files changed

+78
-14
lines changed

src/status_im/common/home/actions/view.cljs

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@
131131
public-key])}])}]))
132132

133133
(defn mark-as-untrusted-action
134-
[{:keys [public-key] :as item}]
134+
[{:keys [public-key primary-name] :as item}]
135135
(hide-sheet-and-dispatch
136136
[:show-bottom-sheet
137137
{:content (fn []
@@ -142,7 +142,13 @@
142142
:context item
143143
:accessibility-label :block-user
144144
:button-text (i18n/label :t/mark-as-untrusted-button)
145-
:on-press #(print "Not implemented")}])}]))
145+
:on-press #(hide-sheet-and-dispatch
146+
[:contact/mark-as-untrusted
147+
public-key primary-name])}])}]))
148+
149+
(defn remove-untrusted-mark-action
150+
[{:keys [public-key primary-name]}]
151+
(hide-sheet-and-dispatch [:contact/remove-trust-status public-key primary-name]))
146152

147153
(defn mute-chat-entry
148154
[chat-id chat-type muted-till]
@@ -314,17 +320,22 @@
314320
:sub-label nil
315321
:chevron? false}))
316322

317-
(defn mark-untrustworthy-entry
318-
[item]
319-
(entry {:icon :i/untrustworthy
320-
:label (i18n/label :t/mark-as-untrusted)
321-
;; :on-press #(js/alert "TODO: to be implemented, requires status-go impl.")
322-
:on-press #(mark-as-untrusted-action item)
323-
:danger? true
324-
:accessibility-label :mark-as-untrusted
325-
:sub-label nil
326-
:chevron? false
327-
:add-divider? true}))
323+
(defn change-trust-status-entry
324+
[{:keys [trust-status] :as item}]
325+
(let [handle-press (if (= trust-status
326+
constants/contact-trust-status-untrustworthy)
327+
remove-untrusted-mark-action
328+
mark-as-untrusted-action)]
329+
(entry {:icon :i/untrustworthy
330+
:label (i18n/label (if (= trust-status
331+
constants/contact-trust-status-untrustworthy)
332+
:t/remove-untrusted-mark
333+
:t/mark-as-untrusted))
334+
:on-press #(handle-press item)
335+
:danger? true
336+
:accessibility-label :mark-as-untrusted
337+
:sub-label nil
338+
:chevron? false})))
328339

329340
(defn block-user-entry
330341
[item]
@@ -460,7 +471,7 @@
460471
(show-qr-entry public-key)
461472
(share-profile-entry public-key)]
462473
[(when-not (= current-pub-key public-key)
463-
(mark-untrustworthy-entry contact))
474+
(change-trust-status-entry contact))
464475
(when added? (remove-from-contacts-entry contact))
465476
(when-not (= current-pub-key public-key) (block-user-entry contact))]
466477
(when (and admin? chat-id)

src/status_im/constants.cljs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,3 +494,8 @@
494494

495495
(def ^:const pre-login-log-level-key "pre-login-log-level")
496496
(def ^:const report-email "[email protected]")
497+
498+
;; Contact trust status
499+
(def ^:const contact-trust-status-unknown 0)
500+
(def ^:const contact-trust-status-trusted 1)
501+
(def ^:const contact-trust-status-untrustworthy 2)

src/status_im/contexts/chat/contacts/events.cljs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
:last-updated (oops/oget js-contact "lastUpdated")
2323
:active? (oops/oget js-contact "active")
2424
:blocked? (oops/oget js-contact "blocked")
25+
:trust-status (oops/oget js-contact "trustStatus")
2526
:added? (oops/oget js-contact "added")
2627
:has-added-us? (oops/oget js-contact "hasAddedUs")
2728
:mutual? (oops/oget js-contact "mutual")
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
(ns status-im.contexts.contact.trust.events
2+
(:require
3+
[re-frame.core :as re-frame]
4+
[status-im.constants :as constants]
5+
[taoensso.timbre :as log]
6+
[utils.i18n :as i18n]
7+
[utils.re-frame :as rf]))
8+
9+
(rf/reg-event-fx :contact/mark-as-untrusted-success
10+
(fn [{:keys [db]} [contact-id name]]
11+
{:db (update-in db
12+
[:contacts/contacts contact-id]
13+
#(assoc % :trust-status constants/contact-trust-status-untrustworthy))
14+
:dispatch
15+
[:toasts/upsert
16+
{:type :positive
17+
:text (i18n/label :t/marked-as-untrusted {:username name})}]}))
18+
19+
(rf/reg-event-fx :contact/mark-as-untrusted
20+
(fn [_ [contact-id name]]
21+
{:json-rpc/call
22+
[{:method "wakuext_markAsUntrustworthy"
23+
:params [contact-id]
24+
:on-success #(re-frame/dispatch [:contact/mark-as-untrusted-success contact-id name])
25+
:on-error #(log/error "failed mark contact as untrusted" % contact-id)}]}))
26+
27+
(rf/reg-event-fx :contact/remove-trust-status-success
28+
(fn [{:keys [db]} [contact-id name]]
29+
{:db (update-in db
30+
[:contacts/contacts contact-id]
31+
#(assoc % :trust-status constants/contact-trust-status-unknown))
32+
:dispatch
33+
[:toasts/upsert
34+
{:type :positive
35+
:text (i18n/label :t/trust-mark-removed {:username name})}]}))
36+
37+
(rf/reg-event-fx :contact/remove-trust-status
38+
(fn [_ [contact-id name]]
39+
{:json-rpc/call
40+
[{:method "wakuext_removeTrustStatus"
41+
:params [contact-id]
42+
:on-success #(re-frame/dispatch [:contact/remove-trust-status-success contact-id name])
43+
:on-error #(log/error "failed remove contact trust status" % contact-id)}]}))

src/status_im/events.cljs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
status-im.contexts.communities.overview.events
2727
status-im.contexts.communities.sharing.events
2828
status-im.contexts.contact.blocking.events
29+
status-im.contexts.contact.trust.events
2930
status-im.contexts.keycard.change-pin.events
3031
status-im.contexts.keycard.effects
3132
status-im.contexts.keycard.events

translations/en.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1608,6 +1608,7 @@
16081608
"mark-as-untrusted-button": "Mark",
16091609
"mark-as-untrusted-description": "{{username}} will be marked as untrusted. This mark will only be visible to you.",
16101610
"mark-user-untrustworthy": "Mark {{username}} as untrustworthy",
1611+
"marked-as-untrusted": "{{username}} is marked as untrusted",
16111612
"market": "Market",
16121613
"market-cap": "Market cap",
16131614
"master-account": "Master account",
@@ -2235,6 +2236,7 @@
22352236
"remove-saved-address": "Remove saved address",
22362237
"remove-saved-address-description": "Transaction history relating to this address will no longer be labelled ‘{{name}}’.",
22372238
"remove-token": "Remove token",
2239+
"remove-untrusted-mark": "Remove untrusted mark",
22382240
"remove-user-from-group": "Remove {{username}} from the group",
22392241
"remove-watched-address-desc": "The watched address will be removed from all of your synced devices.",
22402242
"remove-watched-address-title": "Remove watched address",
@@ -2756,6 +2758,7 @@
27562758
"tribute-to-talk-tribute-received2": " are now contacts and can securely chat with each other.",
27572759
"tribute-to-talk-you-require-snt": "You require SNT for new people to start a chat.",
27582760
"trip-accounts": "Trip accounts",
2761+
"trust-mark-removed": "Trust mark removed for {{username}}",
27592762
"try-again": "Try again",
27602763
"try-keeping-the-card-still": "Try keeping the card still",
27612764
"try-to-search-something-else": "Try to search something else",

0 commit comments

Comments
 (0)