Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wallet: suggested routes list #18388

Merged
merged 14 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
nil))

(defn view
[{:keys [on-press accessibility-label icon-name switcher-type]
[{:keys [on-press accessibility-label icon-name switcher-type margin-top]
:or {icon-name :i/close
accessibility-label :top-bar
switcher-type :account-options}}]
(let [{:keys [color emoji watch-only?]} (rf/sub [:wallet/current-viewing-account])
networks (rf/sub [:wallet/network-details])]
[quo/page-nav
{:icon-name icon-name
:margin-top margin-top
:background :blur
:on-press on-press
:accessibility-label accessibility-label
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
:removed false}
:wallet/wallet-send-token {:symbol :eth}
:wallet/wallet-send-loading-suggested-routes? false
:wallet/wallet-send-route {:route []}})
:wallet/wallet-send-route {:route []}
:wallet/wallet-send-suggested-routes {:candidates []}})

(h/describe "Send > input amount screen"
(h/setup-restorable-re-frame)
Expand Down
44 changes: 15 additions & 29 deletions src/status_im/contexts/wallet/send/input_amount/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
[react-native.safe-area :as safe-area]
[reagent.core :as reagent]
[status-im.contexts.wallet.common.account-switcher.view :as account-switcher]
[status-im.contexts.wallet.common.utils :as utils]
[status-im.contexts.wallet.send.input-amount.style :as style]
[status-im.contexts.wallet.send.routes.view :as routes]
[utils.debounce :as debounce]
Expand Down Expand Up @@ -58,7 +57,6 @@
[{:keys [rate limit]}]
(let [bottom (safe-area/get-bottom)
{:keys [currency]} (rf/sub [:profile/profile])
networks (rf/sub [:wallet/network-details])
token (rf/sub [:wallet/wallet-send-token])
loading-suggested-routes? (rf/sub [:wallet/wallet-send-loading-suggested-routes?])
token-symbol (:symbol token)
Expand Down Expand Up @@ -101,18 +99,16 @@
:or {on-confirm #(rf/dispatch [:wallet/send-select-amount
{:amount @input-value
:stack-id :wallet-send-input-amount}])}}]
(let [limit-label (make-limit-label @current-limit)
input-num-value (parse-double @input-value)
route (rf/sub [:wallet/wallet-send-route])
loading-suggested-routes? (rf/sub [:wallet/wallet-send-loading-suggested-routes?])
confirm-disabled? (or
(nil? route)
(empty? @input-value)
(<= input-num-value 0)
(> input-num-value (:amount @current-limit)))
from-network (utils/id->network (get-in route [:From :chainId]))
to-network (utils/id->network (get-in route [:To :chainId]))
amount (str @input-value " " token-symbol)]
(let [limit-label (make-limit-label @current-limit)
input-num-value (parse-double @input-value)
suggested-routes (rf/sub [:wallet/wallet-send-suggested-routes])
route (rf/sub [:wallet/wallet-send-route])
confirm-disabled? (or
(nil? route)
(empty? @input-value)
(<= input-num-value 0)
(> input-num-value (:amount @current-limit)))
amount (str @input-value " " token-symbol)]
(rn/use-effect
(fn []
(let [dismiss-keyboard-fn #(when (= % "active") (rn/dismiss-keyboard!))
Expand All @@ -137,28 +133,18 @@
{:container-style style/input-container
:token token-symbol
:currency currency
:networks networks
:networks (:networks token)
:title (i18n/label :t/send-limit {:limit limit-label})
:conversion conversion-rate
:show-keyboard? false
:value @input-value
:on-swap handle-swap
:on-change-text (fn [text]
(handle-on-change text))}]
;; Network routing content to be added
[rn/scroll-view
{:content-container-style {:flex-grow 1
:align-items :center
:justify-content :center}}
(cond loading-suggested-routes?
[quo/text "Loading routes"]
(and (not loading-suggested-routes?) route)
[routes/view
{:amount amount
:from-network from-network
:to-network to-network}]
(and (not loading-suggested-routes?) (nil? route))
[quo/text "Route not found"])]
[routes/view
{:amount amount
:routes suggested-routes
:networks (:networks token)}]
[quo/bottom-actions
{:actions :1-action
:button-one-label (i18n/label :t/confirm)
Expand Down
6 changes: 6 additions & 0 deletions src/status_im/contexts/wallet/send/routes/style.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

(def routes-container
{:padding-horizontal 20
:flex 1
:padding-vertical 16
:width "100%"
:height "100%"})
Expand All @@ -24,3 +25,8 @@
(def network-link
{:right 6
:z-index 1})

(def empty-container
{:flex-grow 1
:align-items :center
:justify-content :center})
72 changes: 47 additions & 25 deletions src/status_im/contexts/wallet/send/routes/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,53 @@
(:require
[quo.core :as quo]
[react-native.core :as rn]
[status-im.contexts.wallet.common.utils :as utils]
[status-im.contexts.wallet.send.routes.style :as style]
[utils.i18n :as i18n]))
[utils.i18n :as i18n]
[utils.re-frame :as rf]))

(defn route-item
[{:keys [amount from-network to-network status]}]
[rn/view {:style style/routes-inner-container}
[quo/network-bridge
{:amount amount
:network from-network
:status status}]
[quo/network-link
{:shape :linear
:source from-network
:destination to-network
:container-style style/network-link}]
[quo/network-bridge
{:amount amount
:network to-network
:status status
:container-style {:right 12}}]])

(defn view
[{:keys [amount from-network to-network]}]
[rn/view {:style style/routes-container}
[rn/view {:style style/routes-header-container}
[quo/section-label
{:section (i18n/label :t/from-label)
:container-style (style/section-label 0)}]
[quo/section-label
{:section (i18n/label :t/to-label)
:container-style (style/section-label 64)}]]
[rn/view {:style style/routes-inner-container}
[quo/network-bridge
{:amount amount
:network from-network
:status :default}]
[quo/network-link
{:shape :linear
:source from-network
:destination to-network
:container-style style/network-link}]
[quo/network-bridge
{:amount amount
:network to-network
:status :default
:container-style {:right 12}}]]])
[{:keys [amount routes]}]
(let [loading-suggested-routes? (rf/sub [:wallet/wallet-send-loading-suggested-routes?])
candidates (:candidates routes)]
(if (and (not loading-suggested-routes?) (not-empty candidates))
[rn/flat-list
{:data candidates
:content-container-style style/routes-container
:header [rn/view {:style style/routes-header-container}
[quo/section-label
{:section (i18n/label :t/from-label)
:container-style (style/section-label 0)}]
[quo/section-label
{:section (i18n/label :t/to-label)
:container-style (style/section-label 64)}]]
:render-fn (fn [route]
[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]))}])}]
[rn/view {:style style/empty-container}
(if loading-suggested-routes?
[rn/activity-indicator]
OmarBasem marked this conversation as resolved.
Show resolved Hide resolved
(when (not (nil? candidates))
[quo/text (i18n/label :t/no-routes-found)]))])))
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@

