Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move status-im from utils #18249

Merged
merged 4 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion scripts/lint/re-frame-in-quo-components.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
#!/usr/bin/env sh

INVALID_CHANGES=$(grep -E -r '(re-frame/dispatch|rf/dispatch|re-frame/subscribe|rf/subscribe|rf/sub|<sub|>evt|status-im\.|status-im2\.)' --include '*.cljs' --include '*.clj' './src/quo')
INVALID_CHANGES=$(grep -E -r '(re-frame/dispatch|rf/dispatch|re-frame/subscribe|rf/subscribe|rf/sub|<sub|>evt|status-im\.)' --include '*.cljs' --include '*.clj' './src/quo')

if test -n "$INVALID_CHANGES"; then
echo "WARNING: re-frame, status-im are not allowed in quo components"
echo ''
echo "$INVALID_CHANGES"
exit 1
fi

INVALID_CHANGES2=$(grep -E -r '(status-im\.)' --include '*.cljs' --include '*.clj' './src/utils')

if test -n "$INVALID_CHANGES2"; then
echo "WARNING: status-im are not allowed in utils package"
echo ''
echo "$INVALID_CHANGES2"
exit 1
fi

INVALID_CHANGES3=$(grep -E -r '(status-im\.)' --include '*.cljs' --include '*.clj' './src/react_native')

if test -n "$INVALID_CHANGES3"; then
echo "WARNING: status-im are not allowed in react-native package"
echo ''
echo "$INVALID_CHANGES3"
exit 1
fi
siddarthkay marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion src/legacy/status_im/browser/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
[native-module.core :as native-module]
[re-frame.core :as re-frame]
[react-native.platform :as platform]
[status-im.common.universal-links :as links]
[status-im.constants :as constants]
[status-im.contexts.chat.events :as chat.events]
[status-im.navigation.events :as navigation]
Expand All @@ -27,7 +28,6 @@
[utils.i18n :as i18n]
[utils.re-frame :as rf]
[utils.security.core :as security]
[utils.universal-links :as links]
[utils.url :as url]))

(rf/defn update-browser-option
Expand Down
2 changes: 1 addition & 1 deletion src/legacy/status_im/wallet/choose_recipient/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
[legacy.status-im.wallet.utils :as wallet.utils]
[re-frame.core :as re-frame]
[status-im.common.router :as router]
[status-im.common.universal-links :as links]
[status-im.navigation.events :as navigation]
[utils.ethereum.chain :as chain]
[utils.i18n :as i18n]
[utils.money :as money]
[utils.re-frame :as rf]
[utils.universal-links :as links]
[utils.url :as url]))

;; FIXME(Ferossgp): Should be part of QR scanner not wallet
Expand Down
8 changes: 7 additions & 1 deletion src/status_im/common/font/effects.cljs
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
(ns status-im.common.font.effects
(:require
[react-native.platform :as platform]
[status-im.constants :as constants]
utils.image-server
[utils.re-frame :as rf]))

(rf/reg-fx :effects.font/get-font-file-for-initials-avatar
(fn [callback]
(utils.image-server/get-font-file-ready callback)))
(utils.image-server/get-font-file-ready
(if platform/ios?
(:ios constants/initials-avatar-font-conf)
(:android constants/initials-avatar-font-conf))
callback)))
4 changes: 2 additions & 2 deletions src/status_im/common/router.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
[legacy.status-im.ethereum.ens :as ens]
[native-module.core :as native-module]
[re-frame.core :as re-frame]
[status-im.common.validators :as validators]
[status-im.constants :as constants]
[status-im.contexts.chat.events :as chat.events]
[taoensso.timbre :as log]
Expand All @@ -15,8 +16,7 @@
[utils.ethereum.eip.eip681 :as eip681]
[utils.security.core :as security]
[utils.transforms :as transforms]
[utils.url :as url]
[utils.validators :as validators]))
[utils.url :as url]))

(def ethereum-scheme "ethereum:")

