From 19aa78cc8164bb15fcfd7ac26c6a4c3701cdce66 Mon Sep 17 00:00:00 2001 From: Omar Basem Date: Wed, 17 Jan 2024 13:57:02 +0400 Subject: [PATCH 1/3] Wallet: loading networks (#18491) Wallet: loading networks --- src/status_im/constants.cljs | 3 +- .../wallet/account/tabs/about/view.cljs | 21 ++- .../common/sheets/account_options/view.cljs | 8 +- .../contexts/wallet/common/utils.cljs | 12 ++ .../contexts/wallet/common/validation.cljs | 2 +- .../contexts/wallet/send/events.cljs | 169 ++++++------------ .../wallet/send/input_amount/view.cljs | 14 +- .../contexts/wallet/send/routes/view.cljs | 38 ++-- .../wallet/send/select_address/view.cljs | 4 +- src/status_im/subs/wallet/wallet.cljs | 5 + 10 files changed, 127 insertions(+), 149 deletions(-) diff --git a/src/status_im/constants.cljs b/src/status_im/constants.cljs index e67c5512d87c..9155c6704aaa 100644 --- a/src/status_im/constants.cljs +++ b/src/status_im/constants.cljs @@ -219,7 +219,8 @@ (def regx-community-universal-link #"((^https?://status.app/)|(^status-app://))c/([\x00-\x7F]+)$") (def regx-deep-link #"((^ethereum:.*)|(^status-app://[\x00-\x7F]+$))") (def regx-ens #"^(?=.{5,255}$)([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.[a-zA-Z]{2,}$") -(def regx-address #"^0x[a-fA-F0-9]{40}$") +(def regx-multichain-address #"^(?:(?:eth:|arb1:|opt:)(?=:|))*0x[0-9a-fA-F]{40}$") + (def regx-address-contains #"(?i)0x[a-fA-F0-9]{40}") (def regx-starts-with-uuid #"^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}") (def regx-full-or-partial-address #"^0x[a-fA-F0-9]{1,40}$") diff --git a/src/status_im/contexts/wallet/account/tabs/about/view.cljs b/src/status_im/contexts/wallet/account/tabs/about/view.cljs index 0bab2cf3dfd7..2015eadc8a9b 100644 --- a/src/status_im/contexts/wallet/account/tabs/about/view.cljs +++ b/src/status_im/contexts/wallet/account/tabs/about/view.cljs @@ -8,13 +8,16 @@ [status-im.config :as config] [status-im.contexts.profile.utils :as profile.utils] [status-im.contexts.wallet.account.tabs.about.style :as style] + [status-im.contexts.wallet.common.utils :as utils] [utils.i18n :as i18n] [utils.re-frame :as rf])) (defn about-options [] (let [{:keys [address] :as account} (rf/sub [:wallet/current-viewing-account]) - share-title (str (:name account) " " (i18n/label :t/address))] + networks (rf/sub [:wallet/network-preference-details]) + share-title (str (:name account) " " (i18n/label :t/address)) + multichain-address (utils/get-multichain-address networks address)] [quo/action-drawer [[{:icon :i/link :accessibility-label :view-on-eth @@ -44,7 +47,7 @@ :accessibility-label :copy-address :label (i18n/label :t/copy-address) :on-press (fn [] - (clipboard/set-string address) + (clipboard/set-string multichain-address) (rf/dispatch [:toasts/upsert {:type :positive :text (i18n/label :t/address-copied)}]))} @@ -59,15 +62,17 @@ (js/setTimeout #(share/open (if platform/ios? - {:activityItemSources [{:placeholderItem {:type "text" - :content address} - :item {:default {:type "text" - :content - address}} + {:activityItemSources [{:placeholderItem {:type "text" + :content + multichain-address} + :item {:default + {:type "text" + :content + multichain-address}} :linkMetadata {:title share-title}}]} {:title share-title :subject share-title - :message address})) + :message multichain-address})) 600))}]]])) (defn view diff --git a/src/status_im/contexts/wallet/common/sheets/account_options/view.cljs b/src/status_im/contexts/wallet/common/sheets/account_options/view.cljs index 7b841db7093b..f5ac6b98ec40 100644 --- a/src/status_im/contexts/wallet/common/sheets/account_options/view.cljs +++ b/src/status_im/contexts/wallet/common/sheets/account_options/view.cljs @@ -10,6 +10,7 @@ [react-native.platform :as platform] [reagent.core :as reagent] [status-im.contexts.wallet.common.sheets.account-options.style :as style] + [status-im.contexts.wallet.common.utils :as utils] [utils.i18n :as i18n] [utils.re-frame :as rf])) @@ -31,7 +32,10 @@ (defn- options [{:keys [theme show-account-selector? options-height]}] (let [{:keys [name color emoji address watch-only?]} (rf/sub [:wallet/current-viewing-account]) - network-preference-details (rf/sub [:wallet/network-preference-details])] + network-preference-details (rf/sub [:wallet/network-preference-details]) + multichain-address (utils/get-multichain-address + network-preference-details + address)] [rn/view {:on-layout #(reset! options-height (oops/oget % "nativeEvent.layout.height")) :style (when show-account-selector? style/options-container)} @@ -72,7 +76,7 @@ (rf/dispatch [:toasts/upsert {:type :positive :text (i18n/label :t/address-copied)}]) - (clipboard/set-string address))} + (clipboard/set-string multichain-address))} {:icon :i/share :accessibility-label :share-account :label (i18n/label :t/share-account)} diff --git a/src/status_im/contexts/wallet/common/utils.cljs b/src/status_im/contexts/wallet/common/utils.cljs index 02e666c824a2..37c0bc325e6e 100644 --- a/src/status_im/contexts/wallet/common/utils.cljs +++ b/src/status_im/contexts/wallet/common/utils.cljs @@ -202,3 +202,15 @@ :customization-color color :values {:crypto-value crypto-value :fiat-value fiat-value}})) + +(defn get-multichain-address + [networks address] + (str (->> networks + (map #(str (:short-name %) ":")) + (clojure.string/join "")) + address)) + +(defn split-prefix-and-address + [input-string] + (let [split-result (string/split input-string #"0x")] + [(first split-result) (str "0x" (second split-result))])) diff --git a/src/status_im/contexts/wallet/common/validation.cljs b/src/status_im/contexts/wallet/common/validation.cljs index 2e9ab0d379ed..9d4d11c6d6f6 100644 --- a/src/status_im/contexts/wallet/common/validation.cljs +++ b/src/status_im/contexts/wallet/common/validation.cljs @@ -2,4 +2,4 @@ (:require [status-im.constants :as constants])) (defn ens-name? [s] (re-find constants/regx-ens s)) -(defn eth-address? [s] (re-find constants/regx-address s)) +(defn eth-address? [s] (re-find constants/regx-multichain-address s)) diff --git a/src/status_im/contexts/wallet/send/events.cljs b/src/status_im/contexts/wallet/send/events.cljs index 109acfee3d64..6ba7c9789e1c 100644 --- a/src/status_im/contexts/wallet/send/events.cljs +++ b/src/status_im/contexts/wallet/send/events.cljs @@ -2,11 +2,10 @@ (:require [camel-snake-kebab.core :as csk] [camel-snake-kebab.extras :as cske] - [native-module.core :as native-module] [status-im.constants :as constants] + [status-im.contexts.wallet.common.utils :as utils] [status-im.contexts.wallet.send.utils :as send-utils] [taoensso.timbre :as log] - [utils.address :as address] [utils.money :as money] [utils.number] [utils.re-frame :as rf])) @@ -42,23 +41,32 @@ (update-in [:wallet :ui :send] dissoc :route) (update-in [:wallet :ui :send] dissoc :loading-suggested-routes?))})) +(rf/reg-event-fx :wallet/select-send-account-address + (fn [{:keys [db]} [{:keys [address stack-id]}]] + {:db (-> db + (assoc-in [:wallet :ui :send :send-account-address] address) + (update-in [:wallet :ui :send] dissoc :to-address)) + :fx [[:navigate-to-within-stack [:wallet-select-asset stack-id]]]})) + (rf/reg-event-fx :wallet/clean-send-address (fn [{:keys [db]}] {:db (update-in db [:wallet :ui :send] dissoc :recipient :to-address)})) (rf/reg-event-fx :wallet/select-send-address (fn [{:keys [db]} [{:keys [address token recipient stack-id]}]] - {:db (-> db - (assoc-in [:wallet :ui :send :recipient] (or recipient address)) - (assoc-in [:wallet :ui :send :to-address] address)) - :fx [[:navigate-to-within-stack - (if token [:wallet-send-input-amount stack-id] [:wallet-select-asset stack-id])]]})) + (let [[prefix to-address] (utils/split-prefix-and-address address)] + {:db (-> db + (assoc-in [:wallet :ui :send :recipient] (or recipient address)) + (assoc-in [:wallet :ui :send :to-address] to-address) + (assoc-in [:wallet :ui :send :address-prefix] prefix)) + :fx [[:navigate-to-within-stack + (if token + [:wallet-send-input-amount stack-id] + [:wallet-select-asset stack-id])]]}))) (rf/reg-event-fx :wallet/send-select-token (fn [{:keys [db]} [{:keys [token stack-id]}]] - {:db (-> db - (update-in [:wallet :ui :send] dissoc :collectible) - (assoc-in [:wallet :ui :send :token] token)) + {:db (assoc-in db [:wallet :ui :send :token] token) :fx [[:navigate-to-within-stack [:wallet-send-input-amount stack-id]]]})) (rf/reg-event-fx :wallet/send-select-token-drawer @@ -69,15 +77,6 @@ (fn [{:keys [db]}] {:db (assoc-in db [:wallet :ui :send :token] nil)})) -(rf/reg-event-fx :wallet/send-select-collectible - (fn [{:keys [db]} [{:keys [collectible stack-id]}]] - {:db (-> db - (update-in [:wallet :ui :send] dissoc :token) - (assoc-in [:wallet :ui :send :collectible] collectible) - (assoc-in [:wallet :ui :send :amount] 1)) - :fx [[:dispatch [:wallet/get-suggested-routes 1]] - [:navigate-to-within-stack [:wallet-transaction-confirmation stack-id]]]})) - (rf/reg-event-fx :wallet/send-select-amount (fn [{:keys [db]} [{:keys [amount stack-id]}]] {:db (assoc-in db [:wallet :ui :send :amount] amount) @@ -87,25 +86,18 @@ (fn [{:keys [db now]} [amount]] (let [wallet-address (get-in db [:wallet :current-viewing-account-address]) token (get-in db [:wallet :ui :send :token]) - collectible (get-in db [:wallet :ui :send :collectible]) - to-address (get-in db [:wallet :ui :send :to-address]) - token-decimal (when token (:decimals token)) - token-id (if token - (:symbol token) - (str (get-in collectible [:id :contract-id :address]) - ":" - (get-in collectible [:id :token-id]))) - network-preferences (if token [] [(get-in collectible [:id :contract-id :chain-id])]) + account-address (get-in db [:wallet :ui :send :send-account-address]) + to-address (or account-address (get-in db [:wallet :ui :send :to-address])) + token-decimal (:decimals token) + token-id (:symbol token) + network-preferences [] gas-rates constants/gas-rate-medium - amount-in (send-utils/amount-in-hex amount (if token token-decimal 0)) + amount-in (send-utils/amount-in-hex amount token-decimal) from-address wallet-address disabled-from-chain-ids [] disabled-to-chain-ids [] from-locked-amount {} - transaction-type (if token - constants/send-type-transfer - constants/send-type-erc-721-transfer) - request-params [transaction-type + request-params [constants/send-type-transfer from-address to-address amount-in @@ -142,46 +134,21 @@ :fx [[:dispatch [:navigate-to :wallet-transaction-progress]]]}))) (defn- transaction-bridge - [{:keys [from-address from-chain-id to-address token-id token-address route data eth-transfer?]}] - (let [{:keys [bridge-name amount-out gas-amount - gas-fees]} route - eip-1559-enabled? (:eip-1559-enabled gas-fees) - {:keys [gas-price max-fee-per-gas-medium - max-priority-fee-per-gas]} gas-fees - transfer-tx (cond-> {:From from-address - :To (or token-address to-address) - :Gas (money/to-hex gas-amount) - :Value (when eth-transfer? amount-out) - :Nonce nil - :Input "" - :Data (or data "0x")} - eip-1559-enabled? (assoc :TxType "0x02" - :MaxFeePerGas - (money/to-hex - (money/->wei - :gwei - max-fee-per-gas-medium)) - :MaxPriorityFeePerGas - (money/to-hex - (money/->wei - :gwei - max-priority-fee-per-gas))) - (not eip-1559-enabled?) (assoc :TxType "0x00" - :GasPrice (money/to-hex - (money/->wei - :gwei - gas-price))))] - [(cond-> {:BridgeName bridge-name - :ChainID from-chain-id} - - (= bridge-name constants/bridge-name-erc-721-transfer) - (assoc :ERC721TransferTx - (assoc transfer-tx - :Recipient to-address - :TokenID token-id)) - - (= bridge-name constants/bridge-name-transfer) - (assoc :TransferTx transfer-tx))])) + [{:keys [from-address to-address route]}] + (let [{:keys [from bridge-name amount-out gas-amount gas-fees]} route + {:keys [gas-price max-fee-per-gas-medium max-priority-fee-per-gas]} gas-fees] + [{:BridgeName bridge-name + :ChainID (:chain-id from) + :TransferTx {:From from-address + :To to-address + :Gas (money/to-hex gas-amount) + :GasPrice (money/to-hex (money/->wei :gwei gas-price)) + :Value amount-out + :Nonce nil + :MaxFeePerGas (money/to-hex (money/->wei :gwei max-fee-per-gas-medium)) + :MaxPriorityFeePerGas (money/to-hex (money/->wei :gwei max-priority-fee-per-gas)) + :Input "" + :Data "0x"}}])) (defn- multi-transaction-command [{:keys [from-address to-address from-asset to-asset amount-out transfer-type] @@ -195,53 +162,27 @@ (rf/reg-event-fx :wallet/send-transaction (fn [{:keys [db]} [sha3-pwd]] - (let [route (get-in db [:wallet :ui :send :route]) - from-address (get-in db [:wallet :current-viewing-account-address]) - token (get-in db [:wallet :ui :send :token]) - collectible (get-in db [:wallet :ui :send :collectible]) - from-chain-id (get-in route [:from :chain-id]) - token-id (if token - (:symbol token) - (get-in collectible [:id :token-id])) - erc20-transfer? (and token (not= token-id "ETH")) - eth-transfer? (and token (not erc20-transfer?)) - token-address (cond collectible - (get-in collectible - [:id :contract-id :address]) - erc20-transfer? - (get-in token [:balances-per-chain from-chain-id :address])) - to-address (get-in db [:wallet :ui :send :to-address]) - data (when erc20-transfer? - (native-module/encode-transfer (address/normalized-hex to-address) - (:amount-out route))) - request-params [(multi-transaction-command - {:from-address from-address - :to-address to-address - :from-asset token-id - :to-asset token-id - :amount-out (if eth-transfer? (:amount-out route) "0x0")}) - (transaction-bridge {:to-address to-address - :from-address from-address - :route route - :from-chain-id from-chain-id - :token-address token-address - :token-id (when collectible - (money/to-hex (js/parseInt token-id))) - :data data - :eth-transfer? eth-transfer?}) - sha3-pwd]] + (let [route (get-in db [:wallet :ui :send :route]) + from-address (get-in db [:wallet :current-viewing-account-address]) + to-address (get-in db [:wallet :ui :send :to-address]) + token (get-in db [:wallet :ui :send :token]) + token-id (:symbol token) + request-params [(multi-transaction-command {:from-address from-address + :to-address to-address + :from-asset token-id + :to-asset token-id + :amount-out (:amount-out route)}) + (transaction-bridge {:to-address to-address + :from-address from-address + :route route}) + sha3-pwd]] {:json-rpc/call [{:method "wallet_createMultiTransaction" :params request-params :on-success (fn [result] (rf/dispatch [:hide-bottom-sheet]) - (rf/dispatch [:wallet/add-authorized-transaction result]) - (rf/dispatch [:wallet/clean-scanned-address]) - (rf/dispatch [:wallet/clean-local-suggestions]) - (rf/dispatch [:wallet/clean-send-address]) - (rf/dispatch [:wallet/select-address-tab nil])) + (rf/dispatch [:wallet/add-authorized-transaction result])) :on-error (fn [error] (log/error "failed to send transaction" {:event :wallet/send-transaction :error error :params request-params}))}]}))) - diff --git a/src/status_im/contexts/wallet/send/input_amount/view.cljs b/src/status_im/contexts/wallet/send/input_amount/view.cljs index d0f2e438f905..5ee3895f91a5 100644 --- a/src/status_im/contexts/wallet/send/input_amount/view.cljs +++ b/src/status_im/contexts/wallet/send/input_amount/view.cljs @@ -53,6 +53,13 @@ (normalize-input current v) current)) +(defn- find-affordable-networks + [{:keys [balances-per-chain]} input-value] + (->> balances-per-chain + (filter (fn [[_ {:keys [balance]}]] + (>= (js/parseFloat balance) input-value))) + (map first))) + (defn- f-view-internal [{:keys [rate limit]}] (let [bottom (safe-area/get-bottom) @@ -142,9 +149,10 @@ :on-change-text (fn [text] (handle-on-change text))}] [routes/view - {:amount amount - :routes suggested-routes - :networks (:networks token)}] + {:amount amount + :routes suggested-routes + :loading-networks (find-affordable-networks token @input-value) + :networks (:networks token)}] [quo/bottom-actions {:actions :1-action :button-one-label (i18n/label :t/confirm) diff --git a/src/status_im/contexts/wallet/send/routes/view.cljs b/src/status_im/contexts/wallet/send/routes/view.cljs index 5ee5994126fa..ff8c1f7ea974 100644 --- a/src/status_im/contexts/wallet/send/routes/view.cljs +++ b/src/status_im/contexts/wallet/send/routes/view.cljs @@ -14,11 +14,13 @@ {:amount amount :network from-network :status status}] - [quo/network-link - {:shape :linear - :source from-network - :destination to-network - :container-style style/network-link}] + (if (= status :default) + [quo/network-link + {:shape :linear + :source from-network + :destination to-network + :container-style style/network-link}] + [rn/view {:style {:width 73}}]) [quo/network-bridge {:amount amount :network to-network @@ -26,12 +28,12 @@ :container-style {:right 12}}]]) (defn view - [{:keys [amount routes]}] + [{:keys [amount routes loading-networks]}] (let [loading-suggested-routes? (rf/sub [:wallet/wallet-send-loading-suggested-routes?]) candidates (:candidates routes)] - (if (and (not loading-suggested-routes?) (not-empty candidates)) + (if (or (and (not-empty loading-networks) loading-suggested-routes?) (not-empty candidates)) [rn/flat-list - {:data candidates + {:data (if loading-suggested-routes? loading-networks candidates) :content-container-style style/routes-container :header [rn/view {:style style/routes-header-container} [quo/section-label @@ -40,15 +42,17 @@ [quo/section-label {:section (i18n/label :t/to-label) :container-style (style/section-label 64)}]] - :render-fn (fn [route] + :render-fn (fn [item] [route-item {:amount amount - :status :default - :from-network (utils/id->network (get-in route [:from :chain-id])) - :to-network (utils/id->network (get-in route - [:to :chain-id]))}])}] + :status (if loading-suggested-routes? :loading :default) + :from-network (if loading-suggested-routes? + (utils/id->network item) + (utils/id->network (get-in item [:from :chain-id]))) + :to-network (if loading-suggested-routes? + (utils/id->network item) + (utils/id->network (get-in item + [:to :chain-id])))}])}] [rn/view {:style style/empty-container} - (if loading-suggested-routes? - [rn/activity-indicator] - (when (not (nil? candidates)) - [quo/text (i18n/label :t/no-routes-found)]))]))) + (when (and (not (nil? candidates)) (not loading-suggested-routes?)) + [quo/text (i18n/label :t/no-routes-found)])]))) diff --git a/src/status_im/contexts/wallet/send/select_address/view.cljs b/src/status_im/contexts/wallet/send/select_address/view.cljs index 6a9e74fb4a13..07ae2e684c1c 100644 --- a/src/status_im/contexts/wallet/send/select_address/view.cljs +++ b/src/status_im/contexts/wallet/send/select_address/view.cljs @@ -38,8 +38,8 @@ (rn/dismiss-keyboard!) (rf/dispatch [:open-modal :scan-address])) :ens-regex constants/regx-ens - :address-regex constants/regx-address :scanned-value (or (when recipient-plain-address? send-address) scanned-address) + :address-regex constants/regx-multichain-address :on-detect-address #(debounce/debounce-and-dispatch [:wallet/validate-address %] 300) @@ -48,8 +48,6 @@ [:wallet/find-ens text contacts chain-id cb] 300)) :on-change-text (fn [text] - (when-not (= scanned-address text) - (rf/dispatch [:wallet/clean-scanned-address])) (when (empty? text) (rf/dispatch [:wallet/clean-local-suggestions])) (reset! input-value text)) diff --git a/src/status_im/subs/wallet/wallet.cljs b/src/status_im/subs/wallet/wallet.cljs index a619a016d7e9..f9fa40f23c87 100644 --- a/src/status_im/subs/wallet/wallet.cljs +++ b/src/status_im/subs/wallet/wallet.cljs @@ -43,6 +43,11 @@ :<- [:wallet/wallet-send] :-> :to-address) +(rf/reg-sub + :wallet/wallet-send-address-prefix + :<- [:wallet/wallet-send] + :-> :address-prefix) + (rf/reg-sub :wallet/wallet-send-route :<- [:wallet/wallet-send] From 49e9b4212b3d804301ba4939ee3d63a14f7ff789 Mon Sep 17 00:00:00 2001 From: mmilad75 <55688834+mmilad75@users.noreply.github.com> Date: Wed, 17 Jan 2024 14:12:35 +0330 Subject: [PATCH 2/3] Wallet - Account switcher - add Share Account functionality #18376 (#18444) * add share account functionality * add share qr code address functionality * rename file * finalize code * move logic to events and effects * fix lint issues * resolve comments * change translation --- .../wallet/account/tabs/about/view.cljs | 20 ++++--------------- .../contexts/wallet/account/view.cljs | 2 +- .../common/sheets/account_options/view.cljs | 15 ++++++++++++-- src/status_im/contexts/wallet/effects.cljs | 7 +++++++ src/status_im/contexts/wallet/events.cljs | 15 ++++++++++++++ .../{receive => share_address}/style.cljs | 2 +- .../{receive => share_address}/view.cljs | 13 ++++++++---- src/status_im/events.cljs | 1 + src/status_im/navigation/screens.cljs | 6 +++--- 9 files changed, 54 insertions(+), 27 deletions(-) create mode 100644 src/status_im/contexts/wallet/effects.cljs rename src/status_im/contexts/wallet/{receive => share_address}/style.cljs (60%) rename src/status_im/contexts/wallet/{receive => share_address}/view.cljs (88%) diff --git a/src/status_im/contexts/wallet/account/tabs/about/view.cljs b/src/status_im/contexts/wallet/account/tabs/about/view.cljs index 2015eadc8a9b..0cb3ab0bb953 100644 --- a/src/status_im/contexts/wallet/account/tabs/about/view.cljs +++ b/src/status_im/contexts/wallet/account/tabs/about/view.cljs @@ -3,8 +3,6 @@ [quo.core :as quo] [react-native.clipboard :as clipboard] [react-native.core :as rn] - [react-native.platform :as platform] - [react-native.share :as share] [status-im.config :as config] [status-im.contexts.profile.utils :as profile.utils] [status-im.contexts.wallet.account.tabs.about.style :as style] @@ -53,26 +51,16 @@ :text (i18n/label :t/address-copied)}]))} {:icon :i/qr-code :accessibility-label :show-address-qr - :label (i18n/label :t/show-address-qr)} + :label (i18n/label :t/show-address-qr) + :on-press #(rf/dispatch [:open-modal :wallet-share-address {:status :share}])} {:icon :i/share :accessibility-label :share-address :label (i18n/label :t/share-address) :on-press (fn [] (rf/dispatch [:hide-bottom-sheet]) (js/setTimeout - #(share/open - (if platform/ios? - {:activityItemSources [{:placeholderItem {:type "text" - :content - multichain-address} - :item {:default - {:type "text" - :content - multichain-address}} - :linkMetadata {:title share-title}}]} - {:title share-title - :subject share-title - :message multichain-address})) + #(rf/dispatch [:wallet/share-account + {:title share-title :content multichain-address}]) 600))}]]])) (defn view diff --git a/src/status_im/contexts/wallet/account/view.cljs b/src/status_im/contexts/wallet/account/view.cljs index b5faf353cfe0..54da1094fd5f 100644 --- a/src/status_im/contexts/wallet/account/view.cljs +++ b/src/status_im/contexts/wallet/account/view.cljs @@ -47,7 +47,7 @@ (when (not watch-only?) [quo/wallet-ctas {:send-action #(rf/dispatch [:open-modal :wallet-select-address]) - :receive-action #(rf/dispatch [:open-modal :wallet-receive]) + :receive-action #(rf/dispatch [:open-modal :wallet-share-address {:status :receive}]) :buy-action #(rf/dispatch [:show-bottom-sheet {:content buy-drawer}]) :bridge-action #(rf/dispatch [:open-modal :wallet-bridge])}]) diff --git a/src/status_im/contexts/wallet/common/sheets/account_options/view.cljs b/src/status_im/contexts/wallet/common/sheets/account_options/view.cljs index f5ac6b98ec40..365859ca9cc5 100644 --- a/src/status_im/contexts/wallet/common/sheets/account_options/view.cljs +++ b/src/status_im/contexts/wallet/common/sheets/account_options/view.cljs @@ -35,7 +35,8 @@ network-preference-details (rf/sub [:wallet/network-preference-details]) multichain-address (utils/get-multichain-address network-preference-details - address)] + address) + share-title (str name " " (i18n/label :t/address))] [rn/view {:on-layout #(reset! options-height (oops/oget % "nativeEvent.layout.height")) :style (when show-account-selector? style/options-container)} @@ -77,9 +78,19 @@ {:type :positive :text (i18n/label :t/address-copied)}]) (clipboard/set-string multichain-address))} + {:icon :i/qr-code + :accessibility-label :show-address-qr + :label (i18n/label :t/show-address-qr) + :on-press #(rf/dispatch [:open-modal :wallet-share-address {:status :share}])} {:icon :i/share :accessibility-label :share-account - :label (i18n/label :t/share-account)} + :label (i18n/label :t/share-address) + :on-press (fn [] + (rf/dispatch [:hide-bottom-sheet]) + (js/setTimeout + #(rf/dispatch [:wallet/share-account + {:title share-title :content address}]) + 600))} {:add-divider? (not show-account-selector?) :icon :i/delete :accessibility-label :remove-account diff --git a/src/status_im/contexts/wallet/effects.cljs b/src/status_im/contexts/wallet/effects.cljs new file mode 100644 index 000000000000..cad9a4680b19 --- /dev/null +++ b/src/status_im/contexts/wallet/effects.cljs @@ -0,0 +1,7 @@ +(ns status-im.contexts.wallet.effects + (:require [re-frame.core :as rf] + [react-native.share :as share])) + +(rf/reg-fx :effects.share/open + (fn [content] + (share/open content))) diff --git a/src/status_im/contexts/wallet/events.cljs b/src/status_im/contexts/wallet/events.cljs index a0c37ffc4b8c..394aa60f28dc 100644 --- a/src/status_im/contexts/wallet/events.cljs +++ b/src/status_im/contexts/wallet/events.cljs @@ -2,6 +2,7 @@ (:require [clojure.string :as string] [react-native.background-timer :as background-timer] + [react-native.platform :as platform] [status-im.contexts.wallet.data-store :as data-store] [status-im.contexts.wallet.events.collectibles] [status-im.contexts.wallet.item-types :as item-types] @@ -329,3 +330,17 @@ (rf/reg-event-fx :wallet/initialize (fn [] {:fx [[:dispatch-n [[:wallet/get-ethereum-chains] [:wallet/get-accounts]]]]})) + +(rf/reg-event-fx :wallet/share-account + (fn [_ [{:keys [content title]}]] + {:fx [[:effects.share/open + (if platform/ios? + {:activityItemSources + [{:placeholderItem {:type "text" + :content content} + :item {:default {:type "text" + :content content}} + :linkMetadata {:title title}}]} + {:title title + :subject title + :message content})]]})) diff --git a/src/status_im/contexts/wallet/receive/style.cljs b/src/status_im/contexts/wallet/share_address/style.cljs similarity index 60% rename from src/status_im/contexts/wallet/receive/style.cljs rename to src/status_im/contexts/wallet/share_address/style.cljs index e4dc1a9b6caf..f4a108f6d0c8 100644 --- a/src/status_im/contexts/wallet/receive/style.cljs +++ b/src/status_im/contexts/wallet/share_address/style.cljs @@ -1,4 +1,4 @@ -(ns status-im.contexts.wallet.receive.style) +(ns status-im.contexts.wallet.share-address.style) (def header-container {:padding-horizontal 20 diff --git a/src/status_im/contexts/wallet/receive/view.cljs b/src/status_im/contexts/wallet/share_address/view.cljs similarity index 88% rename from src/status_im/contexts/wallet/receive/view.cljs rename to src/status_im/contexts/wallet/share_address/view.cljs index e256f0dde359..e098e4565dc4 100644 --- a/src/status_im/contexts/wallet/receive/view.cljs +++ b/src/status_im/contexts/wallet/share_address/view.cljs @@ -1,4 +1,4 @@ -(ns status-im.contexts.wallet.receive.view +(ns status-im.contexts.wallet.share-address.view (:require [quo.core :as quo] [react-native.core :as rn] @@ -8,7 +8,7 @@ [reagent.core :as reagent] [status-im.contexts.wallet.common.sheets.network-preferences.view :as network-preferences] [status-im.contexts.wallet.common.utils :as utils] - [status-im.contexts.wallet.receive.style :as style] + [status-im.contexts.wallet.share-address.style :as style] [utils.i18n :as i18n] [utils.image-server :as image-server] [utils.re-frame :as rf])) @@ -64,7 +64,12 @@ {:url qr-url :port (rf/sub [:mediaserver/port]) :qr-size qr-size - :error-level :highest})] + :error-level :highest}) + {:keys [status]} (rf/sub [:get-screen-params]) + title (case status + :share (i18n/label :t/share-address) + :receive (i18n/label :t/receive) + nil)] [quo/overlay {:type :shell} [rn/view {:flex 1 @@ -78,7 +83,7 @@ :accessibility-label :top-bar}] [quo/text-combinations {:container-style style/header-container - :title (i18n/label :t/receive)}] + :title title}] [rn/view {:style {:padding-horizontal 20}} [quo/share-qr-code {:type @wallet-type diff --git a/src/status_im/events.cljs b/src/status_im/events.cljs index b7d48274f0a7..59d45116116d 100644 --- a/src/status_im/events.cljs +++ b/src/status_im/events.cljs @@ -23,6 +23,7 @@ status-im.contexts.profile.settings.events status-im.contexts.shell.share.events status-im.contexts.syncing.events + status-im.contexts.wallet.effects status-im.contexts.wallet.events status-im.contexts.wallet.send.events [status-im.db :as db] diff --git a/src/status_im/navigation/screens.cljs b/src/status_im/navigation/screens.cljs index 3d942de1381f..0e7d2ab9e8af 100644 --- a/src/status_im/navigation/screens.cljs +++ b/src/status_im/navigation/screens.cljs @@ -58,7 +58,6 @@ [status-im.contexts.wallet.create-account.select-keypair.view :as wallet-select-keypair] [status-im.contexts.wallet.create-account.view :as wallet-create-account] [status-im.contexts.wallet.edit-account.view :as wallet-edit-account] - [status-im.contexts.wallet.receive.view :as wallet-receive] [status-im.contexts.wallet.saved-addresses.view :as wallet-saved-addresses] [status-im.contexts.wallet.scan-account.view :as scan-address] [status-im.contexts.wallet.send.input-amount.view :as wallet-send-input-amount] @@ -66,6 +65,7 @@ [status-im.contexts.wallet.send.select-asset.view :as wallet-select-asset] [status-im.contexts.wallet.send.transaction-confirmation.view :as wallet-transaction-confirmation] [status-im.contexts.wallet.send.transaction-progress.view :as wallet-transaction-progress] + [status-im.contexts.wallet.share-address.view :as wallet-share-address] [status-im.navigation.options :as options] [status-im.navigation.transitions :as transitions])) @@ -330,9 +330,9 @@ :options {:insets {:top? true :bottom? true}} :component wallet-backup-recovery-phrase/view} - {:name :wallet-receive + {:name :wallet-share-address :options options/transparent-screen-options - :component wallet-receive/view} + :component wallet-share-address/view} {:name :wallet-saved-addresses :component wallet-saved-addresses/view} From 72bf8a87020f9be93161d538d0147cf4fef77869 Mon Sep 17 00:00:00 2001 From: Lungu Cristian Date: Wed, 17 Jan 2024 13:24:13 +0200 Subject: [PATCH 3/3] fix: composer size when re-entering with unfinished multiline message (#18089) fix: composer space when expanding after re-entering fix: composer bottom shadow and maximized state atom fix: removing composer bottom gradient style changes --- .../chat/messenger/composer/effects.cljs | 22 ++++++++++++------- .../messenger/composer/gradients/style.cljs | 3 +-- .../messenger/composer/gradients/view.cljs | 1 + .../chat/messenger/composer/handlers.cljs | 10 +++++---- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/status_im/contexts/chat/messenger/composer/effects.cljs b/src/status_im/contexts/chat/messenger/composer/effects.cljs index f9b3d270d411..d3e689e0d985 100644 --- a/src/status_im/contexts/chat/messenger/composer/effects.cljs +++ b/src/status_im/contexts/chat/messenger/composer/effects.cljs @@ -16,13 +16,19 @@ (defn reenter-screen-effect [{:keys [text-value saved-cursor-position maximized?]} {:keys [content-height]} - {:keys [input-content-height input-text input-maximized?]}] - (when (and (empty? @text-value) (not= input-text nil)) - (reset! text-value input-text) - (reset! content-height input-content-height) - (reset! saved-cursor-position (count input-text))) - (when input-maximized? - (reset! maximized? true))) + {:keys [input-content-height input-text input-maximized?]} + {:keys [height]}] + (let [lines (utils/calc-lines input-content-height) + minimized-height (if (or (= lines 1) (empty? input-text)) + constants/input-height + constants/multiline-minimized-height)] + (when (and (empty? @text-value) (not= input-text nil)) + (reset! text-value input-text) + (reset! content-height input-content-height) + (reset! saved-cursor-position (count input-text)) + (reanimated/set-shared-value height minimized-height)) + (when input-maximized? + (reset! maximized? true)))) (defn maximized-effect [{:keys [maximized?]} @@ -101,7 +107,7 @@ [max-height]) (rn/use-effect (fn [] - (reenter-screen-effect state dimensions subscriptions)) + (reenter-screen-effect state dimensions subscriptions animations)) [max-height subscriptions])) (defn use-edit diff --git a/src/status_im/contexts/chat/messenger/composer/gradients/style.cljs b/src/status_im/contexts/chat/messenger/composer/gradients/style.cljs index fa038d2e1378..65c8f5b48482 100644 --- a/src/status_im/contexts/chat/messenger/composer/gradients/style.cljs +++ b/src/status_im/contexts/chat/messenger/composer/gradients/style.cljs @@ -31,8 +31,7 @@ :position :absolute :bottom 0 :left 0 - :right 0 - :z-index 2}) + :right 0}) (defn bottom-gradient [] diff --git a/src/status_im/contexts/chat/messenger/composer/gradients/view.cljs b/src/status_im/contexts/chat/messenger/composer/gradients/view.cljs index 599b35aeb57a..f4417412c9fd 100644 --- a/src/status_im/contexts/chat/messenger/composer/gradients/view.cljs +++ b/src/status_im/contexts/chat/messenger/composer/gradients/view.cljs @@ -19,6 +19,7 @@ (when show-bottom-gradient? [rn/pressable {:on-press #(when @input-ref (.focus ^js @input-ref)) + :style {:z-index 1} :accessibility-label :bottom-gradient} [linear-gradient/linear-gradient (style/bottom-gradient)]])])) diff --git a/src/status_im/contexts/chat/messenger/composer/handlers.cljs b/src/status_im/contexts/chat/messenger/composer/handlers.cljs index 6ae447b3ee63..397fb2892b91 100644 --- a/src/status_im/contexts/chat/messenger/composer/handlers.cljs +++ b/src/status_im/contexts/chat/messenger/composer/handlers.cljs @@ -16,18 +16,20 @@ (defn focus "Animate to the `saved-height`, display background-overlay if needed, and set cursor position" [{:keys [input-ref] :as props} - {:keys [text-value focused? lock-selection? saved-cursor-position composer-focused?]} + {:keys [text-value focused? lock-selection? saved-cursor-position composer-focused? maximized?]} {:keys [height saved-height last-height opacity background-y container-opacity] :as animations} {:keys [max-height] :as dimensions}] (reanimated/set-shared-value composer-focused? true) (reset! focused? true) (rf/dispatch [:chat.ui/set-input-focused true]) - (let [last-height-value (reanimated/get-shared-value last-height)] - (reanimated/animate height last-height-value) - (reanimated/set-shared-value saved-height last-height-value) + (let [last-height-value (reanimated/get-shared-value last-height) + new-height (min max-height last-height-value)] + (reanimated/animate height new-height) + (reanimated/set-shared-value saved-height new-height) (reanimated/animate container-opacity 1) (when (> last-height-value (* constants/background-threshold max-height)) + (reset! maximized? true) (reanimated/animate opacity 1) (reanimated/set-shared-value background-y 0)))