Skip to content

Commit

Permalink
logic and UI for receiver preferences
Browse files Browse the repository at this point in the history
  • Loading branch information
briansztamfater committed May 9, 2024
1 parent 00ed746 commit 7435066
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 30 deletions.
42 changes: 32 additions & 10 deletions src/status_im/contexts/wallet/send/routes/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -101,21 +101,43 @@
(defn- open-preferences
[]
(let [receiver-networks (rf/sub [:wallet/wallet-send-receiver-networks])
receiver-preferred-networks (rf/sub [:wallet/wallet-send-receiver-preferred-networks])]
receiver-preferred-networks (rf/sub [:wallet/wallet-send-receiver-preferred-networks])
{token-symbol :symbol
token-networks :networks} (rf/sub [:wallet/wallet-send-token])
not-available-tokens (filter (fn [preferred-chain-id]
(not-any? (fn [token-chain-id]
(= preferred-chain-id token-chain-id))
token-networks))
receiver-preferred-networks)
warning-label (when (not-empty not-available-tokens)
(i18n/label
:t/token-not-available-on-networks
{:token-symbol token-symbol
:networks (->> not-available-tokens
(map network-utils/id->network)
(map name)
(map string/capitalize)
(string/join ", ")
(fn [s]
(string/replace s
#",\s([^,]+)$"
" and $1")))}))]
(rf/dispatch
[:show-bottom-sheet
{:content (fn []
[network-preferences/view
{:title (i18n/label :t/edit-receiver-networks)
:first-section-label (i18n/label :t/preferred-by-receiver)
:second-section-label (i18n/label :t/not-preferred-by-receiver)
:selected-networks (set (map network-utils/id->network receiver-networks))
{:title (i18n/label :t/edit-receiver-networks)
:first-section-label (i18n/label :t/preferred-by-receiver)
:second-section-label (i18n/label :t/not-preferred-by-receiver)
:selected-networks (set (map network-utils/id->network receiver-networks))
:receiver-preferred-networks receiver-preferred-networks
:button-label (i18n/label :t/apply)
:on-save (fn [chain-ids]
(rf/dispatch [:hide-bottom-sheet])
(rf/dispatch [:wallet/update-receiver-networks
chain-ids]))}])}])))
:button-label (i18n/label :t/apply)
:warning-label warning-label
:on-save
(fn [chain-ids]
(rf/dispatch [:hide-bottom-sheet])
(rf/dispatch [:wallet/update-receiver-networks
chain-ids]))}])}])))

(defn render-network-values
[{:keys [network-values token-symbol on-press to? loading-routes?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,22 @@
(def data-item
{:margin-horizontal 20
:margin-vertical 8})

(defn sending-to-unpreferred-networks-alert-container
[theme]
{:height 76
:flex-direction :row
:background-color (colors/resolve-color :blue theme 5)
:border-color (colors/resolve-color :blue theme 10)
:border-width 1
:border-radius 12
:margin-horizontal 20
:padding 10})

(def sending-to-unpreferred-networks-content-container
{:margin-left 8
:align-items :flex-start})

(def sending-to-unpreferred-networks-text
{:flex 1
:margin-left 8})
66 changes: 47 additions & 19 deletions src/status_im/contexts/wallet/sheets/network_preferences/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[quo.foundations.colors :as colors]
[quo.theme :as quo.theme]
[react-native.blur :as blur]
[react-native.core :as rn]
[reagent.core :as reagent]
[status-im.constants :as constants]
[status-im.contexts.wallet.common.utils :as utils]
Expand All @@ -12,7 +13,7 @@

(defn view
[{:keys [title first-section-label second-section-label selected-networks
receiver-preferred-networks account watch-only?]}]
warning-label receiver-preferred-networks account watch-only?]}]
(let [state (reagent/atom :default)
{:keys [color address
network-preferences-names]} (or account (rf/sub [:wallet/current-viewing-account]))
Expand All @@ -37,24 +38,28 @@
initial-network-preferences-names
@network-preferences-names-state))]
(fn [{:keys [on-save blur? button-label]}]
(let [theme (quo.theme/use-theme)
network-details (rf/sub [:wallet/network-details])
first-section-networks (filter (fn [network]
(if receiver-preferred-networks
(some (fn [chain-id]
(= (:chain-id network) chain-id))
receiver-preferred-networks)
(= (:network-name network) :mainnet)))
network-details)
second-section-networks (remove (fn [network]
(some (fn [chain-id]
(= (:chain-id network) chain-id))
(map :chain-id first-section-networks)))
network-details)
current-networks (filter (fn [network]
(contains? (get-current-preferences-names)
(:network-name network)))
network-details)]
(let [theme (quo.theme/use-theme)
network-details (rf/sub [:wallet/network-details])
first-section-networks (filter (fn [network]
(if receiver-preferred-networks
(some (fn [chain-id]
(= (:chain-id network) chain-id))
receiver-preferred-networks)
(= (:network-name network) :mainnet)))
network-details)
second-section-networks (remove (fn [network]
(some (fn [chain-id]
(= (:chain-id network) chain-id))
(map :chain-id first-section-networks)))
network-details)
current-networks (filter (fn [network]
(contains? (get-current-preferences-names)
(:network-name network)))
network-details)
sending-to-unpreferred-networks? (and receiver?
(some #(contains? @network-preferences-names-state
(:network-name %))
second-section-networks))]
[:<>
;; quo/overlay isn't compatible with sheets
(when blur?
Expand Down Expand Up @@ -101,6 +106,18 @@
:on-change #(toggle-network (:network-name
network))}))
first-section-networks)}]
(when warning-label
[rn/view
{:style {:flex-direction :row
:margin-horizontal 20}}
[quo/icon :i/alert
{:size 16
:color colors/danger-50}]
[quo/text
{:size :paragraph-2
:style {:margin-left 4
:color colors/danger-50}}
warning-label]])
(when (not-empty second-section-networks)
[quo/category
{:list-type :settings
Expand All @@ -115,6 +132,17 @@
:on-change #(toggle-network (:network-name
network))}))
second-section-networks)}])
(when sending-to-unpreferred-networks?
[rn/view {:style (style/sending-to-unpreferred-networks-alert-container theme)}
[rn/view
[quo/icon :i/alert
{:size 16
:color (colors/resolve-color :blue theme)
:style {:margin-top 2}}]]
[quo/text
{:style style/sending-to-unpreferred-networks-text
:size :paragraph-2}
(i18n/label :t/sending-to-networks-the-receiver-does-not-prefer)]])
[quo/bottom-actions
{:actions :one-action
:blur? blur?
Expand Down
4 changes: 3 additions & 1 deletion translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2615,5 +2615,7 @@
"status-is-a-secure-messaging-app": "Status is a secure messaging app, crypto wallet and web3 browser built with the state of the art technology",
"token-not-available-on-receiver-networks": "{{token-symbol}} is not available on the recipient’s desired networks. Proceed with caution.",
"add-networks-token-can-be-sent-to": "Add networks {{token-symbol}} can be sent to",
"not-available": "Not available"
"not-available": "Not available",
"token-not-available-on-networks": "{{token-symbol}} is not available on {{networks}}.",
"sending-to-networks-the-receiver-does-not-prefer": "Sending to networks the receiver does not prefer may result in recipient having difficulty accessing the sent tokens."
}

0 comments on commit 7435066

Please sign in to comment.