fix: generate_profile_url crash when login (#18364)

* fix: generate_profile_url.cljs$core$IFn$_invoke$arity$2 crash when login

'status_im.common.universal_links.generate_profile_url.cljs$core$IFn$_invoke$arity$2' is undefined

update the function to a fixed arity function

* fix: schema/=> macro for :function schema

Signed-off-by: yqrashawn <namy.19@gmail.com>

---------

Signed-off-by: yqrashawn <namy.19@gmail.com>
This commit is contained in:
yqrashawn 2024-01-05 20:08:13 +08:00 committed by GitHub
parent c91b4339dc
commit be2d0feda3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 66 additions and 75 deletions

View File

@ -5,11 +5,17 @@
in non-debug environments. in non-debug environments.
`value` is first transformed via `malli.core/schema` to make sure we fail fast `value` is first transformed via `malli.core/schema` to make sure we fail fast
and only register valid schemas." and only register valid schemas.
Pass raw schema `value` instead of schema instance when it's `:function` schema
https://github.com/status-im/status-mobile/pull/18364#issuecomment-1875543794"
[sym value] [sym value]
`(if ^boolean js/goog.DEBUG `(if ^boolean js/goog.DEBUG
(try (try
(malli.core/=> ~sym (malli.core/schema ~value)) (let [schema-instance# (malli.core/schema ~value)]
(if (and (seq ~value) (= :function (first ~value)))
(malli.core/=> ~sym ~value)
(malli.core/=> ~sym schema-instance#)))
(catch js/Error e# (catch js/Error e#
(taoensso.timbre/error "Failed to instrument function" (taoensso.timbre/error "Failed to instrument function"
{:symbol ~sym :error e#}) {:symbol ~sym :error e#})

View File

@ -200,8 +200,7 @@
(handle-url url)))) (handle-url url))))
(defn generate-profile-url (defn generate-profile-url
([cofx] (generate-profile-url cofx nil)) [{:keys [db]} [{:keys [public-key cb]}]]
([{:keys [db]} [{:keys [public-key cb]}]]
(let [profile-public-key (get-in db [:profile/profile :public-key]) (let [profile-public-key (get-in db [:profile/profile :public-key])
profile? (or (not public-key) (= public-key profile-public-key)) profile? (or (not public-key) (= public-key profile-public-key))
ens-name? (if profile? ens-name? (if profile?
@ -217,7 +216,7 @@
(when (fn? cb) (cb))) (when (fn? cb) (cb)))
:on-error #(log/error "failed to wakuext_shareUserURLWithData" :on-error #(log/error "failed to wakuext_shareUserURLWithData"
{:error % {:error %
:public-key public-key})}]})))) :public-key public-key})}]})))
(schema/=> generate-profile-url (schema/=> generate-profile-url
[:=> [:=>

View File

@ -5,10 +5,13 @@
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[status-im.common.universal-links :as links])) [status-im.common.universal-links :as links]))
(def pubkey
"0x04fbce10971e1cd7253b98c7b7e54de3729ca57ce41a2bfb0d1c4e0a26f72c4b6913c3487fa1b4bb86125770f1743fb4459da05c1cbe31d938814cfaf36e252073")
(deftest handle-url-test (deftest handle-url-test
(testing "the user is not logged in" (testing "the user is not logged in"
(testing "it stores the url for later processing" (testing "it stores the url for later processing"
(is (= {:db {:universal-links/url "some-url"}} (is (match? {:db {:universal-links/url "some-url"}}
(links/handle-url {:db {}} "some-url"))))) (links/handle-url {:db {}} "some-url")))))
(testing "the user is logged in" (testing "the user is logged in"
(let [db {:profile/profile {:public-key "pk"} (let [db {:profile/profile {:public-key "pk"}
@ -18,7 +21,7 @@
(is (nil? (get-in (links/handle-url {:db db} "some-url") (is (nil? (get-in (links/handle-url {:db db} "some-url")
[:db :universal-links/url])))) [:db :universal-links/url]))))
(testing "Handle a custom string" (testing "Handle a custom string"
(is (= (get-in (links/handle-url {:db db} "https://status.app/u#statuse2e") (is (match? (get-in (links/handle-url {:db db} "https://status.app/u#statuse2e")
[:router/handle-uri :uri]) [:router/handle-uri :uri])
"https://status.app/u#statuse2e")))))) "https://status.app/u#statuse2e"))))))
@ -28,77 +31,58 @@
(let [actual (atom nil)] (let [actual (atom nil)]
(with-redefs [re-frame/dispatch #(reset! actual %)] (with-redefs [re-frame/dispatch #(reset! actual %)]
(links/url-event-listener #js {:url "some-url"}) (links/url-event-listener #js {:url "some-url"})
(is (= [:universal-links/handle-url "some-url"] @actual)))))) (is (match? [:universal-links/handle-url "some-url"] @actual))))))
(testing "the url is nil" (testing "the url is nil"
(testing "it does not dispatches the url" (testing "it does not dispatches the url"
(let [actual (atom nil)] (let [actual (atom nil)]
(with-redefs [re-frame/dispatch #(reset! actual %)] (with-redefs [re-frame/dispatch #(reset! actual %)]
(links/url-event-listener #js {}) (links/url-event-listener #js {})
(is (= nil @actual))))))) (is (match? nil @actual)))))))
(deftest generate-profile-url (deftest generate-profile-url
(testing "user has ens name" (testing "user has ens name"
(testing "it calls the ens rpc method with ens name as param" (testing "it calls the ens rpc method with ens name as param"
(let [pubkey "pubkey" (let [db {:profile/profile {:ens-name? true :public-key pubkey}}
db {:profile/profile {:ens-name? true :public-key pubkey}} rst (links/generate-profile-url {:db db} [])]
rst (links/generate-profile-url {:db db})] (are [result expected] (match? result expected)
(are [result expected] (= result expected)
"wakuext_shareUserURLWithENS" (-> rst :json-rpc/call first :method) "wakuext_shareUserURLWithENS" (-> rst :json-rpc/call first :method)
pubkey (-> rst :json-rpc/call first :params first))))) pubkey (-> rst :json-rpc/call first :params first)))))
(testing "user has no ens name" (testing "user has no ens name"
(testing "it calls the ens rpc method with public keyas param" (testing "it calls the ens rpc method with public keyas param"
(let [pubkey "pubkey" (let [db {:profile/profile {:public-key pubkey}}
db {:profile/profile {:public-key pubkey}} rst (links/generate-profile-url {:db db} [])]
rst (links/generate-profile-url {:db db})] (are [result expected] (match? result expected)
(are [result expected] (= result expected)
"wakuext_shareUserURLWithData" (-> rst :json-rpc/call first :method) "wakuext_shareUserURLWithData" (-> rst :json-rpc/call first :method)
pubkey (-> rst :json-rpc/call first :params first))))) pubkey (-> rst :json-rpc/call first :params first)))))
(testing "contact has ens name" (testing "contact has ens name"
(testing "it calls the ens rpc method with ens name as param" (testing "it calls the ens rpc method with ens name as param"
(let [pubkey "pubkey" (let [ens "ensname.eth"
ens "ensname.eth"
db {:contacts/contacts {pubkey {:ens-name ens}}} db {:contacts/contacts {pubkey {:ens-name ens}}}
rst (links/generate-profile-url {:db db} [{:public-key pubkey}])] rst (links/generate-profile-url {:db db} [{:public-key pubkey}])]
(are [result expected] (= result expected) (are [result expected] (match? result expected)
"wakuext_shareUserURLWithENS" (-> rst :json-rpc/call first :method) "wakuext_shareUserURLWithENS" (-> rst :json-rpc/call first :method)
pubkey (-> rst :json-rpc/call first :params first))))) pubkey (-> rst :json-rpc/call first :params first)))))
(testing "contact has no ens name" (testing "contact has no ens name"
(testing "it calls the ens rpc method with public keyas param" (testing "it calls the ens rpc method with public keyas param"
(let [pubkey "pubkey" (let [db {:contacts/contacts {pubkey {:public-key pubkey}}}
db {:contacts/contacts {pubkey {:public-key pubkey}}}
rst (links/generate-profile-url {:db db} [{:public-key pubkey}])] rst (links/generate-profile-url {:db db} [{:public-key pubkey}])]
(are [result expected] (= result expected) (are [result expected] (match? result expected)
"wakuext_shareUserURLWithData" (-> rst :json-rpc/call first :method) "wakuext_shareUserURLWithData" (-> rst :json-rpc/call first :method)
pubkey (-> rst :json-rpc/call first :params first)))))) pubkey (-> rst :json-rpc/call first :params first))))))
(deftest save-profile-url (deftest save-profile-url
(testing "given a contact public key and profile url" (testing "given a contact public key and profile url"
(testing "it updates the contact in db" (testing "it updates the contact in db"
(let [pubkey "pubkey" (let [url "url"
url "url"
db {:contacts/contacts {pubkey {:public-key pubkey}}} db {:contacts/contacts {pubkey {:public-key pubkey}}}
rst (links/save-profile-url {:db db} [pubkey url])] rst (links/save-profile-url {:db db} [pubkey url])]
(is (= (get-in rst [:db :contacts/contacts pubkey :universal-profile-url]) url))))) (is (match? (get-in rst [:db :contacts/contacts pubkey :universal-profile-url]) url)))))
(testing "given a user public key and profile url" (testing "given a user public key and profile url"
(testing "it updates the user profile in db" (testing "it updates the user profile in db"
(let [pubkey "pubkey" (let [url "url"
url "url"
db {:profile/profile {:public-key pubkey}} db {:profile/profile {:public-key pubkey}}
rst (links/save-profile-url {:db db} [pubkey url])] rst (links/save-profile-url {:db db} [pubkey url])]
(is (= (get-in rst [:db :profile/profile :universal-profile-url]) url))))) (is (match? (get-in rst [:db :profile/profile :universal-profile-url]) url))))))
(testing "given a invalid url"
(testing "it returns the db untouched"
(let [pubkey "pubkey"
url "url"
db {:profile/profile {:public-key pubkey}}
rst (links/save-profile-url {:db db} ["invalid pubkey" url])]
(is (= (:db rst) db)))))
(testing "given a nil as url"
(testing "it returns nil"
(let [pubkey "pubkey"
db {:profile/profile {:public-key pubkey}}
rst (links/save-profile-url {:db db} ["invalid pubkey"])]
(is (nil? rst))))))
(deftest universal-link-test (deftest universal-link-test
(testing "universal-link?" (testing "universal-link?"

View File

@ -80,9 +80,10 @@
[:cofx :schema.re-frame/cofx] [:cofx :schema.re-frame/cofx]
[:args [:args
[:schema [:catn [:community-id [:? :string]]]]]] [:schema [:catn [:community-id [:? :string]]]]]]
[:maybe
[:map [:map
[:db map?] [:db map?]
[:json-rpc/call :schema.common/rpc-call]]]) [:json-rpc/call :schema.common/rpc-call]]]])
(rf/reg-event-fx :chat.ui/fetch-community fetch-community) (rf/reg-event-fx :chat.ui/fetch-community fetch-community)
@ -124,9 +125,10 @@
[:cofx :schema.re-frame/cofx] [:cofx :schema.re-frame/cofx]
[:args [:args
[:schema [:catn [:community-id [:? :string]]]]]] [:schema [:catn [:community-id [:? :string]]]]]]
[:maybe
[:map [:map
[:db map?] [:db map?]
[:json-rpc/call :schema.common/rpc-call]]]) [:json-rpc/call :schema.common/rpc-call]]]])
(rf/reg-event-fx :chat.ui/spectate-community spectate-community) (rf/reg-event-fx :chat.ui/spectate-community spectate-community)

View File

@ -17,11 +17,11 @@
:TryDatabase true :TryDatabase true
:WaitForResponse true}]}]} :WaitForResponse true}]}]}
(sut/fetch-community {} ["community-id"]))))) (sut/fetch-community {} ["community-id"])))))
(t/testing "with nil community id" (t/testing "with no community id"
(t/testing "do nothing" (t/testing "do nothing"
(t/is (match? (t/is (match?
nil nil
(sut/fetch-community {} nil)))))) (sut/fetch-community {} []))))))
(t/deftest community-failed-to-resolve (t/deftest community-failed-to-resolve
(t/testing "given a community id" (t/testing "given a community id"