Expand Down
23 changes: 23 additions & 0 deletions src/status_im/common/universal_links.cljs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
(ns status-im.common.universal-links
(:require
[clojure.string :as string]
[goog.string :as gstring]
[native-module.core :as native-module]
[re-frame.core :as re-frame]
[react-native.async-storage :as async-storage]
[react-native.core :as rn]
[schema.core :as schema]
[status-im.constants :as constants]
[status-im.navigation.events :as navigation]
[taoensso.timbre :as log]
[utils.ethereum.chain :as chain]
Expand All @@ -17,6 +19,27 @@
{:external "https://status.app"
:internal "status-app:/"})

(def links
{:private-chat "%s/p/%s"
:user "%s/u#%s"
:browse "%s/b/%s"})

(defn universal-link?
[url]
(boolean
(re-matches constants/regx-universal-link url)))

(defn deep-link?
[url]
(boolean
(re-matches constants/regx-deep-link url)))

(defn generate-link
[link-type domain-type param]
(gstring/format (get links link-type)
(get domains domain-type)
param))

(rf/defn handle-browse
[_ {:keys [url]}]
(log/info "universal-links: handling browse" url)
Expand Down
49 changes: 49 additions & 0 deletions src/status_im/common/universal_links_test.cljs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(ns status-im.common.universal-links-test
(:require
[cljs.test :refer-macros [deftest is are testing]]
matcher-combinators.test
[re-frame.core :as re-frame]
[status-im.common.universal-links :as links]))

Expand Down Expand Up @@ -98,3 +99,51 @@
db {:profile/profile {:public-key pubkey}}
rst (links/save-profile-url {:db db} ["invalid pubkey"])]
(is (nil? rst))))))

