Skip to content

Commit

Permalink
Improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
ibrkhalil committed May 5, 2024
1 parent 3675056 commit eb7c1f3
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 16 deletions.
111 changes: 106 additions & 5 deletions src/status_im/contexts/settings/wallet/saved_addresses/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
[quo.foundations.colors :as colors]
[quo.theme :as quo.theme]
[react-native.core :as rn]
[react-native.platform :as platform]
[react-native.safe-area :as safe-area]
[status-im.common.resources :as resources]
[status-im.config :as config]
[status-im.contexts.settings.wallet.saved-addresses.style :as style]
[utils.i18n :as i18n]
[utils.re-frame :as rf]))
Expand All @@ -18,19 +20,118 @@
:image (resources/get-themed-image :sweating-man theme)
:container-style style/empty-container-style}]))

(defn- not-implemented
[]
(js/alert "Not implemented"))

(defn option
[{:keys [icon label on-press danger? sub-label add-divider? accessibility-label right-icon] :as opt}]
(when opt
^{:key label}
{:icon icon
:label label
:on-press on-press
:danger? danger?
:sub-label sub-label
:right-icon right-icon
:add-divider? add-divider?
:accessibility-label accessibility-label}))

(defn options
[account-name address]
[(when config/show-not-implemented-features?
{:icon :i/arrow-up
:label (i18n/label :t/send-to-user {:user account-name})
:on-press not-implemented
:accessibility-label :manage-notifications})
(when config/show-not-implemented-features?
{:icon :i/link
:right-icon :i/external
:label (i18n/label :t/view-address-on-website {:website "Etherscan"})
:on-press not-implemented
:accessibility-label :manage-notifications})
(when config/show-not-implemented-features?
{:icon :i/link
:right-icon :i/external
:label (i18n/label :t/view-address-on-website {:website "Optimistic"})
:on-press not-implemented
:accessibility-label :manage-notifications})
{:icon :i/share
:on-press #(rf/dispatch
[:open-share
{:options (if platform/ios?
{:activityItemSources [{:placeholderItem {:type :text
:content address}
:item {:default {:type :text
:content
address}}
:linkMetadata {:title address}}]}
{:title address
:subject address
:message address
:isNewTask true})}])
:label (i18n/label :t/share-address)
:accessibility-label :manage-notifications}
{:icon :i/qr-code
:label (i18n/label :t/show-address-qr)
:on-press (fn []
(rf/dispatch [:wallet/set-current-viewing-account address])
(rf/dispatch [:open-modal :screen/wallet.share-address {:status :share}]))
:accessibility-label :manage-notifications}
(when config/show-not-implemented-features?
{:icon :i/edit
:label (i18n/label :t/edit-account)
:on-press #(rf/dispatch [:navigate-to :screen/wallet.edit-account])
:accessibility-label :manage-notifications})
(when config/show-not-implemented-features?
{:icon :i/delete
:label (i18n/label :t/remove-account)
:on-press not-implemented
:danger? true
:accessibility-label :manage-notifications
:add-divider? true})])

(defn sample-options
[account-name address]
(keep option (options account-name address)))

(defn account-sheet
[address account-name]
[quo/action-drawer
[(sample-options account-name address)]])

(defn on-press-saved-address
[{:keys [address account-name ens-name customization-color]}]
(rf/dispatch
[:show-bottom-sheet
{:selected-item (fn []
[quo/saved-address
{:active-state? false
:user-props {:name account-name
:address address
:ens ens-name
:customization-color customization-color}}])
:content (fn []
[account-sheet
address account-name])}]))