(def button
{:justify-self :flex-end
:margin-bottom 46
:margin-bottom 20
:margin-horizontal 20})
36 changes: 17 additions & 19 deletions src/status_im/contexts/wallet/send/select_address/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
[quo.core :as quo]
[quo.foundations.colors :as colors]
[react-native.core :as rn]
[react-native.safe-area :as safe-area]
[reagent.core :as reagent]
[status-im.common.floating-button-page.view :as floating-button-page]
[status-im.constants :as constants]
[status-im.contexts.wallet.common.account-switcher.view :as account-switcher]
[status-im.contexts.wallet.item-types :as types]
Expand Down Expand Up @@ -127,13 +129,20 @@
(fn []
(rf/dispatch [:wallet/clean-scanned-address])
(rf/dispatch [:wallet/clean-local-suggestions]))))
[rn/scroll-view
{:content-container-style style/container
:keyboard-should-persist-taps :handled
:scroll-enabled false}
[account-switcher/view
{:on-press on-close
:switcher-type :select-account}]
[floating-button-page/view
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@OmarBasem just to check for feedback, this component was working alright etc? does it need any updates etc?

Copy link
Contributor Author

@OmarBasem OmarBasem Jan 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@J-Son89 it is working fine. Just one thing, why are we not using insets from navigation instead of having to apply margin-top https://github.com/status-im/status-mobile/pull/18388/files#diff-1fc8418ccf535f4dd924ee5e62463e5359e24b383c052afc4ab39d40c645d465R22-R24

{:header [account-switcher/view
{:on-press on-close
:margin-top (safe-area/get-top)
:switcher-type :select-account}]
:footer (when (> (count @input-value) 0)
[quo/button
{:accessibility-label :continue-button
:type :primary
:disabled? (not valid-ens-or-address?)
:on-press #(rf/dispatch [:wallet/select-send-address
{:address @input-value
:stack-id :wallet-select-address}])}
(i18n/label :t/continue)])}
[quo/text-combinations
{:title (i18n/label :t/send-to)
:container-style style/title-container
Expand All @@ -147,17 +156,7 @@
[rn/view
{:style {:flex 1
:padding 8}}
[local-suggestions-list]]
(when (> (count @input-value) 0)
[quo/button
{:accessibility-label :continue-button
:type :primary
:disabled? (not valid-ens-or-address?)
:container-style style/button
:on-press #(rf/dispatch [:wallet/select-send-address
{:address @input-value
:stack-id :wallet-select-address}])}
(i18n/label :t/continue)])]
[local-suggestions-list]]]
[:<>
[quo/tabs
{:style style/tabs
Expand All @@ -173,4 +172,3 @@
(defn view
[]
[:f> f-view])

3 changes: 2 additions & 1 deletion src/status_im/navigation/screens.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,8 @@

{:name :wallet-send-input-amount
:options {:modalPresentationStyle :overCurrentContext
:insets {:top? true}}
:insets {:top? true
:bottom? true}}
:component wallet-send-input-amount/view}

{:name :wallet-select-address
Expand Down
5 changes: 5 additions & 0 deletions src/status_im/subs/wallet/wallet.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@
:<- [:wallet/wallet-send]
:-> :loading-suggested-routes?)

(rf/reg-sub
:wallet/wallet-send-suggested-routes
:<- [:wallet/wallet-send]
:-> :suggested-routes)

(rf/reg-sub
:wallet/watch-address-activity-state
:<- [:wallet/ui]
Expand Down
3 changes: 2 additions & 1 deletion translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2457,5 +2457,6 @@
"to-label": "To",
"oops-wrong-word": "Oops! Wrong word",
"time-in-mins": "{{minutes}} min",
"amount-with-currency-symbol": "{{symbol}} {{amount}}"
"amount-with-currency-symbol": "{{symbol}} {{amount}}",
"no-routes-found": "No routes found"
}