Skip to content

Commit 3e94c50

Browse files
authored
Currency list and banner ui enhancements (#23)
* Update currency list font sizes * Add support to display only date values * Layout, font and color improvements in the calculator banner * Code refactor on assign price type * Add support to select price on click * Add support to update prices on keybindings
1 parent 8647b34 commit 3e94c50

5 files changed

Lines changed: 155 additions & 111 deletions

File tree

lib/ex_finance_web/components/custom_components/calculator_banner.ex

Lines changed: 54 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,53 @@ defmodule ExFinanceWeb.CustomComponents.CalculatorBanner do
2222
class={[
2323
"fixed bottom-0 w-full lg:w-1/2 lg:left-1/4",
2424
"bg-white dark:bg-zinc-800",
25-
"rounded-t-lg z-50"
25+
"rounded-t-lg z-50 shadow-2xl"
2626
]}
2727
phx-hook="AnimateCurrencyBanner"
2828
data-animations={banner_animation_dataset()}
2929
>
3030
<%= if @show_calculator do %>
31-
<div class="p-4 pb-1 flex justify-between items-center">
32-
<div>
33-
<h3 class="text-center text-lg font-semibold text-zinc-700 dark:text-zinc-100 cursor-default select-none">
31+
<div class="grid grid-cols-2 border-b-[1px] border-zinc-200 mx-4 mt-[0.75rem]">
32+
<div class="justify-self-start pb-2">
33+
<h3 class="text-center text-lg font-normal text-zinc-700 dark:text-zinc-100 cursor-default select-none">
3434
<%= render_currency_name(@selected_currency) %>
3535
</h3>
3636
</div>
37-
<div phx-window-keyup="update_price_type">
38-
<%= if @selected_currency.info_type == :market do %>
39-
<div class="flex flex-row items-center gap-4 cursor-default text-xs select-none">
37+
<div class="justify-self-end pb-2 duration-300 opacity-20 hover:opacity-100">
38+
<button
39+
phx-click="toggle_calculator"
40+
phx-value-currency_id={@selected_currency.id}
41+
class="hover:text-red-500 dark:hover:text-red-500"
42+
>
43+
<svg
44+
xmlns="http://www.w3.org/2000/svg"
45+
fill="none"
46+
viewBox="0 0 24 24"
47+
stroke-width="1.5"
48+
stroke="currentColor"
49+
class="w-6 h-6"
50+
>
51+
<path
52+
stroke-linecap="round"
53+
stroke-linejoin="round"
54+
d="M6 18L18 6M6 6l12 12"
55+
/>
56+
</svg>
57+
</button>
58+
</div>
59+
</div>
60+
<div phx-window-keyup="update_price_type" class="mx-4 mt-4">
61+
<%= if @selected_currency.info_type == :market do %>
62+
<div class="grid grid-cols-2 gap-4 cursor-default text-xs select-none">
63+
<div class="justify-self-end">
4064
<div
4165
class={[
4266
"p-2 rounded-md inline-block",
4367
"bg-zinc-200 dark:bg-zinc-700 ",
4468
"#{if @market_price_type == :buy_price, do: "border-[1px] border-zinc-800 dark:border-zinc-200", else: "cursor-pointer"}",
4569
"text-green-700 dark:text-green-300",
4670
"transform duration-100 ease-linear",
71+
"hover:shadow-outer-xs",
4772
"flex flex-row"
4873
]}
4974
phx-click="set_market_price_type"
@@ -57,12 +82,15 @@ defmodule ExFinanceWeb.CustomComponents.CalculatorBanner do
5782
"w-4 h-4 ml-2 rounded-sm",
5883
"text-center",
5984
"bg-zinc-200 text-zinc-500",
60-
"border-[1px] border-zinc-400",
61-
"shadow-inner-xxs"
85+
"dark:bg-zinc-800 dark:text-zinc-400",
86+
"border-[1px] border-zinc-500",
87+
"shadow-inner-xs"
6288
]}>
6389
<%= gettext("Buy_Shortcut") %>
6490
</div>
6591
</div>
92+
</div>
93+
<div class="justify-self-start">
6694
<div
6795
class={[
6896
"p-2 rounded-md inline-block",
@@ -71,6 +99,7 @@ defmodule ExFinanceWeb.CustomComponents.CalculatorBanner do
7199
"#{if @market_price_type == :sell_price, do: "border-zinc-800 dark:border-zinc-200", else: "border-white dark:border-zinc-800 cursor-pointer"}",
72100
"text-red-700 dark:text-red-300",
73101
"transform duration-100 ease-linear",
102+
"hover:shadow-outer-xs",
74103
"flex flex-row"
75104
]}
76105
phx-click="set_market_price_type"
@@ -84,54 +113,33 @@ defmodule ExFinanceWeb.CustomComponents.CalculatorBanner do
84113
"w-4 h-4 ml-2 rounded-sm",
85114
"text-center",
86115
"bg-zinc-200 text-zinc-500",
87-
"border-[1px] border-zinc-400",
88-
"shadow-inner-xxs"
116+
"dark:bg-zinc-800 dark:text-zinc-400",
117+
"border-[1px] border-zinc-500",
118+
"shadow-inner-xs"
89119
]}>
90120
<%= gettext("Sell_Shortcut") %>
91121
</div>
92122
</div>
93123
</div>
94-
<% end %>
95-
<%= if @selected_currency.info_type == :reference do %>
96-
<div class="flex flex-row items-center gap-4 cursor-default text-xs select-none">
97-
<div class="p-2 rounded-md bg-zinc-200 dark:bg-zinc-700 inline-block text-secondary">
98-
<%= gettext("Reference Price") %> <%= render_price(
99-
@selected_currency.variation_price
100-
) %>
101-
</div>
124+
</div>
125+
<% end %>
126+
<%= if @selected_currency.info_type == :reference do %>
127+
<div class="flex flex-row items-center gap-4 cursor-default text-xs select-none justify-self-center">
128+
<div class="p-2 rounded-md bg-zinc-200 dark:bg-zinc-700 inline-block text-zinc-900 dark:text-zinc-200">
129+
<%= gettext("Reference Price") %> <%= render_price(
130+
@selected_currency.variation_price
131+
) %>
102132
</div>
103-
<% end %>
104-
</div>
105-
<div>
106-
<button
107-
phx-click="toggle_calculator"
108-
phx-value-currency_id={@selected_currency.id}
109-
class="text-zinc-700 dark:text-zinc-100 hover:text-red-500 dark:hover:text-red-500"
110-
>
111-
<svg
112-
xmlns="http://www.w3.org/2000/svg"
113-
fill="none"
114-
viewBox="0 0 24 24"
115-
stroke-width="1.5"
116-
stroke="currentColor"
117-
class="w-6 h-6"
118-
>
119-
<path
120-
stroke-linecap="round"
121-
stroke-linejoin="round"
122-
d="M6 18L18 6M6 6l12 12"
123-
/>
124-
</svg>
125-
</button>
126-
</div>
133+
</div>
134+
<% end %>
127135
</div>
128136
<div class="p-4 pt-1 mt-4 flex flex-row">
129137
<.simple_form
130138
for={@conversion_form}
131139
id="conversion_form"
132140
phx-change="validate_conversion"
133141
class="w-full"
134-
container_classes="flex-row gap-8"
142+
container_classes="flex-row gap-4"
135143
>
136144
<.input_pill
137145
container_class="w-full"
@@ -144,7 +152,7 @@ defmodule ExFinanceWeb.CustomComponents.CalculatorBanner do
144152
min={0}
145153
step={100}
146154
required
147-
class="shadow-inner-xs dark:shadow-dark-inner-xs !text-sky-500 font-bold dark:bg-zinc-700"
155+
class="shadow-inner-xs dark:shadow-dark-inner-xs !text-sky-500 font-bold dark:bg-zinc-700 select-text"
148156
/>
149157
<.input_pill
150158
container_class="w-full"
@@ -156,7 +164,7 @@ defmodule ExFinanceWeb.CustomComponents.CalculatorBanner do
156164
value={@conversion_form["usd_amount"]}
157165
min={0}
158166
required
159-
class="shadow-inner-xs dark:shadow-dark-inner-xs !text-green-500 font-bold dark:bg-zinc-700"
167+
class="shadow-inner-xs dark:shadow-dark-inner-xs !text-green-500 font-bold dark:bg-zinc-700 select-text"
160168
/>
161169
</.simple_form>
162170
</div>