(defn- saved-address
[{:keys [address colorId chainShortNames isTest]
address-name :name}]
[{:keys [address colorId _chain-short-names _test? ens?]
account-name :name}]
[quo/saved-address
{:user-props {:name address-name
{:on-press #(on-press-saved-address
{:account-name account-name
:address address
:ens-name (when ens? address)
:customization-color (keyword colorId)})
:user-props {:name account-name
:address address
:customization-color (keyword colorId)}}])

(defn header
[{:keys [title]}]
[quo/divider-label
{:container-style {:background-color :transparent
:border-top-color colors/white-opa-5
{:container-style {:border-top-color colors/white-opa-5
:margin-top 16}}
title])

Expand Down
12 changes: 9 additions & 3 deletions src/status_im/contexts/wallet/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,16 @@
:type :positive
:text (i18n/label :t/account-created {:name (:name account)})}]]]})))

(defn set-current-viewing-account
[{:keys [db]} [address]]
{:db (assoc-in db [:wallet :current-viewing-account-address] address)})

(rf/reg-event-fx :wallet/set-current-viewing-account set-current-viewing-account)

(rf/reg-event-fx :wallet/navigate-to-account
(fn [{:keys [db]} [address]]
{:db (assoc-in db [:wallet :current-viewing-account-address] address)
:fx [[:dispatch [:navigate-to :screen/wallet.accounts address]]]}))
(fn [_cofx [address]]
{:fx [[:dispatch [:wallet/set-current-viewing-account address]]
[:dispatch [:navigate-to :screen/wallet.accounts address]]]}))

(rf/reg-event-fx :wallet/navigate-to-new-account
(fn [{:keys [db]} [address]]
Expand Down
2 changes: 1 addition & 1 deletion src/status_im/contexts/wallet/save_address/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
(rf/reg-event-fx
:wallet/get-saved-addresses-success
(fn [{:keys [db]} [saved-addresses]]
{:db (assoc-in db [:wallet :saved-addresses] saved-addresses)}))
{:db (assoc-in db [:wallet :saved-addresses] (group-by :address saved-addresses))}))

(rf/reg-event-fx
:wallet/get-saved-addresses-error
Expand Down
16 changes: 9 additions & 7 deletions src/status_im/subs/wallet/saved_addresses.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,21 @@
:<- [:wallet]
:-> :saved-addresses)

(rf/reg-sub
:wallet/address-saved?
:<- [:wallet]
(fn [wallet [address]]
(some #(= address (:address %))
(:saved-addresses wallet))))

(rf/reg-sub
:wallet/grouped-saved-addresses
:<- [:wallet/saved-addresses]
(fn [saved-addresses]
(->> saved-addresses
vals
flatten
(group-by #(string/upper-case (first (:name %))))
(map (fn [[k v]]
{:title k
:data v})))))

(rf/reg-sub
:wallet/address-saved?
:<- [:wallet]
(fn [wallet [address]]
(some #(= address (:address %))
(:saved-addresses wallet))))
25 changes: 25 additions & 0 deletions src/status_im/subs/wallet/saved_addresses_test.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
(ns status-im.subs.wallet.saved-addresses-test
(:require [clojure.test :refer [is testing]]
[re-frame.db :as rf-db]
[test-helpers.unit :as h]
[utils.re-frame :as rf]))

(def saved-addresses-data
[{:address "0x0" :colorId "blue" :chainShortNames "eth:" :isTest false :name "Alice's address"}
{:address "0x1" :colorId "purple" :chainShortNames "eth:" :isTest false :name "Bob's address"}])

(def grouped-saved-addresses-data
[{:title "A"
:data
[{:address "0x0" :colorId "blue" :chainShortNames "eth:" :isTest false :name "Alice's address"}]}
{:title "B"
:data
[{:address "0x1" :colorId "purple" :chainShortNames "eth:" :isTest false :name "Bob's address"}]}])

(h/deftest-sub :wallet/grouped-saved-addresses
[sub-name]
(testing "returns data with prod"
(swap! rf-db/app-db assoc-in [:wallet :saved-addresses] saved-addresses-data)
(is
(= grouped-saved-addresses-data
(rf/sub [sub-name])))))

0 comments on commit eb7c1f3

Please sign in to comment.