diff --git a/src/status_im/contexts/profile/edit/bio/events.cljs b/src/status_im/contexts/profile/edit/bio/events.cljs index dea797226cea..c72b8674bea4 100644 --- a/src/status_im/contexts/profile/edit/bio/events.cljs +++ b/src/status_im/contexts/profile/edit/bio/events.cljs @@ -4,8 +4,9 @@ [utils.re-frame :as rf])) (rf/reg-event-fx :profile/edit-profile-bio-success - (fn [_ [added?]] - {:fx [[:dispatch [:navigate-back]] + (fn [_ [{:keys [bio added?]}]] + {:fx [[:dispatch [:profile/save-local-profile-bio bio]] + [:dispatch [:navigate-back]] [:dispatch [:toasts/upsert {:type :positive @@ -14,13 +15,18 @@ (i18n/label :t/bio-added) (i18n/label :t/bio-updated))}]]]})) +(rf/reg-event-fx :profile/save-local-profile-bio + (fn [{:keys [db]} [bio]] + {:db (assoc-in db [:profile/profile :bio] bio)})) + (defn edit-profile-bio [{:keys [db]} [new-bio]] (let [{:keys [bio]} (:profile/profile db)] - {:db (assoc-in db [:profile/profile :bio] new-bio) - :fx [[:json-rpc/call + {:fx [[:json-rpc/call [{:method "wakuext_setBio" :params [new-bio] - :on-success [:profile/edit-profile-bio-success (string/blank? bio)]}]]]})) + :on-success [:profile/edit-profile-bio-success + {:bio new-bio + :added? (string/blank? bio)}]}]]]})) (rf/reg-event-fx :profile/edit-bio edit-profile-bio) diff --git a/src/status_im/contexts/profile/edit/bio/events_test.cljs b/src/status_im/contexts/profile/edit/bio/events_test.cljs index 19f887d20a4d..d1f8684a6525 100644 --- a/src/status_im/contexts/profile/edit/bio/events_test.cljs +++ b/src/status_im/contexts/profile/edit/bio/events_test.cljs @@ -10,6 +10,8 @@ :fx [[:json-rpc/call [{:method "wakuext_setBio" :params [new-bio] - :on-success [:profile/edit-profile-bio-success false]}]]]}] + :on-success [:profile/edit-profile-bio-success + {:bio new-bio + :added? false}]}]]]}] (is (match? expected (sut/edit-profile-bio cofx [new-bio]))))) diff --git a/src/tests/contract_test/profile_test.cljs b/src/tests/contract_test/profile_test.cljs new file mode 100644 index 000000000000..7de03fa98eb6 --- /dev/null +++ b/src/tests/contract_test/profile_test.cljs @@ -0,0 +1,25 @@ +(ns tests.contract-test.profile-test + (:require + [cljs.test :refer [deftest is]] + [day8.re-frame.test :as rf-test] + legacy.status-im.events + [legacy.status-im.multiaccounts.logout.core :as logout] + legacy.status-im.subs.root + status-im.events + status-im.navigation.core + status-im.subs.root + [test-helpers.integration :as h] + [tests.contract-test.utils :as contract-utils])) + +(deftest profile-set-bio-contract + (h/log-headline :contract/wakuext_setBio) + (rf-test/run-test-async + (h/with-app-initialized + (h/with-account + (contract-utils/call-rpc-endpoint + {:rpc-endpoint "wakuext_setBio" + :params ["new bio"] + :on-error #(is (nil? %) "Set bio RPC call should have succeeded")}) + (h/logout) + (rf-test/wait-for + [::logout/logout-method])))))