Compare commits

..
246 changed files with 7283 additions and 10171 deletions
+31 -31
View File
@@ -22,37 +22,37 @@
:multi-lhs-hang] :multi-lhs-hang]
:fn-map :fn-map
{"reg-sub" :arg1-pair {"reg-sub" :arg1-pair
"h/describe" :arg1-body "h/describe" :arg1-body
"h/describe-skip" :arg1-body "h/describe-skip" :arg1-body
"h/describe-only" :arg1-body "h/describe-only" :arg1-body
"h/test" :arg1-body "h/test" :arg1-body
"h/test-skip" :arg1-body "h/test-skip" :arg1-body
"h/test-only" :arg1-body "h/test-only" :arg1-body
"test/async" :arg1-body "test/async" :arg1-body
"test/use-fixtures" :arg1-body "test/use-fixtures" :arg1-body
"global.describe" :arg1-body "global.describe" :arg1-body
"global.test" :arg1-body "global.test" :arg1-body
"list-comp" :binding "list-comp" :binding
"defview" :arg1-body "defview" :arg1-body
"letsubs" :binding "letsubs" :binding
"with-let" "let" "with-let" "let"
"reg-event-fx" :arg1-pair "reg-event-fx" :arg1-pair
"reg-fx" :arg1-pair "reg-fx" :arg1-pair
"testing" :arg1-body "testing" :arg1-body
"deftest-sub" :arg1-body "deftest-sub" :arg1-body
"test-async" :arg1-body "h/integration-test" :arg1-body
"wait-for" :arg1-body "wait-for" :arg1-body
"with-deps-check" :arg1-body "with-deps-check" :arg1-body
"schema/=>" :arg1-body "schema/=>" :arg1-body
"->" [:noarg1-body "->" [:noarg1-body
{:list {:constant-pair? false :force-nl? false} {:list {:constant-pair? false :force-nl? false}
:next-inner-restore [[:list :constant-pair?]]}] :next-inner-restore [[:list :constant-pair?]]}]
"set!" "reset!" "set!" "reset!"
"assoc-when" "assoc" "assoc-when" "assoc"
"assoc-some" "assoc" "assoc-some" "assoc"
"conj-when" "conj" "conj-when" "conj"
"conj-some" "conj"} "conj-some" "conj"}
:style-map :style-map
{:no-comma {:map {:comma? false}} {:no-comma {:map {:comma? false}}
+3 -5
View File
@@ -331,14 +331,13 @@ shadow-server:##@ Start shadow-cljs in server mode for watching
_test-clojure: export TARGET := clojure _test-clojure: export TARGET := clojure
_test-clojure: export WATCH ?= false _test-clojure: export WATCH ?= false
_test-clojure: status-go-library
_test-clojure: _test-clojure:
ifeq ($(WATCH), true) ifeq ($(WATCH), true)
yarn node-pre-gyp rebuild && \ yarn install && \
yarn shadow-cljs compile mocks && \ yarn shadow-cljs compile mocks && \
nodemon --exec "yarn shadow-cljs compile test && node --require ./test-resources/override.js $$SHADOW_OUTPUT_TO" -e cljs nodemon --exec "yarn shadow-cljs compile test && node --require ./test-resources/override.js $$SHADOW_OUTPUT_TO" -e cljs
else else
yarn node-pre-gyp rebuild && \ yarn install && \
yarn shadow-cljs compile mocks && \ yarn shadow-cljs compile mocks && \
yarn shadow-cljs compile test && \ yarn shadow-cljs compile test && \
node --require ./test-resources/override.js "$$SHADOW_OUTPUT_TO" node --require ./test-resources/override.js "$$SHADOW_OUTPUT_TO"
@@ -351,9 +350,8 @@ test: _test-clojure
test-watch-for-repl: export SHADOW_OUTPUT_TO := target/test/test.js test-watch-for-repl: export SHADOW_OUTPUT_TO := target/test/test.js
test-watch-for-repl: export SHADOW_NS_REGEXP := .*-test$$ test-watch-for-repl: export SHADOW_NS_REGEXP := .*-test$$
test-watch-for-repl: status-go-library
test-watch-for-repl: ##@test Watch all Clojure tests and support REPL connections test-watch-for-repl: ##@test Watch all Clojure tests and support REPL connections
yarn node-pre-gyp rebuild yarn install
rm -f target/test/test.js rm -f target/test/test.js
yarn shadow-cljs compile mocks && \ yarn shadow-cljs compile mocks && \
concurrently --kill-others --prefix-colors 'auto' --names 'build,repl' \ concurrently --kill-others --prefix-colors 'auto' --names 'build,repl' \
+3 -6
View File
@@ -1,9 +1,6 @@
module.exports = { module.exports = {
presets: [ presets: ['module:metro-react-native-babel-preset'],
"@babel/preset-env" plugins: ['react-native-reanimated/plugin', '@babel/plugin-transform-named-capturing-groups-regex'],
// 'module:metro-react-native-babel-preset'
],
/*plugins: ['react-native-reanimated/plugin', '@babel/plugin-transform-named-capturing-groups-regex'],
env: { env: {
test: { test: {
presets: [ presets: [
@@ -18,5 +15,5 @@ module.exports = {
], ],
], ],
}, },
},*/ },
}; };
@@ -1888,36 +1888,6 @@ void _InitLogging(const FunctionCallbackInfo<Value>& args) {
delete c; delete c;
} }
void _RestoreAccountAndLogin(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
Local<Context> context = isolate->GetCurrentContext();
if (args.Length() != 1) {
// Throw an Error that is passed back to JavaScript
isolate->ThrowException(Exception::TypeError(
String::NewFromUtf8Literal(isolate, "Wrong number of arguments for RestoreAccountAndLogin")));
return;
}
// Check the argument types
if (!args[0]->IsString()) {
isolate->ThrowException(Exception::TypeError(
String::NewFromUtf8Literal(isolate, "Wrong argument type for 'RestoreAccountAndLogin'")));
return;
}
String::Utf8Value arg0Obj(isolate, args[0]->ToString(context).ToLocalChecked());
char *arg0 = *arg0Obj;
// Call exported Go function, which returns a C string
char *c = RestoreAccountAndLogin(arg0);
Local<String> ret = String::NewFromUtf8(isolate, c).ToLocalChecked();
args.GetReturnValue().Set(ret);
delete c;
}
void init(Local<Object> exports) { void init(Local<Object> exports) {
NODE_SET_METHOD(exports, "multiAccountGenerateAndDeriveAddresses", _MultiAccountGenerateAndDeriveAddresses); NODE_SET_METHOD(exports, "multiAccountGenerateAndDeriveAddresses", _MultiAccountGenerateAndDeriveAddresses);
@@ -1975,7 +1945,6 @@ void init(Local<Object> exports) {
NODE_SET_METHOD(exports, "connectionChange", _ConnectionChange); NODE_SET_METHOD(exports, "connectionChange", _ConnectionChange);
NODE_SET_METHOD(exports, "pollSignal", _PollSignal); NODE_SET_METHOD(exports, "pollSignal", _PollSignal);
NODE_SET_METHOD(exports, "initLogging", _InitLogging); NODE_SET_METHOD(exports, "initLogging", _InitLogging);
NODE_SET_METHOD(exports, "restoreAccountAndLogin", _RestoreAccountAndLogin);
} }
NODE_MODULE(NODE_GYP_MODULE_NAME, init) NODE_MODULE(NODE_GYP_MODULE_NAME, init)
-10
View File
@@ -53,14 +53,6 @@ copyNodeModules() {
# Find files that were modified and should cause a re-copying of node modules. # Find files that were modified and should cause a re-copying of node modules.
# Some files are generated/modified by build processes and should be ignored. # Some files are generated/modified by build processes and should be ignored.
#
# react-native/ReactCommon/react/renderer/components/rncore/*
# generated at runtime by react-native
# related code https://github.com/facebook/react-native/blob/v0.72.5/packages/react-native/ReactCommon/React-rncore.podspec#L19
#
# react-native-config/ios/ReactNativeConfig/GeneratedDotEnv.m
# generated at runtime by react-native-config
# related code https://github.com/lugg/react-native-config/blob/v1.5.0/react-native-config.podspec#L52
findFilesNewerThan() { findFilesNewerThan() {
local sentinel="${1}" local sentinel="${1}"
local dir="${2}" local dir="${2}"
@@ -69,8 +61,6 @@ findFilesNewerThan() {
-not -ipath "*/*android/build/*" -prune \ -not -ipath "*/*android/build/*" -prune \
-not -ipath "*/xcuserdata/*" -prune \ -not -ipath "*/xcuserdata/*" -prune \
-not -ipath "*/scripts/.packager.env" \ -not -ipath "*/scripts/.packager.env" \
-not -path "*/node_modules/react-native/ReactCommon/react/renderer/components/rncore/*" \
-not -path "*/node_modules/react-native-config/ios/ReactNativeConfig/GeneratedDotEnv.m" \
-print -print
} }
-1
View File
@@ -78,7 +78,6 @@
"@babel/helper-builder-react-jsx": "^7.20.0", "@babel/helper-builder-react-jsx": "^7.20.0",
"@babel/plugin-transform-block-scoping": "^7.20.0", "@babel/plugin-transform-block-scoping": "^7.20.0",
"@babel/preset-env": "^7.20.0", "@babel/preset-env": "^7.20.0",
"@babel/preset-es2015": "^7.0.0-beta.53",
"@babel/preset-react": "^7.18.6", "@babel/preset-react": "^7.18.6",
"@babel/register": "7.0.0", "@babel/register": "7.0.0",
"@jest/globals": "^25.1.0", "@jest/globals": "^25.1.0",
-1
View File
@@ -46,7 +46,6 @@
;; To match the folder created by Nix build of JSBundle. ;; To match the folder created by Nix build of JSBundle.
:output-dir "result" :output-dir "result"
:init-fn status-im.core/init :init-fn status-im.core/init
:build-hooks [(status-im.setup.build-hooks.worklets/transform-output)]
;; When false, the Shadow-CLJS watcher won't automatically refresh ;; When false, the Shadow-CLJS watcher won't automatically refresh
;; the target files (a.k.a hot reload). When false, you can manually ;; the target files (a.k.a hot reload). When false, you can manually
;; reload by calling `shadow.cljs.devtools.api/watch-compile-all!`. ;; reload by calling `shadow.cljs.devtools.api/watch-compile-all!`.
+4
View File
@@ -3,6 +3,7 @@
["eth-phishing-detect" :as eth-phishing-detect] ["eth-phishing-detect" :as eth-phishing-detect]
[clojure.string :as string] [clojure.string :as string]
[legacy.status-im.bottom-sheet.events :as bottom-sheet] [legacy.status-im.bottom-sheet.events :as bottom-sheet]
[legacy.status-im.browser.eip3085 :as eip3085]
[legacy.status-im.browser.eip3326 :as eip3326] [legacy.status-im.browser.eip3326 :as eip3326]
[legacy.status-im.browser.permissions :as browser.permissions] [legacy.status-im.browser.permissions :as browser.permissions]
[legacy.status-im.browser.webview-ref :as webview-ref] [legacy.status-im.browser.webview-ref :as webview-ref]
@@ -442,6 +443,9 @@
(= method "wallet_switchEthereumChain") (= method "wallet_switchEthereumChain")
(eip3326/handle-switch-ethereum-chain cofx dapp-name id message-id (first params)) (eip3326/handle-switch-ethereum-chain cofx dapp-name id message-id (first params))
(= method "wallet_addEthereumChain")
(eip3085/handle-add-ethereum-chain cofx dapp-name id message-id (first params))
:else :else
{:browser/call-rpc [payload {:browser/call-rpc [payload
#(re-frame/dispatch [:browser.callback/call-rpc #(re-frame/dispatch [:browser.callback/call-rpc
+38
View File
@@ -2,6 +2,10 @@
;(`wallet_addEthereumChain`) ;(`wallet_addEthereumChain`)
(ns legacy.status-im.browser.eip3085 (ns legacy.status-im.browser.eip3085
(:require (:require
[clojure.string :as string]
[legacy.status-im.network.core :as network]
[legacy.status-im.ui.screens.browser.eip3085.sheet :as sheet]
[legacy.status-im.utils.random :as random]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[status-im.constants :as constants] [status-im.constants :as constants]
[taoensso.timbre :as log] [taoensso.timbre :as log]
@@ -36,3 +40,37 @@
:message "User rejected the request."}} :message "User rejected the request."}}
:dispatch [:bottom-sheet/hide-old]}) :dispatch [:bottom-sheet/hide-old]})
(rf/defn handle-add-ethereum-chain
{:events [:eip3085/handle-add-ethereum-chain]}
[{{:networks/keys [networks] :as db} :db :as cofx}
dapp-name id message-id
{:keys [chainId blockExplorerUrls chainName iconUrls nativeCurrency rpcUrls] :as params}]
(let [manage {:name {:value chainName}
:symbol {:value (:symbol nativeCurrency)}
:url {:value (first rpcUrls)}
:network-id {:value chainId}
:chain {:value :custom}}]
(if (network/valid-manage? manage)
(let [{:keys [name url chain network-id symbol]} manage
random-id (string/replace (random/id) "-" "")
network (network/new-network random-id
(:value name)
(:value symbol)
(:value url)
(:value chain)
(:value network-id))
new-networks (assoc networks random-id network)
params (assoc params
:new-networks new-networks
:id id
:new-network network)]
(if (network/chain-id-available? networks network)
{:dispatch [:bottom-sheet/show-sheet-old
{:content (fn []
[sheet/permissions-panel dapp-name message-id params])}]}
(send-success-call-to-bridge cofx id message-id)))
{:browser/send-to-bridge {:type constants/web3-send-async-callback
:messageId message-id
:error {:code -32602
:message "invalid network parameters"}}})))
+3 -3
View File
@@ -45,12 +45,12 @@
(query-fn (comp participant-set :public-key) (vals all-contacts)))) (query-fn (comp participant-set :public-key) (vals all-contacts))))
(defn get-all-contacts-in-group-chat (defn get-all-contacts-in-group-chat
[members admins contacts {:keys [public-key preferred-name name display-name] :as current-account}] [members admins contacts {:keys [public-key preferred-name name] :as current-account}]
(let [current-contact (some-> (let [current-contact (some->
current-account current-account
(select-keys [:name :preferred-name :public-key :images :compressed-key]) (select-keys [:name :preferred-name :public-key :images])
(set/rename-keys {:name :alias :preferred-name :name}) (set/rename-keys {:name :alias :preferred-name :name})
(assoc :primary-name (or display-name preferred-name name))) (assoc :primary-name (or preferred-name name)))
all-contacts (cond-> contacts all-contacts (cond-> contacts
current-contact current-contact
(assoc public-key current-contact))] (assoc public-key current-contact))]
@@ -29,39 +29,37 @@
(testing "transforms messages from RPC response" (testing "transforms messages from RPC response"
(is (is
(= {:last-message {:quoted-message nil (= {:last-message {:quoted-message nil
:outgoing-status nil :outgoing-status nil
:command-parameters nil :command-parameters nil
:link-previews [] :link-previews []
:status-link-previews [] :content {:sticker nil
:content {:sticker nil :rtl? nil
:rtl? nil :ens-name nil
:ens-name nil :parsed-text nil
:parsed-text nil :response-to nil
:response-to nil :chat-id nil
:chat-id nil :image nil
:image nil :line-count nil
:line-count nil :links nil
:links nil :text nil}
:text nil} :outgoing false}
:outgoing false}
:message nil :message nil
:reply-message {:quoted-message nil :reply-message {:quoted-message nil
:outgoing-status nil :outgoing-status nil
:command-parameters nil :command-parameters nil
:link-previews [] :link-previews []
:status-link-previews [] :content {:sticker nil
:content {:sticker nil :rtl? nil
:rtl? nil :ens-name nil
:ens-name nil :parsed-text nil
:parsed-text nil :response-to nil
:response-to nil :chat-id nil
:chat-id nil :image nil
:image nil :line-count nil
:line-count nil :links nil
:links nil :text nil}
:text nil} :outgoing false}}
:outgoing false}}
(-> raw-notification (-> raw-notification
store/<-rpc store/<-rpc
(select-keys [:last-message :message :reply-message]))))) (select-keys [:last-message :message :reply-message])))))
@@ -4,6 +4,13 @@
[clojure.walk :as walk] [clojure.walk :as walk]
[status-im.constants :as constants])) [status-im.constants :as constants]))
(defn rpc->channel-permissions
[rpc-channels-permissions]
(update-vals rpc-channels-permissions
(fn [{:keys [viewAndPostPermissions viewOnlyPermissions]}]
{:view-only (set/rename-keys viewOnlyPermissions {:satisfied :satisfied?})
:view-and-post (set/rename-keys viewAndPostPermissions {:satisfied :satisfied?})})))
(defn <-revealed-accounts-rpc (defn <-revealed-accounts-rpc
[accounts] [accounts]
(mapv (mapv
@@ -27,9 +34,8 @@
(assoc acc (assoc acc
(name k) (name k)
(-> v (-> v
(assoc :token-gated? (:tokenGated v) (assoc :can-post? (:canPost v))
:can-post? (:canPost v)) (dissoc :canPost)
(dissoc :canPost :tokenGated)
(update :members walk/stringify-keys)))) (update :members walk/stringify-keys))))
{} {}
chats)) chats))
@@ -0,0 +1,23 @@
(ns legacy.status-im.data-store.communities-test
(:require
[cljs.test :refer [deftest is]]
[legacy.status-im.data-store.communities :as sut]))
(def permissions
{"community-id-chat-1"
{:viewOnlyPermissions {:satisfied false
:permissions {:token-permission-id-01 {:criteria [false]}}}
:viewAndPostPermissions {:satisfied true :permissions {}}}
"community-id-chat-2"
{:viewOnlyPermissions {:satisfied true :permissions {}}
:viewAndPostPermissions {:satisfied true :permissions {}}}})
(deftest rpc->channel-permissions-test
(is (= {"community-id-chat-1"
{:view-only {:satisfied? false
:permissions {:token-permission-id-01 {:criteria [false]}}}
:view-and-post {:satisfied? true :permissions {}}}
"community-id-chat-2"
{:view-only {:satisfied? true :permissions {}}
:view-and-post {:satisfied? true :permissions {}}}}
(sut/rpc->channel-permissions permissions))))
+3 -33
View File
@@ -16,41 +16,13 @@
:community-id :communityId :community-id :communityId
:clock-value :clock}))) :clock-value :clock})))
(defn- <-status-link-previews-rpc
[preview]
(-> preview
(update :community
set/rename-keys
{:communityId :community-id
:displayName :display-name
:membersCount :members-count
:activeMembersCount :active-members-count})
(update-in [:community :banner] set/rename-keys {:dataUri :data-uri})
(update-in [:community :icon] set/rename-keys {:dataUri :data-uri})))
(defn ->status-link-previews-rpc
[preview]
(-> preview
(update :community
set/rename-keys
{:community-id :communityId
:display-name :displayName
:members-count :membersCount
:active-members-count :activeMembersCount})
(update-in [:community :banner] set/rename-keys {:data-uri :dataUri})
(update-in [:community :icon] set/rename-keys {:data-uri :dataUri})))
(defn- <-link-preview-rpc (defn- <-link-preview-rpc
[preview] [preview]
(-> preview (update preview :thumbnail set/rename-keys {:dataUri :data-uri}))
(update :thumbnail set/rename-keys {:dataUri :data-uri})
(update :favicon set/rename-keys {:dataUri :data-uri})))
(defn ->link-preview-rpc (defn ->link-preview-rpc
[preview] [preview]
(-> preview (update preview :thumbnail set/rename-keys {:data-uri :dataUri}))
(update :thumbnail set/rename-keys {:data-uri :dataUri})
(update :favicon set/rename-keys {:data-uri :dataUri})))
(defn <-rpc (defn <-rpc
[message] [message]
@@ -81,10 +53,8 @@
:new :new? :new :new?
:albumImagesCount :album-images-count :albumImagesCount :album-images-count
:displayName :display-name :displayName :display-name
:linkPreviews :link-previews :linkPreviews :link-previews})
:statusLinkPreviews :status-link-previews})
(update :link-previews #(map <-link-preview-rpc %)) (update :link-previews #(map <-link-preview-rpc %))
(update :status-link-previews #(map <-status-link-previews-rpc %))
(update :quoted-message (update :quoted-message
set/rename-keys set/rename-keys
{:parsedText :parsed-text {:parsedText :parsed-text
@@ -37,19 +37,7 @@
:compressed-key "c" :compressed-key "c"
:timestamp 3 :timestamp 3
:link-previews [{:thumbnail {:url "http://localhost" :link-previews [{:thumbnail {:url "http://localhost"
:data-uri "data:image/png"} :data-uri "data:image/png"}}]}
:favicon nil}]
:status-link-previews [{:url "http://localhost"
:community {:community-id "0x01"
:display-name "Test Comm"
:members-count 12
:active-members-count 12
:banner
{:data-uri
"data:image/png"}
:icon
{:data-uri
"data:image/png"}}}]}
message {:id message-id message {:id message-id
:whisperTimestamp 1 :whisperTimestamp 1
:parsedText "parsed-text" :parsedText "parsed-text"
@@ -73,17 +61,5 @@
:timestamp 3 :timestamp 3
:outgoingStatus "sending" :outgoingStatus "sending"
:linkPreviews [{:thumbnail {:url "http://localhost" :linkPreviews [{:thumbnail {:url "http://localhost"
:dataUri "data:image/png"} :dataUri "data:image/png"}}]}]
:favicon nil}]
:statusLinkPreviews [{:url "http://localhost"
:community {:communityId "0x01"
:displayName "Test Comm"
:membersCount 12
:activeMembersCount 12
:banner
{:dataUri
"data:image/png"}
:icon
{:dataUri
"data:image/png"}}}]}]
(is (= expected (m/<-rpc message)))))) (is (= expected (m/<-rpc message))))))
+3 -2
View File
@@ -37,6 +37,7 @@
[react-native.core :as rn] [react-native.core :as rn]
[react-native.permissions :as permissions] [react-native.permissions :as permissions]
[react-native.platform :as platform] [react-native.platform :as platform]
[status-im.common.biometric.events :as biometric]
status-im.common.serialization status-im.common.serialization
status-im.common.standard-authentication.events status-im.common.standard-authentication.events
[status-im.common.theme.core :as theme] [status-im.common.theme.core :as theme]
@@ -119,7 +120,7 @@
:content (i18n/label :t/biometric-auth-confirm-message) :content (i18n/label :t/biometric-auth-confirm-message)
:confirm-button-text (i18n/label :t/biometric-auth-confirm-try-again) :confirm-button-text (i18n/label :t/biometric-auth-confirm-try-again)
:cancel-button-text (i18n/label :t/biometric-auth-confirm-logout) :cancel-button-text (i18n/label :t/biometric-auth-confirm-logout)
:on-accept #(rf/dispatch [:biometric/authenticate {:on-fail on-biometric-auth-fail}]) :on-accept #(biometric/authenticate nil {:on-fail on-biometric-auth-fail})
:on-cancel #(re-frame/dispatch [:multiaccounts.logout.ui/logout-confirmed])}))) :on-cancel #(re-frame/dispatch [:multiaccounts.logout.ui/logout-confirmed])})))
(rf/defn on-return-from-background (rf/defn on-return-from-background
@@ -141,7 +142,7 @@
#(when-let [chat-id (:current-chat-id db)] #(when-let [chat-id (:current-chat-id db)]
{:dispatch [:chat/mark-all-as-read chat-id]}) {:dispatch [:chat/mark-all-as-read chat-id]})
#(when requires-bio-auth #(when requires-bio-auth
{:dispatch [:biometric/authenticate {:on-fail on-biometric-auth-fail}]})))) (biometric/authenticate % {:on-fail on-biometric-auth-fail})))))
(rf/defn on-going-in-background (rf/defn on-going-in-background
[{:keys [db now]}] [{:keys [db now]}]
@@ -13,14 +13,15 @@
(native-module/logout))) (native-module/logout)))
(rf/defn initialize-app-db (rf/defn initialize-app-db
[{{:keys [keycard initials-avatar-font-file biometrics] [{{:keys [keycard initials-avatar-font-file]
:network/keys [type]} :biometric/keys [supported-type]
:network/keys [type]}
:db}] :db}]
{:db (assoc db/app-db {:db (assoc db/app-db
:network/type type :network/type type
:initials-avatar-font-file initials-avatar-font-file :initials-avatar-font-file initials-avatar-font-file
:keycard (dissoc keycard :secrets :pin :application-info) :keycard (dissoc keycard :secrets :pin :application-info)
:biometrics biometrics :biometric/supported-type supported-type
:syncing nil)}) :syncing nil)})
(rf/defn logout-method (rf/defn logout-method
@@ -28,7 +29,8 @@
[{:keys [db] :as cofx} {:keys [auth-method logout?]}] [{:keys [db] :as cofx} {:keys [auth-method logout?]}]
(let [key-uid (get-in db [:profile/profile :key-uid])] (let [key-uid (get-in db [:profile/profile :key-uid])]
(rf/merge cofx (rf/merge cofx
{:effects.shell/reset-state nil {:set-root :progress
:effects.shell/reset-state nil
:hide-popover nil :hide-popover nil
::logout nil ::logout nil
:profile.settings/webview-debug-changed false :profile.settings/webview-debug-changed false
@@ -44,7 +46,6 @@
[_] [_]
;; we need to disable notifications before starting the logout process ;; we need to disable notifications before starting the logout process
{:effects/push-notifications-disable nil {:effects/push-notifications-disable nil
:dispatch [:alert-banners/remove-all]
:dispatch-later [{:ms 100 :dispatch-later [{:ms 100
:dispatch [::logout-method :dispatch [::logout-method
{:auth-method keychain/auth-method-none {:auth-method keychain/auth-method-none
+132 -1
View File
@@ -1,6 +1,11 @@
(ns legacy.status-im.network.core (ns legacy.status-im.network.core
(:require (:require
[clojure.string :as string])) [clojure.string :as string]
[re-frame.core :as re-frame]
[status-im.navigation.events :as navigation]
[utils.ethereum.chain :as chain]
[utils.i18n :as i18n]
[utils.re-frame :as rf]))
(def url-regex (def url-regex
#"https?://(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}(\.[a-z]{2,6})?\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)") #"https?://(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}(\.[a-z]{2,6})?\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)")
@@ -9,6 +14,12 @@
[url] [url]
(boolean (re-matches url-regex (str url)))) (boolean (re-matches url-regex (str url))))
(def default-manage
{:name {:value ""}
:url {:value ""}
:symbol {:value ""}
:chain {:value :mainnet}})
(defn validate-string (defn validate-string
[{:keys [value]}] [{:keys [value]}]
{:value value {:value value
@@ -45,3 +56,123 @@
[current-networks network] [current-networks network]
(let [chain-id (get-in network [:config :NetworkId])] (let [chain-id (get-in network [:config :NetworkId])]
(every? #(not= chain-id (get-in % [1 :config :NetworkId])) current-networks))) (every? #(not= chain-id (get-in % [1 :config :NetworkId])) current-networks)))
(defn get-network
[{:keys [db]} network-id]
(get-in db [:networks/networks network-id]))
(rf/defn set-input
{:events [::input-changed]}
[{:keys [db]} input-key value]
{:db (-> db
(update-in [:networks/manage input-key] assoc :value value)
(update-in [:networks/manage] validate-manage))})
;; No edit functionality actually implemented
(rf/defn edit
{:events [::add-network-pressed]}
[{db :db}]
{:db (assoc db :networks/manage (validate-manage default-manage))
:dispatch [:navigate-to :edit-network]})
(rf/defn connect-success
{:events [::connect-success]}
[_ network-id]
{:ui/show-confirmation
{:title (i18n/label :t/close-app-title)
:content (i18n/label :t/logout-app-content)
:confirm-button-text (i18n/label :t/close-app-button)
:on-accept #(re-frame/dispatch [::save-network-settings-pressed network-id])
:on-cancel nil}})
(rf/defn connect-failure
{:events [::connect-failure]}
[_ reason]
{:effects.utils/show-popup
{:title (i18n/label :t/error)
:content (str reason)}})
(rf/defn connect
{:events [::connect-network-pressed]}
[{:keys [db] :as cofx} network-id]
(if (get-in db [:networks/networks network-id :config])
(connect-success cofx network-id)
(connect-failure cofx "A network with the specified id doesn't exist")))
(rf/defn delete
{:events [::delete-network-pressed]}
[{:keys [db]} network]
(let [current-network? (= (:networks/current-network db) network)]
(if (or current-network?
(not (get-in db [:networks/networks network])))
{:ui/show-error (i18n/label :t/delete-network-error)}
{:ui/show-confirmation {:title (i18n/label :t/delete-network-title)
:content (i18n/label :t/delete-network-confirmation)
:confirm-button-text (i18n/label :t/delete)
:on-accept #(re-frame/dispatch [::remove-network-confirmed
network])
:on-cancel nil}})))
(rf/defn save-network-settings
{:events [::save-network-settings-pressed]}
[{:keys [db] :as cofx} network]
{:db (assoc db :networks/current-network network)
:json-rpc/call [{:method "settings_saveSetting"
:params [:networks/current-network network]
:on-success #(re-frame/dispatch [:logout])}]})
(rf/defn remove-network
{:events [::remove-network-confirmed]}
[{:keys [db] :as cofx} network]
(let [networks (dissoc (:networks/networks db) network)]
{:db (assoc db :networks/networks networks)
:json-rpc/call [{:method "settings_saveSetting"
:params [:networks/networks (vals networks)]
:on-success #(re-frame/dispatch [:navigate-back])}]}))
(defn new-network
[random-id network-name sym upstream-url chain-type chain-id]
(let [data-dir (str "/ethereum/" (name chain-type) "_rpc")
config {:NetworkId (or (when chain-id (int chain-id))
(chain/chain-keyword->chain-id chain-type))
:DataDir data-dir
:UpstreamConfig {:Enabled true
:URL upstream-url}}]
{:id random-id
:name network-name
:symbol sym
:config config}))
(rf/defn save
{:events [::save-network-pressed]
:interceptors [(re-frame/inject-cofx :random-id-generator)]}
[{{:networks/keys [manage networks] :as db} :db
random-id-generator :random-id-generator
:as cofx}]
(if (valid-manage? manage)
;; rename network-id from UI to chain-id
(let [{:keys [name url chain network-id symbol]} manage
random-id (string/replace (random-id-generator) "-" "")
network (new-network random-id
(:value name)
(:value symbol)
(:value url)
(:value chain)
(:value network-id))
custom-chain-type? (= :custom (:value chain))
new-networks (assoc networks random-id network)]
(if (or (not custom-chain-type?)
(chain-id-available? networks network))
{:db (-> db
(dissoc :networks/manage)
(assoc :networks/networks new-networks))
:json-rpc/call [{:method "settings_saveSetting"
:params [:networks/networks (vals new-networks)]
:on-success #(re-frame/dispatch [:navigate-back])}]}
{:ui/show-error "chain-id already defined"}))
{:ui/show-error "invalid network parameters"}))
(rf/defn open-network-details
{:events [::network-entry-pressed]}
[cofx network]
(navigation/navigate-to cofx :network-details {:networks/selected-network network}))
+130
View File
@@ -31,6 +31,38 @@
(testing "an https url not on the default port" (testing "an https url not on the default port"
(is (network.core/valid-rpc-url? "https://valid.something.else:65323")))) (is (network.core/valid-rpc-url? "https://valid.something.else:65323"))))
(deftest new-network-test
(let [actual (network.core/new-network "randomid"
"network-name"
"network-symbol"
"upstream-url"
:mainnet
nil)]
(is (= {:id "randomid"
:name "network-name"
:symbol "network-symbol"
:config {:NetworkId 1
:DataDir "/ethereum/mainnet_rpc"
:UpstreamConfig {:Enabled true
:URL "upstream-url"}}}
actual))))
(deftest new-network-id-test
(let [actual (network.core/new-network "randomid"
"network-name"
"network-symbol"
"upstream-url"
:mainnet
"5777")]
(is (= {:id "randomid"
:name "network-name"
:symbol "network-symbol"
:config {:NetworkId 5777
:DataDir "/ethereum/mainnet_rpc"
:UpstreamConfig {:Enabled true
:URL "upstream-url"}}}
actual))))
(deftest valid-manage-test (deftest valid-manage-test
(testing "a valid manage" (testing "a valid manage"
(is (network.core/valid-manage? {:url {:value "http://valid.com"} (is (network.core/valid-manage? {:url {:value "http://valid.com"}
@@ -60,3 +92,101 @@
:name {:value "valid"} :name {:value "valid"}
:symbol {:value ""} :symbol {:value ""}
:chain {:value "valid"}}))))) :chain {:value "valid"}})))))
(deftest set-input-test
(testing "it updates and validate a field"
(is
(= {:db {:networks/manage {:url {:value "http://valid.com"
:error false}
:name {:value ""
:error true}
:symbol {:value "symbol"
:error false}
:chain {:value "mainnet"
:error false}
:network-id {:value nil
:error false}}}}
(network.core/set-input {:db {:networks/manage {:url {:value "something"
:error true}
:name {:value ""
:error false}
:symbol {:value "symbol"
:error false}
:chain {:value "mainnet"
:error false}}}}
:url
"http://valid.com")))))
(deftest not-save-invalid-url
(testing "it does not save a network with an invalid url"
(is
(:ui/show-error (network.core/save {:random-id-generator (constantly "random")
:db {:networks/manage {:url {:value "wrong"}
:chain {:value "1"}
:name {:value "empty"}}
:profile/profile {}}})))))
(deftest save-valid-network
(testing "save a valid network"
(let [fx (network.core/save
{:random-id-generator (constantly "random-id")
:db {:networks/manage {:url {:value "http://valid.com"}
:chain {:value :mainnet}
:symbol {:value "symbol"}
:name {:value "valid"}}
:profile/profile {}
:networks/networks {"random2"
{:id "random2"
:name "network-name"
:symbol "symbol"
:config {:NetworkId 1
:DataDir "/ethereum/mainnet_rpc"
:UpstreamConfig
{:Enabled true
:URL "upstream-url"}}}}}})]
(is (= "settings_saveSetting" (:method (first (:json-rpc/call fx)))))
(is (nil? (:networks/manage (:db fx))))
(testing "and check that it has an id with `-` and the correct mainnet NetworkId"
(is (= 1 (get-in fx [:db :networks/networks "randomid" :config :NetworkId])))))))
(deftest not-save-custom-chain-with-non-unique-id
(testing "it does not save a custom chain with network-id already defined"
(let [result (network.core/save
{:random-id-generator (constantly "already-defined")
:db {:networks/manage {:url {:value "http://valid.com"}
:chain {:value :custom}
:name {:value "valid"}
:network-id {:value 1}}
:profile/profile {}
:networks/networks {"random"
{:id "random"
:name "network-name"
:config {:NetworkId 1
:DataDir "/ethereum/mainnet_rpc"
:UpstreamConfig
{:Enabled true
:URL "upstream-url"}}}}}})]
(is (:ui/show-error result)))))
(deftest save-valid-network-with-unique-chain-id-check
(testing "save a valid network with chain-id not already defined"
(let [fx (network.core/save
{:random-id-generator (constantly "random")
:db {:networks/manage {:url {:value "http://valid.com"}
:chain {:value :mainnet}
:name {:value "valid"}
:symbol {:value "symbol"}
:network-id {:value 5}}
:profile/profile {}
:networks/networks {"randomid"
{:id "randomid"
:name "network-name"
:symbol "symbol"
:config {:NetworkId 3
:DataDir "/ethereum/mainnet_rpc"
:UpstreamConfig
{:Enabled true
:URL "upstream-url"}}}}}})]
(is (= "settings_saveSetting" (:method (first (:json-rpc/call fx)))))
(is (nil? (:networks/manage (:db fx))))
(is (get-in fx [:db :networks/networks "random"])))))
+39
View File
@@ -0,0 +1,39 @@
(ns legacy.status-im.subs.networks
(:require
[re-frame.core :as re-frame]
[status-im.config :as config]
[utils.ethereum.chain :as chain]))
(defn- filter-networks
[network-type]
(fn [network]
(let [chain-id (chain/network->chain-id network)
testnet? (chain/testnet? chain-id)
custom? (:custom? network)]
(case network-type
:custom custom?
:mainnet (and (not custom?) (not testnet?))
:testnet (and (not custom?) testnet?)))))
(defn- label-networks
[default-networks]
(fn [network]
(let [custom? (not (default-networks (:id network)))]
(assoc network :custom? custom?))))
(re-frame/reg-sub
:get-networks
:<- [:networks/networks]
(fn [networks]
(let [networks (map (label-networks (into #{} (map :id config/default-networks)))
(sort-by :name (vals networks)))
types [:mainnet :testnet :custom]]
(zipmap
types
(map #(filter (filter-networks %) networks) types)))))
(re-frame/reg-sub
:manage-network-valid?
:<- [:networks/manage]
(fn [manage]
(not-any? :error (vals manage))))
+1 -2
View File
@@ -5,6 +5,7 @@
legacy.status-im.subs.ens legacy.status-im.subs.ens
legacy.status-im.subs.keycard legacy.status-im.subs.keycard
legacy.status-im.subs.mailservers legacy.status-im.subs.mailservers
legacy.status-im.subs.networks
legacy.status-im.subs.stickers legacy.status-im.subs.stickers
[re-frame.core :as re-frame])) [re-frame.core :as re-frame]))
@@ -22,7 +23,6 @@
(reg-root-key-sub :peers-count :peers-count) (reg-root-key-sub :peers-count :peers-count)
(reg-root-key-sub :peers-summary :peers-summary) (reg-root-key-sub :peers-summary :peers-summary)
(reg-root-key-sub :web3-node-version :web3-node-version) (reg-root-key-sub :web3-node-version :web3-node-version)
(reg-root-key-sub :alert-banners :alert-banners)
;;keycard ;;keycard
(reg-root-key-sub :keycard :keycard) (reg-root-key-sub :keycard :keycard)
@@ -100,7 +100,6 @@
;;; Link previews ;;; Link previews
(reg-root-key-sub :link-previews-whitelist :link-previews-whitelist) (reg-root-key-sub :link-previews-whitelist :link-previews-whitelist)
(reg-root-key-sub :chat/link-previews :chat/link-previews) (reg-root-key-sub :chat/link-previews :chat/link-previews)
(reg-root-key-sub :chat/status-link-previews :chat/status-link-previews)
;;commands ;;commands
(reg-root-key-sub :commands/select-account :commands/select-account) (reg-root-key-sub :commands/select-account :commands/select-account)
@@ -13,7 +13,8 @@
(re-frame/dispatch event)) (re-frame/dispatch event))
(defn- normal-mode-settings-data (defn- normal-mode-settings-data
[{:keys [current-log-level [{:keys [network-name
current-log-level
light-client-enabled? light-client-enabled?
transactions-management-enabled? transactions-management-enabled?
current-fleet current-fleet
@@ -24,6 +25,22 @@
(keep (keep
identity identity
[{:size :small [{:size :small
:title (i18n/label :t/network)
:accessibility-label :network-button
:container-margin-top 8
:on-press
#(re-frame/dispatch [:open-modal :network-settings])
:accessory :text
:accessory-text network-name
:chevron true}
{:size :small
:title (i18n/label :t/network-info)
:accessibility-label :network-button
:container-margin-top 8
:on-press
#(re-frame/dispatch [:open-modal :network-info])
:chevron true}
{:size :small
:title (i18n/label :t/log-level) :title (i18n/label :t/log-level)
:accessibility-label :log-level-settings-button :accessibility-label :log-level-settings-button
:on-press :on-press
@@ -134,13 +151,15 @@
is-goerli-enabled? [:profile/is-goerli-enabled?] is-goerli-enabled? [:profile/is-goerli-enabled?]
light-client-enabled? [:profile/light-client-enabled?] light-client-enabled? [:profile/light-client-enabled?]
webview-debug [:profile/webview-debug] webview-debug [:profile/webview-debug]
network-name [:network-name]
transactions-management-enabled? [:wallet-legacy/transactions-management-enabled?] transactions-management-enabled? [:wallet-legacy/transactions-management-enabled?]
current-log-level [:log-level/current-log-level] current-log-level [:log-level/current-log-level]
current-fleet [:fleets/current-fleet] current-fleet [:fleets/current-fleet]
peer-syncing-enabled? [:profile/peer-syncing-enabled?]] peer-syncing-enabled? [:profile/peer-syncing-enabled?]]
[list/flat-list [list/flat-list
{:data (flat-list-data {:data (flat-list-data
{:current-log-level current-log-level {:network-name network-name
:current-log-level current-log-level
:transactions-management-enabled? transactions-management-enabled? :transactions-management-enabled? transactions-management-enabled?
:light-client-enabled? light-client-enabled? :light-client-enabled? light-client-enabled?
:current-fleet current-fleet :current-fleet current-fleet
@@ -85,7 +85,9 @@
:accessibility-label :share-community-link :accessibility-label :share-community-link
:type :secondary :type :secondary
:on-press #(debounce/throttle-and-dispatch :on-press #(debounce/throttle-and-dispatch
[::communities/share-community-confirmation-pressed @user-pk [(if can-invite?
::communities/invite-people-confirmation-pressed
::communities/share-community-confirmation-pressed) @user-pk
selected] selected]
3000)} 3000)}
(i18n/label (if can-invite? :t/invite :t/share))]}]])))) (i18n/label (if can-invite? :t/invite :t/share))]}]]))))
@@ -0,0 +1,12 @@
(ns legacy.status-im.ui.screens.network.edit-network.styles)
(def edit-network-view
{:flex 1
:margin-horizontal 16
:margin-vertical 15})
(def bottom-container
{:flex-direction :row
:padding-vertical 4})
(def container {:flex 1})
@@ -0,0 +1,72 @@
(ns legacy.status-im.ui.screens.network.edit-network.views
(:require
[legacy.status-im.network.core :as network]
[legacy.status-im.ui.components.core :as quo]
[legacy.status-im.ui.components.list.item :as list.item]
[legacy.status-im.ui.components.list.views :as list]
[legacy.status-im.ui.components.react :as react]
[legacy.status-im.ui.screens.network.edit-network.styles :as styles]
[re-frame.core :as re-frame]
[utils.i18n :as i18n])
(:require-macros [legacy.status-im.utils.views :as views]))
(defn- render-network-type
[type _ _ manage-network]
(let [name (case type
:mainnet (i18n/label :t/mainnet-network)
:goerli (i18n/label :t/goerli-network)
:custom (i18n/label :t/custom))]
[list.item/list-item
{:title name
:accessory :radio
:active (= (get-in manage-network [:chain :value]) type)
:on-press #(re-frame/dispatch [::network/input-changed :chain type])}]))
(views/defview edit-network
[]
(views/letsubs [manage-network [:networks/manage]
is-valid? [:manage-network-valid?]]
(let [custom? (= (get-in manage-network [:chain :value]) :custom)]
[react/keyboard-avoiding-view {:flex 1}
[react/scroll-view
[react/view styles/edit-network-view
[react/view {:padding-vertical 8}
[quo/text-input
{:label (i18n/label :t/name)
:placeholder (i18n/label :t/specify-name)
:default-value (get-in manage-network [:name :value])
:on-change-text #(re-frame/dispatch [::network/input-changed :name %])
:auto-focus true}]]
[react/view {:padding-vertical 8}
[quo/text-input
{:label (i18n/label :t/symbol)
:placeholder (i18n/label :t/specify-symbol)
:default-value (get-in manage-network [:symbol :value])
:on-change-text #(re-frame/dispatch [::network/input-changed :symbol %])
:auto-focus true}]]
[react/view {:padding-vertical 8}
[quo/text-input
{:label (i18n/label :t/rpc-url)
:placeholder (i18n/label :t/specify-rpc-url)
:default-value (get-in manage-network [:url :value])
:on-change-text #(re-frame/dispatch [::network/input-changed :url %])}]]]
[quo/list-header (i18n/label :t/network-chain)]
[list/flat-list
{:data [:mainnet :goerli :custom]
:key-fn (fn [_ i] (str i))
:render-data manage-network
:render-fn render-network-type}]
(when custom?
[react/view styles/edit-network-view
[quo/text-input
{:label (i18n/label :t/network-id)
:placeholder (i18n/label :t/specify-network-id)
:on-change-text #(re-frame/dispatch [::network/input-changed :network-id %])}]])]
[react/view styles/bottom-container
[react/view {:flex 1}]
[quo/button
{:after :main-icons/next
:type :secondary
:disabled (not is-valid?)
:on-press #(re-frame/dispatch [::network/save-network-pressed])}
(i18n/label :t/save)]]])))
@@ -0,0 +1,47 @@
(ns legacy.status-im.ui.screens.network.network-details.views
(:require
[legacy.status-im.network.core :as network]
[legacy.status-im.ui.components.core :as quo]
[legacy.status-im.ui.components.react :as react]
[legacy.status-im.ui.screens.network.styles :as st]
[legacy.status-im.ui.screens.network.views :as network-settings]
[re-frame.core :as re-frame]
[utils.debounce :refer [throttle-and-dispatch]]
[utils.i18n :as i18n])
(:require-macros [legacy.status-im.utils.views :as views]))
(views/defview network-details
[]
(views/letsubs [{:keys [networks/selected-network]} [:get-screen-params]
current-network [:networks/current-network]
networks [:get-networks]]
(let [{:keys [id name config]} selected-network
connected? (= id current-network)
custom? (seq (filter #(= (:id %) id) (:custom networks)))]
[:<>
[react/view {:flex 1}
[network-settings/network-badge
{:name name
:connected? connected?}]
(when-not connected?
[react/touchable-highlight
{:on-press #(throttle-and-dispatch [::network/connect-network-pressed id] 1000)}
[react/view st/connect-button-container
[react/view
{:style st/connect-button
:accessibility-label :network-connect-button}
[react/text {:style st/connect-button-label}
(i18n/label :t/connect)]]
[react/i18n-text
{:style st/connect-button-description
:key :connecting-requires-login}]]])
[react/view (st/network-config-container)
[react/text
{:style st/network-config-text
:accessibility-label :network-details-text}
config]]]
(when custom?
[react/view st/bottom-container
[react/view {:flex 1}
[quo/button {:on-press #(re-frame/dispatch [::network/delete-network-pressed id])}
(i18n/label :t/delete)]]])])))
@@ -0,0 +1,90 @@
(ns legacy.status-im.ui.screens.network.styles
(:require
[legacy.status-im.ui.components.colors :as colors]
[legacy.status-im.utils.styles :as styles]))
(def wrapper
{:flex 1})
(def badge-name-text
{:font-size 17})
(styles/def badge-connected-text
{:color colors/gray
:ios {:margin-top 5}})
(def connect-button-container
{:margin-top 8
:margin-bottom 16
:margin-horizontal 16})
(def connect-button
{:height 52
:align-items :center
:justify-content :center
:background-color colors/blue
:border-radius 8
:ios {:opacity 0.9}})
(def connect-button-label
{:color colors/white-persist
:font-size 17})
(def connect-button-description
{:color colors/gray
:margin-top 8
:height 20})
(styles/defn network-config-container
[]
{:height 160
:margin-top 8
:padding-top 16
:padding-left 16
:margin-horizontal 16
:background-color colors/gray-lighter
:ios {:border-radius 9
:opacity 0.9}
:android {:border-radius 4}})
(styles/def network-config-text
{:font-size 17
:ios {:opacity 0.8}
:android {:opacity 0.4}})
(defn network-icon
[connected? size]
{:width size
:height size
:border-radius (/ size 2)
:background-color (if connected? colors/blue colors/gray-lighter)
:align-items :center
:justify-content :center})
(def network-badge
{:height 88
:padding-left 16
:flex-direction :row
:align-items :center})
(styles/def network-item
{:flex-direction :row
:align-items :center
:padding-horizontal 16
:ios {:height 64}
:android {:height 56}})
(def network-item-name-text
{:font-size 17})
(def network-item-connected-text
{:color colors/gray
:font-size 14
:margin-top 6})
(def bottom-container
{:flex-direction :row
:margin-horizontal 12
:margin-vertical 15})
(def container {:flex 1})
@@ -0,0 +1,71 @@
(ns legacy.status-im.ui.screens.network.views
(:require
[legacy.status-im.network.core :as network]
[legacy.status-im.ui.components.colors :as colors]
[legacy.status-im.ui.components.icons.icons :as icons]
[legacy.status-im.ui.components.list.item :as list.item]
[legacy.status-im.ui.components.list.views :as list]
[legacy.status-im.ui.components.react :as react]
[legacy.status-im.ui.components.topbar :as topbar]
[legacy.status-im.ui.screens.network.styles :as styles]
[re-frame.core :as re-frame]
[utils.i18n :as i18n])
(:require-macros [legacy.status-im.utils.views :as views]))
(defn- network-icon
[connected? size]
[react/view (styles/network-icon connected? size)
[icons/icon :main-icons/network {:color (if connected? colors/white-persist colors/gray)}]])
(defn network-badge
[& [{:keys [name connected?]}]]
[react/view styles/network-badge
[network-icon connected? 56]
[react/view {:padding-left 16}
[react/text {:style styles/badge-name-text}
(or name (i18n/label :t/new-network))]
(when connected?
[react/i18n-text
{:style styles/badge-connected-text
:key :connected}])]])
(def mainnet?
#{"mainnet" "mainnet_rpc"})
(defn render-network
[{:keys [id name] :as network} _ _ current-network]
(let [connected? (= id current-network)]
[list.item/list-item
{:on-press #(re-frame/dispatch [::network/network-entry-pressed network])
:icon :main-icons/network
:icon-bg-color (if connected? colors/blue colors/gray-lighter)
:icon-color (if connected? colors/white-persist colors/gray)
:title name
:subtitle (when connected? (i18n/label :t/connected))
:chevron true}]))
(views/defview network-settings
[]
(views/letsubs [current-network [:networks/current-network]
networks [:get-networks]]
[:<>
[topbar/topbar
{:title (i18n/label :t/network-settings)
:right-accessories
[{:icon :main-icons/add
:on-press #(re-frame/dispatch [::network/add-network-pressed])}]}]
[react/view styles/wrapper
[list/section-list
{:sections [{:title (i18n/label :t/main-networks)
:key :mainnet
:data (:mainnet networks)}
{:title (i18n/label :t/test-networks)
:key :testnet
:data (:testnet networks)}
{:title (i18n/label :t/custom-networks)
:key :custom
:data (:custom networks)}]
:key-fn :id
:default-separator? true
:render-data current-network
:render-fn render-network}]]]))
@@ -0,0 +1,84 @@
(ns legacy.status-im.ui.screens.network-info.views
(:require
[legacy.status-im.ethereum.decode :as decode]
[legacy.status-im.ui.components.react :as react]
[native-module.core :as native-module]
[re-frame.core :as re-frame]
[reagent.core :as reagent]
[status-im.common.json-rpc.events :as json-rpc]
[utils.datetime :as datetime]))
(defn get-block
[block callback]
(json-rpc/call
{:method "eth_getBlockByNumber"
:params [block false]
:on-success callback
:on-error #(js/alert (str "can't fetch latest block" %))}))
(defn to-date
[timestamp]
(datetime/timestamp->long-date
(* 1000 timestamp)))
(defn check-lag
[]
(let [latest-block (reagent/atom nil)
last-loaded-block (reagent/atom nil)
on-press
(fn []
(get-block
"latest"
(fn [res]
(reset! latest-block res)
(get-block
(str "0x"
(native-module/number-to-hex
@(re-frame/subscribe [:ethereum/current-block])))
(fn [res]
(reset! last-loaded-block res))))))]
(fn []
[react/view
{:style {:flex 1
:margin-horizontal 16}}
(if-not @latest-block
[react/text
{:on-press on-press}
"PRESS TO REFRESH"]
[react/text
{:on-press on-press}
(let [latest-block-number
(decode/uint (:number @latest-block))
latest-block-timestamp
(decode/uint (:timestamp @latest-block))
last-loaded-block-number
(decode/uint (:number @last-loaded-block))
last-loaded-block-timestamp
(decode/uint (:timestamp @last-loaded-block))]
(str "Latest block number: "
latest-block-number
"\n"
"Latest block time: "
(to-date latest-block-timestamp)
"\n"
"Last loaded block: "
last-loaded-block-number
"\n"
"Last loaded block time: "
(to-date last-loaded-block-timestamp)
"\n"
"Seconds diff: "
(- latest-block-timestamp
last-loaded-block-timestamp)
"\n"
"Blocks diff: " (- latest-block-number
last-loaded-block-number)
"\n"
"PRESS TO REFRESH"))])])))
(defn network-info
[]
[check-lag])
+60 -47
View File
@@ -1,6 +1,7 @@
(ns legacy.status-im.ui.screens.screens (ns legacy.status-im.ui.screens.screens
(:require (:require
[legacy.status-im.ui.components.colors :as colors] [legacy.status-im.ui.components.colors :as colors]
[legacy.status-im.ui.components.icons.icons :as icons]
[legacy.status-im.ui.screens.about-app.views :as about-app] [legacy.status-im.ui.screens.about-app.views :as about-app]
[legacy.status-im.ui.screens.advanced-settings.views :as advanced-settings] [legacy.status-im.ui.screens.advanced-settings.views :as advanced-settings]
[legacy.status-im.ui.screens.appearance.views :as appearance] [legacy.status-im.ui.screens.appearance.views :as appearance]
@@ -23,6 +24,10 @@
[legacy.status-im.ui.screens.link-previews-settings.views :as link-previews-settings] [legacy.status-im.ui.screens.link-previews-settings.views :as link-previews-settings]
[legacy.status-im.ui.screens.log-level-settings.views :as log-level-settings] [legacy.status-im.ui.screens.log-level-settings.views :as log-level-settings]
[legacy.status-im.ui.screens.mobile-network-settings.view :as mobile-network-settings] [legacy.status-im.ui.screens.mobile-network-settings.view :as mobile-network-settings]
[legacy.status-im.ui.screens.network-info.views :as network-info]
[legacy.status-im.ui.screens.network.edit-network.views :as edit-network]
[legacy.status-im.ui.screens.network.network-details.views :as network-details]
[legacy.status-im.ui.screens.network.views :as network]
[legacy.status-im.ui.screens.notifications-settings.views :as notifications-settings] [legacy.status-im.ui.screens.notifications-settings.views :as notifications-settings]
[legacy.status-im.ui.screens.offline-messaging-settings.edit-mailserver.views :as edit-mailserver] [legacy.status-im.ui.screens.offline-messaging-settings.edit-mailserver.views :as edit-mailserver]
[legacy.status-im.ui.screens.offline-messaging-settings.views :as offline-messaging-settings] [legacy.status-im.ui.screens.offline-messaging-settings.views :as offline-messaging-settings]
@@ -47,18 +52,10 @@
[status-im.contexts.chat.group-details.view :as group-details] [status-im.contexts.chat.group-details.view :as group-details]
[utils.i18n :as i18n])) [utils.i18n :as i18n]))
(defn topbar-options (defn right-button-options
[title] [id icon]
{:elevation 0 {:id id
:title {:color (if (colors/dark?) colors/white colors/black) :icon (icons/icon-source icon)})
:text (i18n/label title)}
:rightButtonColor (if (colors/dark?) colors/white colors/black)
:background {:color (if (colors/dark?) colors/black colors/white)}
:backButton {:color (if (colors/dark?) colors/white colors/black)
:id :legacy-back-button
:testID :back-button
:visible true
:popStackOnPress false}})
(defn screens (defn screens
[] []
@@ -84,7 +81,7 @@
{:name :stickers {:name :stickers
:options {:insets {:top? true} :options {:insets {:top? true}
:topBar (topbar-options :t/sticker-market)} :topBar {:title {:text (i18n/label :t/sticker-market)}}}
:component stickers/packs} :component stickers/packs}
{:name :stickers-pack {:name :stickers-pack
@@ -97,7 +94,7 @@
:component group-chat/new-group} :component group-chat/new-group}
{:name :currency-settings {:name :currency-settings
:options {:topBar (topbar-options :t/main-currency) :options {:topBar {:title {:text (i18n/label :t/main-currency)}}
:insets {:top? true}} :insets {:top? true}}
:component currency-settings/currency-settings} :component currency-settings/currency-settings}
@@ -107,27 +104,27 @@
:options {:topBar {:visible false}} :options {:topBar {:visible false}}
:component profile.user/my-profile} :component profile.user/my-profile}
{:name :contacts-list {:name :contacts-list
:options {:topBar (topbar-options :t/contacts) :options {:topBar {:title {:text (i18n/label :t/contacts)}}
:insets {:top? true}} :insets {:top? true}}
:component contacts-list/contacts-list} :component contacts-list/contacts-list}
{:name :ens-main {:name :ens-main
:options {:topBar (topbar-options :t/ens-usernames) :options {:topBar {:title {:text (i18n/label :t/ens-usernames)}}
:insets {:top? true}} :insets {:top? true}}
:component ens/main} :component ens/main}
{:name :ens-search {:name :ens-search
:options {:topBar (topbar-options :t/ens-your-username) :options {:topBar {:title {:text (i18n/label :t/ens-your-username)}}
:insets {:top? true}} :insets {:top? true}}
:component ens/search} :component ens/search}
{:name :ens-checkout {:name :ens-checkout
:options {:topBar (topbar-options :t/ens-your-username) :options {:topBar {:title {:text (i18n/label :t/ens-your-username)}}
:insets {:top? true}} :insets {:top? true}}
:component ens/checkout} :component ens/checkout}
{:name :ens-confirmation {:name :ens-confirmation
:options {:topBar (topbar-options :t/ens-your-username) :options {:topBar {:title {:text (i18n/label :t/ens-your-username)}}
:insets {:top? true}} :insets {:top? true}}
:component ens/confirmation} :component ens/confirmation}
{:name :ens-terms {:name :ens-terms
:options {:topBar (topbar-options :t/ens-terms-registration) :options {:topBar {:title {:text (i18n/label :t/ens-terms-registration)}}
:insets {:top? true}} :insets {:top? true}}
:component ens/terms} :component ens/terms}
{:name :ens-name-details {:name :ens-name-details
@@ -135,7 +132,7 @@
:options {:insets {:top? true}} :options {:insets {:top? true}}
:component ens/name-details} :component ens/name-details}
{:name :blocked-users-list {:name :blocked-users-list
:options {:topBar (topbar-options :t/blocked-users) :options {:topBar {:title {:text (i18n/label :t/blocked-users)}}
:insets {:top? true}} :insets {:top? true}}
:component contacts-list/blocked-users-list} :component contacts-list/blocked-users-list}
{:name :wakuv2-settings {:name :wakuv2-settings
@@ -151,7 +148,7 @@
:options {:insets {:top? true}} :options {:insets {:top? true}}
:component bootnodes-settings/bootnodes-settings} :component bootnodes-settings/bootnodes-settings}
{:name :installations {:name :installations
:options {:topBar (topbar-options (i18n/label :t/devices)) :options {:topBar {:title {:text (i18n/label :t/devices)}}
:insets {:top? true}} :insets {:top? true}}
:component pairing/installations} :component pairing/installations}
{:name :edit-bootnode {:name :edit-bootnode
@@ -167,91 +164,107 @@
:options {:insets {:top? true}} :options {:insets {:top? true}}
:component edit-mailserver/edit-mailserver} :component edit-mailserver/edit-mailserver}
{:name :dapps-permissions {:name :dapps-permissions
:options {:topBar (topbar-options :t/dapps-permissions) :options {:topBar {:title {:text (i18n/label :t/dapps-permissions)}}
:insets {:top? true}} :insets {:top? true}}
:component dapps-permissions/dapps-permissions} :component dapps-permissions/dapps-permissions}
{:name :privacy-and-security {:name :privacy-and-security
:options {:topBar (topbar-options :t/privacy-and-security) :options {:topBar {:title {:text (i18n/label :t/privacy-and-security)}}
:insets {:top? true}} :insets {:top? true}}
:component privacy-and-security/privacy-and-security} :component privacy-and-security/privacy-and-security}
{:name :messages-from-contacts-only {:name :messages-from-contacts-only
:options {:topBar (topbar-options :t/accept-new-chats-from) :options {:topBar {:title {:text (i18n/label :t/accept-new-chats-from)}}
:insets {:top? true}} :insets {:top? true}}
:component messages-from-contacts-only/messages-from-contacts-only-view} :component messages-from-contacts-only/messages-from-contacts-only-view}
{:name :appearance {:name :appearance
:options {:topBar (topbar-options :t/appearance) :options {:topBar {:title {:text (i18n/label :t/appearance)}}
:insets {:top? true}} :insets {:top? true}}
:component appearance/appearance-view} :component appearance/appearance-view}
{:name :privacy-and-security-profile-pic-show-to {:name :privacy-and-security-profile-pic-show-to
:options {:topbar (topbar-options :t/show-profile-pictures-to) :options {:topbar {:title {:text (i18n/label :t/show-profile-pictures-to)}}
:insets {:top? true}} :insets {:top? true}}
:component privacy-and-security/profile-pic-show-to} :component privacy-and-security/profile-pic-show-to}
{:name :privacy-and-security-profile-pic {:name :privacy-and-security-profile-pic
:options {:topBar (topbar-options :t/show-profile-pictures) :options {:topBar {:title {:text (i18n/label :t/show-profile-pictures)}}
:insets {:top? true}} :insets {:top? true}}
:component privacy-and-security/profile-pic} :component privacy-and-security/profile-pic}
{:name :notifications {:name :notifications
:options {:topBar (topbar-options :t/notification-settings) :options {:topBar {:title {:text (i18n/label :t/notification-settings)}}
:insets {:top? true}} :insets {:top? true}}
:component notifications-settings/notifications-settings} :component notifications-settings/notifications-settings}
{:name :sync-settings {:name :sync-settings
:options {:topBar (topbar-options :t/sync-settings) :options {:topBar {:title {:text (i18n/label :t/sync-settings)}}
:insets {:top? true}} :insets {:top? true}}
:component sync-settings/sync-settings} :component sync-settings/sync-settings}
{:name :advanced-settings {:name :advanced-settings
:options {:topBar (topbar-options :t/advanced) :options {:topBar {:title {:text (i18n/label :t/advanced)}}
:insets {:top? true}} :insets {:top? true}}
:component advanced-settings/advanced-settings} :component advanced-settings/advanced-settings}
{:name :help-center {:name :help-center
:options {:topBar (topbar-options :t/need-help) :options {:topBar {:title {:text (i18n/label :t/need-help)}}
:insets {:top? true}} :insets {:top? true}}
:component help-center/help-center} :component help-center/help-center}
{:name :glossary {:name :glossary
:options {:topBar (topbar-options :t/glossary) :options {:topBar {:title {:text (i18n/label :t/glossary)}}
:insets {:top? true}} :insets {:top? true}}
:component glossary/glossary} :component glossary/glossary}
{:name :about-app {:name :about-app
:options {:topBar (topbar-options :t/about-app) :options {:topBar {:title {:text (i18n/label :t/about-app)}}
:insets {:top? true}} :insets {:top? true}}
:component about-app/about-app} :component about-app/about-app}
{:name :privacy-policy {:name :privacy-policy
:options {:topBar (topbar-options :t/privacy-policy) :options {:topBar {:title {:text (i18n/label :t/privacy-policy)}}
:insets {:top? true}} :insets {:top? true}}
:component about-app/privacy-policy} :component about-app/privacy-policy}
{:name :terms-of-service {:name :terms-of-service
:options {:topBar (topbar-options :t/terms-of-service) :options {:topBar {:title {:text (i18n/label :t/terms-of-service)}}
:insets {:top? true}} :insets {:top? true}}
:component about-app/tos} :component about-app/tos}
{:name :principles {:name :principles
:options {:topBar (topbar-options :t/principles) :options {:topBar {:title {:text (i18n/label :t/principles)}}
:insets {:top? true}} :insets {:top? true}}
:component about-app/principles} :component about-app/principles}
{:name :manage-dapps-permissions {:name :manage-dapps-permissions
;;TODO dynamic title ;;TODO dynamic title
:options {:insets {:top? true}} :options {:insets {:top? true}}
:component dapps-permissions/manage} :component dapps-permissions/manage}
{:name :network-settings
;;TODO accessories
:options {:insets {:top? true}}
:component network/network-settings}
{:name :network-details
:options {:topBar {:title {:text (i18n/label :t/network-details)}}
:insets {:top? true}}
:component network-details/network-details}
{:name :network-info
:options {:topBar {:title {:text (i18n/label :t/network-info)}}
:insets {:top? true}}
:component network-info/network-info}
{:name :rpc-usage-info {:name :rpc-usage-info
:options {:topBar (topbar-options :t/rpc-usage-info) :options {:topBar {:title {:text (i18n/label :t/rpc-usage-info)}}
:insets {:top? true}} :insets {:top? true}}
:component rpc-usage-info/usage-info} :component rpc-usage-info/usage-info}
{:name :peers-stats {:name :peers-stats
:options {:topBar (topbar-options :t/peers-stats) :options {:topBar {:title {:text (i18n/label :t/peers-stats)}}
:insets {:top? true}} :insets {:top? true}}
:component peers-stats/peers-stats} :component peers-stats/peers-stats}
{:name :edit-network
:options {:topBar {:title {:text (i18n/label :t/add-network)}}
:insets {:top? true}}
:component edit-network/edit-network}
{:name :log-level-settings {:name :log-level-settings
:options {:topBar (topbar-options :t/log-level-settings) :options {:topBar {:title {:text (i18n/label :t/log-level-settings)}}
:insets {:top? true}} :insets {:top? true}}
:component log-level-settings/log-level-settings} :component log-level-settings/log-level-settings}
{:name :fleet-settings {:name :fleet-settings
:options {:topBar (topbar-options :t/fleet-settings) :options {:topBar {:title {:text (i18n/label :t/fleet-settings)}}
:insets {:top? true}} :insets {:top? true}}
:component fleet-settings/fleet-settings} :component fleet-settings/fleet-settings}
{:name :mobile-network-settings {:name :mobile-network-settings
:options {:topBar (topbar-options :t/mobile-network-settings) :options {:topBar {:title {:text (i18n/label :t/mobile-network-settings)}}
:insets {:top? true}} :insets {:top? true}}
:component mobile-network-settings/mobile-network-settings} :component mobile-network-settings/mobile-network-settings}
{:name :backup-settings {:name :backup-settings
:options {:topBar (topbar-options :t/backup-settings) :options {:topBar {:title {:text (i18n/label :t/backup-settings)}}
:insets {:top? true}} :insets {:top? true}}
:component backup-settings/backup-settings} :component backup-settings/backup-settings}
{:name :backup-seed {:name :backup-seed
@@ -259,14 +272,14 @@
:options {:insets {:top? true}} :options {:insets {:top? true}}
:component profile.seed/backup-seed} :component profile.seed/backup-seed}
{:name :reset-password {:name :reset-password
:options {:topBar (topbar-options :t/reset-password) :options {:topBar {:title {:text (i18n/label :t/reset-password)}}
:insets {:top? true}} :insets {:top? true}}
:component reset-password/reset-password} :component reset-password/reset-password}
{:name :delete-profile {:name :delete-profile
:insets {:bottom? true} :insets {:bottom? true}
:component delete-profile/delete-profile} :component delete-profile/delete-profile}
{:name :default-sync-period-settings {:name :default-sync-period-settings
:options {:topBar (topbar-options :t/default-sync-period) :options {:topBar {:title {:text (i18n/label :t/default-sync-period)}}
:insets {:top? true}} :insets {:top? true}}
:component default-sync-period-settings/default-sync-period-settings} :component default-sync-period-settings/default-sync-period-settings}
@@ -275,7 +288,7 @@
;[Chat] Link preview settings ;[Chat] Link preview settings
{:name :link-previews-settings {:name :link-previews-settings
:options {:topBar (topbar-options :t/chat-link-previews) :options {:topBar {:title {:text (i18n/label :t/chat-link-previews)}}
:insets {:top? true}} :insets {:top? true}}
:component link-previews-settings/link-previews-settings} :component link-previews-settings/link-previews-settings}
@@ -315,7 +328,7 @@
;;TODO WHY MODAL? ;;TODO WHY MODAL?
;[Profile] Notifications settings ;[Profile] Notifications settings
{:name :notifications-settings {:name :notifications-settings
:options {:topBar (topbar-options :t/notification-settings) :options {:topBar {:title {:text (i18n/label :t/notification-settings)}}
:popGesture false :popGesture false
:hardwareBackButton {:dismissModalOnPress false :hardwareBackButton {:dismissModalOnPress false
:popStackOnPress false} :popStackOnPress false}
+1 -1
View File
@@ -2,7 +2,7 @@
(:require-macros [legacy.status-im.utils.slurp :refer [slurp]]) (:require-macros [legacy.status-im.utils.slurp :refer [slurp]])
(:require (:require
[legacy.status-im.fleet.default-fleet :refer (default-fleets)]) [legacy.status-im.fleet.default-fleet :refer (default-fleets)])
(:require [tests.test-utils :as utils.test])) (:require [legacy.status-im.utils.test :as utils.test]))
;; to generate a js Proxy at js/__STATUS_MOBILE_JS_IDENTITY_PROXY__ that accept any (.xxx) call and ;; to generate a js Proxy at js/__STATUS_MOBILE_JS_IDENTITY_PROXY__ that accept any (.xxx) call and
;; return itself ;; return itself
@@ -1,6 +1,7 @@
(ns quo.components.colors.color-picker.component-spec (ns quo.components.colors.color-picker.component-spec
(:require (:require
[quo.components.colors.color-picker.view :as color-picker] [quo.components.colors.color-picker.view :as color-picker]
[reagent.core :as reagent]
[test-helpers.component :as h])) [test-helpers.component :as h]))
(h/describe "color-picker" (h/describe "color-picker"
@@ -11,7 +12,7 @@
(-> (h/expect event) (-> (h/expect event)
(.toHaveBeenCalled)))) (.toHaveBeenCalled))))
(h/test "color picker color changed" (h/test "color picker color changed"
(let [selected (atom nil)] (let [selected (reagent/atom nil)]
(h/render [color-picker/view {:on-change #(reset! selected %)}]) (h/render [color-picker/view {:on-change #(reset! selected %)}])
(h/fire-event :press (get (h/get-all-by-label-text :color-picker-item) 0)) (h/fire-event :press (get (h/get-all-by-label-text :color-picker-item) 0))
(-> (h/expect @selected) (-> (h/expect @selected)
@@ -20,8 +20,8 @@
[text/text {:size :paragraph-1 :weight :medium :number-of-lines 2} label]]]) [text/text {:size :paragraph-1 :weight :medium :number-of-lines 2} label]]])
(defn channel-actions (defn channel-actions
[{:keys [container-style actions]}] [{:keys [style actions]}]
[rn/view {:style (assoc container-style :flex-direction :row)} [rn/view {:style (merge {:flex-direction :row :flex 1} style)}
(map-indexed (map-indexed
(fn [index action] (fn [index action]
^{:key index} ^{:key index}
+1
View File
@@ -142,6 +142,7 @@
[color] [color]
{:padding 12 {:padding 12
:height 102 :height 102
:flex 1
:border-radius 16 :border-radius 16
:background-color (colors/custom-color color 50 10) :background-color (colors/custom-color color 50 10)
:justify-content :space-between}) :justify-content :space-between})
@@ -76,8 +76,7 @@
(str description " · " (i18n/label :t/on-device))]) (str description " · " (i18n/label :t/on-device))])
(defn- context-tag-subtitle (defn- context-tag-subtitle
[{:keys [context-tag-type community-logo community-name account-name emoji customization-color [{:keys [context-tag-type community-logo community-name account-name emoji customization-color]}]
full-name profile-picture]}]
(let [tag-type (or context-tag-type :account)] (let [tag-type (or context-tag-type :account)]
[rn/view [rn/view
{:accessibility-label :context-tag-wrapper {:accessibility-label :context-tag-wrapper
@@ -89,9 +88,7 @@
:community-name community-name :community-name community-name
:community-logo community-logo :community-logo community-logo
:size 24 :size 24
:customization-color customization-color :customization-color customization-color}]]))
:profile-picture profile-picture
:full-name full-name}]]))
(defn- description-subtitle (defn- description-subtitle
[{:keys [theme blur? description]}] [{:keys [theme blur? description]}]
@@ -103,7 +100,7 @@
(defn- subtitle (defn- subtitle
[{:keys [type theme blur? keycard? networks description community-name community-logo [{:keys [type theme blur? keycard? networks description community-name community-logo
context-tag-type account-name emoji customization-color full-name profile-picture]}] context-tag-type account-name emoji customization-color]}]
(cond (cond
(= :keypair type) (= :keypair type)
[keypair-subtitle [keypair-subtitle
@@ -131,9 +128,7 @@
:community-name community-name :community-name community-name
:account-name account-name :account-name account-name
:emoji emoji :emoji emoji
:customization-color customization-color :customization-color customization-color}]
:profile-picture profile-picture
:full-name full-name}]
(and (not= :label type) description) (and (not= :label type) description)
[description-subtitle [description-subtitle
@@ -192,7 +187,7 @@
on-button-press on-button-press
on-button-long-press on-button-long-press
button-disabled? account-avatar-emoji account-avatar-type customization-color icon-avatar button-disabled? account-avatar-emoji account-avatar-type customization-color icon-avatar
profile-picture keycard? networks label full-name]}] profile-picture keycard? networks label]}]
[rn/view {:style style/container} [rn/view {:style style/container}
(when (left-image-supported-types type) (when (left-image-supported-types type)
[rn/view {:style style/left-container} [rn/view {:style style/left-container}
@@ -223,9 +218,7 @@
:context-tag-type context-tag-type :context-tag-type context-tag-type
:customization-color customization-color :customization-color customization-color
:account-name account-name :account-name account-name
:emoji emoji :emoji emoji}]]
:full-name full-name
:profile-picture profile-picture}]]
[right-icon [right-icon
{:theme theme {:theme theme
:type type :type type
@@ -2,10 +2,5 @@
(defn root-container (defn root-container
[opacity height] [opacity height]
{:height (or height 252) {:height (or height 252)
:opacity opacity :opacity opacity})
:position :absolute
:top 0
:left 0
:right 0
:z-index -1})
+76 -76
View File
@@ -6,7 +6,8 @@
[quo.foundations.colors :as colors] [quo.foundations.colors :as colors]
[quo.theme :as quo.theme] [quo.theme :as quo.theme]
[react-native.core :as rn] [react-native.core :as rn]
[react-native.reanimated :as reanimated])) [react-native.reanimated :as reanimated]
[reagent.core :as reagent]))
(def header-height 56) (def header-height 56)
@@ -56,7 +57,7 @@
:justify-content :center :justify-content :center
:align-items :flex-end}) :align-items :flex-end})
(defn get-title-style (defn title-style
[{:keys [left right]} title-align] [{:keys [left right]} title-align]
(merge (merge
absolute-fill absolute-fill
@@ -132,77 +133,76 @@
:size :large} :size :large}
title])]) title])])
(defn header (defn- header-internal
[{:keys [left-accessories left-component border-bottom left-width right-width [{:keys [left-width right-width]}]
right-accessories right-component insets get-layout (let [layout (reagent/atom {:left {:width (or left-width 8)
title subtitle title-component style title-align :height header-height}
background] :right {:width (or right-width 8)
:or {title-align :center :height header-height}
border-bottom false}}] :title {:width 0
(let [theme (quo.theme/use-theme-value) :height header-height}})
[layout set-layout] (rn/use-state {:left {:width (or left-width 8) handle-layout (fn [el get-layout]
:height header-height} (fn [evt]
:right {:width (or right-width 8) (let [width (oget evt "nativeEvent" "layout" "width")
:height header-height} height (oget evt "nativeEvent" "layout" "height")]
:title {:width 0 (when get-layout
:height header-height}}) (get-layout el
handle-layout (rn/use-callback {:width width
(fn [el get-layout] :height height}))
(fn [evt] (swap! layout assoc
(let [width (oget evt "nativeEvent" "layout" "width") el
height (oget evt "nativeEvent" "layout" "height")] {:width width
(when get-layout :height height}))))]
(get-layout el (fn
{:width width [{:keys [left-accessories left-component border-bottom
:height height})) right-accessories right-component insets get-layout
(set-layout title subtitle title-component style title-align
(assoc layout background theme]
el :or {title-align :center
{:width width border-bottom false}}]
:height height}))))) (let [status-bar-height (get insets :top 0)
[layout]) height (+ header-height status-bar-height)]
status-bar-height (get insets :top 0) [reanimated/view
height (+ header-height status-bar-height) {:style (header-wrapper-style {:height height
title-style (rn/use-memo (fn [] (get-title-style layout title-align)) :background background
[layout title-align])] :border-bottom border-bottom
[reanimated/view :theme theme})}
{:style (header-wrapper-style {:height height [rn/view
:background background {:pointer-events :box-none
:border-bottom border-bottom :height status-bar-height}]
:theme theme})} [rn/view
[rn/view {:style (merge {:height header-height}
{:pointer-events :box-none style)
:height status-bar-height}] :pointer-events :box-none}
[rn/view [rn/view
{:style (merge {:height header-height} {:style absolute-fill
style) :pointer-events :box-none}
:pointer-events :box-none} [rn/view
[rn/view {:style content
{:style absolute-fill :pointer-events :box-none}
:pointer-events :box-none} [rn/view
[rn/view {:style left-style
{:style content :on-layout (handle-layout :left get-layout)
:pointer-events :box-none} :pointer-events :box-none}
[rn/view [header-actions
{:style left-style {:accessories left-accessories
:on-layout (handle-layout :left get-layout) :component left-component}]]
:pointer-events :box-none}
[header-actions [rn/view
{:accessories left-accessories {:style (title-style @layout title-align)
:component left-component}]] :on-layout (handle-layout :title get-layout)
[rn/view :pointer-events :box-none}
{:style title-style [header-title
:on-layout (handle-layout :title get-layout) {:title title
:pointer-events :box-none} :subtitle subtitle
[header-title :title-align title-align
{:title title :component title-component}]]
:subtitle subtitle [rn/view
:title-align title-align {:style right-style
:component title-component}]] :on-layout (handle-layout :right get-layout)
[rn/view :pointer-events :box-none}
{:style right-style [header-actions
:on-layout (handle-layout :right get-layout) {:accessories right-accessories
:pointer-events :box-none} :component right-component}]]]]]]))))
[header-actions
{:accessories right-accessories (def header (quo.theme/with-theme header-internal))
:component right-component}]]]]]]))
@@ -3,7 +3,7 @@
[quo.foundations.colors :as colors])) [quo.foundations.colors :as colors]))
(def ^:private themes (def ^:private themes
{:light {:default {:bg colors/neutral-5 {:light {:default {:bg colors/white
:border colors/neutral-20 :border colors/neutral-20
:icon colors/neutral-50 :icon colors/neutral-50
:text colors/neutral-100} :text colors/neutral-100}
+3 -4
View File
@@ -55,17 +55,16 @@
(def ^:private custom-props (def ^:private custom-props
"Custom properties that must be removed from properties map passed to InputText." "Custom properties that must be removed from properties map passed to InputText."
[:type :blur? :error? :right-icon :left-icon :disabled? :small? :button [:type :blur? :theme :error? :right-icon :left-icon :disabled? :small? :button
:label :char-limit :on-char-limit-reach :icon-name :multiline? :on-focus :on-blur :label :char-limit :on-char-limit-reach :icon-name :multiline? :on-focus :on-blur
:container-style]) :container-style])
(defn- base-input (defn- base-input
[{:keys [blur? error? right-icon left-icon disabled? small? button [{:keys [blur? theme error? right-icon left-icon disabled? small? button
label char-limit multiline? clearable? on-focus on-blur container-style label char-limit multiline? clearable? on-focus on-blur container-style
on-change-text on-char-limit-reach weight default-value] on-change-text on-char-limit-reach weight default-value]
:as props}] :as props}]
(let [theme (quo.theme/use-theme-value) (let [[status set-status] (rn/use-state :default)
[status set-status] (rn/use-state :default)
internal-on-focus (rn/use-callback #(set-status :focus)) internal-on-focus (rn/use-callback #(set-status :focus))
internal-on-blur (rn/use-callback #(set-status :default)) internal-on-blur (rn/use-callback #(set-status :default))
[multiple-lines? [multiple-lines?
@@ -10,7 +10,7 @@
:background-color (colors/theme-colors colors/neutral-10 :background-color (colors/theme-colors colors/neutral-10
colors/neutral-80-opa-80 colors/neutral-80-opa-80
theme) theme)
:min-height 40 :height 40
:padding-horizontal 12 :padding-horizontal 12
:padding-vertical 9 :padding-vertical 9
:margin-top 4}) :margin-top 4})
@@ -22,12 +22,11 @@
(defn- locked-input-internal (defn- locked-input-internal
[{:keys [label icon container-style theme]} value] [{:keys [label icon container-style theme]} value]
[rn/view {:style container-style} [rn/view {:style container-style}
(when label [text/text
[text/text {:size :paragraph-2
{:size :paragraph-2 :weight :medium
:weight :medium :style {:color (colors/theme-colors colors/neutral-50 colors/neutral-40 theme)}}
:style {:color (colors/theme-colors colors/neutral-50 colors/neutral-40 theme)}} label]
label])
[info-box [info-box
{:theme theme {:theme theme
:icon icon :icon icon
@@ -60,8 +60,8 @@
:padding-horizontal 12 :padding-horizontal 12
:padding-top 10 :padding-top 10
:padding-bottom 12 :padding-bottom 12
:width (if (= :message size) 295 335) :height (if (= :message size) 245 266)
:flex 1}) :width (if (= :message size) 295 335)})
(def header-container (def header-container
{:flex-direction :row {:flex-direction :row
@@ -7,6 +7,7 @@
{:title "Some title" {:title "Some title"
:description "Some description" :description "Some description"
:link "status.im" :link "status.im"
:logo "data:image/png,logo-x"
:thumbnail "data:image/png,whatever"}) :thumbnail "data:image/png,whatever"})
(h/describe "Links - Link Preview" (h/describe "Links - Link Preview"
@@ -20,12 +21,17 @@
(h/is-truthy (h/query-by-text (:title props))) (h/is-truthy (h/query-by-text (:title props)))
(h/is-truthy (h/query-by-text (:description props))) (h/is-truthy (h/query-by-text (:description props)))
(h/is-truthy (h/query-by-text (:link props))) (h/is-truthy (h/query-by-text (:link props)))
(h/is-truthy (h/query-by-label-text :logo))
(h/is-truthy (h/query-by-label-text :thumbnail))) (h/is-truthy (h/query-by-label-text :thumbnail)))
(h/test "does not render thumbnail if prop is not present" (h/test "does not render thumbnail if prop is not present"
(h/render [view/view (dissoc props :thumbnail)]) (h/render [view/view (dissoc props :thumbnail)])
(h/is-null (h/query-by-label-text :thumbnail))) (h/is-null (h/query-by-label-text :thumbnail)))
(h/test "does not render logo if prop is not present"
(h/render [view/view (dissoc props :logo)])
(h/is-null (h/query-by-label-text :logo)))
(h/test "shows button to enable preview when preview is disabled" (h/test "shows button to enable preview when preview is disabled"
(h/render [view/view (h/render [view/view
(assoc props (assoc props
@@ -1,14 +1,9 @@
(ns quo.components.links.link-preview.view (ns quo.components.links.link-preview.view
(:require (:require
["react-native-blob-util" :default ReactNativeBlobUtil]
[oops.core :as oops]
[quo.components.buttons.button.view :as button] [quo.components.buttons.button.view :as button]
[quo.components.links.link-preview.style :as style] [quo.components.links.link-preview.style :as style]
[quo.components.markdown.text :as text] [quo.components.markdown.text :as text]
[react-native.core :as rn] [react-native.core :as rn]))
[react-native.platform :as platform]
[react-native.svg :as svg]
[taoensso.timbre :as log]))
(defn- button-disabled (defn- button-disabled
[disabled-text on-enable] [disabled-text on-enable]
@@ -56,30 +51,14 @@
thumbnail) thumbnail)
:accessibility-label :thumbnail}]) :accessibility-label :thumbnail}])
(defn- get-image-data
[logo set-is-svg on-success]
(-> (.config ReactNativeBlobUtil (clj->js {:trusty platform/ios?}))
(.fetch "GET" logo)
(.then (fn [imgObj]
(set-is-svg (= "image/svg"
(oops/oget imgObj
["respInfo" "headers" "Content-Type"])))
(on-success (oops/oget imgObj "data"))))
(.catch #(log/error "could not fetch favicon " logo))))
(defn- logo-comp (defn- logo-comp
[logo] [logo]
(let [[image-data set-image-data] (rn/use-state nil) [rn/image
[is-svg? set-is-svg] (rn/use-state nil) {:accessibility-label :logo
on-success (fn [data-uri] :source (if (string? logo)
(set-image-data data-uri)) {:uri logo}
_get-image-data (get-image-data logo set-is-svg on-success)] logo)
(if is-svg? :style style/logo}])
[svg/svg-xml (merge style/logo {:xml image-data})]
[rn/image
{:accessibility-label :logo
:source {:uri (str "data:image/png;base64," image-data)}
:style style/logo}])))
(defn view (defn view
[{:keys [title logo description link thumbnail [{:keys [title logo description link thumbnail
@@ -21,7 +21,6 @@
:border-radius 12 :border-radius 12
:border-style :dashed :border-style :dashed
:align-items :center :align-items :center
:flex-direction :row
:justify-content :center :justify-content :center
:align-self :stretch :align-self :stretch
:padding horizontal-padding :padding horizontal-padding
+8 -27
View File
@@ -1,31 +1,19 @@
(ns quo.components.links.url-preview.view (ns quo.components.links.url-preview.view
(:require (:require
[clojure.string :as string]
[quo.components.icon :as icon] [quo.components.icon :as icon]
[quo.components.links.url-preview.style :as style] [quo.components.links.url-preview.style :as style]
[quo.components.markdown.text :as text] [quo.components.markdown.text :as text]
[quo.foundations.colors :as colors] [quo.foundations.colors :as colors]
[react-native.core :as rn] [react-native.core :as rn]))
[react-native.svg :as svg]))
(def base64-svg-prefix "data:image/svg;base64,")
(defn- logo-comp (defn- logo-comp
[{:keys [logo]}] [{:keys [logo]}]
(if (and (string? logo) [rn/image
(string/starts-with? logo base64-svg-prefix)) {:accessibility-label :logo
[svg/svg-xml :source (if (string? logo)
(merge style/logo {:uri logo}
{:xml (-> logo logo)
(string/replace base64-svg-prefix "") :style style/logo}])
js/atob)})]
[rn/image
{:accessibility-label :logo
:source (if (string? logo)
{:uri logo}
logo)
:style style/logo
:resize-mode :cover}]))
(defn- content (defn- content
[{:keys [title body]}] [{:keys [title body]}]
@@ -62,10 +50,6 @@
[rn/view [rn/view
{:accessibility-label :url-preview-loading {:accessibility-label :url-preview-loading
:style (merge (style/loading-container) container-style)} :style (merge (style/loading-container) container-style)}
[icon/icon :i/loading
{:size 12
:color (colors/theme-colors colors/neutral-50 colors/neutral-40)
:container-style {:margin-right 8}}]
[rn/text [rn/text
{:size :paragraph-2 {:size :paragraph-2
:weight :medium :weight :medium
@@ -76,9 +60,6 @@
{:accessibility-label :url-preview {:accessibility-label :url-preview
:style (merge (style/container) container-style)} :style (merge (style/container) container-style)}
(when logo (when logo
[logo-comp [logo-comp {:logo logo}])
{:logo (if (map? logo)
(:data-uri logo)
logo)}])
[content {:title title :body body}] [content {:title title :body body}]
[clear-button {:on-press on-clear}]])) [clear-button {:on-press on-clear}]]))
@@ -32,7 +32,7 @@
[rn/view {:style style/url-preview-separator}]) [rn/view {:style style/url-preview-separator}])
(defn- item-component (defn- item-component
[{:keys [title body loading? logo url]} _ _ [{:keys [title body loading? logo]} _ _
{:keys [width on-clear loading-message container-style]}] {:keys [width on-clear loading-message container-style]}]
[url-preview/view [url-preview/view
{:logo logo {:logo logo
@@ -41,8 +41,7 @@
:loading? loading? :loading? loading?
:loading-message loading-message :loading-message loading-message
:on-clear on-clear :on-clear on-clear
:container-style (merge container-style {:width width}) :container-style (merge container-style {:width width})}])
:url url}])
(defn- f-view (defn- f-view
[] []
@@ -27,6 +27,7 @@
[:blur? {:optional true} [:maybe :boolean]] [:blur? {:optional true} [:maybe :boolean]]
[:customization-color {:optional true} [:maybe :schema.common/customization-color]] [:customization-color {:optional true} [:maybe :schema.common/customization-color]]
[:on-press {:optional true} [:maybe fn?]] [:on-press {:optional true} [:maybe fn?]]
[:theme :schema.common/theme]
[:title-icon {:optional true} [:maybe :keyword]] [:title-icon {:optional true} [:maybe :keyword]]
[:account-props [:account-props
[:map [:map
+35 -33
View File
@@ -9,6 +9,7 @@
[quo.foundations.colors :as colors] [quo.foundations.colors :as colors]
[quo.theme :as quo.theme] [quo.theme :as quo.theme]
[react-native.core :as rn] [react-native.core :as rn]
[reagent.core :as reagent]
[schema.core :as schema])) [schema.core :as schema]))
(defn- account-view (defn- account-view
@@ -96,40 +97,41 @@
(colors/resolve-color customization-color theme))}]]) (colors/resolve-color customization-color theme))}]])
(defn- internal-view (defn- internal-view
[{:keys [type state blur? customization-color on-press] [_]
:or {customization-color :blue (let [pressed? (reagent/atom false)
type :default on-press-in #(reset! pressed? true)
state :default on-press-out #(reset! pressed? false)]
blur? false} (fn [{:keys [type state blur? customization-color on-press]
:as props}] :or {customization-color :blue
(let [theme (quo.theme/use-theme-value) type :default
[pressed? set-pressed] (rn/use-state false) state :default
on-press-in (rn/use-callback #(set-pressed true)) blur? false}
on-press-out (rn/use-callback #(set-pressed false)) :as props}]
props (assoc props :theme theme)] [rn/pressable
[rn/pressable {:style (style/container
{:style (style/container {:state state
{:state state :blur? blur?
:blur? blur? :customization-color customization-color
:customization-color customization-color :pressed? @pressed?})
:pressed? pressed?}) :on-press-in on-press-in
:on-press-in on-press-in :on-press on-press
:on-press on-press :on-press-out on-press-out
:on-press-out on-press-out :accessibility-label :container}
:accessibility-label :container} [account-view props]
[account-view props] [rn/view {:style (when (= type :tag) style/token-tag-container)}
[rn/view {:style (when (= type :tag) style/token-tag-container)} (cond
(cond (#{:balance-neutral :balance-negative :balance-positive} type)
(#{:balance-neutral :balance-negative :balance-positive} type) [balance-view props]
[balance-view props]
(= type :tag) (= type :tag)
[token-tag props] [token-tag props]
(= type :action) (= type :action)
[options-button props] [options-button props]
(and (= type :default) (= state :selected)) (and (= type :default) (= state :selected))
[check-icon props])]])) [check-icon props])]])))
(def view (schema/instrument #'internal-view component-schema/?schema)) (def view
(quo.theme/with-theme
(schema/instrument #'internal-view component-schema/?schema)))
@@ -5,6 +5,7 @@
[:action {:optional true} [:enum :icon :none]] [:action {:optional true} [:enum :icon :none]]
[:blur? {:optional true} [:maybe :boolean]] [:blur? {:optional true} [:maybe :boolean]]
[:on-press {:optional true} [:maybe fn?]] [:on-press {:optional true} [:maybe fn?]]
[:theme :schema.common/theme]
[:account-props [:account-props
[:map {:closed true} [:map {:closed true}
[:type [:enum :default :watch-only]] [:type [:enum :default :watch-only]]
@@ -9,37 +9,38 @@
[quo.foundations.colors :as colors] [quo.foundations.colors :as colors]
[quo.theme :as quo.theme] [quo.theme :as quo.theme]
[react-native.core :as rn] [react-native.core :as rn]
[reagent.core :as reagent]
[schema.core :as schema])) [schema.core :as schema]))
(defn- internal-view (defn- internal-view
[{:keys [action blur? account-props networks on-press on-options-press]}] []
(let [theme (quo.theme/use-theme-value) (let [state (reagent/atom :default)]
[state set-state] (rn/use-state :default) (fn [{:keys [action blur? account-props networks on-press on-options-press theme]}]
on-press-in (rn/use-callback #(set-state :pressed)) [rn/pressable
on-press-out (rn/use-callback #(set-state :default))] {:style (style/container {:state @state :blur? blur? :theme theme})
[rn/pressable :on-press-in #(reset! state :pressed)
{:style (style/container {:state state :blur? blur? :theme theme}) :on-press-out #(reset! state :default)
:on-press-in on-press-in :on-press on-press
:on-press-out on-press-out :accessibility-label :container}
:on-press on-press [rn/view {:style style/left-container}
:accessibility-label :container} [account-avatar/view account-props]
[rn/view {:style style/left-container} [rn/view {:style {:margin-left 8}}
[account-avatar/view account-props] [text/text
[rn/view {:style {:margin-left 8}} {:weight :semi-bold
[text/text :size :paragraph-2}
{:weight :semi-bold (:name account-props)]
:size :paragraph-2} [address-text/view
(:name account-props)] {:networks networks
[address-text/view :address (:address account-props)
{:networks networks :format :short}]]]
:address (:address account-props) (when (= action :icon)
:format :short}]]] [rn/pressable {:on-press on-options-press}
(when (= action :icon) [icon/icon :i/options
[rn/pressable {:on-press on-options-press} {:color (if blur?
[icon/icon :i/options colors/white-opa-70
{:color (if blur? (colors/theme-colors colors/neutral-50 colors/neutral-40 theme))
colors/white-opa-70 :accessibility-label :icon}]])])))
(colors/theme-colors colors/neutral-50 colors/neutral-40 theme))
:accessibility-label :icon}]])]))
(def view (schema/instrument #'internal-view component-schema/?schema)) (def view
(quo.theme/with-theme
(schema/instrument #'internal-view component-schema/?schema)))
@@ -9,5 +9,6 @@
[:customization-color {:optional true} [:maybe :schema.common/customization-color]] [:customization-color {:optional true} [:maybe :schema.common/customization-color]]
[:on-press {:optional true} [:maybe fn?]] [:on-press {:optional true} [:maybe fn?]]
[:blur? {:optional true} [:maybe :boolean]] [:blur? {:optional true} [:maybe :boolean]]
[:theme :schema.common/theme]
[:active-state? {:optional true} [:maybe :boolean]]]] [:active-state? {:optional true} [:maybe :boolean]]]]
:any]) :any])
+32 -32
View File
@@ -1,12 +1,13 @@
(ns quo.components.list-items.address.view (ns quo.components.list-items.address.view
(:require (:require
[quo.components.avatars.wallet-user-avatar.view :as wallet-user-avatar] [quo.components.avatars.wallet-user-avatar.view :as wallet-user-avatar]
[quo.components.list-items.address.schema :as component-schema] (quo.components.list-items.address.schema :as component-schema)
[quo.components.list-items.address.style :as style] [quo.components.list-items.address.style :as style]
[quo.components.markdown.text :as text] [quo.components.markdown.text :as text]
[quo.foundations.colors :as colors] [quo.foundations.colors :as colors]
[quo.theme :as quo.theme] [quo.theme :as quo.theme]
[react-native.core :as rn] [react-native.core :as rn]
[reagent.core :as reagent]
[schema.core :as schema] [schema.core :as schema]
[utils.address :as address])) [utils.address :as address]))
@@ -38,35 +39,34 @@
(address/get-shortened-key address)]]]]) (address/get-shortened-key address)]]]])
(defn- internal-view (defn- internal-view
[{:keys [networks address customization-color on-press active-state? blur?] []
:or {customization-color :blue}}] (let [state (reagent/atom :default)
(let [theme (quo.theme/use-theme-value) active? (atom false)
[state set-state] (rn/use-state :default) timer (atom nil)
active? (rn/use-ref-atom false) on-press-in (fn []
timer (rn/use-ref-atom nil) (when-not (= @state :selected)
on-press-in (rn/use-callback (reset! timer (js/setTimeout #(reset! state :pressed) 100))))]
(fn [] (fn [{:keys [networks address customization-color on-press active-state? blur? theme]
(when-not (= state :selected) :or {customization-color :blue}}]
(reset! timer (js/setTimeout #(set-state :pressed) 100)))) (let [on-press-out (fn []
[state]) (let [new-state (if (or (not active-state?) @active?) :default :active)]
on-press-out (rn/use-callback (when @timer (js/clearTimeout @timer))
(fn [] (reset! timer nil)
(let [new-state (if (or (not active-state?) @active?) :default :active)] (reset! active? (= new-state :active))
(when @timer (js/clearTimeout @timer)) (reset! state new-state)))]
(reset! timer nil) [rn/pressable
(reset! active? (= new-state :active)) {:style (style/container @state customization-color blur?)
(set-state new-state))) :on-press-in on-press-in
[active-state?])] :on-press-out on-press-out
[rn/pressable :on-press on-press
{:style (style/container state customization-color blur?) :accessibility-label :container}
:on-press-in on-press-in [left-container
:on-press-out on-press-out {:theme theme
:on-press on-press :networks networks
:accessibility-label :container} :address address
[left-container :blur? blur?}]]))))
{:theme theme
:networks networks (def view
:address address (quo.theme/with-theme
:blur? blur?}]])) (schema/instrument #'internal-view component-schema/?schema)))
(def view (schema/instrument #'internal-view component-schema/?schema))
+39 -37
View File
@@ -5,10 +5,11 @@
[quo.components.icon :as quo.icons] [quo.components.icon :as quo.icons]
[quo.components.list-items.channel.style :as style] [quo.components.list-items.channel.style :as style]
[quo.components.markdown.text :as quo.text] [quo.components.markdown.text :as quo.text]
[quo.theme] [quo.theme :as theme]
[react-native.core :as rn])) [react-native.core :as rn]
[reagent.core :as reagent]))
(defn view (defn- view-internal
"Options: "Options:
- notification - (nil/:notification/:mention/:mute, default: nil): - notification - (nil/:notification/:mention/:mute, default: nil):
- :notification - Display a grey dot. - :notification - Display a grey dot.
@@ -26,37 +27,38 @@
- on-press - (function, default: nil) - Function called when the component is pressed. - on-press - (function, default: nil) - Function called when the component is pressed.
- on-long-press - (function, default: nil) - Function called when the component is long pressed. - on-long-press - (function, default: nil) - Function called when the component is long pressed.
- theme - Theme value from with-theme HOC" - theme - Theme value from with-theme HOC"
[{:keys [notification locked? mentions-count customization-color emoji name on-press on-long-press]}] []
(let [theme (quo.theme/use-theme-value) (let [pressed? (reagent/atom false)]
[pressed? set-pressed] (rn/use-state false) (fn [{:keys [notification locked? mentions-count customization-color emoji name on-press
on-press-in (rn/use-callback #(set-pressed true)) on-long-press theme]}]
on-press-out (rn/use-callback #(set-pressed false))] [rn/pressable
[rn/pressable {:style (style/container @pressed? customization-color theme)
{:style (style/container pressed? customization-color theme) :accessibility-label :channel-list-item
:accessibility-label :channel-list-item :on-press on-press
:on-press on-press :on-long-press on-long-press
:on-long-press on-long-press :on-press-in #(reset! pressed? true)
:on-press-in on-press-in :on-press-out #(reset! pressed? false)}
:on-press-out on-press-out} [channel-avatar/view
[channel-avatar/view {:size :size-32
{:size :size-32 :locked? locked?
:locked? locked? :full-name name
:full-name name :customization-color customization-color
:customization-color customization-color :emoji emoji}]
:emoji emoji}] [quo.text/text
[quo.text/text {:style (style/label notification theme)
{:style (style/label notification theme) :weight :medium
:weight :medium :size :paragraph-1} (str "# " name)]
:size :paragraph-1} (str "# " name)] (when-not locked?
(when-not locked? (condp = notification
(condp = notification :mute [quo.icons/icon :i/muted
:mute [quo.icons/icon :i/muted {:color (style/mute-notification-icon-color theme)}]
{:color (style/mute-notification-icon-color theme)}] :mention [counter/view
:mention [counter/view {:customization-color customization-color
{:customization-color customization-color :container-style (style/counter mentions-count)}
:container-style (style/counter mentions-count)} mentions-count]
mentions-count] :notification [quo.icons/icon :i/notification
:notification [quo.icons/icon :i/notification {:color (style/mute-notification-icon-color theme)
{:color (style/mute-notification-icon-color theme) :accessibility-label :unviewed-messages-public}]
:accessibility-label :unviewed-messages-public}] nil))])))
nil))]))
(def view (theme/with-theme view-internal))
@@ -7,7 +7,8 @@
[quo.components.markdown.text :as text] [quo.components.markdown.text :as text]
[quo.foundations.colors :as colors] [quo.foundations.colors :as colors]
[quo.theme :as quo.theme] [quo.theme :as quo.theme]
[react-native.core :as rn])) [react-native.core :as rn]
[reagent.core :as reagent]))
(defn- logo-component (defn- logo-component
[logo] [logo]
@@ -82,7 +83,7 @@
:style {:margin-left 10}} :style {:margin-left 10}}
component]))) component])))
(defn view (defn- view-internal
"Options: "Options:
:type - :discover/engage/share :type - :discover/engage/share
@@ -115,48 +116,49 @@
:unread-count - number - When the info is :mention, it will be used to show :unread-count - number - When the info is :mention, it will be used to show
the number of unread mentions. the number of unread mentions.
" "
[{:keys [members type info tokens locked? title subtitle logo blur? customization-color []
on-press on-long-press on-press-info container-style unread-count]}] (let [pressed? (reagent/atom false)]
(let [theme (quo.theme/use-theme-value) (fn [{:keys [members type info tokens locked? title subtitle
[pressed? set-pressed] (rn/use-state false) logo blur? customization-color
on-press-in (rn/use-callback #(set-pressed true)) on-press on-long-press on-press-info
on-press-out (rn/use-callback #(set-pressed false))] container-style unread-count theme]}]
[rn/pressable [rn/pressable
{:accessibility-label :container {:accessibility-label :container
:on-press-in (fn [] (reset! pressed? true))
:on-press on-press
:on-long-press on-long-press
:on-press-out (fn [] (reset! pressed? false))
:style (merge (style/container {:blur? blur?
:customization-color customization-color
:info info
:type type
:pressed? @pressed?
:theme theme})
container-style)}
[logo-component logo]
[rn/view {:style {:flex 1}}
[title-component
{:blur? blur?
:info info
:theme theme
:title title
:type type}]
(when (and (= type :share) subtitle)
[subtitle-component subtitle blur? theme])
(when (and members (= type :discover))
[community-view/community-stats-column
{:type :list-view
:members-count (:members-count members)
:active-count (:active-count members)}])]
[info-component
{:blur? blur?
:customization-color customization-color
:info info
:type type
:locked? locked?
:on-press-info on-press-info
:theme theme
:tokens tokens
:unread-count unread-count}]])))
:on-press on-press (def view (quo.theme/with-theme view-internal))
:on-long-press on-long-press
:on-press-in on-press-in
:on-press-out on-press-out
:style (merge (style/container {:blur? blur?
:customization-color customization-color
:info info
:type type
:pressed? pressed?
:theme theme})
container-style)}
[logo-component logo]
[rn/view {:style {:flex 1}}
[title-component
{:blur? blur?
:info info
:theme theme
:title title
:type type}]
(when (and (= type :share) subtitle)
[subtitle-component subtitle blur? theme])
(when (and members (= type :discover))
[community-view/community-stats-column
{:type :list-view
:members-count (:members-count members)
:active-count (:active-count members)}])]
[info-component
{:blur? blur?
:customization-color customization-color
:info info
:type type
:locked? locked?
:on-press-info on-press-info
:theme theme
:tokens tokens
:unread-count unread-count}]]))
+39 -37
View File
@@ -6,41 +6,43 @@
[quo.foundations.colors :as colors] [quo.foundations.colors :as colors]
[quo.theme :as quo.theme] [quo.theme :as quo.theme]
[react-native.core :as rn] [react-native.core :as rn]
[react-native.fast-image :as fast-image])) [react-native.fast-image :as fast-image]
[reagent.core :as reagent]))
(defn view (defn- view-internal
[{:keys [dapp action on-press on-press-icon] :as props}] []
(let [theme (quo.theme/use-theme-value) (let [pressed? (reagent/atom false)]
[pressed? set-pressed] (rn/use-state false) (fn [{:keys [dapp action on-press on-press-icon theme] :as props}]
on-press-in (rn/use-callback #(set-pressed true)) [rn/pressable
on-press-out (rn/use-callback #(set-pressed false))] {:style (style/container (assoc props :pressed? @pressed?))
[rn/pressable :on-press on-press
{:style (style/container (assoc props :pressed? pressed?)) :on-press-in #(reset! pressed? true)
:on-press on-press :on-press-out #(reset! pressed? false)}
:on-press-in on-press-in [rn/view {:style style/container-info}
:on-press-out on-press-out} [fast-image/fast-image
[rn/view {:style style/container-info} {:source (:avatar dapp)
[fast-image/fast-image :style {:width 32 :height 32}}]
{:source (:avatar dapp) [rn/view {:style style/user-info}
:style {:width 32 :height 32}}] [text/text
[rn/view {:style style/user-info} {:weight :semi-bold
[text/text :size :paragraph-1
{:weight :semi-bold :style (style/style-text-name theme)}
:size :paragraph-1 (:name dapp)]
:style (style/style-text-name theme)} [text/text
(:name dapp)] {:weight :regular
[text/text :size :paragraph-2
{:weight :regular :style (style/style-text-value theme)}
:size :paragraph-2 (:value dapp)]]]
:style (style/style-text-value theme)} (when (= action :icon)
(:value dapp)]]] [rn/pressable
(when (= action :icon) {:on-press on-press-icon
[rn/pressable :testID "dapp-component-icon"}
{:on-press on-press-icon [icons/icon :i/options
:testID "dapp-component-icon"} {:color (colors/theme-colors
[icons/icon :i/options colors/neutral-50
{:color (colors/theme-colors colors/neutral-40
colors/neutral-50 theme)
colors/neutral-40 :accessibility-label :icon}]])])))
theme)
:accessibility-label :icon}]])])) (def view
(quo.theme/with-theme view-internal))
@@ -5,6 +5,7 @@
[quo.components.markdown.text :as text] [quo.components.markdown.text :as text]
[quo.theme :as quo.theme] [quo.theme :as quo.theme]
[react-native.core :as rn] [react-native.core :as rn]
[reagent.core :as reagent]
[schema.core :as schema])) [schema.core :as schema]))
(defn- info (defn- info
@@ -21,19 +22,18 @@
(if (string/blank? label) "-" label)]]]) (if (string/blank? label) "-" label)]]])
(defn- values (defn- values
[{:keys [token-value fiat-value]}] [{:keys [token-value fiat-value theme]}]
(let [theme (quo.theme/use-theme-value)] [rn/view {:style style/values-container}
[rn/view {:style style/values-container} [text/text
[text/text {:weight :medium
{:weight :medium :size :paragraph-2
:size :paragraph-2 :number-of-lines 1}
:number-of-lines 1} token-value]
token-value] [text/text
[text/text {:style (style/fiat-value theme)
{:style (style/fiat-value theme) :size :paragraph-2
:size :paragraph-2 :number-of-lines 1}
:number-of-lines 1} fiat-value]])
fiat-value]]))
(def ?schema (def ?schema
[:=> [:=>
@@ -51,21 +51,26 @@
:any]) :any])
(defn- view-internal (defn- view-internal
[{:keys [on-press state customization-color] []
:as props (let [pressed? (reagent/atom false)
:or {customization-color :blue}}] on-press-in #(reset! pressed? true)
(let [theme (quo.theme/use-theme-value) on-press-out #(reset! pressed? false)]
[pressed? set-pressed] (rn/use-state false) (fn [{:keys [on-press state customization-color theme]
on-press-in (rn/use-callback #(set-pressed true)) :as props
on-press-out (rn/use-callback #(set-pressed false)) :or {customization-color :blue}}]
internal-state (if pressed? :pressed state)] (let [internal-state (if @pressed?
[rn/pressable :pressed
{:style (style/container internal-state customization-color theme) state)]
:on-press-in on-press-in
:on-press-out on-press-out
:on-press on-press
:accessibility-label :network-list}
[info props]
[values props]]))
(def view (schema/instrument #'view-internal ?schema)) [rn/pressable
{:style (style/container internal-state customization-color theme)
:on-press-in on-press-in
:on-press-out on-press-out
:on-press on-press
:accessibility-label :network-list}
[info props]
[values props]]))))
(def view
(quo.theme/with-theme
(schema/instrument #'view-internal ?schema)))
@@ -7,69 +7,70 @@
[quo.foundations.colors :as colors] [quo.foundations.colors :as colors]
[quo.theme :as quo.theme] [quo.theme :as quo.theme]
[react-native.core :as rn] [react-native.core :as rn]
[reagent.core :as reagent]
[utils.address :as address])) [utils.address :as address]))
(defn- left-container (defn- left-container
[{:keys [blur? name ens address customization-color]}] [{:keys [blur? theme name ens address customization-color]}]
(let [theme (quo.theme/use-theme-value)] [rn/view {:style style/left-container}
[rn/view {:style style/left-container} [wallet-user-avatar/wallet-user-avatar
[wallet-user-avatar/wallet-user-avatar {:size :size-32
{:size :size-32 :full-name name
:full-name name :customization-color customization-color}]
:customization-color customization-color}] [rn/view {:style style/account-container}
[rn/view {:style style/account-container} [text/text
[text/text {:weight :semi-bold
{:weight :semi-bold :size :paragraph-1
:size :paragraph-1 :style style/name-text}
:style style/name-text} name]
name] [text/text {:size :paragraph-2}
[text/text {:size :paragraph-2} [text/text
[text/text {:size :paragraph-2
{:size :paragraph-2 :weight :monospace
:weight :monospace :style (style/account-address blur? theme)}
:style (style/account-address blur? theme)} (or ens (address/get-shortened-key address))]]]])
(or ens (address/get-shortened-key address))]]]]))
(defn view (defn- internal-view
[{:keys [blur? user-props active-state? customization-color on-press on-options-press] []
:or {customization-color :blue (let [state (reagent/atom :default)
blur? false}}] active? (atom false)
(let [theme (quo.theme/use-theme-value) timer (atom nil)
[state set-state] (rn/use-state :default) on-press-in (fn []
active? (rn/use-ref-atom false) (when-not (= @state :selected)
timer (rn/use-ref-atom nil) (reset! timer (js/setTimeout #(reset! state :pressed) 100))))]
on-press-in (rn/use-callback (fn [{:keys [blur? user-props active-state? customization-color
(fn [] on-press
(when-not (= state :selected) on-options-press
(reset! timer (js/setTimeout #(set-state :pressed) 100)))) theme]
[state]) :or {customization-color :blue
on-press-out (rn/use-callback blur? false}}]
(fn [] (let [on-press-out (fn []
(let [new-state (if (or (not active-state?) @active?) :default :active)] (let [new-state (if (or (not active-state?) @active?) :default :active)]
(when @timer (js/clearTimeout @timer)) (when @timer (js/clearTimeout @timer))
(reset! timer nil) (reset! timer nil)
(reset! active? (= new-state :active)) (reset! active? (= new-state :active))
(set-state new-state))) (reset! state new-state)))]
[active-state?])] [rn/pressable
[rn/pressable {:style (style/container
{:style (style/container {:state @state :blur? blur? :customization-color customization-color})
{:state state :blur? blur? :customization-color customization-color}) :on-press-in on-press-in
:on-press-in on-press-in :on-press-out on-press-out
:on-press-out on-press-out :on-press on-press
:on-press on-press :accessibility-label :container}
:accessibility-label :container} [left-container
[left-container {:blur? blur?
{:blur? blur? :theme theme
:theme theme :name (:name user-props)
:name (:name user-props) :ens (:ens user-props)
:ens (:ens user-props) :address (:address user-props)
:address (:address user-props) :customization-color (or (:customization-color user-props) :blue)}]
:customization-color (or (:customization-color user-props) :blue)}] (when on-options-press
(when on-options-press [rn/pressable
[rn/pressable {:accessibility-label :options-button
{:accessibility-label :options-button :on-press on-options-press}
:on-press on-options-press} [icon/icon :i/options
[icon/icon :i/options {:color (if blur?
{:color (if blur? colors/white-opa-70
colors/white-opa-70 (colors/theme-colors colors/neutral-50 colors/neutral-40 theme))}]])]))))
(colors/theme-colors colors/neutral-50 colors/neutral-40 theme))}]])]))
(def view (quo.theme/with-theme internal-view))
@@ -23,6 +23,7 @@
[:contact-props ?contact] [:contact-props ?contact]
[:accounts {:optional true} ?accounts] [:accounts {:optional true} ?accounts]
[:on-press {:optional true} [:maybe fn?]] [:on-press {:optional true} [:maybe fn?]]
[:theme :schema.common/theme]
[:active-state? {:optional true} [:maybe :boolean]] [:active-state? {:optional true} [:maybe :boolean]]
[:customization-color {:optional true} [:maybe :schema.common/customization-color]]]] [:customization-color {:optional true} [:maybe :schema.common/customization-color]]]]
:any]) :any])
@@ -9,89 +9,91 @@
[quo.foundations.colors :as colors] [quo.foundations.colors :as colors]
[quo.theme :as quo.theme] [quo.theme :as quo.theme]
[react-native.core :as rn] [react-native.core :as rn]
[reagent.core :as reagent]
[schema.core :as schema] [schema.core :as schema]
[utils.address :as address] [utils.address :as address]
[utils.i18n :as i18n])) [utils.i18n :as i18n]))
(defn- account (defn- account
[{:keys [emoji name address customization-color]}] [{:keys [emoji name address customization-color theme]}]
(let [theme (quo.theme/use-theme-value)] [rn/view
[rn/view {:accessibility-label :account-container
{:accessibility-label :account-container :style style/account-container}
:style style/account-container} [account-avatar/view
[account-avatar/view {:emoji emoji
{:emoji emoji :size 16
:size 16 :customization-color customization-color}]
:customization-color customization-color}] [text/text
[text/text {:size :paragraph-2
{:size :paragraph-2 :weight :monospace
:weight :monospace :style (style/account-name theme)}
:style (style/account-name theme)} name]
name] [rn/view {:style (style/dot-divider theme)}]
[rn/view {:style (style/dot-divider theme)}] [text/text
[text/text {:size :paragraph-2
{:size :paragraph-2 :weight :monospace
:weight :monospace :style (style/account-address theme)}
:style (style/account-address theme)} (address/get-shortened-key address)]])
(address/get-shortened-key address)]]))
(defn- internal-view (defn- internal-view
[{:keys [contact-props accounts active-state? customization-color on-press] []
:or {customization-color :blue (let [state (reagent/atom :default)
accounts [] active? (atom false)
active-state? true}}] timer (atom nil)
(let [theme (quo.theme/use-theme-value) on-press-in (fn []
[state set-state] (rn/use-state :default) (when-not (= @state :selected)
active? (rn/use-ref-atom false) (reset! timer (js/setTimeout #(reset! state :pressed) 100))))]
timer (rn/use-ref-atom nil) (fn [{:keys [contact-props accounts active-state? customization-color on-press theme]
on-press (rn/use-callback #(when on-press (on-press))) :or {customization-color :blue
on-press-in (rn/use-callback accounts []
(fn [] active-state? true}}]
(when-not (= state :selected) (let [accounts-count (count accounts)
(reset! timer (js/setTimeout #(set-state :pressed) 100)))) account-props (when (= accounts-count 1)
[state]) (first accounts))
accounts-count (count accounts) on-press-out (fn []
account-props (when (= accounts-count 1) (first accounts))
on-press-out (rn/use-callback
(fn []
(let [new-state (if (or (not active-state?) @active?) :default :active)] (let [new-state (if (or (not active-state?) @active?) :default :active)]
(when @timer (js/clearTimeout @timer)) (when @timer (js/clearTimeout @timer))
(reset! timer nil) (reset! timer nil)
(reset! active? (= new-state :active)) (reset! active? (= new-state :active))
(set-state new-state))) (reset! state new-state)))]
[active-state?])] [rn/pressable
[rn/pressable {:style (style/container
{:style (style/container {:state state :customization-color customization-color}) {:state @state :customization-color customization-color})
:on-press-in on-press-in :on-press-in on-press-in
:on-press-out on-press-out :on-press-out on-press-out
:on-press on-press :on-press #(when on-press
:accessibility-label :container} (on-press))
[rn/view {:style style/left-container} :accessibility-label :container}
[user-avatar/user-avatar (assoc contact-props :size :small)] [rn/view {:style style/left-container}
[rn/view {:style style/saved-contact-container} [user-avatar/user-avatar (assoc contact-props :size :small)]
[rn/view [rn/view {:style style/saved-contact-container}
{:style style/account-title-container} [rn/view
[text/text {:style style/account-title-container}
{:weight :semi-bold [text/text
:size :paragraph-1} {:weight :semi-bold
(:full-name contact-props)] :size :paragraph-1}
[icon/icon :i/contact (:full-name contact-props)]
{:container-style style/contact-icon-container [icon/icon :i/contact
:accessibility-label :contact-icon {:container-style style/contact-icon-container
:size 12 :accessibility-label :contact-icon
:color (colors/theme-colors colors/primary-50 colors/primary-60 theme) :size 12
:color-2 colors/white}]] :color (colors/theme-colors colors/primary-50 colors/primary-60 theme)
(if account-props :color-2 colors/white}]]
[account (assoc account-props :theme theme)] (if account-props
[text/text [account (assoc account-props :theme theme)]
{:accessibility-label :accounts-count [text/text
:size :paragraph-2 {:accessibility-label :accounts-count
:style (style/accounts-count theme)} :size :paragraph-2
(i18n/label :t/accounts-count {:count accounts-count})])]] :style (style/accounts-count theme)}
(when (> accounts-count 1) (i18n/label :t/accounts-count {:count accounts-count})])]]
[icon/icon :i/chevron-right (when (> accounts-count 1)
{:accessibility-label :check-icon [icon/icon :i/chevron-right
:size 20 {:accessibility-label :check-icon
:color (colors/theme-colors colors/neutral-50 colors/neutral-40 theme)}])])) :size 20
:color (colors/theme-colors colors/neutral-50
colors/neutral-40
theme)}])]))))
(def view (schema/instrument #'internal-view component-schema/?schema)) (def view
(quo.theme/with-theme
(schema/instrument #'internal-view component-schema/?schema)))
@@ -11,5 +11,6 @@
[:networks [:* [:map [:source :schema.common/image-source]]]] [:networks [:* [:map [:source :schema.common/image-source]]]]
[:on-press {:optional true} [:maybe fn?]] [:on-press {:optional true} [:maybe fn?]]
[:customization-color {:optional true} [:maybe :schema.common/customization-color]] [:customization-color {:optional true} [:maybe :schema.common/customization-color]]
[:state {:optional true} [:enum :default :active :selected]]]] [:state {:optional true} [:enum :default :active :selected]]
[:theme :schema.common/theme]]]
:any]) :any])
@@ -8,6 +8,7 @@
[quo.components.utilities.token.view :as token] [quo.components.utilities.token.view :as token]
[quo.theme :as quo.theme] [quo.theme :as quo.theme]
[react-native.core :as rn] [react-native.core :as rn]
[reagent.core :as reagent]
[schema.core :as schema])) [schema.core :as schema]))
(defn- info (defn- info
@@ -30,40 +31,44 @@
networks]]]) networks]]])
(defn- values (defn- values
[{:keys [state token-value fiat-value customization-color]}] [{:keys [state token-value fiat-value customization-color theme]}]
(let [theme (quo.theme/use-theme-value)] (if (= state :selected)
(if (= state :selected) [icon/icon :i/check
[icon/icon :i/check {:color (style/check-color customization-color theme)
{:color (style/check-color customization-color theme) :accessibility-label :check-icon}]
:accessibility-label :check-icon}] [rn/view {:style style/values-container}
[rn/view {:style style/values-container} [text/text
[text/text {:weight :medium
{:weight :medium :size :paragraph-2
:size :paragraph-2 :number-of-lines 1}
:number-of-lines 1} token-value]
token-value] [text/text
[text/text {:style (style/fiat-value theme)
{:style (style/fiat-value theme) :size :paragraph-2
:size :paragraph-2 :number-of-lines 1}
:number-of-lines 1} fiat-value]]))
fiat-value]])))
(defn- view-internal (defn- view-internal
[{:keys [on-press state customization-color _token _networks _token-value _fiat-value] []
:as props (let [pressed? (reagent/atom false)
:or {customization-color :blue}}] on-press-in #(reset! pressed? true)
(let [theme (quo.theme/use-theme-value) on-press-out #(reset! pressed? false)]
[pressed? set-pressed] (rn/use-state false) (fn [{:keys [on-press state customization-color
on-press-in (rn/use-callback #(set-pressed true)) _token _networks _token-value _fiat-value theme]
on-press-out (rn/use-callback #(set-pressed false)) :as props
internal-state (if pressed? :pressed state)] :or {customization-color :blue}}]
[rn/pressable (let [internal-state (if @pressed?
{:style (style/container internal-state customization-color theme) :pressed
:on-press-in on-press-in state)]
:on-press-out on-press-out [rn/pressable
:on-press on-press {:style (style/container internal-state customization-color theme)
:accessibility-label :token-network} :on-press-in on-press-in
[info props] :on-press-out on-press-out
[values props]])) :on-press on-press
:accessibility-label :token-network}
[info props]
[values props]]))))
(def view (schema/instrument #'view-internal component-schema/?schema)) (def view
(quo.theme/with-theme
(schema/instrument #'view-internal component-schema/?schema)))
@@ -17,6 +17,7 @@
[:values ?values] [:values ?values]
[:on-press {:optional true} [:maybe fn?]] [:on-press {:optional true} [:maybe fn?]]
[:on-long-press {:optional true} [:maybe fn?]] [:on-long-press {:optional true} [:maybe fn?]]
[:theme :schema.common/theme]
[:customization-color {:optional true} [:maybe :schema.common/customization-color]] [:customization-color {:optional true} [:maybe :schema.common/customization-color]]
[:metrics? {:optional true} [:maybe :boolean]]]] [:metrics? {:optional true} [:maybe :boolean]]]]
:any]) :any])
@@ -9,67 +9,64 @@
[quo.foundations.colors :as colors] [quo.foundations.colors :as colors]
[quo.theme :as quo.theme] [quo.theme :as quo.theme]
[react-native.core :as rn] [react-native.core :as rn]
[reagent.core :as reagent]
[schema.core :as schema])) [schema.core :as schema]))
(defn- internal-view (defn- internal-view
[{:keys [customization-color status token metrics? values on-press on-long-press token-name]}] []
(let [theme (quo.theme/use-theme-value) (let [state (reagent/atom :default)]
[state set-state] (rn/use-state :default) (fn [{:keys [theme customization-color status token metrics? values on-press on-long-press
bg-opacity (case state token-name]}]
:active 10 (let [bg-opacity (case @state
:pressed 5 :active 10
0) :pressed 5
{:keys [crypto-value 0)
fiat-value {:keys [crypto-value fiat-value percentage-change fiat-change]} values]
percentage-change [rn/pressable
fiat-change]} values {:style (style/container customization-color bg-opacity theme)
on-press-in (rn/use-callback #(set-state :pressed)) :on-press-in #(reset! state :pressed)
on-press-out (rn/use-callback #(set-state :default)) :on-press-out #(reset! state :default)
on-press (rn/use-callback :on-press (fn []
(fn [] (reset! state :active)
(set-state :active) (js/setTimeout #(reset! state :default) 300)
(js/setTimeout #(set-state :default) 300) on-press)
on-press))] :on-long-press on-long-press
[rn/pressable :accessibility-label :container}
{:style (style/container customization-color bg-opacity theme) [rn/view
:on-press-in on-press-in {:style {:flex-direction :row
:on-press-out on-press-out :align-items :center
:on-press on-press :flex 1}}
:on-long-press on-long-press [token/view {:token token :size :size-32}]
:accessibility-label :container} [rn/view {:style {:margin-left 8}}
[rn/view [text/text {:weight :semi-bold} token-name]
{:style {:flex-direction :row [text/text
:align-items :center {:size :paragraph-2
:flex 1}} :style {:color (colors/theme-colors colors/neutral-50 colors/neutral-40 theme)}}
[token/view {:token token :size :size-32}] (str crypto-value " " (if token (string/upper-case (clj->js token)) ""))]]]
[rn/view {:style {:margin-left 8}} [rn/view
[text/text {:weight :semi-bold} token-name] {:style {:align-items :flex-end
[text/text :justify-content :space-between}}
{:size :paragraph-2 [text/text
:style {:color (colors/theme-colors colors/neutral-50 colors/neutral-40 theme)}} {:weight :medium
(str crypto-value " " (if token (string/upper-case (clj->js token)) ""))]]] :size :paragraph-2} fiat-value]
[rn/view (when metrics?
{:style {:align-items :flex-end [rn/view
:justify-content :space-between}} {:style {:flex-direction :row
[text/text :align-items :center}}
{:weight :medium [text/text
:size :paragraph-2} fiat-value] {:size :paragraph-2
(when metrics? :style (style/metric-text status theme)} (str percentage-change "%")]
[rn/view [rn/view {:style (style/dot-divider status theme)}]
{:style {:flex-direction :row [text/text
:align-items :center}} {:size :paragraph-2
[text/text :style (style/metric-text status theme)} fiat-change]
{:size :paragraph-2 (when (not= status :empty)
:style (style/metric-text status theme)} (str percentage-change "%")] [rn/view
[rn/view {:style (style/dot-divider status theme)}] {:style {:margin-left 4}
[text/text :accessibility-label :arrow-icon}
{:size :paragraph-2 [icon/icon (if (= status :positive) :i/positive :i/negative)
:style (style/metric-text status theme)} fiat-change] (style/arrow-icon status theme)]])])]]))))
(when (not= status :empty)
[rn/view
{:style {:margin-left 4}
:accessibility-label :arrow-icon}
[icon/icon (if (= status :positive) :i/positive :i/negative)
(style/arrow-icon status theme)]])])]]))
(def view (schema/instrument #'internal-view component-schema/?schema)) (def view
(quo.theme/with-theme
(schema/instrument #'internal-view component-schema/?schema)))
+22 -22
View File
@@ -5,7 +5,8 @@
[quo.components.markdown.text :as text] [quo.components.markdown.text :as text]
[quo.foundations.colors :as colors] [quo.foundations.colors :as colors]
[quo.theme :as theme] [quo.theme :as theme]
[react-native.core :as rn])) [react-native.core :as rn]
[reagent.core :as reagent]))
;;; helpers ;;; helpers
(def themes (def themes
@@ -136,25 +137,24 @@
style style
on-press on-press
warning-label]}] warning-label]}]
(let [[body-height set-body-height] (rn/use-state nil) (let [body-height (reagent/atom nil)]
on-layout (rn/use-callback #(set-body-height (fn []
(oget % "nativeEvent.layout.height")))] [rn/view
[rn/view {:on-layout #(reset! body-height (oget % "nativeEvent.layout.height"))
{:on-layout on-layout :overflow :hidden
:overflow :hidden :flex 1}
:flex 1} [hborder {:type :top}]
[hborder {:type :top}] [hborder {:type :bottom}]
[hborder {:type :bottom}] [rn/view
[rn/view (merge {:width "100%"
(merge {:width "100%" :background-color (get-color :background)
:background-color (get-color :background) :flex-direction :row
:flex-direction :row :padding 20
:padding 20 :padding-left 31
:padding-left 31 :margin-vertical 4}
:margin-vertical 4} style)
style)
[timeline] [timeline]
[body timestamp-far timestamp-near on-info-button-pressed on-press warning-label]] [body timestamp-far timestamp-near on-info-button-pressed on-press warning-label]]
[vborder :left body-height] [vborder :left body-height]
[vborder :right body-height]])) [vborder :right body-height]])))
@@ -35,7 +35,7 @@
:on-press on-press :on-press on-press
:background (if behind-overlay? :background (if behind-overlay?
:blur :blur
(when (button-properties/backgrounds background) background)) (button-properties/backgrounds background))
:accessibility-label accessibility-label} :accessibility-label accessibility-label}
icon-name])] icon-name])]
children)) children))
@@ -4,48 +4,50 @@
[quo.components.markdown.text :as text] [quo.components.markdown.text :as text]
[quo.components.numbered-keyboard.keyboard-key.style :as style] [quo.components.numbered-keyboard.keyboard-key.style :as style]
[quo.theme :as quo.theme] [quo.theme :as quo.theme]
[react-native.core :as rn])) [react-native.core :as rn]
[reagent.core :as reagent]))
(defn- label->accessibility-label (defn- label->accessibility-label
[label] [label]
(let [label-name (if (keyword? label) (name label) label)] (let [label-name (if (keyword? label) (name label) label)]
(keyword (str "keyboard-key-" label-name)))) (keyword (str "keyboard-key-" label-name))))
(defn view (defn- view-internal
[{:keys [disabled? blur? on-press on-long-press type]} label] []
(let [theme (quo.theme/use-theme-value) (let [pressed? (reagent/atom false)]
[pressed? set-pressed?] (rn/use-state false) (fn [{:keys [disabled? theme blur? on-press on-long-press type]} label]
on-press (rn/use-callback #(when on-press (on-press label)) [label]) (let [label-color (style/get-label-color disabled? theme blur?)
on-long-press (rn/use-callback #(when (fn? on-long-press) (on-long-press label)) background-color (style/toggle-background-color @pressed? blur? theme)]
[label]) [rn/pressable
on-press-in (rn/use-callback #(set-pressed? true)) {:accessibility-label (label->accessibility-label label)
on-press-out (rn/use-callback #(set-pressed? false)) :disabled (or disabled? (not label))
label-color (style/get-label-color disabled? theme blur?) :on-press (fn []
background-color (style/toggle-background-color pressed? blur? theme)] (when on-press
[rn/pressable (on-press label)))
{:accessibility-label (label->accessibility-label label) :on-long-press (fn []
:disabled (or disabled? (not label)) (when (fn? on-long-press)
:on-press on-press (on-long-press label)))
:on-long-press on-long-press :allow-multiple-presses? true
:allow-multiple-presses? true :on-press-in #(reset! pressed? true)
:on-press-in on-press-in :on-press-out #(reset! pressed? false)
:on-press-out on-press-out :hit-slop {:top 8 :bottom 8 :left 25 :right 25}
:hit-slop {:top 8 :bottom 8 :left 25 :right 25} :style (style/container background-color)}
:style (style/container background-color)} (case type
(case type :key [icons/icon
:key [icons/icon label
label {:color label-color
{:color label-color :accessibility-label :icon-label}]
:accessibility-label :icon-label}] :digit [text/text
:digit [text/text {:accessibility-label :text-label
{:accessibility-label :text-label :weight :regular
:weight :regular :size :heading-1
:size :heading-1 :style {:color label-color}}
:style {:color label-color}} label]
label] :derivation-path [icons/icon
:derivation-path [icons/icon :i/derivation-path
:i/derivation-path {:color label-color
{:color label-color :size 32
:size 32 :accessibility-label :derivation-path-label}]
:accessibility-label :derivation-path-label}] nil)]))))
nil)]))
(def view (quo.theme/with-theme view-internal))
@@ -1,9 +1,9 @@
(ns quo.components.profile.collectible.view (ns quo.components.profile.collectible.view
(:require (:require
[clojure.string :as string]
[quo.components.markdown.text :as text] [quo.components.markdown.text :as text]
[quo.components.profile.collectible.style :as style] [quo.components.profile.collectible.style :as style]
[react-native.core :as rn])) [react-native.core :as rn]
[react-native.svg :as svg]))
(defn remaining-tiles (defn remaining-tiles
[amount] [amount]
@@ -19,28 +19,11 @@
(let [svg? (and (map? resource) (:svg? resource)) (let [svg? (and (map? resource) (:svg? resource))
image-style (style/tile-style-by-size size)] image-style (style/tile-style-by-size size)]
[rn/view {:style style} [rn/view {:style style}
(cond (if svg?
svg?
[rn/view [rn/view
{:style (assoc image-style {:style {:border-radius (:border-radius image-style)
:border-radius (:border-radius image-style) :overflow :hidden}}
:overflow :hidden [svg/svg-uri (assoc image-style :uri (:uri resource))]]
:justify-content :center
:align-items :center
:background-color :lightblue)}
[text/text "SVG Content"]]
(or (string/blank? resource) (string/blank? (:uri resource)))
[rn/view
{:style (assoc image-style
:border-radius (:border-radius image-style)
:overflow :hidden
:justify-content :center
:align-items :center
:background-color :lightgray)}
[text/text "Missing image"]]
:else
;; NOTE: using react-native-fast-image here causes a crash on devices when used inside a ;; NOTE: using react-native-fast-image here causes a crash on devices when used inside a
;; large flatlist. The library seems to have issues with memory consumption when used with ;; large flatlist. The library seems to have issues with memory consumption when used with
;; large images/GIFs. ;; large images/GIFs.
@@ -3,33 +3,48 @@
[quo.components.avatars.user-avatar.view :as user-avatar] [quo.components.avatars.user-avatar.view :as user-avatar]
[quo.components.markdown.text :as text] [quo.components.markdown.text :as text]
[quo.components.profile.select-profile.style :as style] [quo.components.profile.select-profile.style :as style]
[react-native.core :as rn])) [react-native.core :as rn]
[reagent.core :as reagent]))
(defn- on-change-handler
[selected? on-change]
(swap! selected? not)
(when on-change (on-change @selected?)))
(defn view (defn view
"Options "Options
- `default-selected?` The default selected state. Use when the component is not controlled.
- `selected?` Selected state. Use when the component is controlled. - `selected?` Selected state. Use when the component is controlled.
- `name` Full name - `name` Full name
- `profile-picture` Profile picture - `profile-picture` Profile picture
- `customization-color` Customization color - `customization-color` Customization color
- `(on-change selected?)` On change event handler - `(on-change selected?)` On change event handler
" "
[{:keys [selected? profile-picture name customization-color on-change] [{:keys [default-selected?]}]
:or {customization-color :turquoise}}] (let [internal-selected? (reagent/atom (or default-selected? false))]
[rn/touchable-opacity (fn [{:keys [selected?
{:style (style/container customization-color selected?) profile-picture
:on-press #(when on-change (on-change (not selected?))) name
:accessibility-label :select-profile} customization-color
[rn/view {:style style/header} on-change]
[user-avatar/user-avatar :or {customization-color :turquoise}}]
{:full-name name (when (and (not (nil? selected?)) (not= @internal-selected? selected?))
:status-indicator? false (reset! internal-selected? selected?))
:size :medium [rn/touchable-opacity
:profile-picture profile-picture}] {:style (style/container customization-color @internal-selected?)
[rn/view {:style (style/select-radio selected?)} :on-press #(on-change-handler internal-selected? on-change)
(when selected? :active-opacity 1
[rn/view {:style style/select-radio-inner}])]] :accessibility-label :select-profile}
[text/text [rn/view {:style style/header}
{:size :heading-2 [user-avatar/user-avatar
:weight :semi-bold {:full-name name
:style style/profile-name} :status-indicator? false
name]]) :size :medium
:profile-picture profile-picture}]
[rn/view {:style (style/select-radio @internal-selected?)}
(when @internal-selected? [rn/view {:style style/select-radio-inner}])]]
[text/text
{:size :heading-2
:weight :semi-bold
:style style/profile-name}
name]])))
@@ -1,6 +1,7 @@
(ns quo.components.profile.showcase-nav.component-spec (ns quo.components.profile.showcase-nav.component-spec
(:require (:require
[quo.components.profile.showcase-nav.view :as view] [quo.components.profile.showcase-nav.view :as view]
[reagent.core :as reagent]
[test-helpers.component :as h])) [test-helpers.component :as h]))
(def nav-data (def nav-data
@@ -34,7 +35,7 @@
(.toHaveBeenCalled)))) (.toHaveBeenCalled))))
(h/test "active id updated" (h/test "active id updated"
(let [active-id (atom :recent)] (let [active-id (reagent/atom :recent)]
(h/render [view/view (h/render [view/view
{:data nav-data {:data nav-data
:on-press #(reset! active-id %)}]) :on-press #(reset! active-id %)}])
@@ -4,10 +4,10 @@
[quo.components.record-audio.record-audio.helpers :as helpers] [quo.components.record-audio.record-audio.helpers :as helpers]
[quo.components.record-audio.record-audio.style :as style] [quo.components.record-audio.record-audio.style :as style]
[quo.foundations.colors :as colors] [quo.foundations.colors :as colors]
[react-native.core :as rn] [react-native.core :refer [use-effect]]
[react-native.reanimated :as reanimated])) [react-native.reanimated :as reanimated]))
(defn delete-button (defn f-delete-button
[recording? ready-to-delete? reviewing-audio? force-show-controls?] [recording? ready-to-delete? reviewing-audio? force-show-controls?]
(let [opacity (reanimated/use-shared-value (if force-show-controls? 1 0)) (let [opacity (reanimated/use-shared-value (if force-show-controls? 1 0))
translate-x (reanimated/use-shared-value (if force-show-controls? 35 20)) translate-x (reanimated/use-shared-value (if force-show-controls? 35 20))
@@ -17,68 +17,62 @@
connector-height (reanimated/use-shared-value 12) connector-height (reanimated/use-shared-value 12)
border-radius-first-half (reanimated/use-shared-value 8) border-radius-first-half (reanimated/use-shared-value 8)
border-radius-second-half (reanimated/use-shared-value 8) border-radius-second-half (reanimated/use-shared-value 8)
start-x-animation (rn/use-callback start-x-animation (fn []
(fn [] (helpers/animate-linear-with-delay translate-x 12 50 133.33)
(helpers/animate-linear-with-delay translate-x 12 50 133.33) (helpers/animate-easing-with-delay connector-opacity 1 0 93.33)
(helpers/animate-easing-with-delay connector-opacity 1 0 93.33) (helpers/animate-easing-with-delay connector-width 56 83.33 80)
(helpers/animate-easing-with-delay connector-width 56 83.33 80) (helpers/animate-easing-with-delay connector-height 56 83.33 80)
(helpers/animate-easing-with-delay connector-height 56 83.33 80) (helpers/animate-easing-with-delay border-radius-first-half
(helpers/animate-easing-with-delay border-radius-first-half 28
28 83.33
83.33 80)
80) (helpers/animate-easing-with-delay border-radius-second-half
(helpers/animate-easing-with-delay border-radius-second-half 28
28 83.33
83.33 80))
80))) reset-x-animation (fn []
reset-x-animation (rn/use-callback (helpers/animate-linear translate-x 0 100)
(fn [] (helpers/set-value connector-opacity 0)
(helpers/animate-linear translate-x 0 100) (helpers/set-value connector-width 24)
(helpers/set-value connector-opacity 0) (helpers/set-value connector-height 12)
(helpers/set-value connector-width 24) (helpers/set-value border-radius-first-half 8)
(helpers/set-value connector-height 12) (helpers/set-value border-radius-second-half 16))
(helpers/set-value border-radius-first-half 8) fade-in-animation (fn []
(helpers/set-value border-radius-second-half 16))) (helpers/animate-linear translate-x 0 200)
fade-in-animation (rn/use-callback (helpers/animate-linear opacity 1 200))
(fn [] fade-out-animation (fn []
(helpers/animate-linear translate-x 0 200) (helpers/animate-linear
(helpers/animate-linear opacity 1 200))) translate-x
fade-out-animation (rn/use-callback (if @reviewing-audio? 35 20)
(fn [] 200)
(helpers/animate-linear (if @reviewing-audio?
translate-x (helpers/animate-linear scale 0.75 200)
(if reviewing-audio? 35 20) (helpers/animate-linear opacity 0 200))
200) (helpers/set-value connector-opacity 0)
(if reviewing-audio? (helpers/set-value connector-width 24)
(helpers/animate-linear scale 0.75 200) (helpers/set-value connector-height 12)
(helpers/animate-linear opacity 0 200)) (helpers/set-value border-radius-first-half 8)
(helpers/set-value connector-opacity 0) (helpers/set-value border-radius-second-half 16))
(helpers/set-value connector-width 24) fade-out-reset-animation (fn []
(helpers/set-value connector-height 12) (helpers/animate-linear opacity 0 200)
(helpers/set-value border-radius-first-half 8) (helpers/animate-linear-with-delay translate-x 20 0 200)
(helpers/set-value border-radius-second-half 16)) (helpers/animate-linear-with-delay scale 1 0 200))]
[reviewing-audio?]) (use-effect (fn []
fade-out-reset-animation (rn/use-callback (if @recording?
(fn [] (fade-in-animation)
(helpers/animate-linear opacity 0 200) (fade-out-animation)))
(helpers/animate-linear-with-delay translate-x 20 0 200) [@recording?])
(helpers/animate-linear-with-delay scale 1 0 200)))] (use-effect (fn []
(rn/use-effect (fn [] (when-not @reviewing-audio?
(if recording? (fade-out-reset-animation)))
(fade-in-animation) [@reviewing-audio?])
(fade-out-animation))) (use-effect (fn []
[recording?]) (cond
(rn/use-effect (fn [] @ready-to-delete?
(when-not reviewing-audio? (start-x-animation)
(fade-out-reset-animation))) @recording?
[reviewing-audio?]) (reset-x-animation)))
(rn/use-effect (fn [] [@ready-to-delete?])
(cond
ready-to-delete?
(start-x-animation)
recording?
(reset-x-animation)))
[ready-to-delete?])
[:<> [:<>
[reanimated/view {:style (style/delete-button-container opacity)} [reanimated/view {:style (style/delete-button-container opacity)}
[reanimated/view [reanimated/view
@@ -5,10 +5,10 @@
[quo.components.record-audio.record-audio.style :as style] [quo.components.record-audio.record-audio.style :as style]
[quo.foundations.colors :as colors] [quo.foundations.colors :as colors]
[quo.theme :as quo.theme] [quo.theme :as quo.theme]
[react-native.core :as rn] [react-native.core :refer [use-effect]]
[react-native.reanimated :as reanimated])) [react-native.reanimated :as reanimated]))
(defn lock-button (defn f-lock-button
[recording? ready-to-lock? locked?] [recording? ready-to-lock? locked?]
(let [theme (quo.theme/use-theme-value) (let [theme (quo.theme/use-theme-value)
translate-x-y (reanimated/use-shared-value 20) translate-x-y (reanimated/use-shared-value 20)
@@ -18,58 +18,54 @@
height (reanimated/use-shared-value 12) height (reanimated/use-shared-value 12)
border-radius-first-half (reanimated/use-shared-value 8) border-radius-first-half (reanimated/use-shared-value 8)
border-radius-second-half (reanimated/use-shared-value 8) border-radius-second-half (reanimated/use-shared-value 8)
start-x-y-animation (rn/use-callback start-x-y-animation (fn []
(fn [] (helpers/animate-linear-with-delay translate-x-y 8 50 116.66)
(helpers/animate-linear-with-delay translate-x-y 8 50 116.66) (helpers/animate-easing-with-delay connector-opacity 1 0 80)
(helpers/animate-easing-with-delay connector-opacity 1 0 80) (helpers/animate-easing-with-delay width 56 83.33 63.33)
(helpers/animate-easing-with-delay width 56 83.33 63.33) (helpers/animate-easing-with-delay height 56 83.33 63.33)
(helpers/animate-easing-with-delay height 56 83.33 63.33) (helpers/animate-easing-with-delay border-radius-first-half
(helpers/animate-easing-with-delay border-radius-first-half 28
28 83.33
83.33 63.33)
63.33) (helpers/animate-easing-with-delay border-radius-second-half
(helpers/animate-easing-with-delay border-radius-second-half 28
28 83.33
83.33 63.33))
63.33))) reset-x-y-animation (fn []
reset-x-y-animation (rn/use-callback (helpers/animate-linear translate-x-y 0 100)
(fn [] (helpers/set-value connector-opacity 0)
(helpers/animate-linear translate-x-y 0 100) (helpers/set-value width 24)
(helpers/set-value connector-opacity 0) (helpers/set-value height 12)
(helpers/set-value width 24) (helpers/set-value border-radius-first-half 8)
(helpers/set-value height 12) (helpers/set-value border-radius-second-half 16))
(helpers/set-value border-radius-first-half 8) fade-in-animation (fn []
(helpers/set-value border-radius-second-half 16))) (helpers/animate-linear translate-x-y 0 220)
fade-in-animation (rn/use-callback (helpers/animate-linear opacity 1 220))
(fn [] fade-out-animation (fn []
(helpers/animate-linear translate-x-y 0 220) (helpers/animate-linear translate-x-y 20 200)
(helpers/animate-linear opacity 1 220))) (helpers/animate-linear opacity 0 200)
fade-out-animation (rn/use-callback (helpers/set-value connector-opacity 0)
(fn [] (helpers/set-value width 24)
(helpers/animate-linear translate-x-y 20 200) (helpers/set-value height 12)
(helpers/animate-linear opacity 0 200) (helpers/set-value border-radius-first-half 8)
(helpers/set-value connector-opacity 0) (helpers/set-value border-radius-second-half 16))]
(helpers/set-value width 24) (use-effect (fn []
(helpers/set-value height 12) (if @recording?
(helpers/set-value border-radius-first-half 8) (fade-in-animation)
(helpers/set-value border-radius-second-half 16)))] (fade-out-animation)))
(rn/use-effect (fn [] [@recording?])
(if recording? (use-effect (fn []
(fade-in-animation) (cond
(fade-out-animation))) @ready-to-lock?
[recording?]) (start-x-y-animation)
(rn/use-effect (fn [] (and @recording? (not @locked?))
(cond (reset-x-y-animation)))
ready-to-lock? [@ready-to-lock?])
(start-x-y-animation) (use-effect (fn []
(and recording? (not locked?)) (if @locked?
(reset-x-y-animation))) (fade-out-animation)
[ready-to-lock?]) (reset-x-y-animation)))
(rn/use-effect (fn [] [@locked?])
(if locked?
(fade-out-animation)
(reset-x-y-animation)))
[locked?])
[:<> [:<>
[reanimated/view {:style (style/lock-button-container opacity)} [reanimated/view {:style (style/lock-button-container opacity)}
[reanimated/view [reanimated/view
@@ -81,6 +77,6 @@
[reanimated/view [reanimated/view
{:style (style/lock-button translate-x-y opacity) {:style (style/lock-button translate-x-y opacity)
:pointer-events :none} :pointer-events :none}
[icons/icon (if ready-to-lock? :i/locked :i/unlocked) [icons/icon (if @ready-to-lock? :i/locked :i/unlocked)
{:color (colors/theme-colors colors/black colors/white theme) {:color (colors/theme-colors colors/black colors/white theme)
:size 20}]]])) :size 20}]]]))
@@ -3,17 +3,19 @@
[quo.components.buttons.button.view :as button] [quo.components.buttons.button.view :as button]
[quo.components.record-audio.record-audio.helpers :as helpers] [quo.components.record-audio.record-audio.helpers :as helpers]
[quo.components.record-audio.record-audio.style :as style] [quo.components.record-audio.record-audio.style :as style]
[react-native.core :as rn] [react-native.core :as rn :refer [use-effect]]
[react-native.reanimated :as reanimated])) [react-native.reanimated :as reanimated]))
(defn record-button (defn f-record-button
[recording? reviewing-audio?] [recording? reviewing-audio?]
(let [opacity (reanimated/use-shared-value 1)] (let [opacity (reanimated/use-shared-value 1)
(rn/use-effect (fn [] show-animation #(helpers/set-value opacity 1)
(if (or recording? reviewing-audio?) hide-animation #(helpers/set-value opacity 0)]
(helpers/set-value opacity 0) (use-effect (fn []
(helpers/set-value opacity 1))) (if (or @recording? @reviewing-audio?)
[recording? reviewing-audio?]) (hide-animation)
(show-animation)))
[@recording? @reviewing-audio?])
[reanimated/view {:style (style/record-button-container opacity)} [reanimated/view {:style (style/record-button-container opacity)}
[button/button [button/button
{:type :outline {:type :outline
@@ -5,9 +5,8 @@
[quo.components.record-audio.record-audio.helpers :as helpers] [quo.components.record-audio.record-audio.helpers :as helpers]
[quo.components.record-audio.record-audio.style :as style] [quo.components.record-audio.record-audio.style :as style]
[quo.foundations.colors :as colors] [quo.foundations.colors :as colors]
[quo.theme]
[react-native.audio-toolkit :as audio] [react-native.audio-toolkit :as audio]
[react-native.core :as rn] [react-native.core :as rn :refer [use-effect]]
[react-native.reanimated :as reanimated] [react-native.reanimated :as reanimated]
[reagent.core :as reagent] [reagent.core :as reagent]
[taoensso.timbre :as log] [taoensso.timbre :as log]
@@ -29,16 +28,13 @@
(reagent/as-element (reagent/as-element
[reanimated/view {:style (style/animated-circle scale opacity color)}])))))) [reanimated/view {:style (style/animated-circle scale opacity color)}]))))))
(defn record-button-big (defn f-record-button-big
[{:keys [recording? set-recording ready-to-send? set-ready-to-send ready-to-lock? set-ready-to-lock [{:keys [recording? ready-to-send? ready-to-lock? ready-to-delete? record-button-is-animating?
ready-to-delete? set-ready-to-delete record-button-is-animating? record-button-at-initial-position? locked? reviewing-audio? recording-length-ms
record-button-at-initial-position? locked? set-locked reviewing-audio? recording-length-ms clear-timeout touch-active? recorder-ref reload-recorder-fn idle? on-send on-cancel theme]}]
set-recording-length-ms (let [scale (reanimated/use-shared-value 1)
clear-timeout touch-active? recorder-ref reload-recorder-fn idle? on-send on-cancel]}]
(let [theme (quo.theme/use-theme-value)
scale (reanimated/use-shared-value 1)
opacity (reanimated/use-shared-value 0) opacity (reanimated/use-shared-value 0)
opacity-from (if ready-to-lock? opacity-from-lock opacity-from-default) opacity-from (if @ready-to-lock? opacity-from-lock opacity-from-default)
animations (map animations (map
(fn [index] (fn [index]
(let [ring-scale (worklets.record-audio/ring-scale scale (let [ring-scale (worklets.record-audio/ring-scale scale
@@ -50,155 +46,141 @@
[opacity-from 0])})) [opacity-from 0])}))
(range 0 5)) (range 0 5))
rings-color (cond rings-color (cond
ready-to-lock? (colors/theme-colors colors/neutral-80-opa-5-opaque @ready-to-lock? (colors/theme-colors colors/neutral-80-opa-5-opaque
colors/neutral-80 colors/neutral-80
theme) theme)
ready-to-delete? colors/danger-50 @ready-to-delete? colors/danger-50
:else colors/primary-50) :else colors/primary-50)
translate-y (reanimated/use-shared-value 0) translate-y (reanimated/use-shared-value 0)
translate-x (reanimated/use-shared-value 0) translate-x (reanimated/use-shared-value 0)
button-color colors/primary-50 button-color colors/primary-50
icon-color (if (and (not (= :dark theme)) ready-to-lock?) colors/black colors/white) icon-color (if (and (not (= :dark theme)) @ready-to-lock?) colors/black colors/white)
icon-opacity (reanimated/use-shared-value 1) icon-opacity (reanimated/use-shared-value 1)
red-overlay-opacity (reanimated/use-shared-value 0) red-overlay-opacity (reanimated/use-shared-value 0)
gray-overlay-opacity (reanimated/use-shared-value 0) gray-overlay-opacity (reanimated/use-shared-value 0)
complete-animation complete-animation
(rn/use-callback (fn []
(fn [] (cond
(cond (and @ready-to-lock? (not @record-button-is-animating?))
(and ready-to-lock? (not @record-button-is-animating?)) (do
(do (reset! locked? true)
(set-locked true) (reset! ready-to-lock? false))
(set-ready-to-lock false)) (and (not @locked?) (not @reviewing-audio?))
(and (not locked?) (not reviewing-audio?)) (audio/stop-recording
(audio/stop-recording @recorder-ref
@recorder-ref (fn []
(fn [] (cond
(cond @ready-to-send?
ready-to-send? (when on-send
(when on-send (on-send {:file-path (audio/get-recorder-file-path @recorder-ref)
(on-send {:file-path (audio/get-recorder-file-path @recorder-ref) :duration @recording-length-ms}))
:duration recording-length-ms})) @ready-to-delete?
ready-to-delete? (when on-cancel
(when on-cancel (on-cancel)))
(on-cancel))) (reload-recorder-fn)
(reload-recorder-fn) (reset! recording? false)
(set-recording false) (reset! ready-to-send? false)
(set-ready-to-send false) (reset! ready-to-delete? false)
(set-ready-to-delete false) (reset! ready-to-lock? false)
(set-ready-to-lock false) (reset! idle? true)
(reset! idle? true) (js/setTimeout #(reset! idle? false) 1000)
(js/setTimeout #(reset! idle? false) 1000) (reset! recording-length-ms 0)
(set-recording-length-ms 0) (log/debug "[record-audio] stop recording - success"))
(log/debug "[record-audio] stop recording - success")) #(log/error "[record-audio] stop recording - error: " %))))
#(log/error "[record-audio] stop recording - error: " %)))) start-animation (fn []
[ready-to-lock? locked? reviewing-audio? ready-to-send? recording-length-ms ready-to-delete? (helpers/set-value opacity 1)
idle?]) (helpers/animate-linear scale 2.6 signal-anim-duration)
start-animation (rn/use-callback ;; TODO: Research if we can implement this with withSequence method
(fn [] ;; from Reanimated 2
(helpers/set-value opacity 1) ;; GitHub issue [#14561]:
(helpers/animate-linear scale 2.6 signal-anim-duration) ;; https://github.com/status-im/status-mobile/issues/14561
;; TODO: Research if we can implement this with withSequence method (reset! clear-timeout
;; from Reanimated 2 (js/setTimeout
;; GitHub issue [#14561]:
;; https://github.com/status-im/status-mobile/issues/14561
(reset! clear-timeout
(js/setTimeout
(fn []
(helpers/set-value scale scale-to-each)
(helpers/animate-linear-with-delay-loop scale
scale-to-total
signal-anim-duration-2
0))
signal-anim-duration))))
stop-animation (rn/use-callback
(fn []
(helpers/set-value opacity 0)
(reanimated/cancel-animation scale)
(helpers/set-value scale 1)
(when @clear-timeout (js/clearTimeout @clear-timeout))))
start-y-animation (rn/use-callback
(fn []
(reset! record-button-at-initial-position? false)
(reset! record-button-is-animating? true)
(helpers/animate-easing translate-y -64 250)
(helpers/animate-linear-with-delay icon-opacity 0 33.33 76.66)
(js/setTimeout (fn []
(reset! record-button-is-animating? false)
(when-not @touch-active? (complete-animation)))
250))
[complete-animation])
reset-y-animation (rn/use-callback
(fn []
(helpers/animate-easing translate-y 0 300)
(helpers/animate-linear icon-opacity 1 500)
(js/setTimeout (fn []
(reset! record-button-at-initial-position? true))
500)))
start-x-animation (rn/use-callback
(fn []
(reset! record-button-at-initial-position? false)
(reset! record-button-is-animating? true)
(helpers/animate-easing translate-x -64 250)
(helpers/animate-linear-with-delay icon-opacity 0 33.33 76.66)
(helpers/animate-linear red-overlay-opacity 1 33.33)
(js/setTimeout (fn []
(reset! record-button-is-animating? false)
(when-not @touch-active? (complete-animation)))
250))
[complete-animation])
reset-x-animation (rn/use-callback
(fn []
(helpers/animate-easing translate-x 0 300)
(helpers/animate-linear icon-opacity 1 500)
(helpers/animate-linear red-overlay-opacity 0 100)
(js/setTimeout (fn []
(reset! record-button-at-initial-position? true))
500)))
start-x-y-animation (rn/use-callback
(fn [] (fn []
(reset! record-button-at-initial-position? false) (helpers/set-value scale scale-to-each)
(reset! record-button-is-animating? true) (helpers/animate-linear-with-delay-loop scale
(helpers/animate-easing translate-y -44 200) scale-to-total
(helpers/animate-easing translate-x -44 200) signal-anim-duration-2
(helpers/animate-linear-with-delay icon-opacity 0 33.33 33.33) 0))
(helpers/animate-linear gray-overlay-opacity 1 33.33) signal-anim-duration)))
(js/setTimeout (fn [] stop-animation (fn []
(reset! record-button-is-animating? false) (helpers/set-value opacity 0)
(when-not @touch-active? (complete-animation))) (reanimated/cancel-animation scale)
200)) (helpers/set-value scale 1)
[complete-animation]) (when @clear-timeout (js/clearTimeout @clear-timeout)))
reset-x-y-animation (rn/use-callback start-y-animation (fn []
(fn [] (reset! record-button-at-initial-position? false)
(helpers/animate-easing translate-y 0 300) (reset! record-button-is-animating? true)
(helpers/animate-easing translate-x 0 300) (helpers/animate-easing translate-y -64 250)
(helpers/animate-linear icon-opacity 1 500) (helpers/animate-linear-with-delay icon-opacity 0 33.33 76.66)
(helpers/animate-linear gray-overlay-opacity 0 800) (js/setTimeout (fn []
(js/setTimeout (fn [] (reset! record-button-is-animating? false)
(reset! record-button-at-initial-position? true)) (when-not @touch-active? (complete-animation)))
800)))] 250))
(rn/use-effect (fn [] reset-y-animation (fn []
(cond (helpers/animate-easing translate-y 0 300)
recording? (helpers/animate-linear icon-opacity 1 500)
(start-animation) (js/setTimeout (fn []
(not ready-to-lock?) (reset! record-button-at-initial-position? true))
(stop-animation))) 500))
[recording?]) start-x-animation (fn []
(rn/use-effect (fn [] (reset! record-button-at-initial-position? false)
(if ready-to-lock? (reset! record-button-is-animating? true)
(start-x-y-animation) (helpers/animate-easing translate-x -64 250)
(reset-x-y-animation))) (helpers/animate-linear-with-delay icon-opacity 0 33.33 76.66)
[ready-to-lock?]) (helpers/animate-linear red-overlay-opacity 1 33.33)
(rn/use-effect (fn [] (js/setTimeout (fn []
(if ready-to-send? (reset! record-button-is-animating? false)
(start-y-animation) (when-not @touch-active? (complete-animation)))
(reset-y-animation))) 250))
[ready-to-send?]) reset-x-animation (fn []
(rn/use-effect (fn [] (helpers/animate-easing translate-x 0 300)
(if ready-to-delete? (helpers/animate-linear icon-opacity 1 500)
(start-x-animation) (helpers/animate-linear red-overlay-opacity 0 100)
(reset-x-animation))) (js/setTimeout (fn []
[ready-to-delete?]) (reset! record-button-at-initial-position? true))
500))
start-x-y-animation (fn []
(reset! record-button-at-initial-position? false)
(reset! record-button-is-animating? true)
(helpers/animate-easing translate-y -44 200)
(helpers/animate-easing translate-x -44 200)
(helpers/animate-linear-with-delay icon-opacity 0 33.33 33.33)
(helpers/animate-linear gray-overlay-opacity 1 33.33)
(js/setTimeout (fn []
(reset! record-button-is-animating? false)
(when-not @touch-active? (complete-animation)))
200))
reset-x-y-animation (fn []
(helpers/animate-easing translate-y 0 300)
(helpers/animate-easing translate-x 0 300)
(helpers/animate-linear icon-opacity 1 500)
(helpers/animate-linear gray-overlay-opacity 0 800)
(js/setTimeout (fn []
(reset! record-button-at-initial-position? true))
800))]
(use-effect (fn []
(cond
@recording?
(start-animation)
(not @ready-to-lock?)
(stop-animation)))
[@recording?])
(use-effect (fn []
(if @ready-to-lock?
(start-x-y-animation)
(reset-x-y-animation)))
[@ready-to-lock?])
(use-effect (fn []
(if @ready-to-send?
(start-y-animation)
(reset-y-animation)))
[@ready-to-send?])
(use-effect (fn []
(if @ready-to-delete?
(start-x-animation)
(reset-x-animation)))
[@ready-to-delete?])
[reanimated/view [reanimated/view
{:style (style/record-button-big-container translate-x translate-y opacity) {:style (style/record-button-big-container translate-x translate-y opacity)
:pointer-events :none} :pointer-events :none}
@@ -215,6 +197,6 @@
[reanimated/view {:style (style/record-button-big-red-overlay red-overlay-opacity)}] [reanimated/view {:style (style/record-button-big-red-overlay red-overlay-opacity)}]
[reanimated/view {:style (style/record-button-big-gray-overlay gray-overlay-opacity)}] [reanimated/view {:style (style/record-button-big-gray-overlay gray-overlay-opacity)}]
[reanimated/view {:style (style/record-button-big-icon-container icon-opacity)} [reanimated/view {:style (style/record-button-big-icon-container icon-opacity)}
(if locked? (if @locked?
[rn/view {:style style/stop-icon}] [rn/view {:style style/stop-icon}]
[icons/icon :i/audio {:color icon-color}])]]])) [icons/icon :i/audio {:color icon-color}])]]]))
@@ -4,10 +4,10 @@
[quo.components.record-audio.record-audio.helpers :as helpers] [quo.components.record-audio.record-audio.helpers :as helpers]
[quo.components.record-audio.record-audio.style :as style] [quo.components.record-audio.record-audio.style :as style]
[quo.foundations.colors :as colors] [quo.foundations.colors :as colors]
[react-native.core :as rn] [react-native.core :refer [use-effect]]
[react-native.reanimated :as reanimated])) [react-native.reanimated :as reanimated]))
(defn send-button (defn f-send-button
[recording? ready-to-send? reviewing-audio? force-show-controls?] [recording? ready-to-send? reviewing-audio? force-show-controls?]
(let [opacity (reanimated/use-shared-value (if force-show-controls? 1 0)) (let [opacity (reanimated/use-shared-value (if force-show-controls? 1 0))
translate-y (reanimated/use-shared-value (if force-show-controls? 76 20)) translate-y (reanimated/use-shared-value (if force-show-controls? 76 20))
@@ -16,71 +16,65 @@
height (reanimated/use-shared-value 24) height (reanimated/use-shared-value 24)
border-radius-first-half (reanimated/use-shared-value 16) border-radius-first-half (reanimated/use-shared-value 16)
border-radius-second-half (reanimated/use-shared-value 8) border-radius-second-half (reanimated/use-shared-value 8)
start-y-animation (rn/use-callback start-y-animation (fn []
(fn [] (helpers/animate-linear-with-delay translate-y 12 50 133.33)
(helpers/animate-linear-with-delay translate-y 12 50 133.33) (helpers/animate-easing-with-delay connector-opacity 1 0 93.33)
(helpers/animate-easing-with-delay connector-opacity 1 0 93.33) (helpers/animate-easing-with-delay width 56 83.33 80)
(helpers/animate-easing-with-delay width 56 83.33 80) (helpers/animate-easing-with-delay height 56 83.33 80)
(helpers/animate-easing-with-delay height 56 83.33 80) (helpers/animate-easing-with-delay border-radius-first-half
(helpers/animate-easing-with-delay border-radius-first-half 28
28 83.33
83.33 80)
80) (helpers/animate-easing-with-delay border-radius-second-half
(helpers/animate-easing-with-delay border-radius-second-half 28
28 83.33
83.33 80))
80))) reset-y-animation (fn []
reset-y-animation (rn/use-callback (helpers/animate-linear translate-y 0 100)
(fn [] (helpers/set-value connector-opacity 0)
(helpers/animate-linear translate-y 0 100) (helpers/set-value width 12)
(helpers/set-value connector-opacity 0) (helpers/set-value height 24)
(helpers/set-value width 12) (helpers/set-value border-radius-first-half 16)
(helpers/set-value height 24) (helpers/set-value border-radius-second-half 8))
(helpers/set-value border-radius-first-half 16) fade-in-animation (fn []
(helpers/set-value border-radius-second-half 8))) (helpers/animate-linear translate-y 0 200)
fade-in-animation (rn/use-callback (helpers/animate-linear opacity 1 200))
(fn [] fade-out-animation (fn []
(helpers/animate-linear translate-y 0 200) (when-not force-show-controls?
(helpers/animate-linear opacity 1 200))) (helpers/animate-linear
fade-out-animation (rn/use-callback translate-y
(fn [] (if @reviewing-audio? 76 20)
(when-not force-show-controls? 200))
(helpers/animate-linear (when-not @reviewing-audio?
translate-y (helpers/animate-linear opacity 0 200))
(if reviewing-audio? 76 20) (helpers/set-value connector-opacity 0)
200)) (helpers/set-value width 24)
(when-not reviewing-audio? (helpers/set-value height 12)
(helpers/animate-linear opacity 0 200)) (helpers/set-value border-radius-first-half 8)
(helpers/set-value connector-opacity 0) (helpers/set-value border-radius-second-half 16))
(helpers/set-value width 24) fade-out-reset-animation (fn []
(helpers/set-value height 12) (helpers/animate-linear opacity 0 200)
(helpers/set-value border-radius-first-half 8) (helpers/animate-linear-with-delay translate-y 20 0 200)
(helpers/set-value border-radius-second-half 16)) (helpers/set-value connector-opacity 0)
[reviewing-audio? force-show-controls?]) (helpers/set-value width 24)
fade-out-reset-animation (rn/use-callback (helpers/set-value height 12)
(fn [] (helpers/set-value border-radius-first-half 8)
(helpers/animate-linear opacity 0 200) (helpers/set-value border-radius-second-half 16))]
(helpers/animate-linear-with-delay translate-y 20 0 200) (use-effect (fn []
(helpers/set-value connector-opacity 0) (if @recording?
(helpers/set-value width 24) (fade-in-animation)
(helpers/set-value height 12) (fade-out-animation)))
(helpers/set-value border-radius-first-half 8) [@recording?])
(helpers/set-value border-radius-second-half 16)))] (use-effect (fn []
(rn/use-effect (fn [] (when-not @reviewing-audio?
(if recording? (fade-out-reset-animation)))
(fade-in-animation) [@reviewing-audio?])
(fade-out-animation))) (use-effect (fn []
[recording?]) (cond
(rn/use-effect (fn [] @ready-to-send?
(when-not reviewing-audio? (start-y-animation)
(fade-out-reset-animation))) @recording? (reset-y-animation)))
[reviewing-audio?]) [@ready-to-send?])
(rn/use-effect (fn []
(cond
ready-to-send?
(start-y-animation)
recording? (reset-y-animation)))
[ready-to-send?])
[:<> [:<>
[reanimated/view {:style (style/send-button-container opacity)} [reanimated/view {:style (style/send-button-container opacity)}
[reanimated/view [reanimated/view
@@ -2,6 +2,7 @@
(:require (:require
[quo.components.record-audio.record-audio.view :as record-audio] [quo.components.record-audio.record-audio.view :as record-audio]
[react-native.audio-toolkit :as audio] [react-native.audio-toolkit :as audio]
[reagent.core :as reagent]
[test-helpers.component :as h] [test-helpers.component :as h]
[utils.datetime :as datetime])) [utils.datetime :as datetime]))
@@ -10,10 +11,8 @@
(h/test "renders record-audio" (h/test "renders record-audio"
(h/render [record-audio/record-audio]) (h/render [record-audio/record-audio])
(-> (h/wait-for #(h/get-by-test-id "record-audio")) (-> (h/expect (h/get-by-test-id "record-audio"))
(.then (fn [] (.toBeTruthy)))
(-> (h/expect (h/get-by-test-id "record-audio"))
(.toBeTruthy))))))
(h/test "record-audio on-start-recording works" (h/test "record-audio on-start-recording works"
(let [event (js/jest.fn)] (let [event (js/jest.fn)]
@@ -32,7 +31,7 @@
(h/test "record-audio on-reviewing-audio works" (h/test "record-audio on-reviewing-audio works"
(let [event (js/jest.fn) (let [event (js/jest.fn)
on-meter (atom nil)] on-meter (reagent/atom nil)]
(h/render [record-audio/record-audio (h/render [record-audio/record-audio
{:on-reviewing-audio event {:on-reviewing-audio event
:record-audio-permission-granted true}]) :record-audio-permission-granted true}])
@@ -40,7 +39,7 @@
(reset! on-meter on-meter-fn)) (reset! on-meter on-meter-fn))
audio/start-recording (fn [_ on-start _] audio/start-recording (fn [_ on-start _]
(on-start) (on-start)
(js/setInterval @on-meter 100)) (js/setInterval #(@on-meter) 100))
audio/get-recorder-file-path (fn [] "file-path")] audio/get-recorder-file-path (fn [] "file-path")]
(h/fire-event (h/fire-event
:on-start-should-set-responder :on-start-should-set-responder
@@ -49,7 +48,6 @@
:locationY 70 :locationY 70
:timestamp 0 :timestamp 0
:identifier 0}}) :identifier 0}})
(with-redefs [datetime/timestamp (fn [] (+ (.now js/Date) 1000))] (with-redefs [datetime/timestamp (fn [] (+ (.now js/Date) 1000))]
(h/advance-timers-by-time 100) (h/advance-timers-by-time 100)
(h/fire-event (h/fire-event
@@ -65,7 +63,7 @@
(h/test "record-audio on-send works after reviewing audio" (h/test "record-audio on-send works after reviewing audio"
(let [event (js/jest.fn) (let [event (js/jest.fn)
on-meter (atom nil)] on-meter (reagent/atom nil)]
(h/render [record-audio/record-audio (h/render [record-audio/record-audio
{:on-send event {:on-send event
:record-audio-permission-granted true}]) :record-audio-permission-granted true}])
@@ -116,15 +114,14 @@
(h/test "record-audio on-send works after sliding to the send button" (h/test "record-audio on-send works after sliding to the send button"
(let [event (js/jest.fn) (let [event (js/jest.fn)
on-meter (atom nil) on-meter (reagent/atom nil)
last-now-ms (atom nil) last-now-ms (atom nil)
duration-ms (atom nil)] duration-ms (atom nil)]
(h/render [record-audio/record-audio (h/render [record-audio/record-audio
{:on-send event {:on-send event
:record-audio-permission-granted true}]) :record-audio-permission-granted true}])
(with-redefs [audio/new-recorder (fn [_ on-meter-fn _] (with-redefs [audio/new-recorder (fn [_ on-meter-fn _]
(reset! on-meter on-meter-fn) (reset! on-meter on-meter-fn))
#js {:destroy #()})
audio/start-recording (fn [_ on-start _] audio/start-recording (fn [_ on-start _]
(on-start) (on-start)
(js/setInterval #(@on-meter) 100)) (js/setInterval #(@on-meter) 100))
@@ -173,16 +170,15 @@
(h/test "record-audio on-cancel works after reviewing audio" (h/test "record-audio on-cancel works after reviewing audio"
(let [event (js/jest.fn) (let [event (js/jest.fn)
on-meter (atom nil)] on-meter (reagent/atom nil)]
(h/render [record-audio/record-audio (h/render [record-audio/record-audio
{:on-cancel event {:on-cancel event
:record-audio-permission-granted true}]) :record-audio-permission-granted true}])
(with-redefs [audio/new-recorder (fn [_ on-meter-fn _] (with-redefs [audio/new-recorder (fn [_ on-meter-fn _]
(reset! on-meter on-meter-fn) (reset! on-meter on-meter-fn))
#js {:destroy #()})
audio/start-recording (fn [_ on-start _] audio/start-recording (fn [_ on-start _]
(on-start) (on-start)
(js/setInterval @on-meter 100))] (js/setInterval #(@on-meter) 100))]
(h/fire-event (h/fire-event
:on-start-should-set-responder :on-start-should-set-responder
(h/get-by-test-id "record-audio") (h/get-by-test-id "record-audio")
@@ -199,7 +195,6 @@
:locationY 70 :locationY 70
:timestamp 200 :timestamp 200
:identifier 0}}) :identifier 0}})
(h/advance-timers-by-time 250)
(h/fire-event (h/fire-event
:on-responder-release :on-responder-release
(h/get-by-test-id "record-audio") (h/get-by-test-id "record-audio")
@@ -207,12 +202,13 @@
:locationY 80 :locationY 80
:timestamp 200 :timestamp 200
:identifier 0}}) :identifier 0}})
(h/advance-timers-by-time 250)
(-> (js/expect event) (-> (js/expect event)
(.toHaveBeenCalledTimes 1)))))) (.toHaveBeenCalledTimes 1))))))
(h/test "record-audio on-cancel works after sliding to the cancel button" (h/test "record-audio on-cancel works after sliding to the cancel button"
(let [event (js/jest.fn) (let [event (js/jest.fn)
on-meter (atom nil)] on-meter (reagent/atom nil)]
(h/render [record-audio/record-audio (h/render [record-audio/record-audio
{:on-cancel event {:on-cancel event
:record-audio-permission-granted true}]) :record-audio-permission-granted true}])
@@ -1,81 +0,0 @@
(ns quo.components.record-audio.record-audio.constants
(:require [react-native.audio-toolkit :as audio]
[react-native.platform :as platform]
[utils.datetime :as datetime]))
(def min-audio-duration-ms 1000)
(def max-audio-duration-ms (if platform/ios? 120800 120500))
(def metering-interval 25)
(def base-filename "am")
(def default-format ".aac")
(def min-touch-duration 150)
(def record-button-area-big
{:width 56
:height 56
:x 64
:y 64})
(def record-button-area
{:width 48
:height 48
:x 68
:y 68})
(defn delete-button-area
[{:keys [active? reviewing-audio?]}]
{:width (cond
active? 72
reviewing-audio? 32
:else 82)
:height (if reviewing-audio? 32 56)
:x (cond
active? -16
reviewing-audio? 36
:else -32)
:y (cond
active? 64
reviewing-audio? 76
:else 70)})
(defn lock-button-area
[{:keys [active?]}]
{:width (if active? 72 100)
:height (if active? 72 102)
:x -32
:y -32})
(defn send-button-area
[{:keys [active? reviewing-audio?]}]
{:width (if reviewing-audio? 32 56)
:height (cond
active? 72
reviewing-audio? 47
:else 92)
:x (if reviewing-audio? 76 32)
:y (cond
active? -16
reviewing-audio? 76
:else -32)})
(defn touch-inside-area?
[{:keys [location-x location-y ignore-min-y? ignore-max-y? ignore-min-x? ignore-max-x?]}
{:keys [width height x y]}]
(let [max-x (+ x width)
max-y (+ y height)]
(and
(and
(or ignore-min-x? (>= location-x x))
(or ignore-max-x? (<= location-x max-x)))
(and
(or ignore-min-y? (>= location-y y))
(or ignore-max-y? (<= location-y max-y))))))
(def rec-options
(merge
audio/default-recorder-options
{:filename (str base-filename
(datetime/timestamp)
default-format)
:meteringInterval metering-interval}))
@@ -1,345 +0,0 @@
(ns quo.components.record-audio.record-audio.handlers
(:require [oops.core :as oops]
[quo.components.record-audio.record-audio.constants :as record-audio.constants]
[react-native.audio-toolkit :as audio]
[taoensso.timbre :as log]
[utils.datetime :as datetime]))
(def get-reload-player
(memoize
(fn
[[player-ref destroy-player set-playing-audio playing-timer set-audio-current-time-ms
set-seeking-audio]]
(fn [audio-file]
(when @player-ref
(destroy-player))
(reset! player-ref
(audio/new-player
(or audio-file (:filename record-audio.constants/rec-options))
{:autoDestroy false
:continuesToPlayInBackground false
:category audio/PLAYBACK}
(fn []
(set-playing-audio false)
(when @playing-timer
(js/clearInterval @playing-timer)
(reset! playing-timer nil)
(set-audio-current-time-ms 0)
(set-seeking-audio false)))))
(audio/prepare-player
@player-ref
#(log/debug "[record-audio] prepare player - success")
#(log/error "[record-audio] prepare player - error: " %))))))
(def get-recorder-on-meter
(memoize
(fn
[[recording-start-ms set-recording-length-ms reached-max-duration? locked? set-locked
set-reviewing-audio
idle? set-recording
set-ready-to-lock set-ready-to-send set-ready-to-delete recorder-ref output-file reload-player
on-reviewing-audio]]
(fn []
(when @recording-start-ms
(let [now-ms (datetime/timestamp)
recording-duration (- now-ms @recording-start-ms)]
(set-recording-length-ms recording-duration)
(when (>= recording-duration record-audio.constants/max-audio-duration-ms)
(reset! reached-max-duration? (not locked?))
(set-reviewing-audio true)
(reset! idle? false)
(set-locked false)
(set-recording false)
(set-ready-to-lock false)
(set-ready-to-send false)
(set-ready-to-delete false)
(audio/stop-recording
@recorder-ref
(fn []
(reset! output-file (audio/get-recorder-file-path @recorder-ref))
(reload-player nil)
(log/debug "[record-audio] stop recording - success"))
#(log/error "[record-audio] stop recording - error: " %))
(js/setTimeout #(reset! idle? false) 1000)
(set-recording-length-ms 0)
(reset! recording-start-ms nil)
(when on-reviewing-audio
(on-reviewing-audio (audio/get-recorder-file-path @recorder-ref))))
(log/debug "[record-audio] new recorder - on meter")))))))
(def get-reload-recorder
(memoize
(fn
[[recorder-ref recorder-on-meter]]
(fn []
(when @recorder-ref
(audio/destroy-recorder @recorder-ref)
(reset! recorder-ref nil))
(reset! recorder-ref (audio/new-recorder
record-audio.constants/rec-options
recorder-on-meter
#(log/debug "[record-audio] new recorder - on ended")))))))
(def get-on-start-should-set-responder
(memoize
(fn
[[locked? idle? disabled? recorder-on-meter touch-timestamp touch-identifier
reviewing-audio? record-audio-permission-granted set-recording set-playing-audio output-file
recorder-ref recording-start-ms set-audio-current-time-ms on-start-recording
on-request-record-audio-permission touch-active?]]
(fn [e]
(when-not (or locked? @idle? (nil? e) @disabled?)
(let [pressed-record-button? (record-audio.constants/touch-inside-area?
{:location-x (oops/oget e "nativeEvent.locationX")
:location-y (oops/oget e "nativeEvent.locationY")
:ignore-min-y? false
:ignore-max-y? false
:ignore-min-x? false
:ignore-max-x? false}
record-audio.constants/record-button-area)
new-recorder (audio/new-recorder
record-audio.constants/rec-options
recorder-on-meter
#(log/debug "[record-audio] new recorder - on ended"))]
(reset! touch-timestamp (oops/oget e "nativeEvent.timestamp"))
(reset! touch-identifier (oops/oget e "nativeEvent.identifier"))
(when-not reviewing-audio?
(if record-audio-permission-granted
(do
(when (not @idle?)
(set-recording pressed-record-button?))
(when pressed-record-button?
(set-playing-audio false)
(reset! output-file nil)
(reset! recorder-ref new-recorder)
(audio/start-recording
new-recorder
(fn []
(reset! recording-start-ms (datetime/timestamp))
(set-audio-current-time-ms 0)
(log/debug "[record-audio] start recording - success"))
#(log/error "[record-audio] start recording - error: " %))
(when on-start-recording
(on-start-recording))))
(when on-request-record-audio-permission
(on-request-record-audio-permission))))
(when record-audio-permission-granted
(reset! touch-active? true))))
(and (not @idle?) (not @disabled?))))))
(def get-on-responder-move
(memoize
(fn
[[locked? ready-to-send? set-ready-to-send ready-to-delete? set-ready-to-delete ready-to-lock?
set-ready-to-lock touch-identifier
record-button-at-initial-position? recording?]]
(fn [^js e]
(when-not locked?
(let [location-x (oops/oget e "nativeEvent.locationX")
location-y (oops/oget e "nativeEvent.locationY")
page-x (oops/oget e "nativeEvent.pageX")
page-y (oops/oget e "nativeEvent.pageY")
identifier (oops/oget e "nativeEvent.identifier")
moved-to-send-button? (record-audio.constants/touch-inside-area?
{:location-x location-x
:location-y location-y
:ignore-min-y? true
:ignore-max-y? false
:ignore-min-x? false
:ignore-max-x? true}
(record-audio.constants/send-button-area
{:active? ready-to-send?
:reviewing-audio? false}))
moved-to-delete-button? (record-audio.constants/touch-inside-area?
{:location-x location-x
:location-y location-y
:ignore-min-y? false
:ignore-max-y? true
:ignore-min-x? true
:ignore-max-x? false}
(record-audio.constants/delete-button-area
{:active? ready-to-delete?
:reviewing-audio? false}))
moved-to-lock-button? (record-audio.constants/touch-inside-area?
{:location-x location-x
:location-y location-y
:ignore-min-y? false
:ignore-max-y? false
:ignore-min-x? false
:ignore-max-x? false}
(record-audio.constants/lock-button-area {:active?
ready-to-lock?}))
moved-to-record-button? (and
(record-audio.constants/touch-inside-area?
{:location-x location-x
:location-y location-y
:ignore-min-y? false
:ignore-max-y? false
:ignore-min-x? false
:ignore-max-x? false}
record-audio.constants/record-button-area-big)
(not= location-x page-x)
(not= location-y page-y))]
(when (= identifier @touch-identifier)
(cond
(and
(or
(and moved-to-record-button? ready-to-lock?)
(and (not locked?) moved-to-lock-button? @record-button-at-initial-position?))
(not ready-to-delete?)
(not ready-to-send?)
recording?)
(set-ready-to-lock moved-to-lock-button?)
(and
(or
(and moved-to-record-button? ready-to-delete?)
(and moved-to-delete-button? @record-button-at-initial-position?))
(not ready-to-lock?)
(not ready-to-send?)
recording?)
(set-ready-to-delete moved-to-delete-button?)
(and
(or
(and moved-to-record-button? ready-to-send?)
(and moved-to-send-button? @record-button-at-initial-position?))
(not ready-to-lock?)
(not ready-to-delete?)
recording?)
(set-ready-to-send moved-to-send-button?)))))))))
(def get-on-responder-release
(memoize
(fn
[[idle? reached-max-duration? touch-timestamp recording-length-ms set-recording-length-ms
reviewing-audio? set-reviewing-audio
set-audio-current-time-ms set-force-show-controls on-send output-file player-ref
destroy-player on-cancel record-button-is-animating? ready-to-lock? set-ready-to-lock
locked? set-locked on-lock ready-to-delete? set-ready-to-delete ready-to-send? set-ready-to-send
disabled? on-reviewing-audio recorder-ref set-recording reload-player recording-start-ms
touch-active?]]
(fn [^js e]
(when (and
(not @idle?)
(not @reached-max-duration?))
(let [touch-area {:location-x (oops/oget e "nativeEvent.locationX")
:location-y (oops/oget e "nativeEvent.locationY")
:ignore-min-y? false
:ignore-max-y? false
:ignore-min-x? false
:ignore-max-x? false}
on-record-button? (record-audio.constants/touch-inside-area?
touch-area
record-audio.constants/record-button-area-big)
on-send-button? (record-audio.constants/touch-inside-area?
touch-area
(record-audio.constants/send-button-area
{:active? false
:reviewing-audio? true}))
on-delete-button? (record-audio.constants/touch-inside-area?
touch-area
(record-audio.constants/delete-button-area
{:active? false
:reviewing-audio? true}))
release-touch-timestamp (oops/oget e "nativeEvent.timestamp")
touch-timestamp-diff (- release-touch-timestamp @touch-timestamp)
audio-length recording-length-ms]
(cond
(and reviewing-audio? on-send-button?)
(do
(set-reviewing-audio false)
(set-audio-current-time-ms 0)
(set-force-show-controls false)
(when on-send
(on-send {:file-path @output-file
:duration (min record-audio.constants/max-audio-duration-ms
(int (audio/get-player-duration @player-ref)))}))
(when @player-ref
(audio/stop-playing
@player-ref
(fn []
(destroy-player)
(log/debug "[record-audio] stop playing - success"))
#(log/error "[record-audio] stop playing - error: " %))))
(and reviewing-audio? on-delete-button?)
(do
(set-reviewing-audio false)
(set-audio-current-time-ms 0)
(set-force-show-controls false)
(destroy-player)
(when on-cancel
(on-cancel)))
(and ready-to-lock? (not @record-button-is-animating?))
(do
(set-locked true)
(set-ready-to-lock false)
(when on-lock
(on-lock)))
(and (not reviewing-audio?)
(or on-record-button?
(and (not ready-to-delete?)
(not ready-to-lock?)
(not ready-to-send?))))
(do
(reset! disabled? (<= touch-timestamp-diff record-audio.constants/min-touch-duration))
(js/setTimeout
(fn []
(if (>= recording-length-ms record-audio.constants/min-audio-duration-ms)
(do (set-reviewing-audio true)
(reset! idle? false)
(when on-reviewing-audio
(on-reviewing-audio (audio/get-recorder-file-path @recorder-ref))))
(do (when on-cancel
(on-cancel))
(reset! idle? true)))
(set-locked false)
(set-recording false)
(set-ready-to-lock false)
(audio/stop-recording
@recorder-ref
(fn []
(reset! output-file (audio/get-recorder-file-path @recorder-ref))
(when (>= audio-length record-audio.constants/min-audio-duration-ms)
(reload-player nil))
(log/debug "[record-audio] stop recording - success"))
#(log/error "[record-audio] stop recording - error: " %))
(js/setTimeout #(reset! idle? false) 1000)
(set-recording-length-ms 0)
(reset! recording-start-ms nil)
(reset! disabled? false))
(if (> touch-timestamp-diff record-audio.constants/min-touch-duration) 0 250)))
(and (not locked?) (not reviewing-audio?) (not @record-button-is-animating?))
(do
(reset! disabled? (<= touch-timestamp-diff record-audio.constants/min-touch-duration))
(js/setTimeout
(fn []
(audio/stop-recording
@recorder-ref
(fn []
(cond
ready-to-send?
(when on-send
(on-send {:file-path (audio/get-recorder-file-path @recorder-ref)
:duration recording-length-ms}))
ready-to-delete?
(when on-cancel
(on-cancel)))
(set-recording false)
(set-ready-to-send false)
(set-ready-to-delete false)
(set-ready-to-lock false)
(reset! idle? true)
(js/setTimeout #(reset! idle? false) 1000)
(set-recording-length-ms 0)
(reset! recording-start-ms nil)
(reset! disabled? false)
(log/debug "[record-audio] stop recording - success"))
#(log/error "[record-audio] stop recording - error: " %)))
(if (> touch-timestamp-diff record-audio.constants/min-touch-duration) 0 250)))))
(reset! touch-active? false))
(when @reached-max-duration?
(reset! reached-max-duration? false))
(reset! touch-timestamp nil)))))
@@ -2,6 +2,7 @@
(:require (:require
[clojure.string :as string] [clojure.string :as string]
[goog.string :as gstring] [goog.string :as gstring]
[oops.core :as oops]
[quo.components.icon :as icons] [quo.components.icon :as icons]
[quo.components.markdown.text :as text] [quo.components.markdown.text :as text]
[quo.components.record-audio.record-audio.buttons.delete-button :as delete-button] [quo.components.record-audio.record-audio.buttons.delete-button :as delete-button]
@@ -9,23 +10,93 @@
[quo.components.record-audio.record-audio.buttons.record-button :as record-button] [quo.components.record-audio.record-audio.buttons.record-button :as record-button]
[quo.components.record-audio.record-audio.buttons.record-button-big :as record-button-big] [quo.components.record-audio.record-audio.buttons.record-button-big :as record-button-big]
[quo.components.record-audio.record-audio.buttons.send-button :as send-button] [quo.components.record-audio.record-audio.buttons.send-button :as send-button]
[quo.components.record-audio.record-audio.constants :as record-audio.constants]
[quo.components.record-audio.record-audio.handlers :as handlers]
[quo.components.record-audio.record-audio.style :as style] [quo.components.record-audio.record-audio.style :as style]
[quo.components.record-audio.soundtrack.view :as soundtrack] [quo.components.record-audio.soundtrack.view :as soundtrack]
[quo.foundations.colors :as colors] [quo.foundations.colors :as colors]
[quo.theme :as quo.theme]
[react-native.audio-toolkit :as audio] [react-native.audio-toolkit :as audio]
[react-native.core :as rn] [react-native.core :as rn]
[react-native.platform :as platform]
[reagent.core :as reagent]
[taoensso.timbre :as log] [taoensso.timbre :as log]
[utils.datetime :as datetime])) [utils.datetime :as datetime]))
(defn- recording-bar (def ^:private min-audio-duration-ms 1000)
(def ^:private max-audio-duration-ms (if platform/ios? 120800 120500))
(def ^:private metering-interval 25)
(def ^:private base-filename "am")
(def ^:private default-format ".aac")
(def min-touch-duration 150)
(def ^:private record-button-area-big
{:width 56
:height 56
:x 64
:y 64})
(def ^:private record-button-area
{:width 48
:height 48
:x 68
:y 68})
(defn- delete-button-area
[{:keys [active? reviewing-audio?]}]
{:width (cond
active? 72
reviewing-audio? 32
:else 82)
:height (if reviewing-audio? 32 56)
:x (cond
active? -16
reviewing-audio? 36
:else -32)
:y (cond
active? 64
reviewing-audio? 76
:else 70)})
(defn- lock-button-area
[{:keys [active?]}]
{:width (if active? 72 100)
:height (if active? 72 102)
:x -32
:y -32})
(defn- send-button-area
[{:keys [active? reviewing-audio?]}]
{:width (if reviewing-audio? 32 56)
:height (cond
active? 72
reviewing-audio? 47
:else 92)
:x (if reviewing-audio? 76 32)
:y (cond
active? -16
reviewing-audio? 76
:else -32)})
(defn touch-inside-area?
[{:keys [location-x location-y ignore-min-y? ignore-max-y? ignore-min-x? ignore-max-x?]}
{:keys [width height x y]}]
(let [max-x (+ x width)
max-y (+ y height)]
(and
(and
(or ignore-min-x? (>= location-x x))
(or ignore-max-x? (<= location-x max-x)))
(and
(or ignore-min-y? (>= location-y y))
(or ignore-max-y? (<= location-y max-y))))))
(defn- f-recording-bar
[recording-length-ms ready-to-delete?] [recording-length-ms ready-to-delete?]
(let [fill-percentage (/ (* recording-length-ms 100) record-audio.constants/max-audio-duration-ms)] (let [fill-percentage (/ (* recording-length-ms 100) max-audio-duration-ms)]
[rn/view {:style (style/recording-bar-container)} [rn/view {:style (style/recording-bar-container)}
[rn/view {:style (style/recording-bar fill-percentage ready-to-delete?)}]])) [rn/view {:style (style/recording-bar fill-percentage ready-to-delete?)}]]))
(defn- time-counter (defn- f-time-counter
[recording? recording-length-ms ready-to-delete? reviewing-audio? audio-current-time-ms] [recording? recording-length-ms ready-to-delete? reviewing-audio? audio-current-time-ms]
(let [s (quot (if recording? recording-length-ms audio-current-time-ms) 1000) (let [s (quot (if recording? recording-length-ms audio-current-time-ms) 1000)
time-str (gstring/format "%02d:%02d" (quot s 60) (mod s 60))] time-str (gstring/format "%02d:%02d" (quot s 60) (mod s 60))]
@@ -40,12 +111,10 @@
{:style (style/timer-text)})) {:style (style/timer-text)}))
time-str]])) time-str]]))
(defn- play-button (defn- f-play-button
[playing-audio? set-playing-audio player-ref playing-timer set-audio-current-time-ms seeking-audio? [playing-audio? player-ref playing-timer audio-current-time-ms seeking-audio? max-duration-ms]
set-seeking-audio
max-duration-ms]
(let [on-play (fn [] (let [on-play (fn []
(set-playing-audio true) (reset! playing-audio? true)
(reset! playing-timer (reset! playing-timer
(js/setInterval (js/setInterval
(fn [] (fn []
@@ -53,24 +122,24 @@
player-state (audio/get-state @player-ref) player-state (audio/get-state @player-ref)
playing? (= player-state audio/PLAYING)] playing? (= player-state audio/PLAYING)]
(when (and playing? (when (and playing?
(not seeking-audio?) (not @seeking-audio?)
(> current-time 0) (> current-time 0)
(< current-time max-duration-ms)) (< current-time max-duration-ms))
(set-audio-current-time-ms current-time)) (reset! audio-current-time-ms current-time))
(when (>= current-time max-duration-ms) (when (>= current-time max-duration-ms)
(audio/stop-playing (audio/stop-playing
@player-ref @player-ref
(fn [] (fn []
(set-playing-audio false) (reset! playing-audio? false)
(when @playing-timer (when @playing-timer
(js/clearInterval @playing-timer) (js/clearInterval @playing-timer)
(reset! playing-timer nil) (reset! playing-timer nil)
(set-audio-current-time-ms 0) (reset! audio-current-time-ms 0)
(set-seeking-audio false))) (reset! seeking-audio? false)))
#(log/error "[record-audio] stop player - error: " %))))) #(log/error "[record-audio] stop player - error: " %)))))
100))) 100)))
on-pause (fn [] on-pause (fn []
(set-playing-audio false) (reset! playing-audio? false)
(when @playing-timer (when @playing-timer
(js/clearInterval @playing-timer) (js/clearInterval @playing-timer)
(reset! playing-timer nil)) (reset! playing-timer nil))
@@ -85,186 +154,445 @@
{:style (style/play-button) {:style (style/play-button)
:on-press on-press} :on-press on-press}
[icons/icon [icons/icon
(if playing-audio? :i/pause :i/play) (if @playing-audio? :i/pause :i/play)
{:color (colors/theme-colors colors/neutral-100 colors/white)}]])) {:color (colors/theme-colors colors/neutral-100 colors/white)}]]))
(defn record-audio (defn- record-audio-internal
[{:keys [on-init on-start-recording on-send on-cancel on-reviewing-audio audio-file on-lock [{:keys [on-init on-start-recording on-send on-cancel on-reviewing-audio
max-duration-ms on-check-audio-permissions record-audio-permission-granted record-audio-permission-granted
on-request-record-audio-permission]}] on-request-record-audio-permission on-check-audio-permissions
(let [;;STATE audio-file on-lock max-duration-ms theme]}]
[recording? set-recording] (rn/use-state false) [:f>
[locked? set-locked] (rn/use-state false) ;; TODO we need to refactor this, and use :f> with defined function, currenly state is reseted each
[ready-to-send? set-ready-to-send] (rn/use-state false) ;; time parent component
[ready-to-lock? set-ready-to-lock] (rn/use-state false) ;; is re-rendered
[ready-to-delete? (fn []
set-ready-to-delete] (rn/use-state false) (let [recording? (reagent/atom false)
[reviewing-audio? locked? (reagent/atom false)
set-reviewing-audio] (rn/use-state (some? audio-file)) ready-to-send? (reagent/atom false)
[playing-audio? ready-to-lock? (reagent/atom false)
set-playing-audio] (rn/use-state false) ready-to-delete? (reagent/atom false)
[recording-length-ms reviewing-audio? (reagent/atom (some? audio-file))
set-recording-length-ms] (rn/use-state 0) playing-audio? (reagent/atom false)
[audio-current-time-ms recording-length-ms (reagent/atom 0)
set-audio-current-time-ms] (rn/use-state 0) audio-current-time-ms (reagent/atom 0)
[seeking-audio? set-seeking-audio] (rn/use-state false) seeking-audio? (reagent/atom false)
[force-show-controls? force-show-controls? (reagent/atom (some? audio-file))
set-force-show-controls] (rn/use-state (some? audio-file)) recording-start-ms (atom (datetime/timestamp))
;;ATOMS clear-timeout (atom nil)
recording-start-ms (rn/use-ref-atom (datetime/timestamp)) record-button-at-initial-position? (atom true)
clear-timeout (rn/use-ref-atom nil) record-button-is-animating? (atom false)
record-button-at-initial-position? (rn/use-ref-atom true) idle? (atom false)
record-button-is-animating? (rn/use-ref-atom false) recorder-ref (atom nil)
idle? (rn/use-ref-atom false) player-ref (atom nil)
recorder-ref (rn/use-ref-atom nil) touch-active? (atom false)
player-ref (rn/use-ref-atom nil) playing-timer (atom nil)
touch-active? (rn/use-ref-atom false) output-file (atom audio-file)
playing-timer (rn/use-ref-atom nil) reached-max-duration? (atom false)
output-file (rn/use-ref-atom audio-file) touch-timestamp (atom nil)
reached-max-duration? (rn/use-ref-atom false) touch-identifier (atom nil)
touch-timestamp (rn/use-ref-atom nil) disabled? (atom false)
touch-identifier (rn/use-ref-atom nil) app-state-listener (atom nil)
disabled? (rn/use-ref-atom false) rec-options
app-state-listener (rn/use-ref-atom nil) (merge
;;HANDLERS audio/default-recorder-options
destroy-player (rn/use-callback {:filename (str base-filename (datetime/timestamp) default-format)
(fn [] :meteringInterval metering-interval})
(audio/destroy-player @player-ref) destroy-player
(reset! player-ref nil))) (fn []
reload-player (handlers/get-reload-player (audio/destroy-player @player-ref)
[player-ref destroy-player set-playing-audio playing-timer (reset! player-ref nil))
set-audio-current-time-ms set-seeking-audio]) reload-player
recorder-on-meter (handlers/get-recorder-on-meter (fn [audio-file]
[recording-start-ms set-recording-length-ms (when @player-ref
reached-max-duration? (destroy-player))
locked? set-locked set-reviewing-audio idle? set-recording (reset! player-ref
set-ready-to-lock set-ready-to-send set-ready-to-delete (audio/new-player
recorder-ref (or audio-file (:filename rec-options))
output-file reload-player {:autoDestroy false
on-reviewing-audio]) :continuesToPlayInBackground false
reload-recorder (handlers/get-reload-recorder [recorder-ref :category audio/PLAYBACK}
recorder-on-meter]) (fn []
on-start-should-set-responder (handlers/get-on-start-should-set-responder (reset! playing-audio? false)
[locked? idle? disabled? recorder-on-meter touch-timestamp (when @playing-timer
touch-identifier (js/clearInterval @playing-timer)
reviewing-audio? record-audio-permission-granted (reset! playing-timer nil)
set-recording set-playing-audio output-file (reset! audio-current-time-ms 0)
recorder-ref recording-start-ms set-audio-current-time-ms (reset! seeking-audio? false)))))
on-start-recording (audio/prepare-player
on-request-record-audio-permission touch-active?]) @player-ref
on-responder-move (handlers/get-on-responder-move #(log/debug "[record-audio] prepare player - success")
[locked? ready-to-send? set-ready-to-send #(log/error "[record-audio] prepare player - error: " %)))
ready-to-delete? set-ready-to-delete destroy-recorder
ready-to-lock? set-ready-to-lock (fn []
touch-identifier (audio/destroy-recorder @recorder-ref)
record-button-at-initial-position? (reset! recorder-ref nil))
recording?]) recorder-on-meter
on-responder-release (handlers/get-on-responder-release (fn []
[idle? reached-max-duration? touch-timestamp (when @recording-start-ms
recording-length-ms set-recording-length-ms (let [now-ms (datetime/timestamp)
reviewing-audio? set-reviewing-audio recording-duration (- now-ms
set-audio-current-time-ms set-force-show-controls on-send @recording-start-ms)]
output-file player-ref (reset! recording-length-ms recording-duration)
destroy-player on-cancel record-button-is-animating? (when (>= recording-duration max-audio-duration-ms)
ready-to-lock? set-ready-to-lock (reset! reached-max-duration? (not @locked?))
locked? set-locked on-lock ready-to-delete? (reset! reviewing-audio? true)
set-ready-to-delete ready-to-send? set-ready-to-send (reset! idle? false)
disabled? on-reviewing-audio (reset! locked? false)
recorder-ref set-recording reload-player recording-start-ms (reset! recording? false)
touch-active?])] (reset! ready-to-lock? false)
(reset! ready-to-send? false)
(reset! ready-to-delete? false)
(audio/stop-recording
@recorder-ref
(fn []
(reset! output-file (audio/get-recorder-file-path
@recorder-ref))
(reload-player nil)
(log/debug "[record-audio] stop recording - success"))
#(log/error "[record-audio] stop recording - error: " %))
(js/setTimeout #(reset! idle? false) 1000)
(reset! recording-length-ms 0)
(reset! recording-start-ms nil)
(when on-reviewing-audio
(on-reviewing-audio (audio/get-recorder-file-path
@recorder-ref))))
(log/debug "[record-audio] new recorder - on meter"))))
reload-recorder
(fn []
(when @recorder-ref
(destroy-recorder))
(reset! recorder-ref (audio/new-recorder
rec-options
recorder-on-meter
#(log/debug "[record-audio] new recorder - on ended"))))
reset-recorder
(fn []
(reset! recording? false)
(reset! reviewing-audio? false)
(reset! locked? false)
(reset! ready-to-send? false)
(reset! ready-to-lock? false)
(reset! ready-to-delete? false)
(reset! audio-current-time-ms 0)
(reset! recording-length-ms 0)
(reset! seeking-audio? false)
(reset! playing-audio? false)
(reset! touch-active? false)
(reset! reached-max-duration? false)
(reset! output-file nil)
(reset! idle? false)
(reset! record-button-is-animating? false)
(reset! record-button-at-initial-position? true)
(when @clear-timeout
(js/clearTimeout @clear-timeout)
(reset! clear-timeout nil))
(when @playing-timer
(js/clearInterval @playing-timer)
(reset! playing-timer nil))
(reload-recorder))
on-start-should-set-responder
(fn [^js e]
(when-not (or @locked? @idle? (nil? e) @disabled?)
(let [pressed-record-button? (touch-inside-area?
{:location-x (oops/oget e "nativeEvent.locationX")
:location-y (oops/oget e "nativeEvent.locationY")
:ignore-min-y? false
:ignore-max-y? false
:ignore-min-x? false
:ignore-max-x? false}
record-button-area)
new-recorder (audio/new-recorder
rec-options
recorder-on-meter
#(log/debug "[record-audio] new recorder - on ended"))]
(reset! touch-timestamp (oops/oget e "nativeEvent.timestamp"))
(reset! touch-identifier (oops/oget e "nativeEvent.identifier"))
(when-not @reviewing-audio?
(if record-audio-permission-granted
(do
(when (not @idle?)
(reset! recording? pressed-record-button?))
(when pressed-record-button?
(reset! playing-audio? false)
(reset! output-file nil)
(reset! recorder-ref new-recorder)
(audio/start-recording
new-recorder
(fn []
(reset! recording-start-ms (datetime/timestamp))
(reset! audio-current-time-ms 0)
(log/debug "[record-audio] start recording - success"))
#(log/error "[record-audio] start recording - error: " %))
(when on-start-recording
(on-start-recording))))
(when on-request-record-audio-permission
(on-request-record-audio-permission))))
(when record-audio-permission-granted
(reset! touch-active? true))))
(and (not @idle?) (not @disabled?)))
on-responder-move
(fn [^js e]
(when-not @locked?
(let [location-x (oops/oget e "nativeEvent.locationX")
location-y (oops/oget e "nativeEvent.locationY")
page-x (oops/oget e "nativeEvent.pageX")
page-y (oops/oget e "nativeEvent.pageY")
identifier (oops/oget e "nativeEvent.identifier")
moved-to-send-button? (touch-inside-area?
{:location-x location-x
:location-y location-y
:ignore-min-y? true
:ignore-max-y? false
:ignore-min-x? false
:ignore-max-x? true}
(send-button-area
{:active? @ready-to-send?
:reviewing-audio? false}))
moved-to-delete-button? (touch-inside-area?
{:location-x location-x
:location-y location-y
:ignore-min-y? false
:ignore-max-y? true
:ignore-min-x? true
:ignore-max-x? false}
(delete-button-area
{:active? @ready-to-delete?
:reviewing-audio? false}))
moved-to-lock-button? (touch-inside-area?
{:location-x location-x
:location-y location-y
:ignore-min-y? false
:ignore-max-y? false
:ignore-min-x? false
:ignore-max-x? false}
(lock-button-area {:active? @ready-to-lock?}))
moved-to-record-button? (and
(touch-inside-area?
{:location-x location-x
:location-y location-y
:ignore-min-y? false
:ignore-max-y? false
:ignore-min-x? false
:ignore-max-x? false}
record-button-area-big)
(not= location-x page-x)
(not= location-y page-y))]
(when (= identifier @touch-identifier)
(cond
(and
(or
(and moved-to-record-button? @ready-to-lock?)
(and (not @locked?) moved-to-lock-button? @record-button-at-initial-position?))
(not @ready-to-delete?)
(not @ready-to-send?)
@recording?)
(reset! ready-to-lock? moved-to-lock-button?)
(and
(or
(and moved-to-record-button? @ready-to-delete?)
(and moved-to-delete-button? @record-button-at-initial-position?))
(not @ready-to-lock?)
(not @ready-to-send?)
@recording?)
(reset! ready-to-delete? moved-to-delete-button?)
(and
(or
(and moved-to-record-button? @ready-to-send?)
(and moved-to-send-button? @record-button-at-initial-position?))
(not @ready-to-lock?)
(not @ready-to-delete?)
@recording?)
(reset! ready-to-send? moved-to-send-button?))))))
on-responder-release
(fn [^js e]
(when (and
(not @idle?)
(not @reached-max-duration?))
(let [touch-area {:location-x (oops/oget e "nativeEvent.locationX")
:location-y (oops/oget e "nativeEvent.locationY")
:ignore-min-y? false
:ignore-max-y? false
:ignore-min-x? false
:ignore-max-x? false}
on-record-button? (touch-inside-area?
touch-area
record-button-area-big)
on-send-button? (touch-inside-area?
touch-area
(send-button-area
{:active? false
:reviewing-audio? true}))
on-delete-button? (touch-inside-area?
touch-area
(delete-button-area
{:active? false
:reviewing-audio? true}))
release-touch-timestamp (oops/oget e "nativeEvent.timestamp")
touch-timestamp-diff (- release-touch-timestamp @touch-timestamp)
audio-length @recording-length-ms]
(cond
(and @reviewing-audio? on-send-button?)
(do
(reset! reviewing-audio? false)
(reset! audio-current-time-ms 0)
(reset! force-show-controls? false)
(when on-send
(on-send {:file-path @output-file
:duration (min max-audio-duration-ms
(int (audio/get-player-duration @player-ref)))}))
(when @player-ref
(audio/stop-playing
@player-ref
(fn []
(destroy-player)
(log/debug "[record-audio] stop playing - success"))
#(log/error "[record-audio] stop playing - error: " %))))
(and @reviewing-audio? on-delete-button?)
(do
(reset! reviewing-audio? false)
(reset! audio-current-time-ms 0)
(reset! force-show-controls? false)
(destroy-player)
(when on-cancel
(on-cancel)))
(and @ready-to-lock? (not @record-button-is-animating?))
(do
(reset! locked? true)
(reset! ready-to-lock? false)
(when on-lock
(on-lock)))
(and (not @reviewing-audio?)
(or on-record-button?
(and (not @ready-to-delete?)
(not @ready-to-lock?)
(not @ready-to-send?))))
(do
(reset! disabled? (<= touch-timestamp-diff min-touch-duration))
(js/setTimeout
(fn []
(if (>= @recording-length-ms min-audio-duration-ms)
(do (reset! reviewing-audio? true)
(reset! idle? false)
(when on-reviewing-audio
(on-reviewing-audio (audio/get-recorder-file-path @recorder-ref))))
(do (when on-cancel
(on-cancel))
(reset! idle? true)))
(reset! locked? false)
(reset! recording? false)
(reset! ready-to-lock? false)
(audio/stop-recording
@recorder-ref
(fn []
(reset! output-file (audio/get-recorder-file-path @recorder-ref))
(when (>= audio-length min-audio-duration-ms)
(reload-player nil))
(log/debug "[record-audio] stop recording - success"))
#(log/error "[record-audio] stop recording - error: " %))
(js/setTimeout #(reset! idle? false) 1000)
(reset! recording-length-ms 0)
(reset! recording-start-ms nil)
(reset! disabled? false))
(if (> touch-timestamp-diff min-touch-duration) 0 250)))
(and (not @locked?) (not @reviewing-audio?) (not @record-button-is-animating?))
(do
(reset! disabled? (<= touch-timestamp-diff min-touch-duration))
(js/setTimeout
(fn []
(audio/stop-recording
@recorder-ref
(fn []
(cond
@ready-to-send?
(when on-send
(on-send {:file-path (audio/get-recorder-file-path @recorder-ref)
:duration @recording-length-ms}))
@ready-to-delete?
(when on-cancel
(on-cancel)))
(reset! recording? false)
(reset! ready-to-send? false)
(reset! ready-to-delete? false)
(reset! ready-to-lock? false)
(reset! idle? true)
(js/setTimeout #(reset! idle? false) 1000)
(reset! recording-length-ms 0)
(reset! recording-start-ms nil)
(reset! disabled? false)
(log/debug "[record-audio] stop recording - success"))
#(log/error "[record-audio] stop recording - error: " %)))
(if (> touch-timestamp-diff min-touch-duration) 0 250)))))
(reset! touch-active? false))
(when @reached-max-duration?
(reset! reached-max-duration? false))
(reset! touch-timestamp nil))]
(fn []
(rn/use-mount (fn []
(when on-check-audio-permissions
(on-check-audio-permissions))
(when on-init
(on-init reset-recorder))
(when audio-file
(let [filename (last (string/split audio-file "/"))]
(reload-player filename)))
(reset! app-state-listener
(.addEventListener rn/app-state
"change"
#(when (= % "background")
(reset! playing-audio? false))))
#(.remove @app-state-listener)))
[rn/view
{:style style/bar-container
:pointer-events :box-none}
(when @reviewing-audio?
[:<>
[:f> f-play-button playing-audio? player-ref playing-timer audio-current-time-ms
seeking-audio? max-duration-ms]
[:f> soundtrack/f-soundtrack
{:audio-current-time-ms audio-current-time-ms
:player-ref @player-ref
:seeking-audio? seeking-audio?
:max-audio-duration-ms max-duration-ms}]])
(when (or @recording? @reviewing-audio?)
[:f> f-time-counter @recording? @recording-length-ms @ready-to-delete? @reviewing-audio?
@audio-current-time-ms])
(when @recording?
[:f> f-recording-bar @recording-length-ms @ready-to-delete?])
[rn/view
{:test-ID "record-audio"
:style style/button-container
:hit-slop {:top -70
:bottom 0
:left 0
:right 0}
:pointer-events :box-only
:on-start-should-set-responder on-start-should-set-responder
:on-responder-move on-responder-move
:on-responder-release on-responder-release}
[:f> delete-button/f-delete-button recording? ready-to-delete? reviewing-audio?
@force-show-controls?]
[:f> lock-button/f-lock-button recording? ready-to-lock? locked?]
[:f> send-button/f-send-button recording? ready-to-send? reviewing-audio?
@force-show-controls?]
[:f> record-button-big/f-record-button-big
{:recording? recording?
:ready-to-send? ready-to-send?
:ready-to-lock? ready-to-lock?
:ready-to-delete? ready-to-delete?
:record-button-is-animating? record-button-is-animating?
:record-button-at-initial-position? record-button-at-initial-position?
:locked? locked?
:reviewing-audio? reviewing-audio?
:recording-length-ms recording-length-ms
:clear-timeout clear-timeout
:touch-active? touch-active?
:recorder-ref recorder-ref
:reload-recorder-fn reload-recorder
:idle? idle?
:on-send on-send
:on-cancel on-cancel
:theme theme}]
[:f> record-button/f-record-button recording? reviewing-audio?]]])))])
;;ON MOUNT (def record-audio (quo.theme/with-theme record-audio-internal))
(rn/use-mount
(fn []
(when on-check-audio-permissions (on-check-audio-permissions))
(when on-init
(on-init
(fn reset-recorder []
(set-recording false)
(set-reviewing-audio false)
(set-locked false)
(set-ready-to-send false)
(set-ready-to-lock false)
(set-ready-to-delete false)
(set-audio-current-time-ms 0)
(set-recording-length-ms 0)
(set-seeking-audio false)
(set-playing-audio false)
(reset! touch-active? false)
(reset! reached-max-duration? false)
(reset! output-file nil)
(reset! idle? false)
(reset! record-button-is-animating? false)
(reset! record-button-at-initial-position? true)
(when @clear-timeout
(js/clearTimeout @clear-timeout)
(reset! clear-timeout nil))
(when @playing-timer
(js/clearInterval @playing-timer)
(reset! playing-timer nil))
(reload-recorder))))
(when audio-file
(let [filename (last (string/split audio-file "/"))]
(reload-player filename)))
(reset! app-state-listener
(.addEventListener rn/app-state
"change"
#(when (= % "background")
(set-playing-audio false))))))
;;ON UNMOUNT
(rn/use-unmount #(.remove @app-state-listener))
[rn/view
{:style style/bar-container
:pointer-events :box-none}
(when reviewing-audio?
[:<>
[play-button playing-audio? set-playing-audio player-ref playing-timer set-audio-current-time-ms
seeking-audio? set-seeking-audio max-duration-ms]
[soundtrack/soundtrack
{:audio-current-time-ms audio-current-time-ms
:set-audio-current-time-ms set-audio-current-time-ms
:player-ref @player-ref
:seeking-audio? seeking-audio?
:set-seeking-audio set-seeking-audio
:max-audio-duration-ms max-duration-ms}]])
(when (or recording? reviewing-audio?)
[time-counter recording? recording-length-ms ready-to-delete? reviewing-audio?
audio-current-time-ms])
(when recording?
[recording-bar recording-length-ms ready-to-delete?])
[rn/view
{:test-ID "record-audio"
:style style/button-container
:hit-slop {:top -70 :bottom 0 :left 0 :right 0}
:pointer-events :box-only
:on-start-should-set-responder on-start-should-set-responder
:on-responder-move on-responder-move
:on-responder-release on-responder-release}
[delete-button/delete-button recording? ready-to-delete? reviewing-audio? force-show-controls?]
[lock-button/lock-button recording? ready-to-lock? locked?]
[send-button/send-button recording? ready-to-send? reviewing-audio? force-show-controls?]
[record-button-big/record-button-big
{:recording? recording?
:set-recording set-recording
:ready-to-send? ready-to-send?
:set-ready-to-send set-ready-to-send
:ready-to-lock? ready-to-lock?
:set-ready-to-lock set-ready-to-lock
:ready-to-delete? ready-to-delete?
:set-ready-to-delete set-ready-to-delete
:record-button-is-animating? record-button-is-animating?
:record-button-at-initial-position? record-button-at-initial-position?
:locked? locked?
:set-locked set-locked
:reviewing-audio? reviewing-audio?
:recording-length-ms recording-length-ms
:set-recording-length-ms set-recording-length-ms
:clear-timeout clear-timeout
:touch-active? touch-active?
:recorder-ref recorder-ref
:reload-recorder-fn reload-recorder
:idle? idle?
:on-send on-send
:on-cancel on-cancel}]
[record-button/record-button recording? reviewing-audio?]]]))
@@ -2,6 +2,7 @@
(:require (:require
[quo.components.record-audio.soundtrack.view :as soundtrack] [quo.components.record-audio.soundtrack.view :as soundtrack]
[react-native.audio-toolkit :as audio] [react-native.audio-toolkit :as audio]
[reagent.core :as reagent]
[test-helpers.component :as h])) [test-helpers.component :as h]))
(h/describe "soundtrack component" (h/describe "soundtrack component"
@@ -9,21 +10,23 @@
(h/test "renders soundtrack" (h/test "renders soundtrack"
(with-redefs [audio/get-player-duration (fn [] 2000)] (with-redefs [audio/get-player-duration (fn [] 2000)]
(h/render [soundtrack/soundtrack (let [player-ref (reagent/atom {})
{:player-ref {} audio-current-time-ms (reagent/atom 0)]
:audio-current-time-ms 0}]) (h/render [:f> soundtrack/f-soundtrack
(-> (h/expect (h/get-by-test-id "soundtrack")) {:player-ref @player-ref
(.toBeTruthy)))) :audio-current-time-ms audio-current-time-ms}])
(-> (h/expect (h/get-by-test-id "soundtrack"))
(.toBeTruthy)))))
(h/test "soundtrack on-sliding-start works" (h/test "soundtrack on-sliding-start works"
(with-redefs [audio/get-player-duration (fn [] 2000)] (with-redefs [audio/get-player-duration (fn [] 2000)]
(let [seeking-audio? (atom false)] (let [seeking-audio? (reagent/atom false)
(h/render [soundtrack/soundtrack player-ref (reagent/atom {})
{:seeking-audio? seeking-audio? audio-current-time-ms (reagent/atom 0)]
:set-seeking-audio #(reset! seeking-audio? %) (h/render [:f> soundtrack/f-soundtrack
:player-ref {} {:seeking-audio? seeking-audio?
:audio-current-time-ms 0 :player-ref @player-ref
:set-audio-current-time-ms #()}]) :audio-current-time-ms audio-current-time-ms}])
(h/fire-event (h/fire-event
:on-sliding-start :on-sliding-start
(h/get-by-test-id "soundtrack")) (h/get-by-test-id "soundtrack"))
@@ -33,13 +36,13 @@
(h/test "soundtrack on-sliding-complete works" (h/test "soundtrack on-sliding-complete works"
(with-redefs [audio/get-player-duration (fn [] 2000) (with-redefs [audio/get-player-duration (fn [] 2000)
audio/seek-player (js/jest.fn)] audio/seek-player (js/jest.fn)]
(let [seeking-audio? (atom false)] (let [seeking-audio? (reagent/atom false)
(h/render [soundtrack/soundtrack player-ref (reagent/atom {})
{:seeking-audio? seeking-audio? audio-current-time-ms (reagent/atom 0)]
:set-seeking-audio #(reset! seeking-audio? %) (h/render [:f> soundtrack/f-soundtrack
:player-ref {} {:seeking-audio? seeking-audio?
:audio-current-time-ms 0 :player-ref @player-ref
:set-audio-current-time-ms #()}]) :audio-current-time-ms audio-current-time-ms}])
(h/fire-event (h/fire-event
:on-sliding-start :on-sliding-start
(h/get-by-test-id "soundtrack")) (h/get-by-test-id "soundtrack"))
@@ -55,14 +58,13 @@
(h/test "soundtrack on-value-change when seeking audio works" (h/test "soundtrack on-value-change when seeking audio works"
(with-redefs [audio/get-player-duration (fn [] 2000) (with-redefs [audio/get-player-duration (fn [] 2000)
audio/seek-player (js/jest.fn)] audio/seek-player (js/jest.fn)]
(let [seeking-audio? (atom false) (let [seeking-audio? (reagent/atom false)
audio-current-time-ms (atom 0)] player-ref (reagent/atom {})
(h/render [soundtrack/soundtrack audio-current-time-ms (reagent/atom 0)]
{:seeking-audio? seeking-audio? (h/render [:f> soundtrack/f-soundtrack
:set-seeking-audio #(reset! seeking-audio? %) {:seeking-audio? seeking-audio?
:player-ref {} :player-ref @player-ref
:audio-current-time-ms audio-current-time-ms :audio-current-time-ms audio-current-time-ms}])
:set-audio-current-time-ms #(reset! audio-current-time-ms %)}])
(h/fire-event (h/fire-event
:on-sliding-start :on-sliding-start
(h/get-by-test-id "soundtrack")) (h/get-by-test-id "soundtrack"))
@@ -1,47 +1,42 @@
(ns quo.components.record-audio.soundtrack.view (ns quo.components.record-audio.soundtrack.view
(:require (:require
[quo.components.icons.icons :as icons]
[quo.components.record-audio.soundtrack.style :as style] [quo.components.record-audio.soundtrack.style :as style]
[quo.foundations.colors :as colors] [quo.foundations.colors :as colors]
[quo.theme :as quo.theme] [quo.theme :as quo.theme]
[react-native.audio-toolkit :as audio] [react-native.audio-toolkit :as audio]
[react-native.core :as rn]
[react-native.platform :as platform] [react-native.platform :as platform]
[react-native.slider :as slider] [react-native.slider :as slider]
[taoensso.timbre :as log])) [taoensso.timbre :as log]))
(def ^:private thumb-light (icons/icon-source :thumb-light12)) (def ^:private thumb-light (js/require "../resources/images/icons2/12x12/thumb-light.png"))
(def ^:private thumb-dark (icons/icon-source :thumb-dark12)) (def ^:private thumb-dark (js/require "../resources/images/icons2/12x12/thumb-dark.png"))
(defn soundtrack (defn f-soundtrack
[{:keys [audio-current-time-ms set-audio-current-time-ms player-ref style [{:keys [audio-current-time-ms player-ref style seeking-audio? max-audio-duration-ms]}]
seeking-audio? set-seeking-audio max-audio-duration-ms]}] (let [audio-duration-ms (min max-audio-duration-ms (audio/get-player-duration player-ref))
(let [audio-duration-ms (min max-audio-duration-ms (audio/get-player-duration player-ref)) theme (quo.theme/use-theme-value)]
theme (quo.theme/use-theme-value) [:<>
on-sliding-start (rn/use-callback #(set-seeking-audio true)) [slider/slider
on-sliding-complete (rn/use-callback {:test-ID "soundtrack"
(fn [seek-time] :style (merge
(set-seeking-audio false) (style/player-slider-container)
(audio/seek-player (or style {}))
player-ref :minimum-value 0
seek-time :maximum-value audio-duration-ms
#(log/debug "[record-audio] on seek - seek time: " seek-time) :value @audio-current-time-ms
#(log/error "[record-audio] on seek - error: " %))) :on-sliding-start #(reset! seeking-audio? true)
[player-ref]) :on-sliding-complete (fn [seek-time]
on-value-change (rn/use-callback #(when seeking-audio? (set-audio-current-time-ms %)) (reset! seeking-audio? false)
[seeking-audio?])] (audio/seek-player
[slider/slider player-ref
{:test-ID "soundtrack" seek-time
:style (merge (style/player-slider-container) style) #(log/debug "[record-audio] on seek - seek time: " seek-time)
:minimum-value 0 #(log/error "[record-audio] on seek - error: " %)))
:maximum-value audio-duration-ms :on-value-change #(when @seeking-audio?
:value audio-current-time-ms (reset! audio-current-time-ms %))
:on-sliding-start on-sliding-start :thumb-image (quo.theme/theme-value thumb-light thumb-dark theme)
:on-sliding-complete on-sliding-complete :minimum-track-tint-color (colors/theme-colors colors/primary-50 colors/primary-60 theme)
:on-value-change on-value-change :maximum-track-tint-color (colors/theme-colors
:thumb-image (quo.theme/theme-value thumb-light thumb-dark theme) (if platform/ios? colors/neutral-20 colors/neutral-40)
:minimum-track-tint-color (colors/theme-colors colors/primary-50 colors/primary-60 theme) (if platform/ios? colors/neutral-80 colors/neutral-60)
:maximum-track-tint-color (colors/theme-colors theme)}]]))
(if platform/ios? colors/neutral-20 colors/neutral-40)
(if platform/ios? colors/neutral-80 colors/neutral-60)
theme)}]))
@@ -7,23 +7,17 @@
[quo.foundations.colors :as colors] [quo.foundations.colors :as colors]
[quo.theme :as quo.theme] [quo.theme :as quo.theme]
[react-native.core :as rn] [react-native.core :as rn]
[react-native.draggable-flatlist :as draggable-flatlist])) [react-native.draggable-flatlist :as draggable-flatlist]
[reagent.core :as reagent]))
(defn key-fn [item index] (str (:title item) index)) (defn on-drag-end-fn
[data atom-data]
(reset! atom-data data)
(reagent/flush))
(defn reorder-category (defn- reorder-category-internal
[{:keys [label data blur? container-style]}] [{:keys [label data blur? theme container-style]}]
(let [theme (quo.theme/use-theme-value) (reagent/with-let [atom-data (reagent/atom data)]
[atom-data set-atom-data] (rn/use-state data)
render-fn (rn/use-callback
(fn [item _ _ _ _ drag]
[reorder-item/reorder-item item types/item
{:blur? blur? :drag drag}])
[blur?])
on-drag-end-fn (rn/use-callback (fn [_ _ data] (set-atom-data data)))
separator (rn/use-memo (fn [] [rn/view
{:style (style/reorder-separator blur? theme)}])
[blur? theme])]
[rn/view {:style (merge (style/container label) container-style)} [rn/view {:style (merge (style/container label) container-style)}
[text/text [text/text
{:weight :medium {:weight :medium
@@ -31,9 +25,14 @@
:style {:color (colors/theme-colors colors/neutral-50 colors/neutral-40 theme)}} :style {:color (colors/theme-colors colors/neutral-50 colors/neutral-40 theme)}}
label] label]
[draggable-flatlist/draggable-flatlist [draggable-flatlist/draggable-flatlist
{:data atom-data {:data @atom-data
:key-fn key-fn :key-fn (fn [item index] (str (:title item) index))
:style style/reorder-items :style style/reorder-items
:render-fn render-fn :render-fn (fn [item _ _ _ _ drag] [reorder-item/reorder-item item types/item
:on-drag-end-fn on-drag-end-fn {:blur? blur? :drag drag}])
:separator separator}]])) :on-drag-end-fn (fn [_ _ data]
(on-drag-end-fn data atom-data))
:separator [rn/view
{:style (style/reorder-separator blur? theme)}]}]]))
(def reorder-category (quo.theme/with-theme reorder-category-internal))
@@ -23,7 +23,7 @@
(def ?profile (def ?profile
[:map [:map
[:type [:= :profile]] [:type [:= :profile]]
[:profile-picture [:maybe :schema.quo/profile-picture-source]]]) [:profile-picture :schema.common/image-source]])
(def ?wallet (def ?wallet
[:map [:map
@@ -16,6 +16,7 @@
[quo.foundations.colors :as colors] [quo.foundations.colors :as colors]
[quo.theme] [quo.theme]
[react-native.core :as rn] [react-native.core :as rn]
[reagent.core :as reagent]
[schema.core :as schema] [schema.core :as schema]
[utils.i18n :as i18n])) [utils.i18n :as i18n]))
@@ -149,7 +150,8 @@
profile-picture emoji on-share-press address] profile-picture emoji on-share-press address]
:as props}] :as props}]
[:<> [:<>
[gradient-cover/view {:customization-color customization-color :height 463}] [rn/view {:style style/gradient-bg}
[gradient-cover/view {:customization-color customization-color :height 463}]]
[rn/view {:style style/content-container} [rn/view {:style style/content-container}
[rn/view {:style style/share-qr-container} [rn/view {:style style/share-qr-container}
[rn/view {:style style/share-qr-inner-container} [rn/view {:style style/share-qr-inner-container}
@@ -189,20 +191,20 @@
(defn- view-internal (defn- view-internal
[props] [props]
(let [[component-width (reagent/with-let [component-width (reagent/atom nil)
set-component-width] (rn/use-state nil) container-component [rn/view {:background-color style/overlay-color}]]
on-layout (rn/use-callback #(set-component-width
(oops/oget % "nativeEvent.layout.width")))
props (-> props
(assoc :component-width component-width)
(clojure.set/rename-keys {:type :share-qr-type}))]
[quo.theme/provider {:theme :dark} [quo.theme/provider {:theme :dark}
[rn/view [rn/view
{:accessibility-label :share-qr-code {:accessibility-label :share-qr-code
:style style/outer-container :style style/outer-container
:on-layout on-layout} :on-layout #(reset! component-width (oops/oget % "nativeEvent.layout.width"))}
[rn/view {:style {:background-color style/overlay-color}} (conj container-component
(when component-width (when @component-width
[share-qr-code props])]]])) [share-qr-code
(-> props
(assoc :component-width @component-width)
(clojure.set/rename-keys {:type :share-qr-type}))]))]]))
(def view (schema/instrument #'view-internal component-schema/?schema)) (def view
(quo.theme/with-theme
(schema/instrument #'view-internal component-schema/?schema)))
+40 -39
View File
@@ -3,7 +3,8 @@
[quo.components.tabs.tab.view :as tab] [quo.components.tabs.tab.view :as tab]
[quo.foundations.colors :as colors] [quo.foundations.colors :as colors]
[quo.theme :as quo.theme] [quo.theme :as quo.theme]
[react-native.core :as rn])) [react-native.core :as rn]
[reagent.core :as reagent]))
(def themes-for-blur (def themes-for-blur
{:light {:background-color colors/neutral-80-opa-5} {:light {:background-color colors/neutral-80-opa-5}
@@ -13,41 +14,41 @@
{:light {:background-color colors/neutral-10} {:light {:background-color colors/neutral-10}
:dark {:background-color colors/neutral-90}}) :dark {:background-color colors/neutral-90}})
(defn segmented-control (defn- segmented-control-internal
[{:keys [data size blur? container-style item-container-style [{:keys [default-active on-change]}]
active-item-container-style default-active on-change]}] (let [active-tab-id (reagent/atom default-active)]
(let [theme (quo.theme/use-theme-value) (fn [{:keys [data size theme blur? container-style item-container-style
[active-tab-id active-item-container-style]}]
set-active-tab-id] (rn/use-state default-active) (let [active-id @active-tab-id]
on-press (rn/use-callback [rn/view
(fn [tab-id] (merge
(set-active-tab-id tab-id) {:flex-direction :row
(when on-change (on-change tab-id))) :background-color (get-in (if blur? themes-for-blur themes)
[on-change])] [theme :background-color])
[rn/view :border-radius (case size
(merge 32 10
{:flex-direction :row 28 10
:background-color (get-in (if blur? themes-for-blur themes) 24 8
[theme :background-color]) 20 6)
:border-radius (case size :padding 2}
32 10 container-style)
28 10 (for [[indx {:keys [label id]}] (map-indexed vector data)]
24 8 ^{:key id}
20 6) [rn/view
:padding 2} {:margin-left (if (= 0 indx) 0 2)
container-style) :flex 1}
(for [[indx {:keys [label id]}] (map-indexed vector data)] [tab/view
^{:key id} {:id id
[rn/view :active-item-container-style active-item-container-style
{:margin-left (if (= 0 indx) 0 2) :item-container-style item-container-style
:flex 1} :segmented? true
[tab/view :size size
{:id id :blur? blur?
:active-item-container-style active-item-container-style :active (= id active-id)
:item-container-style item-container-style :on-press (fn [tab-id]
:segmented? true (reset! active-tab-id tab-id)
:size size (when on-change
:blur? blur? (on-change tab-id)))}
:active (= id active-tab-id) label]])]))))
:on-press on-press}
label]])])) (def segmented-control (quo.theme/with-theme segmented-control-internal))
+92 -84
View File
@@ -41,7 +41,7 @@
(into [:<>] children))) (into [:<>] children)))
(defn- on-scroll-handler (defn- on-scroll-handler
[{:keys [on-scroll fading set-fading fade-end-percentage fade-end?]} ^js e] [{:keys [on-scroll fading fade-end-percentage fade-end?]} ^js e]
(when fade-end? (when fade-end?
(let [offset-x (oget e "nativeEvent.contentOffset.x") (let [offset-x (oget e "nativeEvent.contentOffset.x")
content-width (oget e "nativeEvent.contentSize.width") content-width (oget e "nativeEvent.contentSize.width")
@@ -52,8 +52,11 @@
:layout-width layout-width :layout-width layout-width
:max-fade-percentage fade-end-percentage})] :max-fade-percentage fade-end-percentage})]
;; Avoid unnecessary re-rendering. ;; Avoid unnecessary re-rendering.
(when (not= new-percentage (get fading :fade-end-percentage)) (when (not= new-percentage
(set-fading (assoc fading :fade-end-percentage new-percentage))))) (get @fading :fade-end-percentage))
(swap! fading assoc
:fade-end-percentage
new-percentage))))
(when on-scroll (when on-scroll
(on-scroll e))) (on-scroll e)))
@@ -61,7 +64,6 @@
[{:keys [id label notification-dot? accessibility-label]} [{:keys [id label notification-dot? accessibility-label]}
index _ index _
{:keys [active-tab-id {:keys [active-tab-id
set-active-tab-id
blur? blur?
customization-color customization-color
flat-list-ref flat-list-ref
@@ -83,9 +85,9 @@
:accessibility-label accessibility-label :accessibility-label accessibility-label
:size size :size size
:blur? blur? :blur? blur?
:active (= id active-tab-id) :active (= id @active-tab-id)
:on-press (fn [id] :on-press (fn [id]
(set-active-tab-id id) (reset! active-tab-id id)
(when (and scroll-on-press? @flat-list-ref) (when (and scroll-on-press? @flat-list-ref)
(.scrollToIndex ^js @flat-list-ref (.scrollToIndex ^js @flat-list-ref
#js #js
@@ -116,81 +118,87 @@
- `scroll-on-press?` When non-nil, clicking on a tag centers it the middle - `scroll-on-press?` When non-nil, clicking on a tag centers it the middle
(with animation enabled). (with animation enabled).
" "
[{:keys [default-active data fade-end-percentage fade-end? on-change on-scroll scroll-on-press? [{:keys [default-active fade-end-percentage]
scrollable? style container-style size blur? in-scroll-view? customization-color] :or {fade-end-percentage 0.8}}]
:or {fade-end-percentage 0.8 (let [active-tab-id (reagent/atom default-active)
fade-end? false fading (reagent/atom {:fade-end-percentage fade-end-percentage})
scrollable? false flat-list-ref (atom nil)]
scroll-on-press? false (fn
size default-tab-size} [{:keys [data
:as props}] fade-end-percentage
(let [[active-tab-id fade-end?
set-active-tab-id] (rn/use-state default-active) on-change
[fading set-fading] (rn/use-state {:fade-end-percentage fade-end-percentage}) on-scroll
flat-list-ref (rn/use-ref-atom nil) scroll-on-press?
clean-props (dissoc props scrollable?
:default-active style
:fade-end-percentage container-style
:fade-end? size
:on-change blur?
:scroll-on-press? in-scroll-view?
:size) customization-color]
on-scroll (rn/use-callback :or {fade-end-percentage fade-end-percentage
(partial on-scroll-handler fade-end? false
{:fade-end-percentage fade-end-percentage scrollable? false
:fade-end? fade-end? scroll-on-press? false
:fading fading size default-tab-size}
:set-fading set-fading :as props}]
:on-scroll on-scroll}) (if scrollable?
[fade-end? fading])] [rn/view {:style {:margin-top (- (dec unread-count-offset))}}
(if scrollable? [masked-view-wrapper
[rn/view {:style {:margin-top (- (dec unread-count-offset))}} {:fade-end-percentage (get @fading :fade-end-percentage) :fade-end? fade-end?}
[masked-view-wrapper [(if in-scroll-view?
{:fade-end-percentage (get fading :fade-end-percentage) :fade-end? fade-end?} gesture/flat-list
[(if in-scroll-view? rn/flat-list)
gesture/flat-list (merge
rn/flat-list) (dissoc props
(merge :default-active
clean-props :fade-end-percentage
(when scroll-on-press? :fade-end?
{:initial-scroll-index (utils.collection/first-index #(= active-tab-id (:id %)) data)}) :on-change
{:ref #(reset! flat-list-ref %) :scroll-on-press?
:style style :size)
;; The padding-top workaround is needed because on Android (when scroll-on-press?
;; {:overflow :visible} doesn't work on components inheriting {:initial-scroll-index (utils.collection/first-index #(= @active-tab-id (:id %)) data)})
;; from ScrollView (e.g. FlatList). There are open issues, here's {:ref #(reset! flat-list-ref %)
;; just one about this topic: :style style
;; https://github.com/facebook/react-native/issues/31218 ;; The padding-top workaround is needed because on Android
:content-container-style ;; {:overflow :visible} doesn't work on components inheriting
(assoc container-style :padding-top (dec unread-count-offset)) ;; from ScrollView (e.g. FlatList). There are open issues, here's
:horizontal true ;; just one about this topic:
:scroll-event-throttle 64 ;; https://github.com/facebook/react-native/issues/31218
:shows-horizontal-scroll-indicator false :content-container-style
:data data (assoc container-style :padding-top (dec unread-count-offset))
:key-fn (comp str :id) :horizontal true
:on-scroll-to-index-failed identity :scroll-event-throttle 64
:on-scroll on-scroll :shows-horizontal-scroll-indicator false
:render-fn tab-view :data data
:render-data {:active-tab-id active-tab-id :key-fn (comp str :id)
:set-active-tab-id set-active-tab-id :on-scroll-to-index-failed identity
:blur? blur? :on-scroll (partial on-scroll-handler
:customization-color customization-color {:fade-end-percentage fade-end-percentage
:flat-list-ref flat-list-ref :fade-end? fade-end?
:number-of-items (count data) :fading fading
:on-change on-change :on-scroll on-scroll})
:scroll-on-press? scroll-on-press? :render-fn tab-view
:size size :render-data {:active-tab-id active-tab-id
:style style}})]]] :blur? blur?
[rn/view (merge style {:flex-direction :row}) :customization-color customization-color
(map-indexed (fn [index item] :flat-list-ref flat-list-ref
^{:key (:id item)} :number-of-items (count data)
[tab-view item index nil :on-change on-change
{:active-tab-id active-tab-id :scroll-on-press? scroll-on-press?
:set-active-tab-id set-active-tab-id :size size
:blur? blur? :style style}})]]]
:customization-color customization-color [rn/view (merge style {:flex-direction :row})
:number-of-items (count data) (map-indexed (fn [index item]
:on-change on-change ^{:key (:id item)}
:size size [tab-view item index nil
:style style}]) {:active-tab-id active-tab-id
data)]))) :blur? blur?
:customization-color customization-color
:number-of-items (count data)
:on-change on-change
:size size
:style style}])
data)]))))
+1 -1
View File
@@ -357,7 +357,7 @@
;;;; Record Audio ;;;; Record Audio
(def record-audio quo.components.record-audio.record-audio.view/record-audio) (def record-audio quo.components.record-audio.record-audio.view/record-audio)
(def soundtrack quo.components.record-audio.soundtrack.view/soundtrack) (def soundtrack quo.components.record-audio.soundtrack.view/f-soundtrack)
;;;; Selectors ;;;; Selectors
(def disclaimer quo.components.selectors.disclaimer.view/view) (def disclaimer quo.components.selectors.disclaimer.view/view)
+8 -6
View File
@@ -38,8 +38,7 @@
(when on-meter (when on-meter
(.on ^js recorder "meter" on-meter)) (.on ^js recorder "meter" on-meter))
(when on-ended (when on-ended
(.on ^js recorder "ended" on-ended)) (.on ^js recorder "ended" on-ended))))
recorder))
(defn new-player (defn new-player
[audio options on-ended] [audio options on-ended]
@@ -47,8 +46,7 @@
audio audio
(clj->js options))] (clj->js options))]
(when on-ended (when on-ended
(.on ^js player "ended" on-ended)) (.on ^js player "ended" on-ended))))
player))
(defn prepare-player (defn prepare-player
[player on-prepared on-error] [player on-prepared on-error]
@@ -159,16 +157,20 @@
(on-error {:error (.-err err) :message (.-message err)}) (on-error {:error (.-err err) :message (.-message err)})
(on-seek)))))) (on-seek))))))
(defn can-play?
[player]
(and player (.-canPlay ^js player)))
(defn destroy-recorder (defn destroy-recorder
[recorder] [recorder]
(stop-recording recorder (stop-recording recorder
#(when (and recorder (.-destroy ^js recorder) (not= (get-state recorder) DESTROYED)) #(when (and recorder (not= (get-state recorder) DESTROYED))
(.destroy ^js recorder)) (.destroy ^js recorder))
#())) #()))
(defn destroy-player (defn destroy-player
[player] [player]
(stop-playing player (stop-playing player
#(when (and player (.-destroy ^js player) (not= (get-state player) IDLE)) #(when (and player (not= (get-state player) IDLE))
(.destroy ^js player)) (.destroy ^js player))
#())) #()))
+5 -5
View File
@@ -39,13 +39,13 @@
[message] [message]
(let [cause (if platform/android? (let [cause (if platform/android?
(condp = message (condp = message
android-not-enrolled-error-message :biometrics/not-enrolled-error android-not-enrolled-error-message ::not-enrolled
android-not-available-error-message :biometrics/not-available-error android-not-available-error-message ::not-available
:biometrics/unknown-error) ::unknown)
(condp #(string/includes? %2 %1) message (condp #(string/includes? %2 %1) message
ios-not-enrolled-error-message :biometrics/not-enrolled-error ios-not-enrolled-error-message ::not-enrolled
:biometrics/unknown-error))] ::unknown))]
(ex-info "Failed to authenticate with biometrics" (ex-info "Failed to authenticate with biometrics"
{:orig-error-message message} {:orig-error-message message}
cause))) cause)))
+4 -13
View File
@@ -25,15 +25,10 @@
(defn image (defn image
[{:keys [source] :as props}] [{:keys [source] :as props}]
(let [props (cond-> props [image-native
platform/ios? (if (string? source)
(dissoc :resize-method) (assoc props :source {:uri source})
(and (:style props) platform/ios?) props)])
(update :style dissoc :resize-method))]
[image-native
(if (string? source)
(assoc props :source {:uri source})
props)]))
(defn image-get-size (defn image-get-size
[uri] [uri]
@@ -224,7 +219,3 @@
(defn open-url [link] (.openURL ^js linking link)) (defn open-url [link] (.openURL ^js linking link))
(def set-status-bar-style react-native/StatusBar.setBarStyle) (def set-status-bar-style react-native/StatusBar.setBarStyle)
(defn sharing
[content]
(.share (.-Share ^js react-native) (clj->js content)))
+1 -4
View File
@@ -20,8 +20,7 @@
LinearTransition LinearTransition
enableLayoutAnimations enableLayoutAnimations
useAnimatedScrollHandler useAnimatedScrollHandler
runOnJS) runOnJS)]
:as reanimated*]
["react-native-redash" :refer (withPause)] ["react-native-redash" :refer (withPause)]
[react-native.flat-list :as rn-flat-list] [react-native.flat-list :as rn-flat-list]
[react-native.utils :as rn.utils] [react-native.utils :as rn.utils]
@@ -108,8 +107,6 @@
(when (and anim (some? v)) (when (and anim (some? v))
(set! (.-value anim) v))) (set! (.-value anim) v)))
(def interpolate* reanimated*/interpolate)
(defn interpolate (defn interpolate
([shared-value input-range output-range] ([shared-value input-range output-range]
(interpolate shared-value input-range output-range nil)) (interpolate shared-value input-range output-range nil))
+1 -6
View File
@@ -29,15 +29,10 @@
[:on-success [:or fn? [:cat keyword? [:* :any]]]] [:on-success [:or fn? [:cat keyword? [:* :any]]]]
[:on-error [:or fn? [:cat keyword? [:* :any]]]]]]) [:on-error [:or fn? [:cat keyword? [:* :any]]]]]])
(def ^:private ?exception
[:fn {:error/message "schema.common/exception should be of type ExceptionInfo"}
(fn [v] (instance? ExceptionInfo v))])
(defn register-schemas (defn register-schemas
[] []
(registry/register ::theme ?theme) (registry/register ::theme ?theme)
(registry/register ::customization-color ?customization-color) (registry/register ::customization-color ?customization-color)
(registry/register ::public-key ?public-key) (registry/register ::public-key ?public-key)
(registry/register ::image-source ?image-source) (registry/register ::image-source ?image-source)
(registry/register ::rpc-call ?rpc-call) (registry/register ::rpc-call ?rpc-call))
(registry/register ::exception ?exception))
@@ -1,27 +0,0 @@
(ns status-im.common.alert-banner.events
(:require [re-frame.core :as re-frame]))
(defn add-alert-banner
[{:keys [db]} [banner]]
(let [current-banners-count (count (get db :alert-banners))
db (assoc-in db [:alert-banners (:type banner)] banner)]
(cond-> {:db db}
(zero? current-banners-count)
(assoc :show-alert-banner nil))))
(defn remove-alert-banner
[{:keys [db]} [banner-type]]
(let [db (update-in db [:alert-banners] dissoc banner-type)
new-count (count (get db :alert-banners))]
(cond-> {:db db}
(zero? new-count)
(assoc :hide-alert-banner nil))))
(defn remove-all-alert-banners
[{:keys [db]}]
{:db (dissoc db :alert-banners)
:hide-alert-banner nil})
(re-frame/reg-event-fx :alert-banners/add add-alert-banner)
(re-frame/reg-event-fx :alert-banners/remove remove-alert-banner)
(re-frame/reg-event-fx :alert-banners/remove-all remove-all-alert-banners)
@@ -1,42 +0,0 @@
(ns status-im.common.alert-banner.events-test
(:require
[cljs.test :refer [deftest is testing]]
matcher-combinators.test
[status-im.common.alert-banner.events :as events]))
(deftest add-alert-banner
(testing "Alert banner is added"
(is (match? {:db {:alert-banners
{:alert {:text "Alert"
:type :alert}}}
:show-alert-banner nil}
(events/add-alert-banner {:db {}}
[{:text "Alert"
:type :alert}])))))
(deftest remove-alert-banner
(testing "Alert banner is removed"
(is (match? {:db {}
:hide-alert-banner nil}
(events/remove-alert-banner {:db {:alert-banners
{:alert {:text "Alert"
:type :alert}}}}
[:alert]))))
(testing "Alert banner is not removed"
(is (match? {:db {:alert-banners
{:alert {:text "Alert"
:type :alert}}}}
(events/remove-alert-banner {:db {:alert-banners
{:alert {:text "Alert"
:type :alert}}}}
[:error])))))
(deftest remove-all-alert-banners
(testing "All Alert banners are removed"
(is (match? {:db {}
:hide-alert-banner nil}
(events/remove-all-alert-banners {:db {:alert-banners
{:alert {:text "Alert"
:type :alert}
:error {:text "Error"
:type :error}}}})))))
@@ -1,20 +0,0 @@
(ns status-im.common.alert-banner.style)
(def border-radius 20)
(defn container
[background-color]
{:background-color background-color})
(def second-banner-wrapper
{:margin-top (- border-radius)
:overflow :hidden
:border-top-left-radius border-radius
:border-top-right-radius border-radius})
(defn hole-view
[background-color]
{:padding-top 11
:align-items :center
:height 60
:background-color background-color})
@@ -1,68 +0,0 @@
(ns status-im.common.alert-banner.view
(:require [quo.core :as quo]
[quo.foundations.colors :as colors]
quo.theme
[react-native.core :as rn]
[react-native.hole-view :as hole-view]
[react-native.safe-area :as safe-area]
[status-im.common.alert-banner.style :as style]
[status-im.constants :as constants]
[utils.re-frame :as rf]))
(defn get-colors-map
[theme]
{:alert
{:background-color (colors/resolve-color :warning theme 20)
:text-color (colors/resolve-color :warning theme)}
:error
{:background-color (colors/resolve-color :danger theme 20)
:text-color (colors/resolve-color :danger theme)}})
(defn- banner
[{:keys [text type second-banner? colors-map]}]
[rn/view (when second-banner? {:style style/second-banner-wrapper})
[hole-view/hole-view
{:style (style/hole-view (get-in colors-map [type :background-color]))
:holes (if second-banner?
[]
[{:x 0
:y constants/alert-banner-height
:width (:width (rn/get-window))
:height constants/alert-banner-height
:borderRadius style/border-radius}])}
[quo/text
{:size :paragraph-2
:weight :medium
:style {:color (get-in colors-map [type :text-color])}}
text]]])
(defn view
[]
(let [banners (rf/sub [:alert-banners])
theme (quo.theme/use-theme-value)
banners-count (count banners)
alert-banner (:alert banners)
error-banner (:error banners)
safe-area-top (safe-area/get-top)
colors-map (get-colors-map theme)]
[hole-view/hole-view
{:style {:background-color colors/neutral-100}
:holes [{:x 0
:y (+ safe-area-top (* constants/alert-banner-height banners-count))
:width (:width (rn/get-window))
:height constants/alert-banner-height
:borderRadius style/border-radius}]}
[rn/view
{:style {:height safe-area-top
:background-color (get-in colors-map
[(if error-banner :error :alert) :background-color])}}]
(when error-banner
[banner
(assoc error-banner
:colors-map colors-map
:second-banner? false)])
(when alert-banner
[banner
(assoc alert-banner
:colors-map colors-map
:second-banner? (= 2 banners-count))])]))
@@ -1,72 +0,0 @@
(ns status-im.common.biometric.effects
(:require
[react-native.biometrics :as biometrics]
[status-im.common.biometric.utils :as utils]
[status-im.common.keychain.events :as keychain]
[status-im.constants :as constant]
[taoensso.timbre :as log]
[utils.i18n :as i18n]
[utils.re-frame :as rf]))
(rf/reg-fx
:effects.biometric/get-supported-type
(fn []
;;NOTE: if we can't save user password, we can't use biometric
(keychain/can-save-user-password?
(fn [can-save?]
(when (and can-save? (not utils/android-device-blacklisted?))
(-> (biometrics/get-supported-type)
(.then (fn [type]
(rf/dispatch [:biometric/set-supported-type type])))))))))
(rf/reg-fx
:effects.biometric/authenticate
(fn [{:keys [prompt-message on-success on-fail on-cancel on-done]
:or {on-done identity
on-success identity
on-cancel identity
on-fail identity}}]
(-> (biometrics/authenticate
{:prompt-message (or prompt-message (i18n/label :t/biometric-auth-reason-login))
:fallback-prompt-message (i18n/label
:t/biometric-auth-login-ios-fallback-label)
:cancel-button-text (i18n/label :t/cancel)})
(.then (fn [success?]
(on-done)
(if success?
(on-success)
(on-cancel))))
(.catch (fn [err]
(on-done)
(on-fail err))))))
(rf/reg-fx
:effects.biometric/check-if-available
(fn [{:keys [key-uid on-success on-fail]
:or {on-success identity
on-fail identity}}]
(keychain/can-save-user-password?
(fn [can-save?]
(if-not can-save?
(on-fail (ex-info "cannot-save-user-password"
{:effect :effects.biometric/check-if-available}))
(-> (biometrics/get-available)
(.then (fn [available?]
(when-not available?
(throw (js/Error. "biometric-not-available")))))
(.then #(keychain/get-auth-method! key-uid))
(.then (fn [auth-method]
(if (= auth-method constant/auth-method-biometric)
(on-success auth-method)
(throw (js/Error. "biometric-not-enabled")))))
(.catch (fn [err]
(let [message (.-message err)]
(on-fail (ex-info message
{:err err
:effect :effects.biometric/check-if-available}))
(when-not (or (= message "biometric-not-available")
(= message "biometric-not-enabled"))
(log/error "Failed to check if biometrics is available"
{:error err
:key-uid key-uid
:effect :effects.biometric/check-biometric})))))))))))
+102 -44
View File
@@ -1,62 +1,120 @@
(ns status-im.common.biometric.events (ns status-im.common.biometric.events
(:require (:require
status-im.common.biometric.effects [native-module.core :as native-module]
[re-frame.core :as re-frame]
[react-native.biometrics :as biometrics]
[react-native.platform :as platform]
[status-im.common.keychain.events :as keychain]
[status-im.constants :as constants] [status-im.constants :as constants]
[taoensso.timbre :as log]
[utils.i18n :as i18n] [utils.i18n :as i18n]
[utils.re-frame :as rf])) [utils.re-frame :as rf]))
(defn set-supported-type (def android-device-blacklisted?
[{:keys [db]} [supported-type]] (and platform/android? (= (:brand (native-module/get-device-model-info)) "bannedbrand")))
{:db (assoc-in db [:biometrics :supported-type] supported-type)})
(rf/reg-event-fx :biometric/set-supported-type set-supported-type) (defn get-label-by-type
[biometric-type]
(condp = biometric-type
constants/biometrics-type-android (i18n/label :t/biometric-fingerprint)
constants/biometrics-type-face-id (i18n/label :t/biometric-faceid)
(i18n/label :t/biometric-touchid)))
(defn show-message (defn get-icon-by-type
[_ [code]] [biometric-type]
(let [content (if (#{:biometrics/not-enrolled-error (condp = biometric-type
:biometrics/not-available-error} constants/biometrics-type-face-id :i/face-id
:i/touch-id))
(re-frame/reg-fx
:biometric/get-supported-biometric-type
(fn []
;;NOTE: if we can't save user password, we can't use biometric
(keychain/can-save-user-password?
(fn [can-save?]
(when (and can-save? (not android-device-blacklisted?))
(-> (biometrics/get-supported-type)
(.then (fn [type]
(rf/dispatch [:biometric/get-supported-biometric-type-success type])))))))))
(rf/defn get-supported-biometric-auth-success
{:events [:biometric/get-supported-biometric-type-success]}
[{:keys [db]} supported-type]
{:db (assoc db :biometric/supported-type supported-type)})
(rf/defn show-message
{:events [:biometric/show-message]}
[_ error]
(let [code (ex-cause error)
content (if (#{::biometrics/not-enrolled
::biometrics/not-available}
code) code)
(i18n/label :t/grant-face-id-permissions) (i18n/label :t/grant-face-id-permissions)
(i18n/label :t/biometric-auth-error {:code code}))] (i18n/label :t/biometric-auth-error {:code code}))]
{:fx [[:effects.utils/show-popup {:effects.utils/show-popup
{:title (i18n/label :t/biometric-auth-login-error-title) {:title (i18n/label :t/biometric-auth-login-error-title)
:content content}]]})) :content content}}))
(rf/reg-event-fx :biometric/show-message show-message)
(defn on-authentication-done (re-frame/reg-fx
[{:keys [db]}] :biometric/authenticate
{:db (assoc-in db [:biometrics :auth-pending?] false)}) (fn [{:keys [on-success on-fail prompt-message]}]
(-> (biometrics/authenticate
{:prompt-message (or prompt-message (i18n/label :t/biometric-auth-reason-login))
:fallback-prompt-message (i18n/label
:t/biometric-auth-login-ios-fallback-label)
:cancel-button-text (i18n/label :t/cancel)})
(.then (fn [not-canceled?]
(when (and on-success not-canceled?)
(on-success))))
(.catch (fn [err]
(when on-fail
(on-fail err)))))))
(rf/reg-event-fx :biometric/on-authentication-done on-authentication-done) (rf/defn authenticate
{:events [:biometric/authenticate]}
[_ opts]
{:biometric/authenticate opts})
(defn authenticate (rf/reg-event-fx
[{:keys [db]} [opts]] :biometric/on-enable-success
(let [pending? (get-in db [:biometrics :auth-pending?])] (fn [{:keys [db]} [password]]
;;NOTE: prompting biometric check while another one is pending triggers error (let [key-uid (get-in db [:profile/profile :key-uid])]
(when-not pending? {:db (assoc db :auth-method constants/auth-method-biometric)
{:db (assoc-in db [:biometrics :auth-pending?] true) :dispatch [:keychain/save-password-and-auth-method
:fx [[:effects.biometric/authenticate {:key-uid key-uid
(assoc opts :on-done #(rf/dispatch [:biometric/on-authentication-done]))]]}))) :masked-password password}]})))
(rf/reg-event-fx :biometric/authenticate authenticate) (rf/reg-event-fx
:biometric/enable
(fn [_ [password]]
{:dispatch [:biometric/authenticate
{:on-success #(rf/dispatch [:biometric/on-enable-success password])
:on-fail #(rf/dispatch [:biometric/show-message %])}]}))
(defn enable-biometrics (rf/reg-event-fx
[{:keys [db]} [password]] :biometric/disable
(let [key-uid (get-in db [:profile/profile :key-uid])] (fn [{:keys [db]}]
{:db (assoc db :auth-method constants/auth-method-biometric) (let [key-uid (get-in db [:profile/profile :key-uid])]
:fx [[:dispatch {:db (assoc db :auth-method constants/auth-method-none)
[:keychain/save-password-and-auth-method :keychain/clear-user-password key-uid})))
{:key-uid key-uid
:masked-password password}]]]}))
(rf/reg-event-fx :biometric/enable enable-biometrics)
(defn disable-biometrics
[{:keys [db]}]
(let [key-uid (get-in db [:profile/profile :key-uid])]
{:db (assoc db :auth-method constants/auth-method-none)
:fx [[:keychain/clear-user-password key-uid]]}))
(rf/reg-event-fx :biometric/disable disable-biometrics)
(rf/reg-fx
:biometric/check-if-available
(fn [[key-uid callback]]
(keychain/can-save-user-password?
(fn [can-save?]
(when can-save?
(-> (biometrics/get-available)
(.then (fn [available?]
(when-not available?
(throw (js/Error. "biometric-not-available")))))
(.then #(keychain/get-auth-method! key-uid))
(.then (fn [auth-method]
(when auth-method (callback auth-method))))
(.catch (fn [err]
(when-not (= (.-message err) "biometric-not-available")
(log/error "Failed to check if biometrics is available"
{:error err
:key-uid key-uid
:event :profile.login/check-biometric}))))))))))
@@ -1,68 +0,0 @@
(ns status-im.common.biometric.events-test
(:require [cljs.test :refer [deftest is testing]]
matcher-combinators.test
[status-im.common.biometric.events :as sut]
[status-im.constants :as constants]
[utils.i18n :as i18n]
[utils.security.core :as security]))
(deftest set-supported-biometrics-type-test
(testing "successfully setting supported biometrics type"
(let [cofx {:db {}}
supported-type constants/biometrics-type-face-id
expected {:db (assoc-in (:db cofx) [:biometrics :supported-type] supported-type)}]
(is (match? expected (sut/set-supported-type cofx [supported-type]))))))
(deftest show-message-test
(testing "informs the user to enable biometrics from settings"
(let [cofx {:db {}}
expected {:fx [[:effects.utils/show-popup
{:title (i18n/label :t/biometric-auth-login-error-title)
:content (i18n/label :t/grant-face-id-permissions)}]]}]
(is (match? expected
(sut/show-message cofx
[:biometrics/not-available-error])))))
(testing "shows a generic error message"
(let [cofx {:db {}}
error-cause :test-error
expected {:fx [[:effects.utils/show-popup
{:title (i18n/label :t/biometric-auth-login-error-title)
:content (i18n/label :t/biometric-auth-error {:code error-cause})}]]}]
(is (match? expected
(sut/show-message cofx
[error-cause]))))))
(deftest authenticate-biometrics-test
(testing "passing the right args to authenticate"
(let [cofx {:db {}}
args {:on-success identity
:on-fail identity
:prompt-message "test"}
result (sut/authenticate cofx [args])]
(is (= (:prompt-message args) (get-in result [:fx 0 1 :prompt-message])))
(is (not (nil? (get-in result [:fx 0 1 :on-success]))))
(is (not (nil? (get-in result [:fx 0 1 :on-fail]))))))
(testing "skips biometric check if another one pending"
(let [cofx {:db {:biometrics {:auth-pending? true}}}
result (sut/authenticate cofx [{}])]
(is (nil? result)))))
(deftest enable-biometrics-test
(testing "successfully enabling biometrics"
(let [key-uid "test-uid"
password (security/mask-data "test-pw")
cofx {:db {:profile/profile {:key-uid key-uid}}}
expected-db (assoc (:db cofx) :auth-method constants/auth-method-biometric)
result (sut/enable-biometrics cofx [password])]
(is (match? expected-db (:db result)))
(is (= password (get-in result [:fx 0 1 1 :masked-password]))))))
(deftest disable-biometrics-test
(testing "successfully disabling biometrics"
(let [key-uid "test-uid"
cofx {:db {:profile/profile {:key-uid key-uid}}}
expected {:db (assoc (:db cofx) :auth-method constants/auth-method-none)
:fx [[:keychain/clear-user-password key-uid]]}]
(is (match? expected (sut/disable-biometrics cofx))))))
-22
View File
@@ -1,22 +0,0 @@
(ns status-im.common.biometric.utils
(:require
[native-module.core :as native-module]
[react-native.platform :as platform]
[status-im.constants :as constants]
[utils.i18n :as i18n]))
(def android-device-blacklisted?
(and platform/android? (= (:brand (native-module/get-device-model-info)) "bannedbrand")))
(defn get-label-by-type
[biometric-type]
(condp = biometric-type
constants/biometrics-type-android (i18n/label :t/biometric-fingerprint)
constants/biometrics-type-face-id (i18n/label :t/biometric-faceid)
(i18n/label :t/biometric-touchid)))
(defn get-icon-by-type
[biometric-type]
(condp = biometric-type
constants/biometrics-type-face-id :i/face-id
:i/touch-id))

Some files were not shown because too many files have changed in this diff Show More