Skip to content

Commit

Permalink
Merge pull request #11 from sgobotta/feature/fetch-stock-prices-on-de…
Browse files Browse the repository at this point in the history
…mand

feature/fetch stock prices on demand
  • Loading branch information
sgobotta authored Mar 11, 2024
2 parents 2af65e1 + ef0ce48 commit 773361a
Show file tree
Hide file tree
Showing 31 changed files with 1,196 additions and 206 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ make docker.logs
Once the environment file and the project is properly set up, a development server can be started using the `make server` command.

+ Visit [`localhost:4000`](http://localhost:4000) from your browser to access the application main page.
+ Visit [`localhost:4000/dashboard`](http://localhost:4000/dashboard/home) from your browser to access a devellopment dashboard with information about your app.
+ Visit [`localhost:4000/dev/dashboard`](http://localhost:4000/dev/dashboard/home) from your browser to access a development dashboard with information about your app.

## License

Expand Down
2 changes: 1 addition & 1 deletion config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ if System.get_env("PHX_SERVER") do
config :ex_finance, ExFinanceWeb.Endpoint, server: true
end

config :ex_finnhub, api_key: System.fetch_env!("FINNHUB_API_KEY")
config :ex_finance, ExFinnhub, api_key: System.fetch_env!("FINNHUB_API_KEY")

config :ex_finance, stage: System.fetch_env!("STAGE")

Expand Down
1 change: 1 addition & 0 deletions devops/builder/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ ENV RECAPTCHA_PUBLIC_KEY=${RECAPTCHA_PUBLIC_KEY}
ENV RECAPTCHA_SECRET=${RECAPTCHA_SECRET}

# install mix dependencies
COPY version.txt ./version.txt
COPY mix.exs mix.lock ./
RUN mix deps.get --only $MIX_ENV
RUN mkdir config
Expand Down
18 changes: 11 additions & 7 deletions lib/ex_finance/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ defmodule ExFinance.Application do
alias ExFinance.Currencies.CurrencyProducer
alias ExFinance.Instruments.CedearProducer

@type env :: :dev | :test | :prod
@type stage :: :local | :dev

@impl true
def start(_type, _args) do
children = [
Expand All @@ -34,7 +37,10 @@ defmodule ExFinance.Application do
module_name: fetch_cedear_supplier_producer_name()
),
# Start to serve requests, typically the last entry
ExFinanceWeb.Endpoint
ExFinanceWeb.Endpoint,
ExFinnhub.StockPrices
# {ExFinnhub.StockPrices.Producer,
# [counter: 5, name: ExFinnhub.StockPrices.Producer]}
]

# See https://hexdocs.pm/elixir/Supervisor.html
Expand All @@ -51,16 +57,12 @@ defmodule ExFinance.Application do
:ok
end

@spec env :: :dev | :test | :prod
@spec env :: env()
def env, do: Application.fetch_env!(:ex_finance, :environment)

@spec stage :: :local | :dev
@spec stage :: stage()
def stage, do: Application.fetch_env!(:ex_finance, :stage)

def redis_host, do: Application.fetch_env!(:ex_finance, :redis_host)

def redis_pass, do: Application.fetch_env!(:ex_finance, :redis_pass)

defp fetch_currency_supplier, do: System.fetch_env!("CURRENCY_SUPPLIER")

defp fetch_cedear_supplier, do: System.fetch_env!("CEDEAR_SUPPLIER")
Expand All @@ -70,4 +72,6 @@ defmodule ExFinance.Application do

defp fetch_cedear_supplier_producer_name,
do: System.fetch_env!("CEDEAR_SUPPLIER_PRODUCER_NAME")

def fetch_finnhub_config!, do: Application.fetch_env!(:ex_finance, ExFinnhub)
end
3 changes: 3 additions & 0 deletions lib/ex_finance_web.ex
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,11 @@ defmodule ExFinanceWeb do
import Phoenix.HTML
# Core UI components and translation
import ExFinanceWeb.CoreComponents
import ExFinanceWeb.CustomComponents
import ExFinanceWeb.Gettext

use PhoenixInlineSvg.Helpers

# Shortcut for generating JS commands
alias Phoenix.LiveView.JS

Expand Down
18 changes: 18 additions & 0 deletions lib/ex_finance_web/components/custom_components.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
defmodule ExFinanceWeb.CustomComponents do
@moduledoc false
use Phoenix.Component

import ExFinanceWeb.Gettext

def cafecito_button(assigns) do
~H"""
<a href="https://cafecito.app/sgobotta" rel="noopener" target="_blank">
<img
srcset="https://cdn.cafecito.app/imgs/buttons/button_6.png 1x, https://cdn.cafecito.app/imgs/buttons/button_6_2x.png 2x, https://cdn.cafecito.app/imgs/buttons/button_6_3.75x.png 3.75x"
src="https://cdn.cafecito.app/imgs/buttons/button_6.png"
alt={gettext("Invite me a coffee in cafecito.app")}
/>
</a>
"""
end
end
93 changes: 37 additions & 56 deletions lib/ex_finance_web/controllers/page_html/home.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@
/>
</svg>
</div>
<div class="px-4 py-10 sm:px-6 sm:py-28 lg:px-8 xl:px-28 xl:py-32">
<div class="px-4 py-10 sm:px-6 sm:py-28 lg:px-8 xl:px-28 xl:py-32 cursor-default">
<div class="mx-auto max-w-xl lg:mx-0">
<svg viewBox="0 0 71 48" class="h-12" aria-hidden="true">
<path
d="m26.371 33.477-.552-.1c-3.92-.729-6.397-3.1-7.57-6.829-.733-2.324.597-4.035 3.035-4.148 1.995-.092 3.362 1.055 4.57 2.39 1.557 1.72 2.984 3.558 4.514 5.305 2.202 2.515 4.797 4.134 8.347 3.634 3.183-.448 5.958-1.725 8.371-3.828.363-.316.761-.592 1.144-.886l-.241-.284c-2.027.63-4.093.841-6.205.735-3.195-.16-6.24-.828-8.964-2.582-2.486-1.601-4.319-3.746-5.19-6.611-.704-2.315.736-3.934 3.135-3.6.948.133 1.746.56 2.463 1.165.583.493 1.143 1.015 1.738 1.493 2.8 2.25 6.712 2.375 10.265-.068-5.842-.026-9.817-3.24-13.308-7.313-1.366-1.594-2.7-3.216-4.095-4.785-2.698-3.036-5.692-5.71-9.79-6.623C12.8-.623 7.745.14 2.893 2.361 1.926 2.804.997 3.319 0 4.149c.494 0 .763.006 1.032 0 2.446-.064 4.28 1.023 5.602 3.024.962 1.457 1.415 3.104 1.761 4.798.513 2.515.247 5.078.544 7.605.761 6.494 4.08 11.026 10.26 13.346 2.267.852 4.591 1.135 7.172.555ZM10.751 3.852c-.976.246-1.756-.148-2.56-.962 1.377-.343 2.592-.476 3.897-.528-.107.848-.607 1.306-1.336 1.49Zm32.002 37.924c-.085-.626-.62-.901-1.04-1.228-1.857-1.446-4.03-1.958-6.333-2-1.375-.026-2.735-.128-4.031-.61-.595-.22-1.26-.505-1.244-1.272.015-.78.693-1 1.31-1.184.505-.15 1.026-.247 1.6-.382-1.46-.936-2.886-1.065-4.787-.3-2.993 1.202-5.943 1.06-8.926-.017-1.684-.608-3.179-1.563-4.735-2.408l-.043.03a2.96 2.96 0 0 0 .04-.029c-.038-.117-.107-.12-.197-.054l.122.107c1.29 2.115 3.034 3.817 5.004 5.271 3.793 2.8 7.936 4.471 12.784 3.73A66.714 66.714 0 0 1 37 40.877c1.98-.16 3.866.398 5.753.899Zm-9.14-30.345c-.105-.076-.206-.266-.42-.069 1.745 2.36 3.985 4.098 6.683 5.193 4.354 1.767 8.773 2.07 13.293.51 3.51-1.21 6.033-.028 7.343 3.38.19-3.955-2.137-6.837-5.843-7.401-2.084-.318-4.01.373-5.962.94-5.434 1.575-10.485.798-15.094-2.553Zm27.085 15.425c.708.059 1.416.123 2.124.185-1.6-1.405-3.55-1.517-5.523-1.404-3.003.17-5.167 1.903-7.14 3.972-1.739 1.824-3.31 3.87-5.903 4.604.043.078.054.117.066.117.35.005.699.021 1.047.005 3.768-.17 7.317-.965 10.14-3.7.89-.86 1.685-1.817 2.544-2.71.716-.746 1.584-1.159 2.645-1.07Zm-8.753-4.67c-2.812.246-5.254 1.409-7.548 2.943-1.766 1.18-3.654 1.738-5.776 1.37-.374-.066-.75-.114-1.124-.17l-.013.156c.135.07.265.151.405.207.354.14.702.308 1.07.395 4.083.971 7.992.474 11.516-1.803 2.221-1.435 4.521-1.707 7.013-1.336.252.038.503.083.756.107.234.022.479.255.795.003-2.179-1.574-4.526-2.096-7.094-1.872Zm-10.049-9.544c1.475.051 2.943-.142 4.486-1.059-.452.04-.643.04-.827.076-2.126.424-4.033-.04-5.733-1.383-.623-.493-1.257-.974-1.889-1.457-2.503-1.914-5.374-2.555-8.514-2.5.05.154.054.26.108.315 3.417 3.455 7.371 5.836 12.369 6.008Zm24.727 17.731c-2.114-2.097-4.952-2.367-7.578-.537 1.738.078 3.043.632 4.101 1.728.374.388.763.768 1.182 1.106 1.6 1.29 4.311 1.352 5.896.155-1.861-.726-1.861-.726-3.601-2.452Zm-21.058 16.06c-1.858-3.46-4.981-4.24-8.59-4.008a9.667 9.667 0 0 1 2.977 1.39c.84.586 1.547 1.311 2.243 2.055 1.38 1.473 3.534 2.376 4.962 2.07-.656-.412-1.238-.848-1.592-1.507Zm17.29-19.32c0-.023.001-.045.003-.068l-.006.006.006-.006-.036-.004.021.018.012.053Zm-20 14.744a7.61 7.61 0 0 0-.072-.041.127.127 0 0 0 .015.043c.005.008.038 0 .058-.002Zm-.072-.041-.008-.034-.008.01.008-.01-.022-.006.005.026.024.014Z"
fill="#FD4F00"
/>
</svg>
<%= PhoenixInlineSvg.Helpers.svg_image(@conn, "logo", class: "w-14 h-14") %>
<h1 class="text-brand mt-10 flex items-center text-sm font-semibold leading-6">
<%= gettext("Finance Apps") %>
<small class="bg-brand/5 text-[0.8125rem] ml-3 rounded-full px-2 font-medium leading-6">
v<%= Application.spec(:ex_finance, :vsn) %>
<small class="bg-brand/5 text-[0.8125rem] ml-3 rounded-full px-2 font-medium leading-6 hover:bg-zinc-50">
<.link
target="_blank"
href={"https://github.com/sgobotta/ex_finance/releases/tag/v#{Application.spec(:ex_finance, :vsn)}"}
>
v<%= Application.spec(:ex_finance, :vsn) %>
</.link>
</small>
</h1>
<p class="text-[2rem] mt-4 font-semibold leading-10 tracking-tighter text-zinc-900">
Expand All @@ -70,26 +70,13 @@
<span class="absolute inset-0 rounded-2xl bg-zinc-50 transition group-hover:bg-zinc-100 sm:group-hover:scale-105">
</span>
<span class="relative flex items-center gap-4 sm:flex-col">
<svg
viewBox="0 0 24 24"
fill="none"
aria-hidden="true"
class="h-6 w-6"
>
<path
d="m12 4 10-2v18l-10 2V4Z"
fill="#18181B"
fill-opacity=".15"
/>
<path
d="M12 4 2 2v18l10 2m0-18v18m0-18 10-2v18l-10 2"
stroke="#18181B"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
/>
</svg>
<%= gettext("Currencies") %>
<.icon
name="hero-currency-dollar"
class="h-7 w-7 group-hover:text-brand"
/>
<span class="group-hover:text-brand">
<%= gettext("Currencies") %>
</span>
</span>
</a>
<a
Expand Down Expand Up @@ -123,20 +110,22 @@

<g>
<polygon
class="st0"
class="st0 group-hover:fill-brand"
points="204.344,155.188 249.469,200.297 409.344,40.422 268.031,40.422 316.063,88.453 249.469,155.031 204.953,110.516 41.906,264.969 63.906,288.219 "
>
</polygon>

<polygon
class="st0"
class="st0 group-hover:fill-brand"
points="512,102.313 276.031,330.281 212.656,266.906 0,471.578 512,471.578 "
>
</polygon>
</g>
</g>
</svg>
<%= gettext("Cedears") %>
<span class="group-hover:text-brand">
<%= gettext("Cedears") %>
</span>
</span>
</a>
<a
Expand All @@ -153,9 +142,12 @@
clip-rule="evenodd"
d="M12 0C5.37 0 0 5.506 0 12.303c0 5.445 3.435 10.043 8.205 11.674.6.107.825-.262.825-.585 0-.292-.015-1.261-.015-2.291C6 21.67 5.22 20.346 4.98 19.654c-.135-.354-.72-1.446-1.23-1.738-.42-.23-1.02-.8-.015-.815.945-.015 1.62.892 1.845 1.261 1.08 1.86 2.805 1.338 3.495 1.015.105-.8.42-1.338.765-1.645-2.67-.308-5.46-1.37-5.46-6.075 0-1.338.465-2.446 1.23-3.307-.12-.308-.54-1.569.12-3.26 0 0 1.005-.323 3.3 1.26.96-.276 1.98-.415 3-.415s2.04.139 3 .416c2.295-1.6 3.3-1.261 3.3-1.261.66 1.691.24 2.952.12 3.26.765.861 1.23 1.953 1.23 3.307 0 4.721-2.805 5.767-5.475 6.075.435.384.81 1.122.81 2.276 0 1.645-.015 2.968-.015 3.383 0 .323.225.707.825.585a12.047 12.047 0 0 0 5.919-4.489A12.536 12.536 0 0 0 24 12.304C24 5.505 18.63 0 12 0Z"
fill="#18181B"
class="group-hover:fill-brand"
/>
</svg>
<%= gettext("Source Code") %>
<span class="group-hover:text-brand">
<%= gettext("Source Code") %>
</span>
</span>
</a>
</div>
Expand All @@ -171,26 +163,13 @@
<span class="absolute inset-0 rounded-2xl bg-zinc-50 transition group-hover:bg-zinc-100 sm:group-hover:scale-105">
</span>
<span class="relative flex items-center gap-4 sm:flex-col">
<svg
viewBox="0 0 24 24"
fill="none"
aria-hidden="true"
class="h-6 w-6"
>
<path
d="m12 4 10-2v18l-10 2V4Z"
fill="#18181B"
fill-opacity=".15"
/>
<path
d="M12 4 2 2v18l10 2m0-18v18m0-18 10-2v18l-10 2"
stroke="#18181B"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
/>
</svg>
<%= gettext("Currencies") %>
<.icon
name="hero-currency-dollar"
class="h-7 w-7 group-hover:text-brand"
/>
<span class="group-hover:text-brand">
<%= gettext("Currencies") %>
</span>
</span>
</a>
<a
Expand Down Expand Up @@ -224,20 +203,22 @@

<g>
<polygon
class="st0"
class="st0 group-hover:fill-brand"
points="204.344,155.188 249.469,200.297 409.344,40.422 268.031,40.422 316.063,88.453 249.469,155.031 204.953,110.516 41.906,264.969 63.906,288.219 "
>
</polygon>

<polygon
class="st0"
class="st0 group-hover:fill-brand"
points="512,102.313 276.031,330.281 212.656,266.906 0,471.578 512,471.578 "
>
</polygon>
</g>
</g>
</svg>
<%= gettext("Cedears") %>
<span class="group-hover:text-brand">
<%= gettext("Cedears") %>
</span>
</span>
</a>
</div>
Expand Down
Loading

0 comments on commit 773361a

Please sign in to comment.