(deftest universal-link-test
(testing "universal-link?"
(are [l rst] (match? (links/universal-link? l) rst)
"status-app://blah"
false
"http://status.app/blah"
false
"http://status.app/c#zQ3shPyZJnxZK4Bwyx9QsaksNKDYTPmpwPvGSjMYVHoXHeEgB"
true
"http://status.app/u#zQ3shPyZJnxZK4Bwyx9QsaksNKDYTPmpwPvGSjMYVHoXHeEgB"
true
"https://status.app/u/Ow==#zQ3shsKnV5HJMWJR61c6dssWzHszdbLfBoMF1gcLtSQAYdw2d"
true
"https://status.app/c/Ow==#zQ3shYSHp7GoiXaauJMnDcjwU2yNjdzpXLosAWapPS4CFxc11"
true
"https://status.app/c/Ow==#zQ3shYSHp7GoiXaauJMnDcjwU2yNjdzpXLosAWapPS4CFxc111"
false
"https://status.app/u/G10A4B0JdgwyRww90WXtnP1oNH1ZLQNM0yX0Ja9YyAMjrqSZIYINOHCbFhrnKRAcPGStPxCMJDSZlGCKzmZrJcimHY8BbcXlORrElv_BbQEegnMDPx1g9C5VVNl0fE4y#zQ3shwQPhRuDJSjVGVBnTjCdgXy5i9WQaeVPdGJD6yTarJQSj"
true
"https://status.app/c/G00AAGS9TbI9mSR-ZNmFrhRjNuEeXAAbcAIUaLLJyjMOG3ACJQ12oIHD78QhzO9s_T5bUeU7rnATWJg3mGgTUemrAg==#zQ3shYf5SquxkiY3FmCW6Nz2wuFWFcM6JEdUD62ApjAvE5YPv"
true
"http://status.app/c#zQ3shPyZJnxZK4Bwyx9QsaksNKDYTPmpwPvGSjMYVHoXHeEgBhttp://status.app/c#zQ3shPyZJnxZK4Bwyx9QsaksNKDYTPmpwPvGSjMYVHoXHeEgB"
false
"http://status.app/u#zQ3shPyZJnxZK4Bwyx9QsaksNKDYTPmpwPvGSjMYVHoXHeEgBhttp://status.app/u#zQ3shPyZJnxZK4Bwyx9QsaksNKDYTPmpwPvGSjMYVHoXHeEgB"
false
"https://status.app/u/Ow==#zQ3shsKnV5HJMWJR61c6dssWzHszdbLfBoMF1gcLtSQAYdw2dhttps://status.app/u/Ow==#zQ3shsKnV5HJMWJR61c6dssWzHszdbLfBoMF1gcLtSQAYdw2d"
false
"https://status.app/c/Ow==#zQ3shYSHp7GoiXaauJMnDcjwU2yNjdzpXLosAWapPS4CFxc11https://status.app/c/Ow==#zQ3shYSHp7GoiXaauJMnDcjwU2yNjdzpXLosAWapPS4CFxc11"
false
"https://status.app/u/G10A4B0JdgwyRww90WXtnP1oNH1ZLQNM0yX0Ja9YyAMjrqSZIYINOHCbFhrnKRAcPGStPxCMJDSZlGCKzmZrJcimHY8BbcXlORrElv_BbQEegnMDPx1g9C5VVNl0fE4y#zQ3shwQPhRuDJSjVGVBnTjCdgXy5i9WQaeVPdGJD6yTarJQSjhttps://status.app/u/G10A4B0JdgwyRww90WXtnP1oNH1ZLQNM0yX0Ja9YyAMjrqSZIYINOHCbFhrnKRAcPGStPxCMJDSZlGCKzmZrJcimHY8BbcXlORrElv_BbQEegnMDPx1g9C5VVNl0fE4y#zQ3shwQPhRuDJSjVGVBnTjCdgXy5i9WQaeVPdGJD6yTarJQSj"
false
"https://status.app/c/Ow==#zQ3shbmfT3hvh4mKa1v6uAjjyztQEroh8Mfn6Ckegjd7LT3XKhttps://status.app/c#zQ3shbmfT3hvh4mKa1v6uAjjyztQEroh8Mfn6Ckegjd7LT3XK"
false
"https://status.app/blah"
false
"https://status.app/browse/www.аррӏе.com"
false
"https://not.status.im/blah"
false
"http://not.status.im/blah"
false))

(testing "deep-link?"
(are [l rst] (match? (links/deep-link? l) rst)
"status-app://blah" true
"http://status.app/blah" false
"ethereum:0x89205a3a3b2a69de6dbf7f01ed13b2108b2c43e7" true)))
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns utils.validators
(ns status-im.common.validators
(:require
[status-im.constants :as constants]))

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(ns utils.validators-test
(ns status-im.common.validators-test
(:require
[cljs.test :refer-macros [deftest testing is]]
[utils.validators :refer [valid-compressed-key?]]))
[status-im.common.validators :refer [valid-compressed-key?]]))

(deftest test-valid-compressed-key
(testing "valid"
Expand Down
4 changes: 2 additions & 2 deletions src/status_im/contexts/add_new_contact/events.cljs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
(ns status-im.contexts.add-new-contact.events
(:require
[clojure.string :as string]
[status-im.common.validators :as validators]
status-im.contexts.add-new-contact.effects
[status-im.contexts.contacts.events :as data-store.contacts]
[status-im.navigation.events :as navigation]
[utils.ens.stateofus :as stateofus]
[utils.ethereum.chain :as chain]
[utils.re-frame :as rf]
[utils.string :as utils.string]
[utils.validators :as validators]))
[utils.string :as utils.string]))

