This commit is contained in:
Volodymyr Kozieiev 2024-12-06 18:17:32 +00:00
parent 0f036ca9c4
commit 71186c8a8f
No known key found for this signature in database
GPG Key ID: 82B04968DF4C0535
17 changed files with 16 additions and 423 deletions

View File

@ -149,7 +149,6 @@ legacy.status-im.desktop.core/app-root
legacy.status-im.desktop.core/init legacy.status-im.desktop.core/init
legacy.status-im.chat.models-test/test-db legacy.status-im.chat.models-test/test-db
legacy.status-im.ui.components.spacing/padding-vertical legacy.status-im.ui.components.spacing/padding-vertical
legacy.status-im.utils.money/percent-change
utils.debounce/clear-all utils.debounce/clear-all
legacy.status-im.transport.db/create-chat legacy.status-im.transport.db/create-chat
legacy.status-im.utils.priority-map/priority-map legacy.status-im.utils.priority-map/priority-map

View File

@ -1,6 +1,4 @@
(ns legacy.status-im.react-native.resources (ns legacy.status-im.react-native.resources)
(:require
[legacy.status-im.ui.components.colors :as colors]))
(def ui (def ui
{:empty-chats-header (js/require "../resources/images/ui/empty-chats-header.png") {:empty-chats-header (js/require "../resources/images/ui/empty-chats-header.png")
@ -52,10 +50,6 @@
:no-contacts (js/require "../resources/images/ui/no-contacts.png") :no-contacts (js/require "../resources/images/ui/no-contacts.png")
:no-contacts-dark (js/require "../resources/images/ui/no-contacts-dark.png")}) :no-contacts-dark (js/require "../resources/images/ui/no-contacts-dark.png")})
(defn get-theme-image
[k]
(get ui (when (colors/dark?) (keyword (str (name k) "-dark"))) (get ui k)))
(def loaded-images (atom {})) (def loaded-images (atom {}))
(defn get-image (defn get-image

View File

@ -1,64 +1,6 @@
(ns legacy.status-im.subs.ens (ns legacy.status-im.subs.ens
(:require (:require
[clojure.string :as string] [re-frame.core :as re-frame]))
[legacy.status-im.ens.core :as ens]
[re-frame.core :as re-frame]
[utils.address :as address]
[utils.ethereum.chain :as chain]
[utils.money :as money]))
(re-frame/reg-sub
:ens/preferred-name
:<- [:profile/profile]
(fn [multiaccount]
(:preferred-name multiaccount)))
(re-frame/reg-sub
:ens/search-screen
:<- [:ens/registration]
(fn [{:keys [custom-domain? username state]}]
{:state state
:username username
:custom-domain? custom-domain?}))
(defn- ens-amount-label
[chain-id]
(str (ens/registration-cost chain-id)
(case chain-id
3 " STT"
1 " SNT"
"")))
(re-frame/reg-sub
:ens/checkout-screen
:<- [:ens/registration]
:<- [:chain-keyword]
:<- [:multiaccount/default-account]
:<- [:multiaccount/public-key]
:<- [:chain-id]
:<- [:wallet-legacy]
(fn [[{:keys [custom-domain? username address]}
chain default-account public-key chain-id wallet]]
(let [address (or address (address/normalized-hex (:address default-account)))
balance (get-in wallet [:accounts address :balance])]
{:address address
:username username
:public-key public-key
:custom-domain? custom-domain?
:chain chain
:amount-label (ens-amount-label chain-id)
:sufficient-funds? (money/sufficient-funds?
(money/formatted->internal (money/bignumber 10)
(chain/chain-keyword->snt-symbol chain)
18)
(get balance (chain/chain-keyword->snt-symbol chain)))})))
(re-frame/reg-sub
:ens/confirmation-screen
:<- [:ens/registration]
(fn [{:keys [username state]}]
{:state state
:username username}))
(re-frame/reg-sub (re-frame/reg-sub
:ens/current-names :ens/current-names
@ -66,37 +8,3 @@
:<- [:chain-id] :<- [:chain-id]
(fn [[all-names chain-id]] (fn [[all-names chain-id]]
(get all-names chain-id))) (get all-names chain-id)))
(re-frame/reg-sub
:ens.name/screen
:<- [:get-screen-params :ens-name-details]
:<- [:ens/current-names]
(fn [[name ens]]
(let [{:keys [address public-key expiration-date releasable?]} (get ens name)
pending? (nil? address)]
(cond-> {:name name
:custom-domain? (not (string/ends-with? name ".stateofus.eth"))}
pending?
(assoc :pending? true)
(not pending?)
(assoc :address address
:public-key public-key
:releasable? releasable?
:expiration-date expiration-date)))))
(re-frame/reg-sub
:ens.main/screen
:<- [:ens/current-names]
:<- [:profile/profile]
:<- [:ens/preferred-name]
:<- [:ens/registrations]
(fn [[names multiaccount preferred-name registrations]]
(let [not-in-progress-names (reduce (fn [acc {:keys [username custom-domain?]}]
(let [full-name (ens/fullname custom-domain? username)]
(remove #(= % full-name) acc)))
(keys names)
(vals registrations))]
{:names not-in-progress-names
:profile/profile multiaccount
:preferred-name preferred-name
:registrations registrations})))

View File

@ -1,7 +1,7 @@
(ns legacy.status-im.ui.components.action-sheet (ns legacy.status-im.ui.components.action-sheet
(:require (:require
["react-native" :refer (ActionSheetIOS)] ["react-native" :refer (ActionSheetIOS)]
[legacy.status-im.utils.core :as utils] [utils.collection :as utils]
[utils.i18n :as i18n])) [utils.i18n :as i18n]))
(defn- callback (defn- callback

View File

@ -1,57 +0,0 @@
(ns legacy.status-im.ui.screens.browser.eip3085.sheet
(:require
[legacy.status-im.ui.components.chat-icon.screen :as chat-icon.screen]
[legacy.status-im.ui.components.colors :as colors]
[legacy.status-im.ui.components.core :as quo]
[legacy.status-im.ui.components.icons.icons :as icons]
[legacy.status-im.ui.components.react :as react]
[legacy.status-im.ui.screens.browser.styles :as styles]
[re-frame.core :as re-frame]
[utils.i18n :as i18n])
(:require-macros [legacy.status-im.utils.views :as views]))
(views/defview permissions-panel
[_dapp-name message-id params]
(views/letsubs [{:keys [dapp? dapp]} [:get-current-browser]]
[react/view {}
[react/view styles/permissions-panel-icons-container
(if dapp?
[chat-icon.screen/dapp-icon-permission dapp 40]
[react/view styles/permissions-panel-dapp-icon-container
[icons/icon :main-icons/dapp {:color colors/gray}]])
[react/view {:margin-left 8 :margin-right 4}
[react/view styles/dot]]
[react/view {:margin-right 4}
[react/view styles/dot]]
[react/view {:margin-right 8}
[react/view styles/dot]]
[react/view styles/permissions-panel-ok-icon-container
[icons/icon :tiny-icons/tiny-check styles/permissions-panel-ok-ico]]
[react/view {:margin-left 8 :margin-right 4}
[react/view styles/dot]]
[react/view {:margin-right 4}
[react/view styles/dot]]
[react/view {:margin-right 8}
[react/view styles/dot]]
[react/view styles/permissions-panel-wallet-icon-container
[icons/icon :main-icons/wallet {:color colors/white}]]]
[react/view
{:style {:flex-direction :row
:justify-content :center
:margin-horizontal 8
:margin-top 24}}
[react/view
{:flex 1
:margin-horizontal 8}
[quo/button
{:theme :negative
:on-press #(re-frame/dispatch [:eip3085.ui/dapp-permission-denied message-id params])}
(i18n/label :t/deny)]]
[react/view
{:flex 1
:margin-horizontal 8}
[quo/button
{:theme :positive
:style {:margin-horizontal 8}
:on-press #(re-frame/dispatch [:eip3085.ui/dapp-permission-allowed message-id params])}
(i18n/label :t/allow)]]]]))

View File

@ -1,68 +0,0 @@
(ns legacy.status-im.ui.screens.browser.eip3326.sheet
(:require
[legacy.status-im.network.core :as network]
[legacy.status-im.ui.components.chat-icon.screen :as chat-icon.screen]
[legacy.status-im.ui.components.colors :as colors]
[legacy.status-im.ui.components.core :as quo]
[legacy.status-im.ui.components.icons.icons :as icons]
[legacy.status-im.ui.components.react :as react]
[legacy.status-im.ui.screens.browser.styles :as styles]
[re-frame.core :as re-frame]
[utils.debounce :as debounce]
[utils.i18n :as i18n])
(:require-macros [legacy.status-im.utils.views :as views]))
(views/defview permissions-panel
[dapp-name message-id {:keys [network-from network-to target-network-id] :as params}]
(views/letsubs [{:keys [dapp? dapp]} [:get-current-browser]]
[react/view {}
[react/view styles/permissions-panel-icons-container
(if dapp?
[chat-icon.screen/dapp-icon-permission dapp 40]
[react/view styles/permissions-panel-dapp-icon-container
[icons/icon :main-icons/dapp {:color colors/gray}]])
[react/view {:margin-left 8 :margin-right 4}
[react/view styles/dot]]
[react/view {:margin-right 4}
[react/view styles/dot]]
[react/view {:margin-right 8}
[react/view styles/dot]]
[react/view styles/permissions-panel-ok-icon-container
[icons/icon :tiny-icons/tiny-check styles/permissions-panel-ok-ico]]
[react/view {:margin-left 8 :margin-right 4}
[react/view styles/dot]]
[react/view {:margin-right 4}
[react/view styles/dot]]
[react/view {:margin-right 8}
[react/view styles/dot]]
[react/view styles/permissions-panel-wallet-icon-container
[icons/icon :main-icons/wallet {:color colors/white}]]]
[react/text {:style styles/permissions-panel-title-label :number-of-lines 2}
(str "\"" dapp-name "\" Allow this site to switch the network?")]
[react/text {:style styles/permissions-panel-description-label :number-of-lines 5}
(str "This will switch the selected network within Status to a previously added network:\n"
network-from
" -> "
network-to
"\nit will require login/logout")]
[react/view
{:style {:flex-direction :row
:justify-content :center
:margin-horizontal 8
:margin-top 24}}
[react/view
{:flex 1
:margin-horizontal 8}
[quo/button
{:theme :negative
:on-press #(re-frame/dispatch [:eip3326.ui/dapp-permission-denied message-id params])}
(i18n/label :t/deny)]]
[react/view
{:flex 1
:margin-horizontal 8}
[quo/button
{:theme :positive
:style {:margin-horizontal 8}
:on-press #(debounce/throttle-and-dispatch [::network/connect-network-pressed target-network-id]
1000)}
(i18n/label :t/allow)]]]]))

View File

@ -18,18 +18,3 @@
s)) s))
(def truncate-str (memoize truncate-str-memo)) (def truncate-str (memoize truncate-str-memo))
(defn first-index
"Returns first index in coll where predicate on coll element is truthy"
[pred coll]
(->> coll
(keep-indexed (fn [idx e]
(when (pred e)
idx)))
first))
(defn index-by
"Given a collection and a unique key function, returns a map that indexes the collection.
Similar to group-by except that the map values are single objects (depends on key uniqueness)."
[k coll]
(into {} (map #(vector (k %) %) coll)))

View File

@ -11,14 +11,6 @@
(is (= (u/truncate-str "Long string" 11) "Long string")) ; threshold is the same as string length (is (= (u/truncate-str "Long string" 11) "Long string")) ; threshold is the same as string length
(is (= (u/truncate-str "Long string" 20) "Long string"))) ; threshold is more then string length (is (= (u/truncate-str "Long string" 20) "Long string"))) ; threshold is more then string length
(deftest first-index-test
(is (= 2
(u/first-index (partial = :test)
'(:a :b :test :c :test))))
(is (= nil
(u/first-index (partial = :test)
'(:a :b :c)))))
(deftest format-decimals-test (deftest format-decimals-test
(is (= "1" (uu/format-decimals 1 5))) (is (= "1" (uu/format-decimals 1 5)))
(is (= "1.1" (uu/format-decimals 1.1 5))) (is (= "1.1" (uu/format-decimals 1.1 5)))

View File

@ -44,19 +44,3 @@
:background-color (if blur? :background-color (if blur?
:transparent :transparent
(colors/theme-colors colors/neutral-5 colors/neutral-95 theme))}) (colors/theme-colors colors/neutral-5 colors/neutral-95 theme))})
(defn blur-container
[]
{:position :absolute
:left 0
:right 0
:bottom 0
:top 0
:overflow :hidden})
(defn blur-view
[theme]
{:style {:flex 1}
:blur-radius 10
:blur-type theme
:blur-amount 20})

View File

@ -3,13 +3,6 @@
(def avatar {:width 88 :margin-top 12 :margin-left 20}) (def avatar {:width 88 :margin-top 12 :margin-left 20})
(def hole
{:y (- 80 32)
:x (+ (- 80 32) 8)
:width 32
:height 32
:borderRadius 10})
(def camera {:position :absolute :right 0 :bottom 0}) (def camera {:position :absolute :right 0 :bottom 0})
(defn color-label (defn color-label

View File

@ -28,35 +28,12 @@
(let [current-chat-id (:current-chat-id db)] (let [current-chat-id (:current-chat-id db)]
{:db (assoc-in db [:chat/inputs current-chat-id :input-ref] input-ref)})) {:db (assoc-in db [:chat/inputs current-chat-id :input-ref] input-ref)}))
(rf/defn set-input-content-height
{:events [:chat.ui/set-input-content-height]}
[{db :db} content-height chat-id]
(let [current-chat-id (or chat-id (:current-chat-id db))]
{:db (assoc-in db [:chat/inputs current-chat-id :input-content-height] content-height)}))
(rf/defn set-input-maximized
{:events [:chat.ui/set-input-maximized]}
[{db :db} maximized? chat-id]
(let [current-chat-id (or chat-id (:current-chat-id db))]
{:db (assoc-in db [:chat/inputs current-chat-id :input-maximized?] maximized?)}))
(rf/defn set-input-focused (rf/defn set-input-focused
{:events [:chat.ui/set-input-focused]} {:events [:chat.ui/set-input-focused]}
[{db :db} focused? chat-id] [{db :db} focused? chat-id]
(let [current-chat-id (or chat-id (:current-chat-id db))] (let [current-chat-id (or chat-id (:current-chat-id db))]
{:db (assoc-in db [:chat/inputs current-chat-id :focused?] focused?)})) {:db (assoc-in db [:chat/inputs current-chat-id :focused?] focused?)}))
(rf/defn set-input-audio
{:events [:chat.ui/set-input-audio]}
[{db :db} audio chat-id]
(let [current-chat-id (or chat-id (:current-chat-id db))]
{:db (assoc-in db [:chat/inputs current-chat-id :audio] audio)}))
(rf/defn set-recording
{:events [:chat.ui/set-recording]}
[{db :db} recording?]
{:db (assoc db :chats/recording? recording?)})
(rf/defn reply-to-message (rf/defn reply-to-message
"Sets reference to previous chat message and focuses on input" "Sets reference to previous chat message and focuses on input"
{:events [:chat.ui/reply-to-message]} {:events [:chat.ui/reply-to-message]}
@ -200,25 +177,6 @@
(link-preview/reset-unfurled) (link-preview/reset-unfurled)
(messages.transport/send-chat-messages messages))))) (messages.transport/send-chat-messages messages)))))
(rf/defn send-audio-message
{:events [:chat/send-audio]}
[{:keys [db] :as cofx} audio-path duration]
(let [{:keys [current-chat-id]} db
{:keys [message-id]}
(get-in db [:chat/inputs current-chat-id :metadata :responding-to-message])]
(when-not (string/blank? audio-path)
(rf/merge
{:db (assoc-in db [:chat/inputs current-chat-id :metadata :responding-to-message] nil)}
(messages.transport/send-chat-messages
[(merge
{:chat-id current-chat-id
:content-type constants/content-type-audio
:audio-path audio-path
:audio-duration-ms duration
:text (i18n/label :t/update-to-listen-audio {"locale" "en"})}
(when message-id
{:response-to message-id}))])))))
(defn- process-link-previews (defn- process-link-previews
[link-previews] [link-previews]
(->> link-previews (->> link-previews

View File

@ -14,18 +14,6 @@
:shadow-offset {:width 0 :height (colors/theme-colors 8 12 theme)}) :shadow-offset {:width 0 :height (colors/theme-colors 8 12 theme)})
(assoc styles :elevation 10))) (assoc styles :elevation 10)))
(defn inner
[top theme]
(add-shadow theme
{:position :absolute
:top (- (+ 8 top))
:left 8
:right 8
:border-radius 16
:z-index 4
:max-height constants/mentions-max-height
:background-color (colors/theme-colors colors/white colors/neutral-95 theme)}))
(defn container (defn container
[opacity top theme] [opacity top theme]
[{:opacity opacity} [{:opacity opacity}

View File

@ -20,13 +20,3 @@
:wallet/wallet-buy-crypto-provider :wallet/wallet-buy-crypto-provider
:<- [:wallet/wallet-buy-crypto] :<- [:wallet/wallet-buy-crypto]
:-> :provider) :-> :provider)
(rf/reg-sub
:wallet/wallet-buy-crypto-recurrent?
:<- [:wallet/wallet-buy-crypto]
:-> :recurrent?)
(rf/reg-sub
:wallet/wallet-buy-crypto-network
:<- [:wallet/wallet-buy-crypto]
:-> :network)

View File

@ -20,8 +20,3 @@
[k coll] [k coll]
(let [groups (group-by k coll)] (let [groups (group-by k coll)]
(map #(first (groups %)) (distinct (map k coll))))) (map #(first (groups %)) (distinct (map k coll)))))
(defn map-keys
[f m]
(->> (map (fn [[k v]] [(f k) v]) m)
(into {})))

View File

@ -0,0 +1,12 @@
(ns utils.collection-test
(:require
[cljs.test :refer-macros [deftest is]]
[utils.collection :as c]))
(deftest first-index-test
(is (= 2
(c/first-index (partial = :test)
'(:a :b :test :c :test))))
(is (= nil
(c/first-index (partial = :test)
'(:a :b :c)))))

View File

@ -134,11 +134,6 @@
(when bn (when bn
(.toFixed bn b)))) (.toFixed bn b))))
(defn to-number
[^js bn]
(when (bignumber? bn)
(.toNumber bn)))
(defn to-string (defn to-string
([^js bn] ([^js bn]
(to-string bn 10)) (to-string bn 10))
@ -156,11 +151,6 @@
(new BigNumber hex-str 16) (new BigNumber hex-str 16)
(catch :default _ nil))) (catch :default _ nil)))
(defn wei->str
([unit n display-unit]
(str (to-fixed (wei-> unit n)) " " display-unit))
([unit n] (wei->str unit n (string/upper-case (name unit)))))
(defn wei->ether (defn wei->ether
[n] [n]
(wei-> :eth n)) (wei-> :eth n))
@ -173,64 +163,12 @@
[n] [n]
(->wei :gwei n)) (->wei :gwei n))
(defn ether->wei
[^js bn]
(when (bignumber? bn)
(.times bn ^js (bignumber 1e18))))
(defn token->unit (defn token->unit
[n decimals] [n decimals]
(when-let [^js bn (bignumber n)] (when-let [^js bn (bignumber n)]
(when-let [d (from-decimal decimals)] (when-let [d (from-decimal decimals)]
(.dividedBy bn ^js (bignumber d))))) (.dividedBy bn ^js (bignumber d)))))
(defn unit->token
[n decimals]
(when-let [^js bn (bignumber n)]
(when-let [d (from-decimal decimals)]
(.times bn ^js (bignumber d)))))
;;NOTE(goranjovic) - We have two basic representations of values that refer to cryptocurrency amounts:
;;formatted and
;; internal. Formatted representation is the one we show on screens and include in reports, whereas
;; internal
;; representation is the one that we pass on to ethereum network for execution, transfer, etc.
;; The difference between the two depends on the number of decimals, i.e. internal representation is
;; expressed in terms
;; of a whole number of smallest divisible parts of the formatted value.
;;
;; E.g. for Ether, it's smallest part is wei or 10^(-18) of 1 ether
;; for arbitrary ERC20 token the smallest part is 10^(-decimals) of 1 token
;;
;; Different tokens can have different number of allowed decimals, so it's necessary to include the
;; decimals parameter
;; to get the amount scale right.
(defn formatted->internal
[n sym decimals]
(if (= :ETH sym)
(ether->wei n)
(unit->token n decimals)))
(defn internal->formatted
[n sym decimals]
(if (= :ETH sym)
(wei->ether n)
(token->unit n decimals)))
(defn fee-value
[gas gas-price]
(.times ^js (bignumber gas) ^js (bignumber gas-price)))
(defn percent-change
[from to]
(let [^js bnf (bignumber from)
^js bnt (bignumber to)]
(when (and bnf bnt)
(-> ^js (.dividedBy bnf bnt)
^js (.minus 1)
^js (.times 100)))))
(defn with-precision (defn with-precision
[n decimals] [n decimals]
(when-let [^js bn (bignumber n)] (when-let [^js bn (bignumber n)]
@ -256,15 +194,6 @@
(when (and amount balance) (when (and amount balance)
(greater-than-or-equals balance amount))) (greater-than-or-equals balance amount)))
(defn fiat-amount-value
[amount-str from to prices]
(-> amount-str
(js/parseFloat)
bignumber
(crypto->fiat (get-in prices [from to] ^js (bignumber 0)))
(with-precision 2)
str))
(defn- add* (defn- add*
[bn1 n2] [bn1 n2]
(.add ^js bn1 n2)) (.add ^js bn1 n2))
@ -281,10 +210,6 @@
"Multiply with defaults, this version is able to receive `nil` and takes them as 0." "Multiply with defaults, this version is able to receive `nil` and takes them as 0."
(fnil mul* (bignumber 0) (bignumber 0))) (fnil mul* (bignumber 0) (bignumber 0)))
(defn mul-and-round
[bn1 bn2]
(.round (.mul ^js bn1 bn2) 0))
(defn- div* (defn- div*
[bn1 bn2] [bn1 bn2]
(.dividedBy ^js bn1 bn2)) (.dividedBy ^js bn1 bn2))
@ -293,10 +218,6 @@
"Divides with defaults, this version is able to receive `nil` and takes them as 0." "Divides with defaults, this version is able to receive `nil` and takes them as 0."
(fnil div* (bignumber 0) (bignumber 1))) (fnil div* (bignumber 0) (bignumber 1)))
(defn div-and-round
[bn1 bn2]
(.round (.dividedBy ^js bn1 bn2) 0))
(defn fiat->crypto (defn fiat->crypto
[crypto fiat-price] [crypto fiat-price]
(when-let [crypto-bn (bignumber crypto)] (when-let [crypto-bn (bignumber crypto)]

View File

@ -2,7 +2,6 @@
(:require [clojure.string :as string] (:require [clojure.string :as string]
[native-module.core :as native-module] [native-module.core :as native-module]
[utils.hex :as utils.hex] [utils.hex :as utils.hex]
[utils.money :as utils.money]
[utils.money :as money])) [utils.money :as money]))
(defn naive-round (defn naive-round
@ -80,7 +79,7 @@
(defn to-fixed (defn to-fixed
[num decimals] [num decimals]
(-> num (-> num
(utils.money/to-fixed decimals) (money/to-fixed decimals)
remove-trailing-zeroes)) remove-trailing-zeroes))
(defn small-number-threshold (defn small-number-threshold