Bottom sheet with save and send options not displayed after scanning wallet QR using universal scanner #18928 (#19250)

This commit is contained in:
mmilad75 2024-04-03 15:57:46 +01:00 committed by GitHub
parent df0e9313da
commit b0d2e6e5d7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
22 changed files with 200 additions and 95 deletions

View File

@ -22,6 +22,13 @@
(h/is-truthy (h/get-by-text "Title")) (h/is-truthy (h/get-by-text "Title"))
(h/is-truthy (h/get-by-text "Description"))) (h/is-truthy (h/get-by-text "Description")))
(h/test "component renders in address type"
(h/render-with-theme-provider [quo/drawer-top
{:title "0x1"
:type :address}]
theme)
(h/is-truthy (h/get-by-text "0x1")))
(h/test "component renders in info type" (h/test "component renders in info type"
(h/render-with-theme-provider [quo/drawer-top (h/render-with-theme-provider [quo/drawer-top
{:title "Title" {:title "Title"

View File

@ -168,11 +168,16 @@
(defn- left-title (defn- left-title
[{:keys [type label title title-icon theme blur?]}] [{:keys [type label title title-icon theme blur?]}]
(case type (case type
:label [text/text :label [text/text
{:weight :medium {:weight :medium
:size :paragraph-2 :size :paragraph-2
:style (style/description theme blur?)} :style (style/description theme blur?)}
label] label]
:address [address-text/view
{:address title
:full-address? true
:weight :semi-bold
:size :heading-2}]
[rn/view {:style style/title-container} [rn/view {:style style/title-container}
[text/text [text/text
{:size :heading-2 {:size :heading-2

View File

@ -4,7 +4,7 @@
[:=> [:=>
[:cat [:cat
[:map [:map
[:token :keyword] [:token [:or :string :keyword]]
[:label :string] [:label :string]
[:token-value :string] [:token-value :string]
[:fiat-value :string] [:fiat-value :string]

View File

@ -16,12 +16,6 @@
:padding-top 12 :padding-top 12
:padding-bottom 8}) :padding-bottom 8})
(def gradient-bg
{:position :absolute
:top 0
:left 0
:right 0})
;;; Header ;;; Header
(def header-container (def header-container
{:flex-direction :row {:flex-direction :row
@ -71,41 +65,5 @@
:justify-content :space-between :justify-content :space-between
:flex 1}) :flex 1})
;;; Dashed line
(def ^:private padding-for-divider (+ padding-horizontal 4))
(def ^:private dashed-line-width 2)
(def ^:private dashed-line-space 4)
(def dashed-line
{:flex-direction :row
:margin-left -1})
(def line
{:background-color colors/white-opa-20
:width dashed-line-width
:height 1})
(def line-space
{:width dashed-line-space
:height 1})
(defn number-lines-and-spaces-to-fill
[component-width]
(let [line-and-space-width (+ dashed-line-width dashed-line-space)
width-to-fill (- component-width (* 2 padding-for-divider))
number-of-lines (* (/ width-to-fill line-and-space-width) 2)]
(inc (int number-of-lines))))
(def ^:private get-network-full-name
{"eth" :ethereum
"opt" :optimism
"arb1" :arbitrum})
(defn network-short-name-text
[network-short-name]
{:color (-> network-short-name
(get-network-full-name :unknown)
(colors/resolve-color nil))})
(def watched-account-icon (def watched-account-icon
{:margin-left 4}) {:margin-left 4})

View File

@ -1,6 +1,5 @@
(ns quo.components.share.share-qr-code.view (ns quo.components.share.share-qr-code.view
(:require [clojure.set] (:require [clojure.set]
[clojure.string :as string]
[oops.core :as oops] [oops.core :as oops]
[quo.components.avatars.account-avatar.view :as account-avatar] [quo.components.avatars.account-avatar.view :as account-avatar]
[quo.components.avatars.user-avatar.view :as user-avatar] [quo.components.avatars.user-avatar.view :as user-avatar]
@ -13,6 +12,7 @@
[quo.components.share.share-qr-code.schema :as component-schema] [quo.components.share.share-qr-code.schema :as component-schema]
[quo.components.share.share-qr-code.style :as style] [quo.components.share.share-qr-code.style :as style]
[quo.components.tabs.tab.view :as tab] [quo.components.tabs.tab.view :as tab]
[quo.components.wallet.address-text.view :as address-text]
[quo.foundations.colors :as colors] [quo.foundations.colors :as colors]
[quo.theme] [quo.theme]
[react-native.core :as rn] [react-native.core :as rn]
@ -74,21 +74,6 @@
:on-press on-press} :on-press on-press}
:i/share]]) :i/share]])
(defn- network-colored-text
[network-short-name]
[text/text {:style (style/network-short-name-text network-short-name)}
(str network-short-name ":")])
(defn- wallet-multichain-colored-address
[full-address]
(let [[networks address] (as-> full-address $
(string/split $ ":")
[(butlast $) (last $)])
->network-hiccup-xf (map #(vector network-colored-text %))]
(as-> networks $
(into [:<>] ->network-hiccup-xf $)
(conj $ address))))
(defn- profile-bottom (defn- profile-bottom
[{:keys [component-width qr-data on-text-press on-text-long-press share-qr-type]}] [{:keys [component-width qr-data on-text-press on-text-long-press share-qr-type]}]
[rn/view [rn/view
@ -116,7 +101,11 @@
{:width component-width {:width component-width
:on-press on-text-press :on-press on-text-press
:on-long-press on-text-long-press} :on-long-press on-text-long-press}
[wallet-multichain-colored-address qr-data]] [address-text/view
{:address qr-data
:full-address? true
:weight :regular
:size :paragraph-1}]]
[button/button [button/button
{:icon-only? true {:icon-only? true
:type :grey :type :grey

View File

@ -10,5 +10,10 @@
[:format {:optional true} [:enum :short :long]] [:format {:optional true} [:enum :short :long]]
[:theme :schema.common/theme] [:theme :schema.common/theme]
[:networks {:optional true} [:networks {:optional true}
[:maybe [:sequential [:map [:network-name :keyword] [:short-name :string]]]]]]]] [:maybe [:sequential [:map [:network-name :keyword] [:short-name :string]]]]]
[:full-address? {:optional true} [:maybe :boolean]]
;; TODO: size and weight are text schemas and should be imported here
;; https://github.com/status-im/status-mobile/issues/19443
[:size {:optional true} [:maybe :keyword]]
[:weight {:optional true} [:maybe :keyword]]]]]
:any]) :any])

View File

@ -1,5 +1,6 @@
(ns quo.components.wallet.address-text.view (ns quo.components.wallet.address-text.view
(:require [quo.components.markdown.text :as text] (:require [clojure.string :as string]
[quo.components.markdown.text :as text]
[quo.components.wallet.address-text.schema :as component-schema] [quo.components.wallet.address-text.schema :as component-schema]
[quo.components.wallet.address-text.style :as style] [quo.components.wallet.address-text.style :as style]
[quo.foundations.colors :as colors] [quo.foundations.colors :as colors]
@ -8,27 +9,39 @@
[utils.address :as utils])) [utils.address :as utils]))
(defn- colored-network-text (defn- colored-network-text
[theme network] [{:keys [theme network size weight]}]
(let [{:keys [network-name short-name]} network] [text/text
[text/text {:size size
{:size :paragraph-2 :weight weight
:style {:color (colors/resolve-color network-name theme)}} :style {:color (colors/resolve-color (keyword network) theme)}}
(str short-name ":")])) (str network ":")])
(defn- view-internal (defn- view-internal
[{:keys [networks address blur? theme format]}] [{:keys [networks address blur? theme format full-address? size weight]
(let [network-text-xf (map #(colored-network-text theme %)) :or {size :paragraph-2}}]
address-text [text/text (let [network-colored-text (map #(colored-network-text {:theme theme
{:size :paragraph-2 :network %
;; TODO: monospace font :weight weight
;; https://github.com/status-im/status-mobile/issues/17009 :size size}))
:weight :monospace [splitted-networks splitted-address] (and full-address?
:style (style/address-text format blur? theme)} (as-> address $
(if (= format :short) (string/split $ ":")
(utils/get-short-wallet-address address) [(butlast $) (last $)]))
address)]] address-internal (if full-address? splitted-address address)
(as-> networks $ networks-internal (if full-address?
(into [text/text] network-text-xf $) splitted-networks
(map :short-name networks))
address-text [text/text
{:size size
;; TODO: monospace font
;; https://github.com/status-im/status-mobile/issues/17009
:weight (or weight :monospace)
:style (style/address-text format blur? theme)}
(if (= format :short)
(utils/get-short-wallet-address address-internal)
address-internal)]]
(as-> networks-internal $
(into [text/text] network-colored-text $)
(conj $ address-text)))) (conj $ address-text))))
(def view (def view

View File

@ -5,8 +5,8 @@
[:catn [:catn
[:props [:props
[:map [:map
[:token {:optional true} [:maybe :keyword]] [:token {:optional true} [:maybe :string :keyword]]
[:currency {:optional true} [:maybe :keyword]] [:currency {:optional true} [:maybe :string :keyword]]
[:error? {:optional true} [:maybe :boolean]] [:error? {:optional true} [:maybe :boolean]]
[:title {:optional true} [:maybe :string]] [:title {:optional true} [:maybe :string]]
[:conversion {:optional true} [:maybe :double]] [:conversion {:optional true} [:maybe :double]]

View File

@ -254,6 +254,17 @@
:polygon "#AD71F3" :polygon "#AD71F3"
:unknown "#EEF2F5"}) :unknown "#EEF2F5"})
(def ^:private get-network-full-name
{:eth :ethereum
:opt :optimism
:arb1 :arbitrum})
(def ^:private networks-short-name
(reduce (fn [acc [k v]]
(assoc acc k (get networks v)))
{}
get-network-full-name))
(def socials (def socials
{:social/link "#647084" {:social/link "#647084"
:social/facebook "#1877F2" :social/facebook "#1877F2"
@ -294,6 +305,7 @@
60 warning-60}} 60 warning-60}}
customization customization
networks networks
networks-short-name
socials)) socials))
(defn hex-string? (defn hex-string?

View File

@ -0,0 +1,10 @@
(ns status-im.contexts.shell.qr-reader.events
(:require
[status-im.contexts.shell.qr-reader.sheets.scanned-wallet-address :as scanned-address]
[utils.re-frame :as rf]))
(rf/reg-event-fx
:generic-scanner/scan-success
(fn [_ [address]]
{:fx [[:dispatch [:navigate-back]]
[:dispatch [:show-bottom-sheet {:content #(scanned-address/view address)}]]]}))

View File

@ -0,0 +1,26 @@
(ns status-im.contexts.shell.qr-reader.sheets.scanned-wallet-address
(:require
[quo.core :as quo]
[utils.i18n :as i18n]
[utils.re-frame :as rf]))
(defn view
[address]
[:<>
[quo/drawer-top
{:title address
:type :address}]
[quo/action-drawer
[[{:icon :i/send
:accessibility-label :send-asset
:label (i18n/label :t/send-to-this-address)
:on-press (fn []
(rf/dispatch [:wallet/select-send-address
{:address address
:recipient address
:stack-id :wallet-select-address
:start-flow? true}]))}
{:icon :i/save
:accessibility-label :save-address
:label (i18n/label :t/save-address)
:on-press #(js/alert "feature not implemented")}]]]])

View File

@ -88,7 +88,9 @@
(load-and-show-profile scanned-text) (load-and-show-profile scanned-text)
(eth-address? scanned-text) (eth-address? scanned-text)
(debounce/debounce-and-dispatch [:navigate-to :screen/wallet.accounts scanned-text] 300) (do
(debounce/debounce-and-dispatch [:generic-scanner/scan-success scanned-text] 300)
(debounce/debounce-and-dispatch [:navigate-change-tab :wallet-stack] 300))
(eip681-address? scanned-text) (eip681-address? scanned-text)
(do (do

View File

@ -16,7 +16,7 @@
:label (:name token) :label (:name token)
:token-value (str crypto-formatted " " (:symbol token)) :token-value (str crypto-formatted " " (:symbol token))
:fiat-value fiat-formatted :fiat-value fiat-formatted
:networks (:networks token) :networks (seq (:networks token))
:on-press #(on-token-press token)}])) :on-press #(on-token-press token)}]))
(defn view (defn view

View File

@ -43,10 +43,14 @@
(fn [{:keys [db]} [address]] (fn [{:keys [db]} [address]]
{:db (assoc-in db [:wallet :current-viewing-account-address] address)})) {:db (assoc-in db [:wallet :current-viewing-account-address] address)}))
(rf/reg-event-fx :wallet/close-account-page (rf/reg-event-fx :wallet/clean-current-viewing-account
(fn [{:keys [db]}] (fn [{:keys [db]}]
{:db (update db :wallet dissoc :current-viewing-account-address) {:db (update db :wallet dissoc :current-viewing-account-address)}))
:fx [[:dispatch [:pop-to-root :shell-stack]]]}))
(rf/reg-event-fx :wallet/close-account-page
(fn [_]
{:fx [[:dispatch [:wallet/clean-current-viewing-account]]
[:dispatch [:pop-to-root :shell-stack]]]}))
(rf/reg-event-fx (rf/reg-event-fx
:wallet/get-accounts-success :wallet/get-accounts-success

View File

@ -357,3 +357,13 @@
{:id :send-transaction-error {:id :send-transaction-error
:type :negative :type :negative
:text (:message error)}]))}]}))) :text (:message error)}]))}]})))
(rf/reg-event-fx
:wallet/select-from-account
(fn [_ [{:keys [address stack-id start-flow?]}]]
{:fx [[:dispatch [:wallet/switch-current-viewing-account address]]
[:dispatch
[:wallet/wizard-navigate-forward
{:current-screen stack-id
:start-flow? start-flow?
:flow-id :wallet-flow}]]]}))

View File

@ -1,7 +1,9 @@
(ns status-im.contexts.wallet.send.flow-config) (ns status-im.contexts.wallet.send.flow-config)
(def steps (def steps
[{:screen-id :screen/wallet.select-address [{:screen-id :screen/wallet.select-from
:skip-step? (fn [db] (some? (get-in db [:wallet :current-viewing-account-address])))}
{:screen-id :screen/wallet.select-address
:skip-step? (fn [db] (some? (get-in db [:wallet :ui :send :recipient])))} :skip-step? (fn [db] (some? (get-in db [:wallet :ui :send :recipient])))}
{:screen-id :screen/wallet.select-asset {:screen-id :screen/wallet.select-asset
:skip-step? (fn [db] (some? (get-in db [:wallet :ui :send :token])))} :skip-step? (fn [db] (some? (get-in db [:wallet :ui :send :token])))}

View File

@ -0,0 +1,7 @@
(ns status-im.contexts.wallet.send.from.style)
(def accounts-list
{:padding-bottom 12})
(def accounts-list-container
{:padding-horizontal 8})

View File

@ -0,0 +1,47 @@
(ns status-im.contexts.wallet.send.from.view
(:require
[quo.core :as quo]
[react-native.core :as rn]
[react-native.safe-area :as safe-area]
[status-im.common.floating-button-page.view :as floating-button-page]
[status-im.contexts.wallet.common.account-switcher.view :as account-switcher]
[status-im.contexts.wallet.send.from.style :as style]
[utils.i18n :as i18n]
[utils.re-frame :as rf]))
(defn- on-press
[address]
(rf/dispatch [:wallet/select-from-account
{:address address
:stack-id :screen/wallet.select-from}]))
(defn- on-close
[]
(rf/dispatch [:wallet/clean-current-viewing-account])
(rf/dispatch [:navigate-back]))
(defn- render-fn
[item]
[quo/account-item
{:on-press #(on-press (:address item))
:account-props item}])
(defn view
[]
(let [accounts (rf/sub [:wallet/accounts-without-watched-accounts])]
[floating-button-page/view
{:footer-container-padding 0
:header [account-switcher/view
{:on-press on-close
:margin-top (safe-area/get-top)
:switcher-type :select-account}]}
[quo/page-top
{:title (i18n/label :t/from-label)
:title-accessibility-label :title-label}]
[rn/flat-list
{:style style/accounts-list
:content-container-style style/accounts-list-container
:data accounts
:render-fn render-fn
:shows-horizontal-scroll-indicator false}]]))

View File

@ -265,7 +265,7 @@
:currency current-currency :currency current-currency
:crypto-decimals crypto-decimals :crypto-decimals crypto-decimals
:error? @input-error :error? @input-error
:networks token-networks :networks (seq token-networks)
:title (i18n/label :t/send-limit {:limit limit-label}) :title (i18n/label :t/send-limit {:limit limit-label})
:conversion conversion-rate :conversion conversion-rate
:show-keyboard? false :show-keyboard? false

View File

@ -26,6 +26,7 @@
status-im.contexts.onboarding.events status-im.contexts.onboarding.events
status-im.contexts.profile.events status-im.contexts.profile.events
status-im.contexts.profile.settings.events status-im.contexts.profile.settings.events
status-im.contexts.shell.qr-reader.events
status-im.contexts.shell.share.events status-im.contexts.shell.share.events
status-im.contexts.syncing.events status-im.contexts.syncing.events
status-im.contexts.wallet.common.wizard status-im.contexts.wallet.common.wizard

View File

@ -74,6 +74,7 @@
[status-im.contexts.wallet.create-account.new-keypair.keypair-name.view :as wallet-keypair-name] [status-im.contexts.wallet.create-account.new-keypair.keypair-name.view :as wallet-keypair-name]
[status-im.contexts.wallet.create-account.select-keypair.view :as wallet-select-keypair] [status-im.contexts.wallet.create-account.select-keypair.view :as wallet-select-keypair]
[status-im.contexts.wallet.create-account.view :as wallet-create-account] [status-im.contexts.wallet.create-account.view :as wallet-create-account]
[status-im.contexts.wallet.send.from.view :as wallet-select-from]
[status-im.contexts.wallet.send.save-address.view :as wallet-save-address] [status-im.contexts.wallet.send.save-address.view :as wallet-save-address]
[status-im.contexts.wallet.send.select-address.view :as wallet-select-address] [status-im.contexts.wallet.send.select-address.view :as wallet-select-address]
[status-im.contexts.wallet.send.select-asset.view :as wallet-select-asset] [status-im.contexts.wallet.send.select-asset.view :as wallet-select-asset]
@ -418,6 +419,11 @@
:insets {:top? true}} :insets {:top? true}}
:component wallet-select-address/view} :component wallet-select-address/view}
{:name :screen/wallet.select-from
:options {:modalPresentationStyle :overCurrentContext
:insets {:top? true}}
:component wallet-select-from/view}
{:name :screen/wallet.select-asset {:name :screen/wallet.select-asset
:options {:insets {:top? true}} :options {:insets {:top? true}}
:component wallet-select-asset/view} :component wallet-select-asset/view}

View File

@ -2558,6 +2558,7 @@
"keep-key": "KeepKey", "keep-key": "KeepKey",
"type-your-path": "Type your own derivation path", "type-your-path": "Type your own derivation path",
"default-format": "Default format", "default-format": "Default format",
"send-to-this-address": "Send to this address",
"address-count": { "address-count": {
"one": "1 address", "one": "1 address",
"other": "{{count}} addresses" "other": "{{count}} addresses"