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] 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 2015eadc8a..0cb3ab0bb9 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 b5faf353cf..54da1094fd 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 f5ac6b98ec..365859ca9c 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 0000000000..cad9a4680b --- /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 a0c37ffc4b..394aa60f28 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 e4dc1a9b6c..f4a108f6d0 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 e256f0dde3..e098e4565d 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 b7d48274f0..59d4511611 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 3d942de138..0e7d2ab9e8 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}