|
| 1 | +(ns quo2.components.wallet.wallet-overview.view |
| 2 | + (:require [quo2.components.icon :as icons] |
| 3 | + [quo2.components.markdown.text :as quo2] |
| 4 | + [react-native.core :as rn] |
| 5 | + [utils.i18n :as i18n] |
| 6 | + [quo2.components.wallet.wallet-overview.style :as style] |
| 7 | + [quo2.theme :as quo.theme])) |
| 8 | + |
| 9 | +(def ^:private time-frames |
| 10 | + {:one-week (i18n/label :t/one-week-int) |
| 11 | + :one-month (i18n/label :t/one-month-int) |
| 12 | + :three-months (i18n/label :t/three-months-int) |
| 13 | + :one-year (i18n/label :t/one-year) |
| 14 | + :all-time (i18n/label :t/all-time)}) |
| 15 | + |
| 16 | +(defn- loading-bars |
| 17 | + [bars theme] |
| 18 | + (map (fn [{:keys [width height margin]}] |
| 19 | + [rn/view {:style (style/loading-bar width height margin theme)}]) |
| 20 | + bars)) |
| 21 | + |
| 22 | +;; temporary placeholder for network dropdown component |
| 23 | +(defn- network-dropdown |
| 24 | + [] |
| 25 | + [:<> |
| 26 | + [rn/view {:style style/network-dropdown}]]) |
| 27 | + |
| 28 | +(defn- view-info-top |
| 29 | + [{:keys [state balance theme]}] |
| 30 | + [rn/view {:style style/container-info-top} |
| 31 | + (if (= state :loading) |
| 32 | + (loading-bars [{:width 201 :height 20 :margin 0}] theme) |
| 33 | + [quo2/text |
| 34 | + {:weight :semi-bold |
| 35 | + :size :heading-1 |
| 36 | + :style (style/style-text-heading theme)} |
| 37 | + balance]) |
| 38 | + [network-dropdown]]) |
| 39 | + |
| 40 | +(defn- view-metrics |
| 41 | + [metrics currency-change percentage-change] |
| 42 | + [rn/view |
| 43 | + {:style {:flex-direction :row |
| 44 | + :align-items :center}} |
| 45 | + [quo2/text |
| 46 | + {:weight :medium |
| 47 | + :size :paragraph-2 |
| 48 | + :style {:color (style/color-metrics metrics)}} |
| 49 | + percentage-change] |
| 50 | + [rn/view |
| 51 | + {:style (style/dot-separator metrics)}] |
| 52 | + [quo2/text |
| 53 | + {:weight :medium |
| 54 | + :size :paragraph-2 |
| 55 | + :style {:color (style/color-metrics metrics) |
| 56 | + :margin-right 4}} |
| 57 | + currency-change] |
| 58 | + [icons/icon |
| 59 | + (if (= metrics :positive) :i/positive :i/negative) |
| 60 | + {:color (style/color-metrics metrics) |
| 61 | + :size 16}]]) |
| 62 | + |
| 63 | +(defn- view-info-bottom |
| 64 | + [{:keys [state time-frame metrics date begin-date end-date |
| 65 | + currency-change percentage-change theme]}] |
| 66 | + [rn/view {:flex-direction :row} |
| 67 | + (when (= state :loading) |
| 68 | + [rn/view |
| 69 | + {:style {:flex-direction :row |
| 70 | + :align-items :center}} |
| 71 | + (loading-bars [{:width 32 :height 10 :margin 8} |
| 72 | + {:width 32 :height 10 :margin 4} |
| 73 | + {:width 62 :height 10 :margin 4} |
| 74 | + {:width 10 :height 10 :margin 0}] |
| 75 | + theme)]) |
| 76 | + (when (and (= state :default) (= time-frame :selected)) |
| 77 | + [quo2/text |
| 78 | + {:weight :medium |
| 79 | + :size :paragraph-2 |
| 80 | + :style (style/style-text-paragraph theme)} |
| 81 | + date]) |
| 82 | + (when (and (= state :default) (= time-frame :custom)) |
| 83 | + [rn/view {:style {:flex-direction :row}} |
| 84 | + [quo2/text |
| 85 | + {:weight :medium |
| 86 | + :size :paragraph-2 |
| 87 | + :style (style/style-text-paragraph theme)} |
| 88 | + begin-date] |
| 89 | + [icons/icon :i/positive-right |
| 90 | + {:color (style/color-text-paragraph theme) |
| 91 | + :size 16}] |
| 92 | + [quo2/text |
| 93 | + {:weight :medium |
| 94 | + :size :paragraph-2 |
| 95 | + :style (style/style-text-paragraph theme)} |
| 96 | + end-date]]) |
| 97 | + (when (and (= state :default) (not (#{:none :selected} time-frame))) |
| 98 | + [rn/view {:style {:flex-direction :row}} |
| 99 | + [quo2/text |
| 100 | + {:weight :medium |
| 101 | + :size :paragraph-2 |
| 102 | + :style {:color (style/color-text-paragraph theme) |
| 103 | + :margin-right 8}} |
| 104 | + (time-frame time-frames)] |
| 105 | + (when (and (= state :default) (not= metrics :none)) |
| 106 | + [view-metrics metrics currency-change percentage-change])])]) |
| 107 | + |
| 108 | +(defn- view-internal |
| 109 | + [props] |
| 110 | + [rn/view {:style style/container-info} |
| 111 | + [rn/view {:style {:flex 1}} |
| 112 | + [view-info-top props] |
| 113 | + [view-info-bottom props]]]) |
| 114 | + |
| 115 | +(def view |
| 116 | + (quo.theme/with-theme view-internal)) |
0 commit comments