(defn init-contact
"Create a new contact (persisted to app-db as [:contacts/new-identity]).
Expand Down
31 changes: 20 additions & 11 deletions src/status_im/subs/contact.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
[legacy.status-im.ui.screens.profile.visibility-status.utils :as visibility-status-utils]
[quo.theme :as theme]
[re-frame.core :as re-frame]
[status-im.common.pixel-ratio :as pixel-ratio]
[status-im.constants :as constants]
[status-im.contexts.profile.utils :as profile.utils]
[utils.address :as address]
Expand Down Expand Up @@ -40,14 +41,20 @@
(let [image-name (:type image)
clock (:clock image)
uri (image-server/get-contact-image-uri-fn
{:port port
:public-key public-key
:image-name image-name
{:port port
:ratio pixel-ratio/ratio
:public-key
public-key
:image-name
image-name
; We pass the clock so that we reload the
; image if the image is updated
:clock clock
:theme theme
:override-ring? (when ens-name false)})]
:clock
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have no idea why it was moved next line

clock
:theme
theme
:override-ring?
(when ens-name false)})]
(assoc-in acc [(keyword image-name) :fn] uri)))
images
(vals images))
Expand All @@ -56,11 +63,13 @@
images
{:thumbnail
{:fn (image-server/get-initials-avatar-uri-fn
{:port port
:public-key public-key
:override-ring? (when ens-name false)
:theme theme
:font-file font-file})}})]
{:port port
:ratio pixel-ratio/ratio
:public-key public-key
:override-ring? (when ens-name false)
:uppercase-ratio (:uppercase-ratio constants/initials-avatar-font-conf)
:theme theme
:font-file font-file})}})]

(assoc contact :images images)))

Expand Down
47 changes: 31 additions & 16 deletions src/status_im/subs/profile.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
[legacy.status-im.wallet.utils :as wallet.utils]
[quo.theme :as theme]
[re-frame.core :as re-frame]
[status-im.common.pixel-ratio :as pixel-ratio]
[status-im.constants :as constants]
[utils.address :as address]
[utils.image-server :as image-server]
Expand Down Expand Up @@ -39,14 +40,20 @@
(fn [[port font-file] [_ profile-pic]]
{:fn
(if profile-pic
(image-server/get-account-image-uri-fn {:port port
:image-name profile-pic
:override-ring? false
:theme (theme/get-theme)})
(image-server/get-initials-avatar-uri-fn {:port port
:theme (theme/get-theme)
:override-ring? false
:font-file font-file}))}))
(image-server/get-account-image-uri-fn {:port port
:ratio pixel-ratio/ratio
:image-name profile-pic
:override-ring? false
:uppercase-ratio (:uppercase-ratio
constants/initials-avatar-font-conf)
:theme (theme/get-theme)})
(image-server/get-initials-avatar-uri-fn {:port port
:ratio pixel-ratio/ratio
:theme (theme/get-theme)
:override-ring? false
:uppercase-ratio (:uppercase-ratio
constants/initials-avatar-font-conf)
:font-file font-file}))}))

(re-frame/reg-sub
:profile/login-profiles-picture
Expand All @@ -61,11 +68,13 @@
{:fn
(if image-name
(image-server/get-account-image-uri-fn {:port port
:ratio pixel-ratio/ratio
:image-name image-name
:key-uid target-key-uid
:theme (theme/get-theme)
:override-ring? override-ring?})
(image-server/get-initials-avatar-uri-fn {:port port
:ratio pixel-ratio/ratio
:key-uid target-key-uid
:theme (theme/get-theme)
:override-ring? override-ring?
Expand Down Expand Up @@ -283,19 +292,25 @@
avatar-opts (assoc avatar-opts :override-ring? (when ens-name? false))
images-with-uri (mapv (fn [{key-uid :keyUid image-name :type :as image}]
(let [uri-fn (image-server/get-account-image-uri-fn
(merge {:port port
:image-name image-name
:key-uid key-uid
:theme theme}
avatar-opts))]
(merge
{:port port
:ratio pixel-ratio/ratio
:image-name image-name
:key-uid key-uid
:theme theme}
avatar-opts))]
(assoc image :fn uri-fn)))
images)
new-images (if (seq images-with-uri)
images-with-uri
[{:fn (image-server/get-initials-avatar-uri-fn
(merge {:port port
:key-uid key-uid
:theme theme
(merge {:port port
:ratio pixel-ratio/ratio
:uppercase-ratio
(:uppercase-ratio
constants/initials-avatar-font-conf)
:key-uid key-uid
:theme theme
:font-file font-file}
avatar-opts))}])]
(assoc profile :images new-images)))
Expand Down
Loading