Skip to content

Commit

Permalink
chore(wallet): add flow for selecting own accounts in sendflows
Browse files Browse the repository at this point in the history
  • Loading branch information
J-Son89 committed Dec 12, 2023
1 parent e5179d3 commit a01a5d5
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 42 deletions.
12 changes: 12 additions & 0 deletions src/status_im2/contexts/wallet/send/events.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(ns status-im2.contexts.wallet.send.events
(:require
[utils.number]
[utils.re-frame :as rf]))

(rf/reg-event-fx :wallet/select-address-tab
(fn [{:keys [db]} [tab]]
{:db (assoc-in db [:wallet :ui :send :select-address-tab] tab)}))

(rf/reg-event-fx :wallet/select-send-account-address
(fn [{:keys [db]} [address]]
{:db (assoc db [:wallet :ui :send :send-account-address] address)}))
5 changes: 0 additions & 5 deletions src/status_im2/contexts/wallet/send/select_address/style.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@
{:padding-left 20
:padding-right 8})

(def empty-container-style
{:justify-content :center
:flex 1
:margin-bottom 44})

(def button
{:justify-self :flex-end
:margin-bottom 46
Expand Down
10 changes: 10 additions & 0 deletions src/status_im2/contexts/wallet/send/select_address/tabs/style.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(ns status-im2.contexts.wallet.send.select-address.tabs.style)

(def empty-container-style
{:justify-content :center
:flex 1
:margin-bottom 44})

(def my-accounts-container
{:padding-left 8
:padding-right 8})
57 changes: 57 additions & 0 deletions src/status_im2/contexts/wallet/send/select_address/tabs/view.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
(ns status-im2.contexts.wallet.send.select-address.tabs.view
(:require
[quo.core :as quo]
[react-native.gesture :as gesture]
[status-im2.contexts.wallet.send.select-address.tabs.style :as style]
[utils.i18n :as i18n]
[utils.re-frame :as rf]))

(defn- render-account-item
[{:keys [color address] :as account}]
[quo/account-item
{:account-props (assoc account :customization-color color)
:on-press (fn []
(rf/dispatch [:wallet/select-send-account-address address])
(rf/dispatch [:navigate-to-within-stack
[:wallet-select-asset :wallet-select-address]]))}])

(def data
[{:id :tab/recent :label (i18n/label :t/recent) :accessibility-label :recent-tab}
{:id :tab/saved :label (i18n/label :t/saved) :accessibility-label :saved-tab}
{:id :tab/contacts :label (i18n/label :t/contacts) :accessibility-label :contacts-tab}
{:id :tab/my-accounts :label (i18n/label :t/my-accounts) :accessibility-label :my-accounts-tab}])

(defn my-accounts
[]
(let [other-accounts (rf/sub [:wallet/accounts-without-current-viewing-account])]
(if (zero? (count other-accounts))
[quo/empty-state
{:title (i18n/label :t/no-other-accounts)
:description (i18n/label :t/here-is-a-cat-in-a-box-instead)
:placeholder? true
:container-style style/empty-container-style}]
[gesture/flat-list
{:data other-accounts
:render-fn render-account-item
:content-container-style style/my-accounts-container
:shows-vertical-scroll-indicator false}])))

(defn view
[selected-tab]
(case selected-tab
:tab/recent [quo/empty-state
{:title (i18n/label :t/no-recent-transactions)
:description (i18n/label :t/make-one-it-is-easy-we-promise)
:placeholder? true
:container-style style/empty-container-style}]
:tab/saved [quo/empty-state
{:title (i18n/label :t/no-saved-addresses)
:description (i18n/label :t/you-like-to-type-43-characters)
:placeholder? true
:container-style style/empty-container-style}]
:tab/contacts [quo/empty-state
{:title (i18n/label :t/no-contacts)
:description (i18n/label :t/no-contacts-description)
:placeholder? true
:container-style style/empty-container-style}]
:tab/my-accounts [my-accounts]))
48 changes: 12 additions & 36 deletions src/status_im2/contexts/wallet/send/select_address/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,23 @@
(:require
[quo.core :as quo]
[quo.foundations.colors :as colors]
[quo.theme :as quo.theme]
[react-native.core :as rn]
[reagent.core :as reagent]
[status-im2.constants :as constants]
[status-im2.contexts.wallet.common.account-switcher.view :as account-switcher]
[status-im2.contexts.wallet.item-types :as types]
[status-im2.contexts.wallet.send.select-address.style :as style]
[status-im2.contexts.wallet.send.select-address.tabs.view :as tabs]
[utils.debounce :as debounce]
[utils.i18n :as i18n]
[utils.re-frame :as rf]))

(def tabs-data
(def ^:private tabs-data
[{:id :tab/recent :label (i18n/label :t/recent) :accessibility-label :recent-tab}
{:id :tab/saved :label (i18n/label :t/saved) :accessibility-label :saved-tab}
{:id :tab/contacts :label (i18n/label :t/contacts) :accessibility-label :contacts-tab}
{:id :tab/my-accounts :label (i18n/label :t/my-accounts) :accessibility-label :my-accounts-tab}])

(defn- tab-view
[selected-tab]
(case selected-tab
:tab/recent [quo/empty-state
{:title (i18n/label :t/no-recent-transactions)
:description (i18n/label :t/make-one-it-is-easy-we-promise)
:placeholder? true
:container-style style/empty-container-style}]
:tab/saved [quo/empty-state
{:title (i18n/label :t/no-saved-addresses)
:description (i18n/label :t/you-like-to-type-43-characters)
:placeholder? true
:container-style style/empty-container-style}]
:tab/contacts [quo/empty-state
{:title (i18n/label :t/no-contacts)
:description (i18n/label :t/no-contacts-description)
:placeholder? true
:container-style style/empty-container-style}]
:tab/my-accounts [quo/empty-state
{:title (i18n/label :t/no-other-accounts)
:description (i18n/label :t/here-is-a-cat-in-a-box-instead)
:placeholder? true
:container-style style/empty-container-style}]))

(defn- address-input
[input-value input-focused?]
(fn []
Expand Down Expand Up @@ -131,18 +107,19 @@
:keyboard-should-persist-taps :handled
:render-fn suggestion-component}]])))

