-
Notifications
You must be signed in to change notification settings - Fork 985
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
df76881
commit 675897c
Showing
13 changed files
with
182 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
(ns status-im.contexts.profile.edit.header.events | ||
(:require [clojure.string :as string] | ||
[status-im.common.profile-picture-picker.view :as profile-picture-picker] | ||
[utils.i18n :as i18n] | ||
[utils.re-frame :as rf])) | ||
|
||
(rf/reg-event-fx :profile/update-local-picture | ||
(fn [{:keys [db]} [images]] | ||
{:db (if images | ||
(assoc-in db [:profile/profile :images] images) | ||
(update db :profile/profile dissoc :images))})) | ||
|
||
(rf/reg-event-fx :profile/edit-profile-picture-success | ||
(fn [_ [images]] | ||
{:fx [[:dispatch [:profile/update-local-picture (reverse images)]] | ||
[:dispatch | ||
[:toasts/upsert | ||
{:type :positive | ||
:theme :dark | ||
:text (i18n/label :t/profile-picture-added)}]]]})) | ||
|
||
(defn edit-profile-picture | ||
[{:keys [db]} [picture crop-width crop-height]] | ||
(let [key-uid (get-in db [:profile/profile :key-uid]) | ||
crop-width (or crop-width profile-picture-picker/crop-size) | ||
crop-height (or crop-height profile-picture-picker/crop-size) | ||
path (string/replace-first picture #"file://" "")] | ||
{:fx [[:json-rpc/call | ||
[{:method "multiaccounts_storeIdentityImage" | ||
:params [key-uid path 0 0 crop-width crop-height] | ||
:on-success [:profile/edit-profile-picture-success]}]]]})) | ||
|
||
(rf/reg-event-fx :profile/edit-picture edit-profile-picture) | ||
|
||
(rf/reg-event-fx :profile/delete-profile-picture-success | ||
(fn [_] | ||
{:fx [[:dispatch [:profile/update-local-picture nil]] | ||
[:dispatch | ||
[:toasts/upsert | ||
{:type :positive | ||
:theme :dark | ||
:text (i18n/label :t/profile-picture-removed)}]]]})) | ||
|
||
(defn delete-profile-picture | ||
[{:keys [db]}] | ||
(let [key-uid (get-in db [:profile/profile :key-uid])] | ||
{:fx [[:json-rpc/call | ||
[{:method "multiaccounts_deleteIdentityImage" | ||
:params [key-uid] | ||
:on-success [:profile/delete-profile-picture-success]}]]]})) | ||
|
||
(rf/reg-event-fx :profile/delete-picture delete-profile-picture) |
27 changes: 27 additions & 0 deletions
27
src/status_im/contexts/profile/edit/header/events_test.cljs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
(ns status-im.contexts.profile.edit.header.events-test | ||
(:require [cljs.test :refer [deftest is]] | ||
matcher-combinators.test | ||
[status-im.common.profile-picture-picker.view :as profile-picture-picker] | ||
[status-im.contexts.profile.edit.header.events :as sut])) | ||
|
||
(deftest edit-picture-test | ||
(let [picture "new-picture" | ||
key-uid "key-uid" | ||
cofx {:db {:profile/profile {:key-uid key-uid}}} | ||
expected {:fx [[:json-rpc/call | ||
[{:method "multiaccounts_storeIdentityImage" | ||
:params [key-uid picture 0 0 profile-picture-picker/crop-size | ||
profile-picture-picker/crop-size] | ||
:on-success [:profile/edit-profile-picture-success]}]]]}] | ||
(is (match? expected | ||
(sut/edit-profile-picture cofx [picture]))))) | ||
|
||
(deftest delete-picture-test | ||
(let [key-uid "key-uid" | ||
cofx {:db {:profile/profile {:key-uid key-uid}}} | ||
expected {:fx [[:json-rpc/call | ||
[{:method "multiaccounts_deleteIdentityImage" | ||
:params [key-uid] | ||
:on-success [:profile/delete-profile-picture-success]}]]]}] | ||
(is (match? expected | ||
(sut/delete-profile-picture cofx))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters