Skip to content

Commit

Permalink
Implement transaction progress component (#17933)
Browse files Browse the repository at this point in the history
* copy codes

* refactor preview

* refactor deprecated codes in view

* change condition structure in view-internal

* comment unused codes

* refactor title

* fix title style

* fix icon style

* fix context tag

* fix icon and row

* refactor icon-internal

* rename network-state and network-type

* fix progress-container style

* fix progress-box-container style

* fix progress container naming and style

* change progress-bar component

* fix progress box component

* convert to functional component and bring back the animation

* fix progress box for arbitrum-optimism network

* fix text-steps

* fix status-row

* refactor code style

* refactor get-network-text

* resolve comment

* add translations

* remove btn-title prop

* fix dark mode border color

* fix dark mode icon color

* move interval to preview

* add tests ns

* add tests

* fix lint issues

* fix rendering issue

* fix lint issue

* add arbitrum and optimism as separate networks

* create const for progress percentage

* fix progress bar component and preview

* refactor text-steps

* refactor names

* fix lint issues

* rename arbitrum-progress-percentage and optimism-progress-percentage

* update tests

* convert hard-coded color to customization-color

* fix progress_bar tests

* separate state for each network

* add progress percentage for each network and refactor params of functions

* separate epoch number for  each network

* update tests

* fix lint issues

* refactor codes

* fix lint issues

* resolve comments

* add confirmation progress

* use confirmation-progress component in transaction-progress

* fix preview

* add tests

* fix lint issue

* resolve comment

* refactor networks

* change sending state style

* update tests

* fix lint issues

* remove unused code

* add helper for calculate counter step

* add assoc-props to view-networks

* change text-internal props order

* fix colors/resolve-color usage

* refactor view codes

* add get-networks to preview

* add max-value to progress bar style

* remove threading macros in the previews

* remove inline functional components in the previews

* remove optimism-arbitrum checks in the view

* fix lint issues

* add max-progress and min-progress to confirmation-progress

* refactor text-steps

* fix counter structure in transaction-progress

* fix counter structure in confirmation-progress

* fix resolve-color usage

* fix lint issue

* fix tests

* resolve comments

* fix color issue

* fix margins

* fix lint issue
  • Loading branch information
mmilad75 authored Dec 6, 2023
1 parent 7e14846 commit aaf0b8e
Show file tree
Hide file tree
Showing 18 changed files with 909 additions and 22 deletions.
Binary file added resources/images/icons2/16x16/diamond@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/images/icons2/16x16/diamond@3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
(ns quo.components.wallet.confirmation-progress.component-spec
(:require [quo.core :as quo]
[reagent.core :as reagent]
[test-helpers.component :as h]))

(defn- get-test-data
[{:keys [state network]
:or {state :pending network :mainnet}}]
{:counter (reagent/atom 0)
:total-box 85
:progress-value "10"
:network network
:state state
:customization-color :blue})

(h/describe "Confirmation Progress"
(h/test "component renders when state is sending and network is optimism"
(h/render [quo/confirmation-propgress
(get-test-data {:state :sending
:network :optimism})])
(h/is-truthy (h/get-by-label-text :progress-box)))

(h/test "component renders when state is confirmed and network is optimism"
(h/render [quo/confirmation-propgress
(get-test-data {:state :confirmed
:network :optimism})])
(h/is-truthy (h/get-by-label-text :progress-box)))

(h/test "component renders when state is finalising and network is optimism"
(h/render [quo/confirmation-propgress
(get-test-data {:state :finalising
:network :optimism})])
(h/is-truthy (h/get-by-label-text :progress-box)))

(h/test "component renders when state is finalized and network is optimism"
(h/render [quo/confirmation-propgress
(get-test-data {:state :finalized
:network :optimism})])
(h/is-truthy (h/get-by-label-text :progress-box)))

(h/test "component renders when state is error and network is optimism"
(h/render [quo/confirmation-propgress
(get-test-data {:state :error
:network :optimism})])
(h/is-truthy (h/get-by-label-text :progress-box)))

(h/test "component renders when state is sending and network is arbitrum"
(h/render [quo/confirmation-propgress
(get-test-data {:state :sending
:network :arbitrum})])
(h/is-truthy (h/get-by-label-text :progress-box)))

(h/test "component renders when state is confirmed and network is arbitrum"
(h/render [quo/confirmation-propgress
(get-test-data {:state :confirmed
:network :arbitrum})])
(h/is-truthy (h/get-by-label-text :progress-box)))

(h/test "component renders when state is finalising and network is arbitrum"
(h/render [quo/confirmation-propgress
(get-test-data {:state :finalising
:network :arbitrum})])
(h/is-truthy (h/get-by-label-text :progress-box)))

(h/test "component renders when state is finalized and network is arbitrum"
(h/render [quo/confirmation-propgress
(get-test-data {:state :finalized
:network :arbitrum})])
(h/is-truthy (h/get-by-label-text :progress-box)))

(h/test "component renders when state is error and network is arbitrum"
(h/render [quo/confirmation-propgress
(get-test-data {:state :error
:network :arbitrum})])
(h/is-truthy (h/get-by-label-text :progress-box)))

(h/test "component renders when state is pending and network is mainnet"
(h/render [quo/confirmation-propgress (get-test-data {})])
(h/is-truthy (h/get-by-label-text :mainnet-progress-box)))

(h/test "component renders when state is sending and network is mainnet"
(h/render [quo/confirmation-propgress (get-test-data {:state :sending})])
(h/is-truthy (h/get-by-label-text :mainnet-progress-box)))

(h/test "component renders when state is confirmed and network is mainnet"
(h/render [quo/confirmation-propgress (get-test-data {:state :confirmed})])
(h/is-truthy (h/get-by-label-text :mainnet-progress-box)))

(h/test "component renders when state is finalising and network is mainnet"
(h/render [quo/confirmation-propgress (get-test-data {:state :finalising})])
(h/is-truthy (h/get-by-label-text :mainnet-progress-box)))

(h/test "component renders when state is finalized and network is mainnet"
(h/render [quo/confirmation-propgress (get-test-data {:state :finalized})])
(h/is-truthy (h/get-by-label-text :mainnet-progress-box)))

(h/test "component renders when state is error and network is mainnet"
(h/render [quo/confirmation-propgress (get-test-data {:state :error})])
(h/is-truthy (h/get-by-label-text :mainnet-progress-box))))
9 changes: 9 additions & 0 deletions src/quo/components/wallet/confirmation_progress/style.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(ns quo.components.wallet.confirmation-progress.style)

(def progress-box-container
{:flex-direction :row
:align-items :center
:padding-horizontal 12
:padding-bottom 10
:padding-top 4
:flex-wrap :wrap})
69 changes: 69 additions & 0 deletions src/quo/components/wallet/confirmation_progress/view.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
(ns quo.components.wallet.confirmation-progress.view
(:require [quo.components.wallet.confirmation-progress.style :as style]
[quo.components.wallet.progress-bar.view :as progress-box]
[quo.theme :as quo.theme]
[react-native.core :as rn]))

(def ^:private max-progress 100)
(def ^:private min-progress 0)

(defn- calculate-box-state
[state counter index]
(cond
(and (= state :sending) (>= counter index) (< index 3)) :confirmed
(and (= state :confirmed) (>= counter index) (< index 5)) :confirmed
(and (= state :finalising) (>= counter index) (< index 5)) :confirmed
(and (= state :finalising) (>= counter index) (> index 4) (< index 20)) :finalized
(and (= state :finalized) (>= counter index) (< index 5)) :confirmed
(and (= state :finalized) (>= counter index) (> index 4)) :finalized
(and (= state :error) (>= counter index) (< index 2)) :error
:else :pending))

(defn- calculate-box-state-sidenet
[state]
(case state
:error :error
(:confirmed :finalising :finalized) :finalized
:pending))

(defn- calculate-progressed-value
[state progress-value]
(case state
:finalising progress-value
:finalized max-progress
min-progress))

(defn- progress-boxes-mainnet
[{:keys [state counter total-box]}]
[rn/view
{:accessibility-label :mainnet-progress-box
:style style/progress-box-container}
(let [numbers (range 1 total-box)]
(doall (for [n numbers]
[progress-box/view
{:state (calculate-box-state state counter n)
:customization-color :blue
:key n}])))])

(defn- progress-boxes-sidenet
[{:keys [state progress-value]}]
[rn/view
{:accessibility-label :progress-box
:style style/progress-box-container}
[progress-box/view
{:state (calculate-box-state-sidenet state)
:customization-color :success}]
[progress-box/view
{:state (calculate-box-state-sidenet state)
:full-width? true
:progressed-value (calculate-progressed-value state progress-value)
:customization-color :blue}]])

(defn- view-internal
[{:keys [network] :as props}]
(case network
:mainnet [progress-boxes-mainnet props]
(:arbitrum :optimism) [progress-boxes-sidenet props]
nil))

(def view (quo.theme/with-theme view-internal))
12 changes: 6 additions & 6 deletions src/quo/components/wallet/progress_bar/component_spec.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
:width 8
:borderRadius 3
:borderColor colors/neutral-80-opa-5
:backgroundColor (colors/custom-color (:customization-color props) 50)})))
:backgroundColor (colors/resolve-color (:customization-color props) theme)})))

(h/test "finalized state with customtization-color blue in dark mode"
(let [theme :dark
Expand All @@ -51,7 +51,7 @@
:width 8
:borderRadius 3
:borderColor colors/neutral-80-opa-5
:backgroundColor (colors/custom-color (:customization-color props) 60)})))
:backgroundColor (colors/resolve-color (:customization-color props) theme)})))

(h/test "finalized state with customtization-color army in light mode"
(let [theme :light
Expand All @@ -63,7 +63,7 @@
:width 8
:borderRadius 3
:borderColor colors/neutral-80-opa-5
:backgroundColor (colors/custom-color (:customization-color props) 50)})))
:backgroundColor (colors/resolve-color (:customization-color props) theme)})))

(h/test "confirmed state in light mode"
(let [theme :light
Expand All @@ -75,7 +75,7 @@
:width 8
:borderRadius 3
:borderColor colors/neutral-80-opa-5
:backgroundColor colors/success-50})))
:backgroundColor (colors/resolve-color :success theme)})))

(h/test "confirmed state in dark mode"
(let [theme :dark
Expand All @@ -99,7 +99,7 @@
:width 8
:borderRadius 3
:borderColor colors/neutral-80-opa-5
:backgroundColor colors/danger-50})))
:backgroundColor (colors/resolve-color :danger theme)})))

(h/test "error state in dark mode"
(let [theme :dark
Expand All @@ -111,4 +111,4 @@
:width 8
:borderRadius 3
:borderColor colors/white-opa-5
:backgroundColor colors/danger-60}))))
:backgroundColor (colors/resolve-color :danger theme)}))))
43 changes: 30 additions & 13 deletions src/quo/components/wallet/progress_bar/style.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,48 @@
[quo.foundations.colors :as colors]))

(defn- border-and-background-color
[customization-color]
[customization-color theme]
{:light {:pending {:border-color colors/neutral-80-opa-5
:background-color colors/neutral-5}
:confirmed {:border-color colors/neutral-80-opa-5
:background-color (colors/custom-color :success 50)}
:background-color (colors/resolve-color :success theme)}
:finalized {:border-color colors/neutral-80-opa-5
:background-color (colors/custom-color customization-color 50)}
:background-color (colors/resolve-color customization-color theme)}
:error {:border-color colors/neutral-80-opa-5
:background-color (colors/custom-color :danger 50)}}
:background-color (colors/resolve-color :danger theme)}}
:dark {:pending {:border-color colors/neutral-70
:background-color colors/neutral-80}
:confirmed {:border-color colors/white-opa-5
:background-color (colors/custom-color :success 60)}
:background-color (colors/resolve-color :success theme)}
:finalized {:border-color colors/neutral-80-opa-5
:background-color (colors/custom-color customization-color 60)}
:background-color (colors/resolve-color customization-color theme)}
:error {:border-color colors/white-opa-5
:background-color (colors/custom-color :danger 60)}}})
:background-color (colors/resolve-color :danger theme)}}})

(def max-value 100)

(defn root-container
[{:keys [customization-color state theme]}]
(let [{:keys [background-color border-color]} (get-in (border-and-background-color customization-color)
[theme state])]
[{:keys [customization-color state theme full-width?]}]
(let [{:keys [background-color border-color]} (get-in (border-and-background-color customization-color
theme)
[theme (if full-width? :pending state)])]
{:height 12
:flex (when full-width? 1)
:width (when (not full-width?) 8)
:border-radius 3
:border-width 1
:border-color border-color
:background-color background-color
:margin-horizontal 1
:margin-vertical 2}))

(defn progressed-bar
[{:keys [customization-color state theme progressed-value]}]
(let [{:keys [background-color]} (get-in (border-and-background-color customization-color theme)
[theme state])
progress (if (> progressed-value max-value) max-value progressed-value)]
{:height 12
:width 8
:margin-top -1
:width (str progress "%")
:border-radius 3
:border-width 1
:border-color border-color
:background-color background-color}))
6 changes: 4 additions & 2 deletions src/quo/components/wallet/progress_bar/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
[react-native.core :as rn]))

(defn- view-internal
[props]
[{:keys [full-width?] :as props}]
[rn/view
{:accessibility-label :progress-bar
:style (style/root-container props)}])
:style (style/root-container props)}
(when full-width?
[rn/view {:style (style/progressed-bar props)}])])

(def view (quo.theme/with-theme view-internal))
Loading

0 comments on commit aaf0b8e

Please sign in to comment.