(defn- f-view-internal
(defn- f-view
[]
(let [selected-tab (reagent/atom (:id (first tabs-data)))
on-close (fn []
(let [on-close (fn []
(rf/dispatch [:wallet/clean-scanned-address])
(rf/dispatch [:wallet/clean-local-suggestions])
(rf/dispatch [:wallet/select-address-tab nil])
(rf/dispatch [:navigate-back]))
on-change-tab #(reset! selected-tab %)
on-change-tab #(rf/dispatch [:wallet/select-address-tab %])
input-value (reagent/atom "")
input-focused? (reagent/atom false)]
(fn []
(let [valid-ens-or-address? (boolean (rf/sub [:wallet/valid-ens-or-address?]))]
(let [selected-tab (or (rf/sub [:wallet/send-tab]) (:id (first tabs-data)))
valid-ens-or-address? (boolean (rf/sub [:wallet/valid-ens-or-address?]))]
(rn/use-effect (fn []
(fn []
(rf/dispatch [:wallet/clean-scanned-address])
Expand Down Expand Up @@ -179,15 +156,14 @@
{:style style/tabs
:container-style style/tabs-content
:size 32
:default-active @selected-tab
:default-active selected-tab
:data tabs-data
:scrollable? true
:scroll-on-press? true
:on-change on-change-tab}]
[tab-view @selected-tab]])]))))
[tabs/view selected-tab]])]))))

(defn- view-internal
(defn view
[]
[:f> f-view-internal])
[:f> f-view])

(def view (quo.theme/with-theme view-internal))
1 change: 1 addition & 0 deletions src/status_im2/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
status-im2.contexts.shell.share.events
status-im2.contexts.syncing.events
status-im2.contexts.wallet.events
status-im2.contexts.wallet.send.events
[status-im2.db :as db]
[utils.re-frame :as rf]))

Expand Down
1 change: 1 addition & 0 deletions src/status_im2/subs/root.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
status-im2.subs.shell
status-im2.subs.wallet.collectibles
status-im2.subs.wallet.networks
status-im2.subs.wallet.send
status-im2.subs.wallet.wallet))

(defn reg-root-key-sub
Expand Down
10 changes: 10 additions & 0 deletions src/status_im2/subs/wallet/send.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(ns status-im2.subs.wallet.send
(:require
[re-frame.core :as rf]
[utils.number]))

(rf/reg-sub
:wallet/send-tab
:<- [:wallet/ui]
(fn [ui]
(get-in ui [:send :select-address-tab])))
14 changes: 14 additions & 0 deletions src/status_im2/subs/wallet/send_test.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
(ns status-im2.subs.wallet.send-test
(:require
[cljs.test :refer [is testing]]
[re-frame.db :as rf-db]
status-im2.subs.root
status-im2.subs.wallet.send
[test-helpers.unit :as h]
[utils.re-frame :as rf]))

(h/deftest-sub :wallet/send-tab
[sub-name]
(testing "returns active tab for selecting address"
(swap! rf-db/app-db assoc-in [:wallet :ui :send :select-address-tab] :tabs/recent)
(is (= :tabs/recent (rf/sub [sub-name])))))
1 change: 0 additions & 1 deletion src/status_im2/subs/wallet/wallet_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@
#(-> %
(assoc-in [:wallet :accounts] accounts)
(assoc-in [:wallet :current-viewing-account-address] "0x1")))

(is
(= (set ["0x1" "0x2"])
(rf/sub [sub-name])))))
Expand Down

0 comments on commit a01a5d5

Please sign in to comment.