lib/ex_finance_web/live/public/currency_live/index.ex

Lines changed: 53 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -137,29 +137,11 @@ defmodule ExFinanceWeb.Public.CurrencyLive.Index do
137137
%{"market_price_type" => market_price_type},
138138
socket
139139
) do
140-
socket =
141-
assign(
142-
socket,
143-
:market_price_type,
144-
market_price_type |> String.to_existing_atom()
145-
)
146-
147-
usd_amount = socket.assigns.conversion_form["usd_amount"]
148-
149-
input_value = parse_input_value(usd_amount)
150-
151-
ars_amount = convert_usd_to_ars(socket, input_value)
152-
153-
conversion_form =
154-
Map.put(
155-
socket.assigns.conversion_form,
156-
"ars_amount",
157-
ars_amount
158-
)
159-
160-
socket = assign(socket, :conversion_form, conversion_form)
161-
162-
{:noreply, socket}
140+
{:noreply,
141+
on_price_type_update(
142+
socket,
143+
market_price_type |> String.to_existing_atom()
144+
)}
163145
end
164146

165147
def handle_event("update_price_type", %{"key" => "Escape"}, socket) do
@@ -173,38 +155,37 @@ defmodule ExFinanceWeb.Public.CurrencyLive.Index do
173155
)
174156
when market_price_type != nil do
175157
{:noreply,
176-
assign(
158+
on_price_type_update(
177159
socket,
178-
:market_price_type,
179160
:buy_price
180161
)}
181162
end
182163

183-
def handle_event("update_price_type", %{"key" => "b"}, socket) do
184-
{:noreply,
185-
assign(
186-
socket,
187-
:market_price_type,
188-
:buy_price
189-
)}
164+
def handle_event(
165+
"update_price_type",
166+
%{"key" => "b"},
167+
%{assigns: %{market_price_type: market_price_type}} = socket
168+
)
169+
when market_price_type != nil do
170+
{:noreply, on_price_type_update(socket, :buy_price)}
190171
end
191172

192-
def handle_event("update_price_type", %{"key" => "v"}, socket) do
193-
{:noreply,
194-
assign(
195-
socket,
196-
:market_price_type,
197-
:sell_price
198-
)}
173+
def handle_event(
174+
"update_price_type",
175+
%{"key" => "v"},
176+
%{assigns: %{market_price_type: market_price_type}} = socket
177+
)
178+
when market_price_type != nil do
179+
{:noreply, on_price_type_update(socket, :sell_price)}
199180
end
200181

201-
def handle_event("update_price_type", %{"key" => "s"}, socket) do
202-
{:noreply,
203-
assign(
204-
socket,
205-
:market_price_type,
206-
:sell_price
207-
)}
182+
def handle_event(
183+
"update_price_type",
184+
%{"key" => "s"},
185+
%{assigns: %{market_price_type: market_price_type}} = socket
186+
)
187+
when market_price_type != nil do
188+
{:noreply, on_price_type_update(socket, :sell_price)}
208189
end
209190

210191
def handle_event("update_price_type", _params, socket), do: {:noreply, socket}
@@ -225,17 +206,17 @@ defmodule ExFinanceWeb.Public.CurrencyLive.Index do
225206
nil ->
226207
socket
227208
|> assign(:selected_currency, nil)
228-
|> assign(:market_price_type, nil)
209+
|> assign_price_type(nil)
229210

230211
%Currency{info_type: :reference} = currency ->
231212
socket
232213
|> assign(:selected_currency, currency)
233-
|> assign(:market_price_type, nil)
214+
|> assign_price_type(nil)
234215

235216
%Currency{info_type: :market} = currency ->
236217
socket
237218
|> assign(:selected_currency, currency)
238-
|> assign(:market_price_type, :buy_price)
219+
|> assign_price_type(:buy_price)
239220
end
240221
end
241222

@@ -321,6 +302,10 @@ defmodule ExFinanceWeb.Public.CurrencyLive.Index do
321302
assign(socket, :currencies, currencies)
322303
end
323304

305+
defp assign_price_type(socket, price_type) do
306+
assign(socket, :market_price_type, price_type)
307+
end
308+
324309
# ----------------------------------------------------------------------------
325310
# Helper functions
326311
#
@@ -372,6 +357,25 @@ defmodule ExFinanceWeb.Public.CurrencyLive.Index do
372357
|> Decimal.round(2)
373358
end
374359

360+
defp on_price_type_update(socket, price_type) do
361+
socket = assign_price_type(socket, price_type)
362+
usd_amount = parse_input_value(socket.assigns.conversion_form["usd_amount"])
363+
ars_amount = convert_usd_to_ars(socket, usd_amount)
364+
365+
conversion_form =
366+
Map.put(
367+
socket.assigns.conversion_form,
368+
"ars_amount",
369+
ars_amount
370+
)
371+
372+
socket
373+
|> assign_conversion_form(conversion_form)
374+
end
375+
376+
# ----------------------------------------------------------------------------
377+
# Rendering Helper functions
378+
#
375379
defp get_color_by_currency_type(%Currency{type: "bna"}), do: "green"
376380
defp get_color_by_currency_type(%Currency{type: "euro"}), do: "orange"
377381
defp get_color_by_currency_type(%Currency{type: "blue"}), do: "blue"

lib/ex_finance_web/live/public/currency_live/index.html.heex

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,25 +62,25 @@
6262
id={details_id(currency.id)}
6363
>
6464
<%= if currency.info_type == :reference do %>
65-
<h3 class="mt-2 text-lg font-bold text-default dark:text-zinc-200 text-left cursor-text">
65+
<h3 class="mt-2 text-lg font-normal text-default dark:text-zinc-200 text-left cursor-text">
6666
<%= render_price(currency.variation_price) %>
6767
</h3>
6868
<% end %>
6969
<%= if currency.info_type == :market do %>
70-
<h3 class="mt-2 text-lg font-bold text-default dark:text-zinc-200 text-left cursor-text whitespace-nowrap">
70+
<h3 class="mt-2 text-lg font-normal text-default dark:text-zinc-200 text-left cursor-text whitespace-nowrap">
7171
<%= render_price(currency.buy_price) %> - <%= render_price(
7272
currency.sell_price
7373
) %>
7474
</h3>
75-
<p class="text-sm font-semibold text-default dark:text-zinc-200 text-left">
76-
<%= gettext("Spread") %>:
75+
<p class="text-sm font-normal text-zinc-700 dark:text-zinc-200 text-left mb-2">
76+
<span class="underline"><%= gettext("Spread") %></span>:
7777
<span class="text-default dark:text-zinc-200">
7878
<%= render_spread(currency) %>
7979
</span>
8080
</p>
8181
<% end %>
82-
<p class="text-sm font-semibold text-default dark:text-zinc-200 text-left">
83-
<%= render_update_time(currency) %>
82+
<p class="text-xs font-normal text-zinc-700 dark:text-zinc-300 text-left">
83+
<%= render_update_time(currency) %>hs
8484
</p>
8585
<button class={"
8686
cursor-default

lib/ex_finance_web/live/public/currency_live/show.ex

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,11 @@ defmodule ExFinanceWeb.Public.CurrencyLive.Show do
293293
"rgba(142, 81, 255, 1)"}
294294

295295
defp get_datetime_label(%DateTime{} = datetime),
296-
do: DatetimeUtils.human_readable_datetime(datetime, :shift_timezone)
296+
do:
297+
DatetimeUtils.human_readable_datetime(datetime,
298+
shift_timezone: true,
299+
only_date: true
300+
)
297301

298302
defp get_color_by_currency_type(%Currency{type: "bna"}), do: "green"
299303
defp get_color_by_currency_type(%Currency{type: "euro"}), do: "orange"

0 commit comments

Comments
 (0)