Wallet: suggested routes list (#18388)

* wallet: suggested routes list
This commit is contained in:
Omar Basem 2024-01-09 15:12:11 +04:00 committed by GitHub
parent 3ff6013127
commit 504d92fd57
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 99 additions and 78 deletions

View File

@ -13,7 +13,7 @@
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}}]
@ -21,6 +21,7 @@
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

View File

@ -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)

View File

@ -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]
@ -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)
@ -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!))
@ -137,7 +133,7 @@
{: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
@ -145,20 +141,10 @@
: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)

View File

@ -2,6 +2,7 @@
(def routes-container
{:padding-horizontal 20
:flex 1
:padding-vertical 16
:width "100%"
:height "100%"})
@ -24,3 +25,8 @@
(def network-link
{:right 6
:z-index 1})
(def empty-container
{:flex-grow 1
:align-items :center
:justify-content :center})

View File

@ -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]
(when (not (nil? candidates))
[quo/text (i18n/label :t/no-routes-found)]))])))

View File

@ -17,5 +17,5 @@
(def button
{:justify-self :flex-end
:margin-bottom 46
:margin-bottom 20
:margin-horizontal 20})

View File

@ -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]
@ -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
{: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
@ -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
@ -173,4 +172,3 @@
(defn view
[]
[:f> f-view])

View File

@ -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

View File

@ -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]

View File

@ -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"
}