├── lib
├── easy_wire_web
│ ├── templates
│ │ └── layout
│ │ │ ├── live.html.leex
│ │ │ ├── app.html.eex
│ │ │ └── root.html.leex
│ ├── views
│ │ ├── layout_view.ex
│ │ ├── error_view.ex
│ │ └── error_helpers.ex
│ ├── gettext.ex
│ ├── channels
│ │ └── user_socket.ex
│ ├── router.ex
│ ├── endpoint.ex
│ ├── telemetry.ex
│ └── live
│ │ ├── page_live.ex
│ │ └── page_live.html.leex
├── easy_wire
│ ├── repo.ex
│ ├── accounts
│ │ ├── service.ex
│ │ ├── account.ex
│ │ └── in_memory.ex
│ ├── profiles
│ │ ├── service.ex
│ │ ├── profile.ex
│ │ └── in_memory.ex
│ ├── transactions
│ │ ├── service.ex
│ │ ├── transaction.ex
│ │ ├── denormalize_slow.ex
│ │ ├── denormalize_fast.ex
│ │ └── in_memory.ex
│ ├── service_router.ex
│ ├── application.ex
│ └── types.ex
├── easy_wire.ex
├── service_mesh
│ ├── middleware
│ │ ├── simulate_latency.ex
│ │ ├── simulate_network_failure.ex
│ │ └── telemetry.ex
│ ├── middleware.ex
│ └── router.ex
├── service_mesh.ex
└── easy_wire_web.ex
├── assets
├── .babelrc
├── css
│ └── app.scss
├── static
│ ├── favicon.ico
│ ├── images
│ │ └── phoenix.png
│ └── robots.txt
├── postcss.config.js
├── tailwind.config.js
├── package.json
├── js
│ └── app.js
└── webpack.config.js
├── test
├── test_helper.exs
├── easy_wire_web
│ ├── views
│ │ ├── layout_view_test.exs
│ │ └── error_view_test.exs
│ └── live
│ │ └── page_live_test.exs
└── support
│ ├── channel_case.ex
│ ├── conn_case.ex
│ └── data_case.ex
├── priv
├── repo
│ ├── migrations
│ │ └── .formatter.exs
│ └── seeds.exs
└── gettext
│ ├── en
│ └── LC_MESSAGES
│ │ └── errors.po
│ └── errors.pot
├── .formatter.exs
├── config
├── test.exs
├── prod.secret.exs
├── config.exs
├── prod.exs
└── dev.exs
├── README.md
├── .gitignore
├── mix.exs
└── mix.lock
/lib/easy_wire_web/templates/layout/live.html.leex:
--------------------------------------------------------------------------------
1 | <%= @inner_content %>
2 |
--------------------------------------------------------------------------------
/assets/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": [
3 | "@babel/preset-env"
4 | ]
5 | }
6 |
--------------------------------------------------------------------------------
/assets/css/app.scss:
--------------------------------------------------------------------------------
1 | @tailwind base;
2 | @tailwind components;
3 | @tailwind utilities;
4 |
--------------------------------------------------------------------------------
/test/test_helper.exs:
--------------------------------------------------------------------------------
1 | ExUnit.start()
2 | Ecto.Adapters.SQL.Sandbox.mode(EasyWire.Repo, :manual)
3 |
--------------------------------------------------------------------------------
/priv/repo/migrations/.formatter.exs:
--------------------------------------------------------------------------------
1 | [
2 | import_deps: [:ecto_sql],
3 | inputs: ["*.exs"]
4 | ]
5 |
--------------------------------------------------------------------------------
/assets/static/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuinnWilton/easywire/HEAD/assets/static/favicon.ico
--------------------------------------------------------------------------------
/lib/easy_wire_web/views/layout_view.ex:
--------------------------------------------------------------------------------
1 | defmodule EasyWireWeb.LayoutView do
2 | use EasyWireWeb, :view
3 | end
4 |
--------------------------------------------------------------------------------
/assets/static/images/phoenix.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuinnWilton/easywire/HEAD/assets/static/images/phoenix.png
--------------------------------------------------------------------------------
/assets/postcss.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | plugins: [
3 | require("tailwindcss"),
4 | require("autoprefixer")
5 | ]
6 | }
7 |
--------------------------------------------------------------------------------
/lib/easy_wire/repo.ex:
--------------------------------------------------------------------------------
1 | defmodule EasyWire.Repo do
2 | use Ecto.Repo,
3 | otp_app: :easy_wire,
4 | adapter: Ecto.Adapters.Postgres
5 | end
6 |
--------------------------------------------------------------------------------
/lib/easy_wire/accounts/service.ex:
--------------------------------------------------------------------------------
1 | defprotocol EasyWire.Accounts.Service do
2 | def get_account_for_profile(service, profile_id)
3 | def deposit_money(service, profile_id, amount)
4 | end
5 |
--------------------------------------------------------------------------------
/assets/static/robots.txt:
--------------------------------------------------------------------------------
1 | # See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file
2 | #
3 | # To ban all spiders from the entire site uncomment the next two lines:
4 | # User-agent: *
5 | # Disallow: /
6 |
--------------------------------------------------------------------------------
/lib/easy_wire/profiles/service.ex:
--------------------------------------------------------------------------------
1 | defprotocol EasyWire.Profiles.Service do
2 | def list_profiles(service)
3 | def get_profiles(service, ids)
4 | def get_profile(service, id)
5 | def get_profile_from_session(service, session)
6 | end
7 |
--------------------------------------------------------------------------------
/lib/easy_wire_web/templates/layout/app.html.eex:
--------------------------------------------------------------------------------
1 |
2 | <%= get_flash(@conn, :info) %>
3 | <%= get_flash(@conn, :error) %>
4 | <%= @inner_content %>
5 |
6 |
--------------------------------------------------------------------------------
/lib/easy_wire.ex:
--------------------------------------------------------------------------------
1 | defmodule EasyWire do
2 | @moduledoc """
3 | EasyWire keeps the contexts that define your domain
4 | and business logic.
5 |
6 | Contexts are also responsible for managing your data, regardless
7 | if it comes from the database, an external API or others.
8 | """
9 | end
10 |
--------------------------------------------------------------------------------
/.formatter.exs:
--------------------------------------------------------------------------------
1 | [
2 | import_deps: [:ecto, :phoenix, :stream_data],
3 | inputs: ["*.{ex,exs}", "priv/*/seeds.exs", "{config,lib,test}/**/*.{ex,exs}"],
4 | subdirectories: ["priv/*/migrations"],
5 | locals_without_parens: [
6 | middleware: 1,
7 | middleware: 2,
8 | register: 2,
9 | register: 3
10 | ]
11 | ]
12 |
--------------------------------------------------------------------------------
/lib/service_mesh/middleware/simulate_latency.ex:
--------------------------------------------------------------------------------
1 | defmodule ServiceMesh.Middleware.SimulateLatency do
2 | use ServiceMesh.Middleware
3 |
4 | @impl ServiceMesh.Middleware
5 | def call(next, opts) do
6 | latency = Keyword.get(opts, :latency, 100)
7 |
8 | :timer.sleep(latency)
9 |
10 | next.()
11 | end
12 | end
13 |
--------------------------------------------------------------------------------
/lib/easy_wire/transactions/service.ex:
--------------------------------------------------------------------------------
1 | defprotocol EasyWire.Transactions.Service do
2 | def list_transactions(service, profile_id, page, page_size)
3 | def get_total_pending_transactions(service, profile_id)
4 | def get_total_processed_transactions(service, profile_id)
5 | def post_transaction(service, sender, recipient, amount)
6 | end
7 |
--------------------------------------------------------------------------------
/test/easy_wire_web/views/layout_view_test.exs:
--------------------------------------------------------------------------------
1 | defmodule EasyWireWeb.LayoutViewTest do
2 | use EasyWireWeb.ConnCase, async: true
3 |
4 | # When testing helpers, you may want to import Phoenix.HTML and
5 | # use functions such as safe_to_string() to convert the helper
6 | # result into an HTML string.
7 | # import Phoenix.HTML
8 | end
9 |
--------------------------------------------------------------------------------
/lib/easy_wire/service_router.ex:
--------------------------------------------------------------------------------
1 | defmodule EasyWire.ServiceRouter do
2 | use ServiceMesh.Router, otp_app: :easy_wire
3 |
4 | middleware ServiceMesh.Middleware.Telemetry
5 |
6 | register :accounts, EasyWire.Accounts.Service
7 | register :profiles, EasyWire.Profiles.Service
8 | register :transactions, EasyWire.Transactions.Service
9 | end
10 |
--------------------------------------------------------------------------------
/priv/repo/seeds.exs:
--------------------------------------------------------------------------------
1 | # Script for populating the database. You can run it as:
2 | #
3 | # mix run priv/repo/seeds.exs
4 | #
5 | # Inside the script, you can read and write to any of your
6 | # repositories directly:
7 | #
8 | # EasyWire.Repo.insert!(%EasyWire.SomeSchema{})
9 | #
10 | # We recommend using the bang functions (`insert!`, `update!`
11 | # and so on) as they will fail if something goes wrong.
12 |
--------------------------------------------------------------------------------
/test/easy_wire_web/live/page_live_test.exs:
--------------------------------------------------------------------------------
1 | defmodule EasyWireWeb.PageLiveTest do
2 | use EasyWireWeb.ConnCase
3 |
4 | import Phoenix.LiveViewTest
5 |
6 | test "disconnected and connected render", %{conn: conn} do
7 | {:ok, page_live, disconnected_html} = live(conn, "/")
8 | assert disconnected_html =~ "Welcome to Phoenix!"
9 | assert render(page_live) =~ "Welcome to Phoenix!"
10 | end
11 | end
12 |
--------------------------------------------------------------------------------
/lib/service_mesh/middleware/simulate_network_failure.ex:
--------------------------------------------------------------------------------
1 | defmodule ServiceMesh.Middleware.SimulateNetworkFailure do
2 | use ServiceMesh.Middleware
3 |
4 | @impl ServiceMesh.Middleware
5 | def call(next, opts) do
6 | failure_rate = Keyword.get(opts, :failure_rate, 0.01)
7 |
8 | if :rand.uniform() < failure_rate do
9 | {:error, :econnrefused}
10 | else
11 | next.()
12 | end
13 | end
14 | end
15 |
--------------------------------------------------------------------------------
/lib/service_mesh/middleware.ex:
--------------------------------------------------------------------------------
1 | defmodule ServiceMesh.Middleware do
2 | @callback init(service :: atom(), opts :: Keyword.t()) :: Keyword.t()
3 | @callback call(next :: (() -> any()), opts :: Keyword.t()) :: any()
4 |
5 | defmacro __using__(_opts) do
6 | quote do
7 | @behaviour unquote(__MODULE__)
8 |
9 | @impl unquote(__MODULE__)
10 | def init(_service, opts) do
11 | opts
12 | end
13 |
14 | defoverridable init: 2
15 | end
16 | end
17 | end
18 |
--------------------------------------------------------------------------------
/test/easy_wire_web/views/error_view_test.exs:
--------------------------------------------------------------------------------
1 | defmodule EasyWireWeb.ErrorViewTest do
2 | use EasyWireWeb.ConnCase, async: true
3 |
4 | # Bring render/3 and render_to_string/3 for testing custom views
5 | import Phoenix.View
6 |
7 | test "renders 404.html" do
8 | assert render_to_string(EasyWireWeb.ErrorView, "404.html", []) == "Not Found"
9 | end
10 |
11 | test "renders 500.html" do
12 | assert render_to_string(EasyWireWeb.ErrorView, "500.html", []) == "Internal Server Error"
13 | end
14 | end
15 |
--------------------------------------------------------------------------------
/assets/tailwind.config.js:
--------------------------------------------------------------------------------
1 | const colors = require('tailwindcss/colors')
2 |
3 | module.exports = {
4 | purge: {
5 | enabled: process.env.NODE_ENV === "production",
6 | content: [
7 | "../lib/**/*.eex",
8 | "../lib/**/*.leex",
9 | "../lib/**/*_view.ex"
10 | ],
11 | options: {
12 | whitelist: [/phx/, /nprogress/]
13 | }
14 | },
15 | theme: {
16 | extend: {
17 | colors: {
18 | cyan: colors.cyan,
19 | }
20 | }
21 | },
22 | plugins: [
23 | require('@tailwindcss/forms'),
24 | ]
25 | }
26 |
--------------------------------------------------------------------------------
/lib/easy_wire_web/views/error_view.ex:
--------------------------------------------------------------------------------
1 | defmodule EasyWireWeb.ErrorView do
2 | use EasyWireWeb, :view
3 |
4 | # If you want to customize a particular status code
5 | # for a certain format, you may uncomment below.
6 | # def render("500.html", _assigns) do
7 | # "Internal Server Error"
8 | # end
9 |
10 | # By default, Phoenix returns the status message from
11 | # the template name. For example, "404.html" becomes
12 | # "Not Found".
13 | def template_not_found(template, _assigns) do
14 | Phoenix.Controller.status_message_from_template(template)
15 | end
16 | end
17 |
--------------------------------------------------------------------------------
/lib/easy_wire/accounts/account.ex:
--------------------------------------------------------------------------------
1 | defmodule EasyWire.Accounts.Account do
2 | import Norm
3 |
4 | alias EasyWire.Types
5 |
6 | defstruct [
7 | :profile_id,
8 | :balance
9 | ]
10 |
11 | def schema,
12 | do:
13 | schema(%__MODULE__{
14 | profile_id: Types.id(),
15 | balance: balance()
16 | })
17 |
18 | defp balance() do
19 | # generate mostly positive balances
20 | generator =
21 | StreamData.frequency([
22 | {3, StreamData.positive_integer()},
23 | {1, StreamData.integer()}
24 | ])
25 |
26 | with_gen(spec(is_integer), generator)
27 | end
28 | end
29 |
--------------------------------------------------------------------------------
/lib/easy_wire_web/templates/layout/root.html.leex:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | <%= csrf_meta_tag() %>
8 | <%= live_title_tag assigns[:page_title] || "EasyWire", suffix: " · Phoenix Framework" %>
9 | "/>
10 |
11 |
12 |
13 | <%= @inner_content %>
14 |
15 |
16 |
--------------------------------------------------------------------------------
/lib/easy_wire/application.ex:
--------------------------------------------------------------------------------
1 | defmodule EasyWire.Application do
2 | @moduledoc false
3 |
4 | use Application
5 |
6 | def start(_type, _args) do
7 | children = [
8 | EasyWire.Repo,
9 | EasyWireWeb.Telemetry,
10 | {Phoenix.PubSub, name: EasyWire.PubSub},
11 | {ServiceMesh, EasyWire.ServiceRouter},
12 | EasyWireWeb.Endpoint
13 | ]
14 |
15 | opts = [strategy: :one_for_one, name: EasyWire.Supervisor]
16 | Supervisor.start_link(children, opts)
17 | end
18 |
19 | # Tell Phoenix to update the endpoint configuration
20 | # whenever the application is updated.
21 | def config_change(changed, _new, removed) do
22 | EasyWireWeb.Endpoint.config_change(changed, removed)
23 | :ok
24 | end
25 | end
26 |
--------------------------------------------------------------------------------
/config/test.exs:
--------------------------------------------------------------------------------
1 | use Mix.Config
2 |
3 | # Configure your database
4 | #
5 | # The MIX_TEST_PARTITION environment variable can be used
6 | # to provide built-in test partitioning in CI environment.
7 | # Run `mix help test` for more information.
8 | config :easy_wire, EasyWire.Repo,
9 | username: "postgres",
10 | password: "postgres",
11 | database: "easy_wire_test#{System.get_env("MIX_TEST_PARTITION")}",
12 | hostname: "localhost",
13 | pool: Ecto.Adapters.SQL.Sandbox
14 |
15 | # We don't run a server during test. If one is required,
16 | # you can enable the server option below.
17 | config :easy_wire, EasyWireWeb.Endpoint,
18 | http: [port: 4002],
19 | server: false
20 |
21 | # Print only warnings and errors during test
22 | config :logger, level: :warn
23 |
--------------------------------------------------------------------------------
/lib/easy_wire/profiles/profile.ex:
--------------------------------------------------------------------------------
1 | defmodule EasyWire.Profiles.Profile do
2 | import Norm
3 |
4 | alias EasyWire.Types
5 |
6 | defstruct [
7 | :id,
8 | :name,
9 | :trust,
10 | :company
11 | ]
12 |
13 | def schema,
14 | do:
15 | schema(%__MODULE__{
16 | id: Types.id(),
17 | name: Types.person_name(),
18 | trust: trust(),
19 | company: company()
20 | })
21 |
22 | defp trust() do
23 | alt(
24 | verified: :verified,
25 | unverified: :unverified
26 | )
27 | end
28 |
29 | defp company() do
30 | generator =
31 | StreamData.sized(fn _ ->
32 | StreamData.constant(Faker.Company.name())
33 | end)
34 |
35 | with_gen(spec(is_binary), generator)
36 | end
37 | end
38 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # EasyWire
2 |
3 | To start your Phoenix server:
4 |
5 | * Install dependencies with `mix deps.get`
6 | * Create and migrate your database with `mix ecto.setup`
7 | * Install Node.js dependencies with `npm install` inside the `assets` directory
8 | * Start Phoenix endpoint with `mix phx.server`
9 |
10 | Now you can visit [`localhost:4000`](http://localhost:4000) from your browser.
11 |
12 | Ready to run in production? Please [check our deployment guides](https://hexdocs.pm/phoenix/deployment.html).
13 |
14 | ## Learn more
15 |
16 | * Official website: https://www.phoenixframework.org/
17 | * Guides: https://hexdocs.pm/phoenix/overview.html
18 | * Docs: https://hexdocs.pm/phoenix
19 | * Forum: https://elixirforum.com/c/phoenix-forum
20 | * Source: https://github.com/phoenixframework/phoenix
21 |
--------------------------------------------------------------------------------
/lib/easy_wire_web/gettext.ex:
--------------------------------------------------------------------------------
1 | defmodule EasyWireWeb.Gettext do
2 | @moduledoc """
3 | A module providing Internationalization with a gettext-based API.
4 |
5 | By using [Gettext](https://hexdocs.pm/gettext),
6 | your module gains a set of macros for translations, for example:
7 |
8 | import EasyWireWeb.Gettext
9 |
10 | # Simple translation
11 | gettext("Here is the string to translate")
12 |
13 | # Plural translation
14 | ngettext("Here is the string to translate",
15 | "Here are the strings to translate",
16 | 3)
17 |
18 | # Domain-based translation
19 | dgettext("errors", "Here is the error message to translate")
20 |
21 | See the [Gettext Docs](https://hexdocs.pm/gettext) for detailed usage.
22 | """
23 | use Gettext, otp_app: :easy_wire
24 | end
25 |
--------------------------------------------------------------------------------
/lib/easy_wire/types.ex:
--------------------------------------------------------------------------------
1 | defmodule EasyWire.Types do
2 | use ExUnitProperties
3 | import Norm
4 |
5 | def id do
6 | generator =
7 | StreamData.sized(fn _ ->
8 | StreamData.constant(Faker.UUID.v4())
9 | end)
10 |
11 | with_gen(spec(is_binary), generator)
12 | end
13 |
14 | def person_name() do
15 | generator =
16 | StreamData.sized(fn _ ->
17 | StreamData.constant(Faker.Person.name())
18 | end)
19 |
20 | with_gen(spec(is_binary), generator)
21 | end
22 |
23 | def date do
24 | with_gen(spec(is_struct()), date_generator())
25 | end
26 |
27 | def date_generator() do
28 | gen all year <- integer(1970..2050),
29 | month <- integer(1..12),
30 | day <- integer(1..31),
31 | match?({:ok, _}, Date.from_erl({year, month, day})) do
32 | Date.from_erl!({year, month, day})
33 | end
34 | end
35 | end
36 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # The directory Mix will write compiled artifacts to.
2 | /_build/
3 |
4 | # If you run "mix test --cover", coverage assets end up here.
5 | /cover/
6 |
7 | # The directory Mix downloads your dependencies sources to.
8 | /deps/
9 |
10 | # Where 3rd-party dependencies like ExDoc output generated docs.
11 | /doc/
12 |
13 | # Ignore .fetch files in case you like to edit your project deps locally.
14 | /.fetch
15 |
16 | # If the VM crashes, it generates a dump, let's ignore it too.
17 | erl_crash.dump
18 |
19 | # Also ignore archive artifacts (built via "mix archive.build").
20 | *.ez
21 |
22 | # Ignore package tarball (built via "mix hex.build").
23 | easy_wire-*.tar
24 |
25 | # If NPM crashes, it generates a log, let's ignore it too.
26 | npm-debug.log
27 |
28 | # The directory NPM downloads your dependencies sources to.
29 | /assets/node_modules/
30 |
31 | # Since we are building assets from assets/,
32 | # we ignore priv/static. You may want to comment
33 | # this depending on your deployment strategy.
34 | /priv/static/
35 |
--------------------------------------------------------------------------------
/assets/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "repository": {},
3 | "description": " ",
4 | "license": "MIT",
5 | "scripts": {
6 | "deploy": "webpack --mode production",
7 | "watch": "webpack --mode development --watch"
8 | },
9 | "dependencies": {
10 | "@tailwindcss/forms": "^0.3.2",
11 | "alpinejs": "^2.8.2",
12 | "phoenix": "file:../deps/phoenix",
13 | "phoenix_html": "file:../deps/phoenix_html",
14 | "phoenix_live_view": "file:../deps/phoenix_live_view",
15 | "tailwindcss": "^2.1.2",
16 | "topbar": "^0.1.4"
17 | },
18 | "devDependencies": {
19 | "@babel/core": "^7.0.0",
20 | "@babel/preset-env": "^7.0.0",
21 | "autoprefixer": "^10.2.5",
22 | "babel-loader": "^8.0.0",
23 | "copy-webpack-plugin": "^5.1.1",
24 | "css-loader": "^3.4.2",
25 | "hard-source-webpack-plugin": "^0.13.1",
26 | "mini-css-extract-plugin": "^0.9.0",
27 | "node-sass": "^4.13.1",
28 | "optimize-css-assets-webpack-plugin": "^5.0.1",
29 | "postcss": "^8.2.13",
30 | "postcss-loader": "^4.2.0",
31 | "sass-loader": "^8.0.2",
32 | "terser-webpack-plugin": "^2.3.2",
33 | "webpack": "^4.41.5",
34 | "webpack-cli": "^3.3.2"
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/lib/easy_wire_web/channels/user_socket.ex:
--------------------------------------------------------------------------------
1 | defmodule EasyWireWeb.UserSocket do
2 | use Phoenix.Socket
3 |
4 | ## Channels
5 | # channel "room:*", EasyWireWeb.RoomChannel
6 |
7 | # Socket params are passed from the client and can
8 | # be used to verify and authenticate a user. After
9 | # verification, you can put default assigns into
10 | # the socket that will be set for all channels, ie
11 | #
12 | # {:ok, assign(socket, :user_id, verified_user_id)}
13 | #
14 | # To deny connection, return `:error`.
15 | #
16 | # See `Phoenix.Token` documentation for examples in
17 | # performing token verification on connect.
18 | @impl true
19 | def connect(_params, socket, _connect_info) do
20 | {:ok, socket}
21 | end
22 |
23 | # Socket id's are topics that allow you to identify all sockets for a given user:
24 | #
25 | # def id(socket), do: "user_socket:#{socket.assigns.user_id}"
26 | #
27 | # Would allow you to broadcast a "disconnect" event and terminate
28 | # all active sockets and channels for a given user:
29 | #
30 | # EasyWireWeb.Endpoint.broadcast("user_socket:#{user.id}", "disconnect", %{})
31 | #
32 | # Returning `nil` makes this socket anonymous.
33 | @impl true
34 | def id(_socket), do: nil
35 | end
36 |
--------------------------------------------------------------------------------
/test/support/channel_case.ex:
--------------------------------------------------------------------------------
1 | defmodule EasyWireWeb.ChannelCase do
2 | @moduledoc """
3 | This module defines the test case to be used by
4 | channel tests.
5 |
6 | Such tests rely on `Phoenix.ChannelTest` and also
7 | import other functionality to make it easier
8 | to build common data structures and query the data layer.
9 |
10 | Finally, if the test case interacts with the database,
11 | we enable the SQL sandbox, so changes done to the database
12 | are reverted at the end of every test. If you are using
13 | PostgreSQL, you can even run database tests asynchronously
14 | by setting `use EasyWireWeb.ChannelCase, async: true`, although
15 | this option is not recommended for other databases.
16 | """
17 |
18 | use ExUnit.CaseTemplate
19 |
20 | using do
21 | quote do
22 | # Import conveniences for testing with channels
23 | import Phoenix.ChannelTest
24 | import EasyWireWeb.ChannelCase
25 |
26 | # The default endpoint for testing
27 | @endpoint EasyWireWeb.Endpoint
28 | end
29 | end
30 |
31 | setup tags do
32 | :ok = Ecto.Adapters.SQL.Sandbox.checkout(EasyWire.Repo)
33 |
34 | unless tags[:async] do
35 | Ecto.Adapters.SQL.Sandbox.mode(EasyWire.Repo, {:shared, self()})
36 | end
37 |
38 | :ok
39 | end
40 | end
41 |
--------------------------------------------------------------------------------
/lib/easy_wire/transactions/transaction.ex:
--------------------------------------------------------------------------------
1 | defmodule EasyWire.Transactions.Transaction do
2 | use ExUnitProperties
3 |
4 | import Norm
5 |
6 | alias EasyWire.Types
7 |
8 | defstruct [
9 | :id,
10 | :sender_id,
11 | :recipient_id,
12 | :sender,
13 | :recipient,
14 | :amount,
15 | :status,
16 | :description,
17 | :date
18 | ]
19 |
20 | def schema,
21 | do:
22 | schema(%__MODULE__{
23 | id: Types.id(),
24 | sender_id: Types.id(),
25 | recipient_id: Types.id(),
26 | amount: amount(),
27 | status: status(),
28 | description: description(),
29 | date: Types.date()
30 | })
31 |
32 | defp amount() do
33 | spec(is_integer() and (&(&1 >= 0)))
34 | end
35 |
36 | defp status() do
37 | alt(
38 | done: :done,
39 | pending: :pending,
40 | failed: :failed
41 | )
42 | end
43 |
44 | defp description() do
45 | generator =
46 | StreamData.sized(fn _ ->
47 | StreamData.one_of([
48 | StreamData.constant(Faker.Commerce.product_name()),
49 | StreamData.constant(Faker.Food.dish()),
50 | StreamData.constant(Faker.Lorem.sentence())
51 | ])
52 | end)
53 |
54 | with_gen(spec(is_binary), generator)
55 | end
56 | end
57 |
--------------------------------------------------------------------------------
/lib/easy_wire_web/router.ex:
--------------------------------------------------------------------------------
1 | defmodule EasyWireWeb.Router do
2 | use EasyWireWeb, :router
3 |
4 | pipeline :browser do
5 | plug :accepts, ["html"]
6 | plug :fetch_session
7 | plug :fetch_live_flash
8 | plug :put_root_layout, {EasyWireWeb.LayoutView, :root}
9 | plug :protect_from_forgery
10 | plug :put_secure_browser_headers
11 | end
12 |
13 | pipeline :api do
14 | plug :accepts, ["json"]
15 | end
16 |
17 | scope "/", EasyWireWeb do
18 | pipe_through :browser
19 |
20 | live "/", PageLive, :index
21 | end
22 |
23 | # Other scopes may use custom stacks.
24 | # scope "/api", EasyWireWeb do
25 | # pipe_through :api
26 | # end
27 |
28 | # Enables LiveDashboard only for development
29 | #
30 | # If you want to use the LiveDashboard in production, you should put
31 | # it behind authentication and allow only admins to access it.
32 | # If your application does not have an admins-only section yet,
33 | # you can use Plug.BasicAuth to set up some basic authentication
34 | # as long as you are also using SSL (which you should anyway).
35 | if Mix.env() in [:dev, :test] do
36 | import Phoenix.LiveDashboard.Router
37 |
38 | scope "/" do
39 | pipe_through :browser
40 | live_dashboard "/dashboard", metrics: EasyWireWeb.Telemetry
41 | end
42 | end
43 | end
44 |
--------------------------------------------------------------------------------
/config/prod.secret.exs:
--------------------------------------------------------------------------------
1 | # In this file, we load production configuration and secrets
2 | # from environment variables. You can also hardcode secrets,
3 | # although such is generally not recommended and you have to
4 | # remember to add this file to your .gitignore.
5 | use Mix.Config
6 |
7 | database_url =
8 | System.get_env("DATABASE_URL") ||
9 | raise """
10 | environment variable DATABASE_URL is missing.
11 | For example: ecto://USER:PASS@HOST/DATABASE
12 | """
13 |
14 | config :easy_wire, EasyWire.Repo,
15 | # ssl: true,
16 | url: database_url,
17 | pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10")
18 |
19 | secret_key_base =
20 | System.get_env("SECRET_KEY_BASE") ||
21 | raise """
22 | environment variable SECRET_KEY_BASE is missing.
23 | You can generate one by calling: mix phx.gen.secret
24 | """
25 |
26 | config :easy_wire, EasyWireWeb.Endpoint,
27 | http: [
28 | port: String.to_integer(System.get_env("PORT") || "4000"),
29 | transport_options: [socket_opts: [:inet6]]
30 | ],
31 | secret_key_base: secret_key_base
32 |
33 | # ## Using releases (Elixir v1.9+)
34 | #
35 | # If you are doing OTP releases, you need to instruct Phoenix
36 | # to start each relevant endpoint:
37 | #
38 | # config :easy_wire, EasyWireWeb.Endpoint, server: true
39 | #
40 | # Then you can assemble a release by calling `mix release`.
41 | # See `mix help release` for more information.
42 |
--------------------------------------------------------------------------------
/test/support/conn_case.ex:
--------------------------------------------------------------------------------
1 | defmodule EasyWireWeb.ConnCase do
2 | @moduledoc """
3 | This module defines the test case to be used by
4 | tests that require setting up a connection.
5 |
6 | Such tests rely on `Phoenix.ConnTest` and also
7 | import other functionality to make it easier
8 | to build common data structures and query the data layer.
9 |
10 | Finally, if the test case interacts with the database,
11 | we enable the SQL sandbox, so changes done to the database
12 | are reverted at the end of every test. If you are using
13 | PostgreSQL, you can even run database tests asynchronously
14 | by setting `use EasyWireWeb.ConnCase, async: true`, although
15 | this option is not recommended for other databases.
16 | """
17 |
18 | use ExUnit.CaseTemplate
19 |
20 | using do
21 | quote do
22 | # Import conveniences for testing with connections
23 | import Plug.Conn
24 | import Phoenix.ConnTest
25 | import EasyWireWeb.ConnCase
26 |
27 | alias EasyWireWeb.Router.Helpers, as: Routes
28 |
29 | # The default endpoint for testing
30 | @endpoint EasyWireWeb.Endpoint
31 | end
32 | end
33 |
34 | setup tags do
35 | :ok = Ecto.Adapters.SQL.Sandbox.checkout(EasyWire.Repo)
36 |
37 | unless tags[:async] do
38 | Ecto.Adapters.SQL.Sandbox.mode(EasyWire.Repo, {:shared, self()})
39 | end
40 |
41 | {:ok, conn: Phoenix.ConnTest.build_conn()}
42 | end
43 | end
44 |
--------------------------------------------------------------------------------
/lib/service_mesh/middleware/telemetry.ex:
--------------------------------------------------------------------------------
1 | defmodule ServiceMesh.Middleware.Telemetry do
2 | use ServiceMesh.Middleware
3 |
4 | @impl ServiceMesh.Middleware
5 | def init(service, opts) do
6 | Keyword.put(opts, :service, service)
7 | end
8 |
9 | @impl ServiceMesh.Middleware
10 | def call(next, opts) do
11 | service = Keyword.fetch!(opts, :service)
12 |
13 | start_time = start(service)
14 |
15 | try do
16 | result = next.()
17 | stop(service, start_time)
18 | result
19 | rescue
20 | error ->
21 | exception(service, start_time, :error, error, __STACKTRACE__)
22 | reraise error, __STACKTRACE__
23 | end
24 | end
25 |
26 | defp start(event) do
27 | start_time = System.monotonic_time()
28 | measurements = %{system_time: System.system_time()}
29 |
30 | :telemetry.execute(
31 | [:service_mesh, event, :start],
32 | measurements
33 | )
34 |
35 | start_time
36 | end
37 |
38 | defp stop(event, start_time) do
39 | end_time = System.monotonic_time()
40 | measurements = %{duration: end_time - start_time}
41 |
42 | :telemetry.execute(
43 | [:service_mesh, event, :stop],
44 | measurements
45 | )
46 | end
47 |
48 | defp exception(event, start_time, kind, reason, stack) do
49 | end_time = System.monotonic_time()
50 | measurements = %{duration: end_time - start_time}
51 |
52 | meta =
53 | %{}
54 | |> Map.put(:kind, kind)
55 | |> Map.put(:error, reason)
56 | |> Map.put(:stacktrace, stack)
57 |
58 | :telemetry.execute([:service_mesh, event, :exception], measurements, meta)
59 | end
60 | end
61 |
--------------------------------------------------------------------------------
/config/config.exs:
--------------------------------------------------------------------------------
1 | # This file is responsible for configuring your application
2 | # and its dependencies with the aid of the Mix.Config module.
3 | #
4 | # This configuration file is loaded before any dependency and
5 | # is restricted to this project.
6 |
7 | # General application configuration
8 | use Mix.Config
9 |
10 | config :easy_wire,
11 | ecto_repos: [EasyWire.Repo]
12 |
13 | # Configures the endpoint
14 | config :easy_wire, EasyWireWeb.Endpoint,
15 | url: [host: "localhost"],
16 | secret_key_base: "QyDMe1xs4QjjaWBTCXa+ZpMLWIb2JK4IIQyaE9vogOZc0LD7ByQakqow5EsX0kyg",
17 | render_errors: [view: EasyWireWeb.ErrorView, accepts: ~w(html json), layout: false],
18 | pubsub_server: EasyWire.PubSub,
19 | live_view: [signing_salt: "g/rg/sYk"]
20 |
21 | config :easy_wire, EasyWire.ServiceRouter, fn ->
22 | profile_ids =
23 | EasyWire.Types.id()
24 | |> Norm.gen()
25 | |> Enum.take(10)
26 |
27 | %{
28 | profiles: EasyWire.Profiles.InMemory.new(profile_ids: profile_ids),
29 | accounts: EasyWire.Accounts.InMemory.new(profile_ids: profile_ids),
30 | transactions:
31 | EasyWire.Transactions.DenormalizeFast.new(
32 | EasyWire.Transactions.InMemory.new(profile_ids: profile_ids)
33 | )
34 | }
35 | end
36 |
37 | # Configures Elixir's Logger
38 | config :logger, :console,
39 | format: "$time $metadata[$level] $message\n",
40 | metadata: [:request_id]
41 |
42 | # Use Jason for JSON parsing in Phoenix
43 | config :phoenix, :json_library, Jason
44 |
45 | # Import environment specific config. This must remain at the bottom
46 | # of this file so it overrides the configuration defined above.
47 | import_config "#{Mix.env()}.exs"
48 |
--------------------------------------------------------------------------------
/assets/js/app.js:
--------------------------------------------------------------------------------
1 | import 'alpinejs'
2 |
3 | // We need to import the CSS so that webpack will load it.
4 | // The MiniCssExtractPlugin is used to separate it out into
5 | // its own CSS file.
6 | import "../css/app.scss"
7 |
8 | // webpack automatically bundles all modules in your
9 | // entry points. Those entry points can be configured
10 | // in "webpack.config.js".
11 | //
12 | // Import deps with the dep name or local files with a relative path, for example:
13 | //
14 | // import {Socket} from "phoenix"
15 | // import socket from "./socket"
16 | //
17 | import "phoenix_html"
18 | import { Socket } from "phoenix"
19 | import topbar from "topbar"
20 | import { LiveSocket } from "phoenix_live_view"
21 |
22 | let csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content")
23 | let liveSocket = new LiveSocket("/live", Socket, {
24 | params: { _csrf_token: csrfToken },
25 | dom: {
26 | onBeforeElUpdated(from, to) {
27 | if (from.__x) { window.Alpine.clone(from.__x, to) }
28 | }
29 | }
30 | })
31 |
32 | // Show progress bar on live navigation and form submits
33 | topbar.config({ barColors: { 0: "#29d" }, shadowColor: "rgba(0, 0, 0, .3)" })
34 | window.addEventListener("phx:page-loading-start", info => topbar.show())
35 | window.addEventListener("phx:page-loading-stop", info => topbar.hide())
36 |
37 | // connect if there are any LiveViews on the page
38 | liveSocket.connect()
39 |
40 | // expose liveSocket on window for web console debug logs and latency simulation:
41 | // >> liveSocket.enableDebug()
42 | // >> liveSocket.enableLatencySim(1000) // enabled for duration of browser session
43 | // >> liveSocket.disableLatencySim()
44 | window.liveSocket = liveSocket
45 |
46 |
--------------------------------------------------------------------------------
/lib/easy_wire_web/views/error_helpers.ex:
--------------------------------------------------------------------------------
1 | defmodule EasyWireWeb.ErrorHelpers do
2 | @moduledoc """
3 | Conveniences for translating and building error messages.
4 | """
5 |
6 | use Phoenix.HTML
7 |
8 | @doc """
9 | Generates tag for inlined form input errors.
10 | """
11 | def error_tag(form, field) do
12 | Enum.map(Keyword.get_values(form.errors, field), fn error ->
13 | content_tag(:span, translate_error(error),
14 | class: "invalid-feedback",
15 | phx_feedback_for: input_name(form, field)
16 | )
17 | end)
18 | end
19 |
20 | @doc """
21 | Translates an error message using gettext.
22 | """
23 | def translate_error({msg, opts}) do
24 | # When using gettext, we typically pass the strings we want
25 | # to translate as a static argument:
26 | #
27 | # # Translate "is invalid" in the "errors" domain
28 | # dgettext("errors", "is invalid")
29 | #
30 | # # Translate the number of files with plural rules
31 | # dngettext("errors", "1 file", "%{count} files", count)
32 | #
33 | # Because the error messages we show in our forms and APIs
34 | # are defined inside Ecto, we need to translate them dynamically.
35 | # This requires us to call the Gettext module passing our gettext
36 | # backend as first argument.
37 | #
38 | # Note we use the "errors" domain, which means translations
39 | # should be written to the errors.po file. The :count option is
40 | # set by Ecto and indicates we should also apply plural rules.
41 | if count = opts[:count] do
42 | Gettext.dngettext(EasyWireWeb.Gettext, "errors", msg, msg, count, opts)
43 | else
44 | Gettext.dgettext(EasyWireWeb.Gettext, "errors", msg, opts)
45 | end
46 | end
47 | end
48 |
--------------------------------------------------------------------------------
/test/support/data_case.ex:
--------------------------------------------------------------------------------
1 | defmodule EasyWire.DataCase do
2 | @moduledoc """
3 | This module defines the setup for tests requiring
4 | access to the application's data layer.
5 |
6 | You may define functions here to be used as helpers in
7 | your tests.
8 |
9 | Finally, if the test case interacts with the database,
10 | we enable the SQL sandbox, so changes done to the database
11 | are reverted at the end of every test. If you are using
12 | PostgreSQL, you can even run database tests asynchronously
13 | by setting `use EasyWire.DataCase, async: true`, although
14 | this option is not recommended for other databases.
15 | """
16 |
17 | use ExUnit.CaseTemplate
18 |
19 | using do
20 | quote do
21 | alias EasyWire.Repo
22 |
23 | import Ecto
24 | import Ecto.Changeset
25 | import Ecto.Query
26 | import EasyWire.DataCase
27 | end
28 | end
29 |
30 | setup tags do
31 | :ok = Ecto.Adapters.SQL.Sandbox.checkout(EasyWire.Repo)
32 |
33 | unless tags[:async] do
34 | Ecto.Adapters.SQL.Sandbox.mode(EasyWire.Repo, {:shared, self()})
35 | end
36 |
37 | :ok
38 | end
39 |
40 | @doc """
41 | A helper that transforms changeset errors into a map of messages.
42 |
43 | assert {:error, changeset} = Accounts.create_user(%{password: "short"})
44 | assert "password is too short" in errors_on(changeset).password
45 | assert %{password: ["password is too short"]} = errors_on(changeset)
46 |
47 | """
48 | def errors_on(changeset) do
49 | Ecto.Changeset.traverse_errors(changeset, fn {message, opts} ->
50 | Regex.replace(~r"%{(\w+)}", message, fn _, key ->
51 | opts |> Keyword.get(String.to_existing_atom(key), key) |> to_string()
52 | end)
53 | end)
54 | end
55 | end
56 |
--------------------------------------------------------------------------------
/lib/service_mesh.ex:
--------------------------------------------------------------------------------
1 | defmodule ServiceMesh do
2 | use Supervisor
3 |
4 | alias ServiceMesh.Router
5 |
6 | def start_link(init_arg) do
7 | Supervisor.start_link(__MODULE__, init_arg, name: __MODULE__)
8 | end
9 |
10 | def call(name \\ Registry.ServiceMesh, service, function, args) do
11 | with {:ok, router} <- Registry.meta(name, :router),
12 | {:ok, {impl, middleware}} <-
13 | Registry.meta(
14 | name,
15 | {:service, service}
16 | ) do
17 | Router.dispatch(router, service, middleware, impl, function, args)
18 | end
19 | end
20 |
21 | @impl true
22 | def init(router) do
23 | children = [
24 | {Registry, keys: :unique, name: Registry.ServiceMesh},
25 | {Task, fn -> initialize_services(router) end}
26 | ]
27 |
28 | Supervisor.init(children, strategy: :rest_for_one)
29 | end
30 |
31 | defp initialize_services(router) do
32 | middleware = router.__middleware__()
33 | services = router.__services__()
34 | config = router.runtime_config()
35 |
36 | :ok = Registry.put_meta(Registry.ServiceMesh, :router, router)
37 |
38 | Enum.each(services, fn service ->
39 | case Map.get(config, service) do
40 | nil ->
41 | raise ArgumentError, "missing service implementation for #{service}"
42 |
43 | implementation ->
44 | middleware =
45 | Enum.map(middleware, fn {middleware, opts} ->
46 | {middleware, middleware.init(service, opts)}
47 | end)
48 |
49 | :ok =
50 | Registry.put_meta(
51 | Registry.ServiceMesh,
52 | {:service, service},
53 | {implementation, middleware}
54 | )
55 | end
56 | end)
57 | end
58 | end
59 |
--------------------------------------------------------------------------------
/assets/webpack.config.js:
--------------------------------------------------------------------------------
1 | const path = require('path');
2 | const glob = require('glob');
3 | const HardSourceWebpackPlugin = require('hard-source-webpack-plugin');
4 | const MiniCssExtractPlugin = require('mini-css-extract-plugin');
5 | const TerserPlugin = require('terser-webpack-plugin');
6 | const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
7 | const CopyWebpackPlugin = require('copy-webpack-plugin');
8 |
9 | module.exports = (env, options) => {
10 | const devMode = options.mode !== 'production';
11 |
12 | return {
13 | optimization: {
14 | minimizer: [
15 | new TerserPlugin({ cache: true, parallel: true, sourceMap: devMode }),
16 | new OptimizeCSSAssetsPlugin({})
17 | ]
18 | },
19 | entry: {
20 | 'app': glob.sync('./vendor/**/*.js').concat(['./js/app.js'])
21 | },
22 | output: {
23 | filename: '[name].js',
24 | path: path.resolve(__dirname, '../priv/static/js'),
25 | publicPath: '/js/'
26 | },
27 | devtool: devMode ? 'eval-cheap-module-source-map' : undefined,
28 | module: {
29 | rules: [
30 | {
31 | test: /\.js$/,
32 | exclude: /node_modules/,
33 | use: {
34 | loader: 'babel-loader'
35 | }
36 | },
37 | {
38 | test: /\.[s]?css$/,
39 | use: [
40 | MiniCssExtractPlugin.loader,
41 | 'css-loader',
42 | 'sass-loader',
43 | 'postcss-loader', // Add this
44 | ],
45 | }
46 | ]
47 | },
48 | plugins: [
49 | new MiniCssExtractPlugin({ filename: '../css/app.css' }),
50 | new CopyWebpackPlugin([{ from: 'static/', to: '../' }])
51 | ]
52 | .concat(devMode ? [new HardSourceWebpackPlugin()] : [])
53 | }
54 | };
55 |
--------------------------------------------------------------------------------
/lib/easy_wire_web/endpoint.ex:
--------------------------------------------------------------------------------
1 | defmodule EasyWireWeb.Endpoint do
2 | use Phoenix.Endpoint, otp_app: :easy_wire
3 |
4 | # The session will be stored in the cookie and signed,
5 | # this means its contents can be read but not tampered with.
6 | # Set :encryption_salt if you would also like to encrypt it.
7 | @session_options [
8 | store: :cookie,
9 | key: "_easy_wire_key",
10 | signing_salt: "EuVUkHHR"
11 | ]
12 |
13 | socket "/socket", EasyWireWeb.UserSocket,
14 | websocket: true,
15 | longpoll: false
16 |
17 | socket "/live", Phoenix.LiveView.Socket, websocket: [connect_info: [session: @session_options]]
18 |
19 | # Serve at "/" the static files from "priv/static" directory.
20 | #
21 | # You should set gzip to true if you are running phx.digest
22 | # when deploying your static files in production.
23 | plug Plug.Static,
24 | at: "/",
25 | from: :easy_wire,
26 | gzip: false,
27 | only: ~w(css fonts images js favicon.ico robots.txt)
28 |
29 | # Code reloading can be explicitly enabled under the
30 | # :code_reloader configuration of your endpoint.
31 | if code_reloading? do
32 | socket "/phoenix/live_reload/socket", Phoenix.LiveReloader.Socket
33 | plug Phoenix.LiveReloader
34 | plug Phoenix.CodeReloader
35 | plug Phoenix.Ecto.CheckRepoStatus, otp_app: :easy_wire
36 | end
37 |
38 | plug Phoenix.LiveDashboard.RequestLogger,
39 | param_key: "request_logger",
40 | cookie_key: "request_logger"
41 |
42 | plug Plug.RequestId
43 | plug Plug.Telemetry, event_prefix: [:phoenix, :endpoint]
44 |
45 | plug Plug.Parsers,
46 | parsers: [:urlencoded, :multipart, :json],
47 | pass: ["*/*"],
48 | json_decoder: Phoenix.json_library()
49 |
50 | plug Plug.MethodOverride
51 | plug Plug.Head
52 | plug Plug.Session, @session_options
53 | plug EasyWireWeb.Router
54 | end
55 |
--------------------------------------------------------------------------------
/lib/easy_wire_web/telemetry.ex:
--------------------------------------------------------------------------------
1 | defmodule EasyWireWeb.Telemetry do
2 | use Supervisor
3 | import Telemetry.Metrics
4 |
5 | def start_link(arg) do
6 | Supervisor.start_link(__MODULE__, arg, name: __MODULE__)
7 | end
8 |
9 | @impl true
10 | def init(_arg) do
11 | children = [
12 | # Telemetry poller will execute the given period measurements
13 | # every 10_000ms. Learn more here: https://hexdocs.pm/telemetry_metrics
14 | {:telemetry_poller, measurements: periodic_measurements(), period: 10_000}
15 | # Add reporters as children of your supervision tree.
16 | # {Telemetry.Metrics.ConsoleReporter, metrics: metrics()}
17 | ]
18 |
19 | Supervisor.init(children, strategy: :one_for_one)
20 | end
21 |
22 | def metrics do
23 | [
24 | # Phoenix Metrics
25 | summary("phoenix.endpoint.stop.duration",
26 | unit: {:native, :millisecond}
27 | ),
28 | summary("phoenix.router_dispatch.stop.duration",
29 | tags: [:route],
30 | unit: {:native, :millisecond}
31 | ),
32 |
33 | # Database Metrics
34 | summary("easy_wire.repo.query.total_time", unit: {:native, :millisecond}),
35 | summary("easy_wire.repo.query.decode_time", unit: {:native, :millisecond}),
36 | summary("easy_wire.repo.query.query_time", unit: {:native, :millisecond}),
37 | summary("easy_wire.repo.query.queue_time", unit: {:native, :millisecond}),
38 | summary("easy_wire.repo.query.idle_time", unit: {:native, :millisecond}),
39 |
40 | # VM Metrics
41 | summary("vm.memory.total", unit: {:byte, :kilobyte}),
42 | summary("vm.total_run_queue_lengths.total"),
43 | summary("vm.total_run_queue_lengths.cpu"),
44 | summary("vm.total_run_queue_lengths.io")
45 | ]
46 | end
47 |
48 | defp periodic_measurements do
49 | [
50 | # A module, function and arguments to be invoked periodically.
51 | # This function must call :telemetry.execute/3 and a metric must be added above.
52 | # {EasyWireWeb, :count_users, []}
53 | ]
54 | end
55 | end
56 |
--------------------------------------------------------------------------------
/lib/easy_wire/transactions/denormalize_slow.ex:
--------------------------------------------------------------------------------
1 | defmodule EasyWire.Transactions.DenormalizeSlow do
2 | alias EasyWire.Transactions
3 |
4 | defstruct [
5 | :inner_service
6 | ]
7 |
8 | def new(inner_service) do
9 | %__MODULE__{inner_service: inner_service}
10 | end
11 |
12 | defimpl Transactions.Service do
13 | def get_total_pending_transactions(service, profile_id) do
14 | Transactions.Service.get_total_pending_transactions(
15 | service.inner_service,
16 | profile_id
17 | )
18 | end
19 |
20 | def get_total_processed_transactions(service, profile_id) do
21 | Transactions.Service.get_total_processed_transactions(
22 | service.inner_service,
23 | profile_id
24 | )
25 | end
26 |
27 | def post_transaction(service, sender_id, recipient_id, amount) do
28 | Transactions.Service.post_transaction(
29 | service.inner_service,
30 | sender_id,
31 | recipient_id,
32 | amount
33 | )
34 | end
35 |
36 | def list_transactions(service, profile_id, page, page_size) do
37 | with {:ok, transactions} <-
38 | Transactions.Service.list_transactions(
39 | service.inner_service,
40 | profile_id,
41 | page,
42 | page_size
43 | ) do
44 | result =
45 | Map.update!(transactions, :entries, fn entries ->
46 | Enum.map(entries, fn transaction ->
47 | %{
48 | transaction
49 | | sender: get_profile(transaction.sender_id),
50 | recipient: get_profile(transaction.recipient_id)
51 | }
52 | end)
53 | end)
54 |
55 | {:ok, result}
56 | end
57 | end
58 |
59 | defp get_profile(profile_id) do
60 | get_profile_result =
61 | ServiceMesh.call(
62 | :profiles,
63 | :get_profile,
64 | [profile_id]
65 | )
66 |
67 | case get_profile_result do
68 | {:ok, profile} -> profile
69 | {:error, :econnrefused} -> nil
70 | end
71 | end
72 | end
73 | end
74 |
--------------------------------------------------------------------------------
/config/prod.exs:
--------------------------------------------------------------------------------
1 | use Mix.Config
2 |
3 | # For production, don't forget to configure the url host
4 | # to something meaningful, Phoenix uses this information
5 | # when generating URLs.
6 | #
7 | # Note we also include the path to a cache manifest
8 | # containing the digested version of static files. This
9 | # manifest is generated by the `mix phx.digest` task,
10 | # which you should run after static files are built and
11 | # before starting your production server.
12 | config :easy_wire, EasyWireWeb.Endpoint,
13 | url: [host: "example.com", port: 80],
14 | cache_static_manifest: "priv/static/cache_manifest.json"
15 |
16 | # Do not print debug messages in production
17 | config :logger, level: :info
18 |
19 | # ## SSL Support
20 | #
21 | # To get SSL working, you will need to add the `https` key
22 | # to the previous section and set your `:url` port to 443:
23 | #
24 | # config :easy_wire, EasyWireWeb.Endpoint,
25 | # ...
26 | # url: [host: "example.com", port: 443],
27 | # https: [
28 | # port: 443,
29 | # cipher_suite: :strong,
30 | # keyfile: System.get_env("SOME_APP_SSL_KEY_PATH"),
31 | # certfile: System.get_env("SOME_APP_SSL_CERT_PATH"),
32 | # transport_options: [socket_opts: [:inet6]]
33 | # ]
34 | #
35 | # The `cipher_suite` is set to `:strong` to support only the
36 | # latest and more secure SSL ciphers. This means old browsers
37 | # and clients may not be supported. You can set it to
38 | # `:compatible` for wider support.
39 | #
40 | # `:keyfile` and `:certfile` expect an absolute path to the key
41 | # and cert in disk or a relative path inside priv, for example
42 | # "priv/ssl/server.key". For all supported SSL configuration
43 | # options, see https://hexdocs.pm/plug/Plug.SSL.html#configure/1
44 | #
45 | # We also recommend setting `force_ssl` in your endpoint, ensuring
46 | # no data is ever sent via http, always redirecting to https:
47 | #
48 | # config :easy_wire, EasyWireWeb.Endpoint,
49 | # force_ssl: [hsts: true]
50 | #
51 | # Check `Plug.SSL` for all available options in `force_ssl`.
52 |
53 | # Finally import the config/prod.secret.exs which loads secrets
54 | # and configuration from environment variables.
55 | import_config "prod.secret.exs"
56 |
--------------------------------------------------------------------------------
/lib/easy_wire/profiles/in_memory.ex:
--------------------------------------------------------------------------------
1 | defmodule EasyWire.Profiles.InMemory do
2 | alias EasyWire.Profiles.Profile
3 |
4 | defstruct [:pid]
5 |
6 | def new(opts) do
7 | {:ok, pid} = start_link(opts)
8 |
9 | %__MODULE__{pid: pid}
10 | end
11 |
12 | def start_link(opts) do
13 | Agent.start_link(fn ->
14 | profile_ids = Keyword.get(opts, :profile_ids, [])
15 | generation_size = Keyword.get(opts, :generation_size, 100)
16 |
17 | model = %{
18 | generation_size: generation_size,
19 | profiles: %{}
20 | }
21 |
22 | Enum.reduce(profile_ids, model, fn profile_id, model ->
23 | profile = generate_profile(model, profile_id)
24 |
25 | add_profile(model, profile)
26 | end)
27 | end)
28 | end
29 |
30 | def list_profiles(%__MODULE__{pid: pid}) do
31 | Agent.get(pid, fn model ->
32 | {:ok, Map.values(model.profiles)}
33 | end)
34 | end
35 |
36 | def get_profiles(%__MODULE__{pid: pid}, ids) do
37 | Agent.get(pid, fn model ->
38 | {:ok, Map.take(model.profiles, ids)}
39 | end)
40 | end
41 |
42 | def get_profile(%__MODULE__{pid: pid}, id) do
43 | Agent.get(pid, fn model ->
44 | {:ok, Map.get(model.profiles, id)}
45 | end)
46 | end
47 |
48 | def get_profile_from_session(%__MODULE__{pid: pid}, _session) do
49 | Agent.get(pid, fn model ->
50 | result =
51 | model.profiles
52 | |> Map.values()
53 | |> Enum.random()
54 |
55 | {:ok, result}
56 | end)
57 | end
58 |
59 | defp add_profile(model, profile) do
60 | Map.update!(model, :profiles, &Map.put(&1, profile.id, profile))
61 | end
62 |
63 | defp generate_profile(model, profile_id) do
64 | Profile.schema()
65 | |> Norm.gen()
66 | |> StreamData.resize(model.generation_size)
67 | |> Enum.at(0)
68 | |> Map.put(:id, profile_id)
69 | end
70 |
71 | defimpl EasyWire.Profiles.Service do
72 | alias EasyWire.Profiles.InMemory
73 |
74 | defdelegate list_profiles(service), to: InMemory
75 | defdelegate get_profiles(service, ids), to: InMemory
76 | defdelegate get_profile(service, id), to: InMemory
77 | defdelegate get_profile_from_session(service, sesson), to: InMemory
78 | end
79 | end
80 |
--------------------------------------------------------------------------------
/lib/easy_wire/accounts/in_memory.ex:
--------------------------------------------------------------------------------
1 | defmodule EasyWire.Accounts.InMemory do
2 | alias EasyWire.Accounts.Account
3 |
4 | defstruct [:pid]
5 |
6 | def new(opts) do
7 | {:ok, pid} = start_link(opts)
8 |
9 | %__MODULE__{pid: pid}
10 | end
11 |
12 | def start_link(opts) do
13 | Agent.start_link(fn ->
14 | profile_ids = Keyword.get(opts, :profile_ids, [])
15 | generation_size = Keyword.get(opts, :generation_size, 10000)
16 |
17 | model = %{
18 | generation_size: generation_size,
19 | accounts: %{}
20 | }
21 |
22 | Enum.reduce(profile_ids, model, fn profile_id, model ->
23 | account = generate_account(model, profile_id)
24 |
25 | add_account(model, account)
26 | end)
27 | end)
28 | end
29 |
30 | def get_account_for_profile(%__MODULE__{pid: pid}, profile_id) do
31 | Agent.get(pid, fn model ->
32 | {:ok, get_account(model, profile_id)}
33 | end)
34 | end
35 |
36 | def deposit_money(%__MODULE__{pid: pid}, profile_id, amount) do
37 | Agent.get_and_update(pid, fn model ->
38 | updated =
39 | update_account(
40 | model,
41 | profile_id,
42 | &Map.update!(&1, :balance, fn balance -> balance + amount end)
43 | )
44 |
45 | {{:ok, get_account(updated, profile_id)}, updated}
46 | end)
47 | end
48 |
49 | defp add_account(model, account) do
50 | Map.update!(model, :accounts, &Map.put(&1, account.profile_id, account))
51 | end
52 |
53 | defp get_account(model, profile_id) do
54 | Map.get(model.accounts, profile_id)
55 | end
56 |
57 | defp update_account(model, profile_id, update_fn) do
58 | Map.update!(model, :accounts, &Map.update!(&1, profile_id, update_fn))
59 | end
60 |
61 | defp generate_account(model, profile_id) do
62 | Account.schema()
63 | |> Norm.gen()
64 | |> StreamData.resize(model.generation_size)
65 | |> Enum.at(0)
66 | |> Map.put(:profile_id, profile_id)
67 | end
68 |
69 | defimpl EasyWire.Accounts.Service do
70 | alias EasyWire.Accounts.InMemory
71 |
72 | defdelegate get_account_for_profile(service, profile_id), to: InMemory
73 | defdelegate deposit_money(service, profile_id, amount), to: InMemory
74 | end
75 | end
76 |
--------------------------------------------------------------------------------
/lib/easy_wire/transactions/denormalize_fast.ex:
--------------------------------------------------------------------------------
1 | defmodule EasyWire.Transactions.DenormalizeFast do
2 | alias EasyWire.Transactions
3 |
4 | defstruct [
5 | :inner_service
6 | ]
7 |
8 | def new(inner_service) do
9 | %__MODULE__{inner_service: inner_service}
10 | end
11 |
12 | defimpl Transactions.Service do
13 | def get_total_pending_transactions(service, profile_id) do
14 | Transactions.Service.get_total_pending_transactions(
15 | service.inner_service,
16 | profile_id
17 | )
18 | end
19 |
20 | def get_total_processed_transactions(service, profile_id) do
21 | Transactions.Service.get_total_processed_transactions(
22 | service.inner_service,
23 | profile_id
24 | )
25 | end
26 |
27 | def post_transaction(service, sender_id, recipient_id, amount) do
28 | Transactions.Service.post_transaction(
29 | service.inner_service,
30 | sender_id,
31 | recipient_id,
32 | amount
33 | )
34 | end
35 |
36 | def list_transactions(service, profile_id, page, page_size) do
37 | with {:ok, transactions} <-
38 | Transactions.Service.list_transactions(
39 | service.inner_service,
40 | profile_id,
41 | page,
42 | page_size
43 | ) do
44 | profile_ids =
45 | Enum.flat_map(
46 | transactions.entries,
47 | &[&1.sender_id, &1.recipient_id]
48 | )
49 |
50 | profiles = get_profiles(profile_ids)
51 |
52 | result =
53 | Map.update!(transactions, :entries, fn entries ->
54 | Enum.map(entries, fn transaction ->
55 | %{
56 | transaction
57 | | sender: Map.get(profiles, transaction.sender_id),
58 | recipient: Map.get(profiles, transaction.recipient_id)
59 | }
60 | end)
61 | end)
62 |
63 | {:ok, result}
64 | end
65 | end
66 |
67 | defp get_profiles(profile_ids) do
68 | get_profiles_result =
69 | ServiceMesh.call(
70 | :profiles,
71 | :get_profiles,
72 | [profile_ids]
73 | )
74 |
75 | case get_profiles_result do
76 | {:ok, profiles} -> profiles
77 | {:error, :econnrefused} -> %{}
78 | end
79 | end
80 | end
81 | end
82 |
--------------------------------------------------------------------------------
/mix.exs:
--------------------------------------------------------------------------------
1 | defmodule EasyWire.MixProject do
2 | use Mix.Project
3 |
4 | def project do
5 | [
6 | app: :easy_wire,
7 | version: "0.1.0",
8 | elixir: "~> 1.7",
9 | elixirc_paths: elixirc_paths(Mix.env()),
10 | compilers: [:phoenix, :gettext] ++ Mix.compilers(),
11 | start_permanent: Mix.env() == :prod,
12 | aliases: aliases(),
13 | deps: deps(),
14 | consolidate_protocols: Mix.env() != :test
15 | ]
16 | end
17 |
18 | # Configuration for the OTP application.
19 | #
20 | # Type `mix help compile.app` for more information.
21 | def application do
22 | [
23 | mod: {EasyWire.Application, []},
24 | extra_applications: [:logger, :runtime_tools]
25 | ]
26 | end
27 |
28 | # Specifies which paths to compile per environment.
29 | defp elixirc_paths(:test), do: ["lib", "test/support"]
30 | defp elixirc_paths(_), do: ["lib"]
31 |
32 | # Specifies your project dependencies.
33 | #
34 | # Type `mix help deps` for examples and options.
35 | defp deps do
36 | [
37 | {:phoenix, "~> 1.5.8"},
38 | {:phoenix_ecto, "~> 4.1"},
39 | {:ecto_sql, "~> 3.4"},
40 | {:postgrex, ">= 0.0.0"},
41 | {:phoenix_live_view, "~> 0.15.1"},
42 | {:floki, ">= 0.27.0", only: :test},
43 | {:norm,
44 | github: "keathley/norm", ref: "4d9ac55e0c0711227f9befc872a9f758458eaefd", override: true},
45 | {:phoenix_html, "~> 2.11"},
46 | {:phoenix_live_reload, "~> 1.2", only: :dev},
47 | {:phoenix_live_dashboard, "~> 0.4"},
48 | {:telemetry_metrics, "~> 0.4"},
49 | {:telemetry_poller, "~> 0.4"},
50 | {:gettext, "~> 0.11"},
51 | {:jason, "~> 1.0"},
52 | {:plug_cowboy, "~> 2.0"},
53 | {:stream_data, "~> 0.4"},
54 | {:faker, "~> 0.16"},
55 | {:number, "~> 1.0.1"}
56 | ]
57 | end
58 |
59 | # Aliases are shortcuts or tasks specific to the current project.
60 | # For example, to install project dependencies and perform other setup tasks, run:
61 | #
62 | # $ mix setup
63 | #
64 | # See the documentation for `Mix` for more info on aliases.
65 | defp aliases do
66 | [
67 | setup: ["deps.get", "ecto.setup", "cmd npm install --prefix assets"],
68 | "ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"],
69 | "ecto.reset": ["ecto.drop", "ecto.setup"],
70 | test: ["ecto.create --quiet", "ecto.migrate --quiet", "test"]
71 | ]
72 | end
73 | end
74 |
--------------------------------------------------------------------------------
/config/dev.exs:
--------------------------------------------------------------------------------
1 | use Mix.Config
2 |
3 | # Configure your database
4 | config :easy_wire, EasyWire.Repo,
5 | username: "postgres",
6 | password: "postgres",
7 | database: "easy_wire_dev",
8 | hostname: "localhost",
9 | show_sensitive_data_on_connection_error: true,
10 | pool_size: 10
11 |
12 | # For development, we disable any cache and enable
13 | # debugging and code reloading.
14 | #
15 | # The watchers configuration can be used to run external
16 | # watchers to your application. For example, we use it
17 | # with webpack to recompile .js and .css sources.
18 | config :easy_wire, EasyWireWeb.Endpoint,
19 | http: [port: 4000],
20 | debug_errors: true,
21 | code_reloader: true,
22 | check_origin: false,
23 | watchers: [
24 | node: [
25 | "node_modules/webpack/bin/webpack.js",
26 | "--mode",
27 | "development",
28 | "--watch-stdin",
29 | cd: Path.expand("../assets", __DIR__)
30 | ]
31 | ]
32 |
33 | # ## SSL Support
34 | #
35 | # In order to use HTTPS in development, a self-signed
36 | # certificate can be generated by running the following
37 | # Mix task:
38 | #
39 | # mix phx.gen.cert
40 | #
41 | # Note that this task requires Erlang/OTP 20 or later.
42 | # Run `mix help phx.gen.cert` for more information.
43 | #
44 | # The `http:` config above can be replaced with:
45 | #
46 | # https: [
47 | # port: 4001,
48 | # cipher_suite: :strong,
49 | # keyfile: "priv/cert/selfsigned_key.pem",
50 | # certfile: "priv/cert/selfsigned.pem"
51 | # ],
52 | #
53 | # If desired, both `http:` and `https:` keys can be
54 | # configured to run both http and https servers on
55 | # different ports.
56 |
57 | # Watch static and templates for browser reloading.
58 | config :easy_wire, EasyWireWeb.Endpoint,
59 | live_reload: [
60 | patterns: [
61 | ~r"priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$",
62 | ~r"priv/gettext/.*(po)$",
63 | ~r"lib/easy_wire_web/(live|views)/.*(ex)$",
64 | ~r"lib/easy_wire_web/templates/.*(eex)$"
65 | ]
66 | ]
67 |
68 | # Do not include metadata nor timestamps in development logs
69 | config :logger, :console, format: "[$level] $message\n"
70 |
71 | # Set a higher stacktrace during development. Avoid configuring such
72 | # in production as building large stacktraces may be expensive.
73 | config :phoenix, :stacktrace_depth, 20
74 |
75 | # Initialize plugs at runtime for faster development compilation
76 | config :phoenix, :plug_init_mode, :runtime
77 |
--------------------------------------------------------------------------------
/lib/service_mesh/router.ex:
--------------------------------------------------------------------------------
1 | defmodule ServiceMesh.Router do
2 | require Logger
3 |
4 | defmacro __using__(opts) do
5 | otp_app = Keyword.fetch!(opts, :otp_app)
6 |
7 | quote do
8 | Module.register_attribute(__MODULE__, :middleware, accumulate: true)
9 | Module.register_attribute(__MODULE__, :services, accumulate: true)
10 |
11 | @before_compile ServiceMesh.Router
12 | import ServiceMesh.Router
13 |
14 | def runtime_config() do
15 | Application.get_env(unquote(otp_app), __MODULE__, fn -> %{} end).()
16 | end
17 |
18 | defoverridable runtime_config: 0
19 | end
20 | end
21 |
22 | defmacro __before_compile__(env) do
23 | middleware =
24 | env.module
25 | |> Module.get_attribute(:middleware)
26 | |> Enum.reverse()
27 |
28 | services =
29 | Module.get_attribute(env.module, :services)
30 | |> Enum.into(%{})
31 | |> Macro.escape()
32 |
33 | quote do
34 | def __middleware__() do
35 | unquote(middleware)
36 | end
37 |
38 | def __services__() do
39 | Map.keys(unquote(services))
40 | end
41 |
42 | def __service__(service) do
43 | Map.get(unquote(services), service)
44 | end
45 |
46 | def dispatch(service, middleware, impl, function, args) do
47 | ServiceMesh.Router.dispatch(
48 | __MODULE__,
49 | service,
50 | middleware,
51 | impl,
52 | function,
53 | args
54 | )
55 | end
56 | end
57 | end
58 |
59 | defmacro middleware(middleware, opts \\ []) do
60 | quote do
61 | Module.put_attribute(
62 | __MODULE__,
63 | :middleware,
64 | {unquote(middleware), unquote(opts)}
65 | )
66 | end
67 | end
68 |
69 | defmacro register(service, protocol) do
70 | quote do
71 | Module.put_attribute(
72 | __MODULE__,
73 | :services,
74 | {unquote(service), unquote(protocol)}
75 | )
76 | end
77 | end
78 |
79 | def dispatch(router, service, middleware, impl, function, args) do
80 | protocol = router.__service__(service)
81 |
82 | call_service = fn ->
83 | apply(protocol, function, [impl | args])
84 | end
85 |
86 | continuation =
87 | Enum.reduce(middleware, call_service, fn {middleware, opts}, continuation ->
88 | fn ->
89 | apply(middleware, :call, [continuation, opts])
90 | end
91 | end)
92 |
93 | continuation.()
94 | end
95 | end
96 |
--------------------------------------------------------------------------------
/priv/gettext/en/LC_MESSAGES/errors.po:
--------------------------------------------------------------------------------
1 | ## `msgid`s in this file come from POT (.pot) files.
2 | ##
3 | ## Do not add, change, or remove `msgid`s manually here as
4 | ## they're tied to the ones in the corresponding POT file
5 | ## (with the same domain).
6 | ##
7 | ## Use `mix gettext.extract --merge` or `mix gettext.merge`
8 | ## to merge POT files into PO files.
9 | msgid ""
10 | msgstr ""
11 | "Language: en\n"
12 |
13 | ## From Ecto.Changeset.cast/4
14 | msgid "can't be blank"
15 | msgstr ""
16 |
17 | ## From Ecto.Changeset.unique_constraint/3
18 | msgid "has already been taken"
19 | msgstr ""
20 |
21 | ## From Ecto.Changeset.put_change/3
22 | msgid "is invalid"
23 | msgstr ""
24 |
25 | ## From Ecto.Changeset.validate_acceptance/3
26 | msgid "must be accepted"
27 | msgstr ""
28 |
29 | ## From Ecto.Changeset.validate_format/3
30 | msgid "has invalid format"
31 | msgstr ""
32 |
33 | ## From Ecto.Changeset.validate_subset/3
34 | msgid "has an invalid entry"
35 | msgstr ""
36 |
37 | ## From Ecto.Changeset.validate_exclusion/3
38 | msgid "is reserved"
39 | msgstr ""
40 |
41 | ## From Ecto.Changeset.validate_confirmation/3
42 | msgid "does not match confirmation"
43 | msgstr ""
44 |
45 | ## From Ecto.Changeset.no_assoc_constraint/3
46 | msgid "is still associated with this entry"
47 | msgstr ""
48 |
49 | msgid "are still associated with this entry"
50 | msgstr ""
51 |
52 | ## From Ecto.Changeset.validate_length/3
53 | msgid "should be %{count} character(s)"
54 | msgid_plural "should be %{count} character(s)"
55 | msgstr[0] ""
56 | msgstr[1] ""
57 |
58 | msgid "should have %{count} item(s)"
59 | msgid_plural "should have %{count} item(s)"
60 | msgstr[0] ""
61 | msgstr[1] ""
62 |
63 | msgid "should be at least %{count} character(s)"
64 | msgid_plural "should be at least %{count} character(s)"
65 | msgstr[0] ""
66 | msgstr[1] ""
67 |
68 | msgid "should have at least %{count} item(s)"
69 | msgid_plural "should have at least %{count} item(s)"
70 | msgstr[0] ""
71 | msgstr[1] ""
72 |
73 | msgid "should be at most %{count} character(s)"
74 | msgid_plural "should be at most %{count} character(s)"
75 | msgstr[0] ""
76 | msgstr[1] ""
77 |
78 | msgid "should have at most %{count} item(s)"
79 | msgid_plural "should have at most %{count} item(s)"
80 | msgstr[0] ""
81 | msgstr[1] ""
82 |
83 | ## From Ecto.Changeset.validate_number/3
84 | msgid "must be less than %{number}"
85 | msgstr ""
86 |
87 | msgid "must be greater than %{number}"
88 | msgstr ""
89 |
90 | msgid "must be less than or equal to %{number}"
91 | msgstr ""
92 |
93 | msgid "must be greater than or equal to %{number}"
94 | msgstr ""
95 |
96 | msgid "must be equal to %{number}"
97 | msgstr ""
98 |
--------------------------------------------------------------------------------
/priv/gettext/errors.pot:
--------------------------------------------------------------------------------
1 | ## This is a PO Template file.
2 | ##
3 | ## `msgid`s here are often extracted from source code.
4 | ## Add new translations manually only if they're dynamic
5 | ## translations that can't be statically extracted.
6 | ##
7 | ## Run `mix gettext.extract` to bring this file up to
8 | ## date. Leave `msgstr`s empty as changing them here has no
9 | ## effect: edit them in PO (`.po`) files instead.
10 |
11 | ## From Ecto.Changeset.cast/4
12 | msgid "can't be blank"
13 | msgstr ""
14 |
15 | ## From Ecto.Changeset.unique_constraint/3
16 | msgid "has already been taken"
17 | msgstr ""
18 |
19 | ## From Ecto.Changeset.put_change/3
20 | msgid "is invalid"
21 | msgstr ""
22 |
23 | ## From Ecto.Changeset.validate_acceptance/3
24 | msgid "must be accepted"
25 | msgstr ""
26 |
27 | ## From Ecto.Changeset.validate_format/3
28 | msgid "has invalid format"
29 | msgstr ""
30 |
31 | ## From Ecto.Changeset.validate_subset/3
32 | msgid "has an invalid entry"
33 | msgstr ""
34 |
35 | ## From Ecto.Changeset.validate_exclusion/3
36 | msgid "is reserved"
37 | msgstr ""
38 |
39 | ## From Ecto.Changeset.validate_confirmation/3
40 | msgid "does not match confirmation"
41 | msgstr ""
42 |
43 | ## From Ecto.Changeset.no_assoc_constraint/3
44 | msgid "is still associated with this entry"
45 | msgstr ""
46 |
47 | msgid "are still associated with this entry"
48 | msgstr ""
49 |
50 | ## From Ecto.Changeset.validate_length/3
51 | msgid "should be %{count} character(s)"
52 | msgid_plural "should be %{count} character(s)"
53 | msgstr[0] ""
54 | msgstr[1] ""
55 |
56 | msgid "should have %{count} item(s)"
57 | msgid_plural "should have %{count} item(s)"
58 | msgstr[0] ""
59 | msgstr[1] ""
60 |
61 | msgid "should be at least %{count} character(s)"
62 | msgid_plural "should be at least %{count} character(s)"
63 | msgstr[0] ""
64 | msgstr[1] ""
65 |
66 | msgid "should have at least %{count} item(s)"
67 | msgid_plural "should have at least %{count} item(s)"
68 | msgstr[0] ""
69 | msgstr[1] ""
70 |
71 | msgid "should be at most %{count} character(s)"
72 | msgid_plural "should be at most %{count} character(s)"
73 | msgstr[0] ""
74 | msgstr[1] ""
75 |
76 | msgid "should have at most %{count} item(s)"
77 | msgid_plural "should have at most %{count} item(s)"
78 | msgstr[0] ""
79 | msgstr[1] ""
80 |
81 | ## From Ecto.Changeset.validate_number/3
82 | msgid "must be less than %{number}"
83 | msgstr ""
84 |
85 | msgid "must be greater than %{number}"
86 | msgstr ""
87 |
88 | msgid "must be less than or equal to %{number}"
89 | msgstr ""
90 |
91 | msgid "must be greater than or equal to %{number}"
92 | msgstr ""
93 |
94 | msgid "must be equal to %{number}"
95 | msgstr ""
96 |
--------------------------------------------------------------------------------
/lib/easy_wire_web.ex:
--------------------------------------------------------------------------------
1 | defmodule EasyWireWeb do
2 | @moduledoc """
3 | The entrypoint for defining your web interface, such
4 | as controllers, views, channels and so on.
5 |
6 | This can be used in your application as:
7 |
8 | use EasyWireWeb, :controller
9 | use EasyWireWeb, :view
10 |
11 | The definitions below will be executed for every view,
12 | controller, etc, so keep them short and clean, focused
13 | on imports, uses and aliases.
14 |
15 | Do NOT define functions inside the quoted expressions
16 | below. Instead, define any helper function in modules
17 | and import those modules here.
18 | """
19 |
20 | def controller do
21 | quote do
22 | use Phoenix.Controller, namespace: EasyWireWeb
23 |
24 | import Plug.Conn
25 | import EasyWireWeb.Gettext
26 | alias EasyWireWeb.Router.Helpers, as: Routes
27 | end
28 | end
29 |
30 | def view do
31 | quote do
32 | use Phoenix.View,
33 | root: "lib/easy_wire_web/templates",
34 | namespace: EasyWireWeb
35 |
36 | # Import convenience functions from controllers
37 | import Phoenix.Controller,
38 | only: [get_flash: 1, get_flash: 2, view_module: 1, view_template: 1]
39 |
40 | # Include shared imports and aliases for views
41 | unquote(view_helpers())
42 | end
43 | end
44 |
45 | def live_view do
46 | quote do
47 | use Phoenix.LiveView,
48 | layout: {EasyWireWeb.LayoutView, "live.html"}
49 |
50 | unquote(view_helpers())
51 | end
52 | end
53 |
54 | def live_component do
55 | quote do
56 | use Phoenix.LiveComponent
57 |
58 | unquote(view_helpers())
59 | end
60 | end
61 |
62 | def router do
63 | quote do
64 | use Phoenix.Router
65 |
66 | import Plug.Conn
67 | import Phoenix.Controller
68 | import Phoenix.LiveView.Router
69 | end
70 | end
71 |
72 | def channel do
73 | quote do
74 | use Phoenix.Channel
75 | import EasyWireWeb.Gettext
76 | end
77 | end
78 |
79 | defp view_helpers do
80 | quote do
81 | # Use all HTML functionality (forms, tags, etc)
82 | use Phoenix.HTML
83 |
84 | # Import LiveView helpers (live_render, live_component, live_patch, etc)
85 | import Phoenix.LiveView.Helpers
86 |
87 | # Import basic rendering functionality (render, render_layout, etc)
88 | import Phoenix.View
89 |
90 | import EasyWireWeb.ErrorHelpers
91 | import EasyWireWeb.Gettext
92 | alias EasyWireWeb.Router.Helpers, as: Routes
93 | end
94 | end
95 |
96 | @doc """
97 | When used, dispatch to the appropriate controller/view/etc.
98 | """
99 | defmacro __using__(which) when is_atom(which) do
100 | apply(__MODULE__, which, [])
101 | end
102 | end
103 |
--------------------------------------------------------------------------------
/lib/easy_wire/transactions/in_memory.ex:
--------------------------------------------------------------------------------
1 | defmodule EasyWire.Transactions.InMemory do
2 | alias EasyWire.Transactions.Transaction
3 |
4 | defstruct [:pid]
5 |
6 | def new(opts) do
7 | {:ok, pid} = start_link(opts)
8 |
9 | %__MODULE__{pid: pid}
10 | end
11 |
12 | def start_link(opts) do
13 | Agent.start_link(fn ->
14 | profile_ids = Keyword.get(opts, :profile_ids, [])
15 | number_of_transactions = Keyword.get(opts, :number_of_transactions, 100)
16 | generation_size = Keyword.get(opts, :generation_size, 100)
17 |
18 | model = %{
19 | generation_size: generation_size,
20 | history: []
21 | }
22 |
23 | model =
24 | Enum.reduce(1..number_of_transactions, model, fn _, model ->
25 | transaction = seed_transaction(model, profile_ids)
26 |
27 | add_transaction_to_history(model, transaction)
28 | end)
29 |
30 | Map.update!(model, :history, fn history ->
31 | Enum.sort(history, &(Date.compare(&1.date, &2.date) == :gt))
32 | end)
33 | end)
34 | end
35 |
36 | def list_transactions(
37 | %__MODULE__{pid: pid},
38 | profile_id,
39 | page,
40 | page_size
41 | ) do
42 | Agent.get(pid, fn model ->
43 | start_index = (page - 1) * page_size
44 | end_index = start_index + page_size - 1
45 |
46 | transactions =
47 | Enum.filter(
48 | model.history,
49 | &transaction_for_profile_id?(&1, profile_id)
50 | )
51 |
52 | total_entries = length(transactions)
53 | total_pages = trunc(Float.ceil(total_entries / page_size))
54 |
55 | {:ok,
56 | %{
57 | entries: Enum.slice(transactions, start_index..end_index),
58 | start: start_index,
59 | end: end_index,
60 | total_entries: total_entries,
61 | total_pages: total_pages
62 | }}
63 | end)
64 | end
65 |
66 | def get_total_pending_transactions(%__MODULE__{pid: pid}, profile_id) do
67 | Agent.get(pid, fn model ->
68 | result =
69 | model.history
70 | |> Enum.filter(&transaction_for_profile_id?(&1, profile_id))
71 | |> Enum.filter(&(&1.status == :pending))
72 | |> Enum.reduce(0, fn transaction, total ->
73 | cond do
74 | transaction.sender_id == profile_id ->
75 | total - transaction.amount
76 |
77 | transaction.recipient_id == profile_id ->
78 | total + transaction.amount
79 | end
80 | end)
81 |
82 | {:ok, result}
83 | end)
84 | end
85 |
86 | def get_total_processed_transactions(%__MODULE__{pid: pid}, profile_id) do
87 | Agent.get(pid, fn model ->
88 | result =
89 | model.history
90 | |> Enum.filter(&transaction_for_profile_id?(&1, profile_id))
91 | |> Enum.filter(&(&1.status == :done))
92 | |> Enum.reduce(0, fn transaction, total ->
93 | total + transaction.amount
94 | end)
95 |
96 | {:ok, result}
97 | end)
98 | end
99 |
100 | def post_transaction(%__MODULE__{pid: pid}, sender, recipient, amount) do
101 | Agent.update(pid, fn model ->
102 | transaction =
103 | model
104 | |> generate_transaction()
105 | |> Map.put(:sender_id, sender)
106 | |> Map.put(:recipient_id, recipient)
107 | |> Map.put(:amount, amount)
108 | |> Map.put(:status, :done)
109 |
110 | add_transaction_to_history(model, transaction)
111 | end)
112 | end
113 |
114 | defp add_transaction_to_history(model, transaction) do
115 | Map.update!(model, :history, &[transaction | &1])
116 | end
117 |
118 | def seed_transaction(model, profile_ids) do
119 | [sender_id, recipient_id] = generate_transaction_participants(profile_ids)
120 |
121 | model
122 | |> generate_transaction()
123 | |> Map.put(:sender_id, sender_id)
124 | |> Map.put(:recipient_id, recipient_id)
125 | end
126 |
127 | defp generate_transaction_participants(profile_ids) do
128 | profile_ids
129 | |> Enum.map(&StreamData.constant/1)
130 | |> StreamData.one_of()
131 | |> StreamData.uniq_list_of(length: 2)
132 | |> Enum.at(0)
133 | end
134 |
135 | defp generate_transaction(model) do
136 | Transaction.schema()
137 | |> Norm.gen()
138 | |> StreamData.resize(model.generation_size)
139 | |> Enum.at(0)
140 | end
141 |
142 | defp transaction_for_profile_id?(transaction, profile_id) do
143 | transaction.sender_id == profile_id or
144 | transaction.recipient_id == profile_id
145 | end
146 |
147 | defimpl EasyWire.Transactions.Service do
148 | alias EasyWire.Transactions.InMemory
149 |
150 | defdelegate list_transactions(service, profile_id, page, page_size),
151 | to: InMemory
152 |
153 | defdelegate get_total_pending_transactions(service, profile_id),
154 | to: InMemory
155 |
156 | defdelegate get_total_processed_transactions(service, profile_id),
157 | to: InMemory
158 |
159 | defdelegate post_transaction(service, sender, recipient, amount),
160 | to: InMemory
161 | end
162 | end
163 |
--------------------------------------------------------------------------------
/lib/easy_wire_web/live/page_live.ex:
--------------------------------------------------------------------------------
1 | defmodule EasyWireWeb.PageLive do
2 | use EasyWireWeb, :live_view
3 |
4 | def mount(_params, session, socket) do
5 | if connected?(socket) do
6 | page = 1
7 | page_size = 5
8 |
9 | {:ok, profile} =
10 | ServiceMesh.call(
11 | :profiles,
12 | :get_profile_from_session,
13 | [session]
14 | )
15 |
16 | account = get_account(profile.id)
17 | transactions = get_transactions(profile.id, page, page_size)
18 | pending = get_pending_transactions(profile.id)
19 | processed = get_processed_transactions(profile.id)
20 |
21 | socket =
22 | socket
23 | |> assign(:page, page)
24 | |> assign(:page_size, page_size)
25 | |> assign(:profile, profile)
26 | |> assign(:account, account)
27 | |> assign(:transactions, transactions)
28 | |> assign(:pending, pending)
29 | |> assign(:processed, processed)
30 |
31 | {:ok, socket}
32 | else
33 | {:ok, socket}
34 | end
35 | end
36 |
37 | def handle_event("deposit", _value, socket) do
38 | {:ok, account} = deposit_money(socket.assigns.profile.id, 100)
39 |
40 | socket =
41 | socket
42 | |> assign(:account, account)
43 |
44 | {:noreply, socket}
45 | end
46 |
47 | def handle_event("post_transaction", _value, socket) do
48 | {:ok, profiles} = ServiceMesh.call(:profiles, :list_profiles, [])
49 |
50 | recipient =
51 | profiles
52 | |> Enum.reject(&(&1.id == socket.assigns.profile.id))
53 | |> Enum.random()
54 |
55 | # I know this code is incredibly unsafe. That's not the point :)
56 | {:ok, account} = deposit_money(socket.assigns.profile.id, -100)
57 | _ = deposit_money(recipient.id, 100)
58 |
59 | :ok =
60 | ServiceMesh.call(:transactions, :post_transaction, [
61 | socket.assigns.profile.id,
62 | recipient.id,
63 | 100
64 | ])
65 |
66 | transactions =
67 | get_transactions(
68 | socket.assigns.profile.id,
69 | socket.assigns.page,
70 | socket.assigns.page_size
71 | )
72 |
73 | pending = get_pending_transactions(socket.assigns.profile.id)
74 | processed = get_processed_transactions(socket.assigns.profile.id)
75 |
76 | socket =
77 | socket
78 | |> assign(:account, account)
79 | |> assign(:transactions, transactions)
80 | |> assign(:pending, pending)
81 | |> assign(:processed, processed)
82 |
83 | {:noreply, socket}
84 | end
85 |
86 | def handle_event("previous_page", _value, socket) do
87 | {page, transactions} = change_page(socket, &(&1 - 1))
88 |
89 | socket =
90 | socket
91 | |> assign(:page, page)
92 | |> assign(:transactions, transactions)
93 |
94 | {:noreply, socket}
95 | end
96 |
97 | def handle_event("next_page", _value, socket) do
98 | {page, transactions} = change_page(socket, &(&1 + 1))
99 |
100 | socket =
101 | socket
102 | |> assign(:page, page)
103 | |> assign(:transactions, transactions)
104 |
105 | {:noreply, socket}
106 | end
107 |
108 | defp change_page(socket, f) do
109 | profile = socket.assigns.profile
110 | page = socket.assigns.page
111 | page_size = socket.assigns.page_size
112 | total_pages = socket.assigns.transactions.total_pages
113 |
114 | page = max(min(f.(page), total_pages), 1)
115 | transactions = get_transactions(profile.id, page, page_size)
116 |
117 | {page, transactions}
118 | end
119 |
120 | defp get_account(profile_id) do
121 | result =
122 | ServiceMesh.call(
123 | :accounts,
124 | :get_account_for_profile,
125 | [profile_id]
126 | )
127 |
128 | case result do
129 | {:ok, account} -> account
130 | {:error, :econnrefused} -> nil
131 | end
132 | end
133 |
134 | defp deposit_money(profile_id, amount) do
135 | ServiceMesh.call(
136 | :accounts,
137 | :deposit_money,
138 | [profile_id, amount]
139 | )
140 | end
141 |
142 | defp get_transactions(profile_id, page, page_size) do
143 | result =
144 | ServiceMesh.call(
145 | :transactions,
146 | :list_transactions,
147 | [profile_id, page, page_size]
148 | )
149 |
150 | case result do
151 | {:ok, transactions} -> transactions
152 | {:error, :econnrefused} -> nil
153 | end
154 | end
155 |
156 | defp get_processed_transactions(profile_id) do
157 | result =
158 | ServiceMesh.call(
159 | :transactions,
160 | :get_total_processed_transactions,
161 | [profile_id]
162 | )
163 |
164 | case result do
165 | {:ok, processed} -> processed
166 | {:error, :econnrefused} -> nil
167 | end
168 | end
169 |
170 | defp get_pending_transactions(profile_id) do
171 | result =
172 | ServiceMesh.call(
173 | :transactions,
174 | :get_total_pending_transactions,
175 | [profile_id]
176 | )
177 |
178 | case result do
179 | {:ok, pending} -> pending
180 | {:error, :econnrefused} -> nil
181 | end
182 | end
183 |
184 | defp transaction_message(current_user, transaction) do
185 | cond do
186 | is_nil(transaction.sender) or is_nil(transaction.recipient) ->
187 | "A network error has occurred"
188 |
189 | current_user.id == transaction.recipient.id ->
190 | "Received payment from #{transaction.sender.name}"
191 |
192 | current_user.id == transaction.sender.id ->
193 | "Sent payment to #{transaction.recipient.name}"
194 | end
195 | end
196 |
197 | defp transaction_status_style(status) do
198 | case status do
199 | :done -> "bg-green-100 text-green-800"
200 | :pending -> "bg-yellow-100 text-yellow-800"
201 | :failed -> "bg-gray-100 text-gray-800"
202 | end
203 | end
204 | end
205 |
--------------------------------------------------------------------------------
/mix.lock:
--------------------------------------------------------------------------------
1 | %{
2 | "connection": {:hex, :connection, "1.1.0", "ff2a49c4b75b6fb3e674bfc5536451607270aac754ffd1bdfe175abe4a6d7a68", [:mix], [], "hexpm", "722c1eb0a418fbe91ba7bd59a47e28008a189d47e37e0e7bb85585a016b2869c"},
3 | "cowboy": {:hex, :cowboy, "2.8.0", "f3dc62e35797ecd9ac1b50db74611193c29815401e53bac9a5c0577bd7bc667d", [:rebar3], [{:cowlib, "~> 2.9.1", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "~> 1.7.1", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "4643e4fba74ac96d4d152c75803de6fad0b3fa5df354c71afdd6cbeeb15fac8a"},
4 | "cowboy_telemetry": {:hex, :cowboy_telemetry, "0.3.1", "ebd1a1d7aff97f27c66654e78ece187abdc646992714164380d8a041eda16754", [:rebar3], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "3a6efd3366130eab84ca372cbd4a7d3c3a97bdfcfb4911233b035d117063f0af"},
5 | "cowlib": {:hex, :cowlib, "2.9.1", "61a6c7c50cf07fdd24b2f45b89500bb93b6686579b069a89f88cb211e1125c78", [:rebar3], [], "hexpm", "e4175dc240a70d996156160891e1c62238ede1729e45740bdd38064dad476170"},
6 | "db_connection": {:hex, :db_connection, "2.4.0", "d04b1b73795dae60cead94189f1b8a51cc9e1f911c234cc23074017c43c031e5", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "ad416c21ad9f61b3103d254a71b63696ecadb6a917b36f563921e0de00d7d7c8"},
7 | "decimal": {:hex, :decimal, "2.0.0", "a78296e617b0f5dd4c6caf57c714431347912ffb1d0842e998e9792b5642d697", [:mix], [], "hexpm", "34666e9c55dea81013e77d9d87370fe6cb6291d1ef32f46a1600230b1d44f577"},
8 | "ecto": {:hex, :ecto, "3.6.1", "7bb317e3fd0179ad725069fd0fe8a28ebe48fec6282e964ea502e4deccb0bd0f", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "cbb3294a990447b19f0725488a749f8cf806374e0d9d0dffc45d61e7aeaf6553"},
9 | "ecto_sql": {:hex, :ecto_sql, "3.6.1", "8774dc3fc0ff7b6be510858b99883640f990c0736b8ab54588f9a0c91807f909", [:mix], [{:db_connection, "~> 2.2", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.6.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.4.0 or ~> 0.5.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.15.0 or ~> 1.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.1", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "66f35c3f2d5978b6bffebd1e6351ab8c9d6b68650d62abd1ab8d149de40e0779"},
10 | "faker": {:hex, :faker, "0.16.0", "1e2cf3e8d60d44a30741fb98118fcac18b2020379c7e00d18f1a005841b2f647", [:mix], [], "hexpm", "fbcb9bf1299dff3c9dd7e50f41802bbc472ffbb84e7656394c8aa913ec315141"},
11 | "file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"},
12 | "floki": {:hex, :floki, "0.30.1", "75d35526d3a1459920b6e87fdbc2e0b8a3670f965dd0903708d2b267e0904c55", [:mix], [{:html_entities, "~> 0.5.0", [hex: :html_entities, repo: "hexpm", optional: false]}], "hexpm", "e9c03524447d1c4cbfccd672d739b8c18453eee377846b119d4fd71b1a176bb8"},
13 | "gettext": {:hex, :gettext, "0.18.2", "7df3ea191bb56c0309c00a783334b288d08a879f53a7014341284635850a6e55", [:mix], [], "hexpm", "f9f537b13d4fdd30f3039d33cb80144c3aa1f8d9698e47d7bcbcc8df93b1f5c5"},
14 | "html_entities": {:hex, :html_entities, "0.5.2", "9e47e70598da7de2a9ff6af8758399251db6dbb7eebe2b013f2bbd2515895c3c", [:mix], [], "hexpm", "c53ba390403485615623b9531e97696f076ed415e8d8058b1dbaa28181f4fdcc"},
15 | "jason": {:hex, :jason, "1.2.2", "ba43e3f2709fd1aa1dce90aaabfd039d000469c05c56f0b8e31978e03fa39052", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "18a228f5f0058ee183f29f9eae0805c6e59d61c3b006760668d8d18ff0d12179"},
16 | "mime": {:hex, :mime, "1.6.0", "dabde576a497cef4bbdd60aceee8160e02a6c89250d6c0b29e56c0dfb00db3d2", [:mix], [], "hexpm", "31a1a8613f8321143dde1dafc36006a17d28d02bdfecb9e95a880fa7aabd19a7"},
17 | "norm": {:git, "https://github.com/keathley/norm.git", "4d9ac55e0c0711227f9befc872a9f758458eaefd", [ref: "4d9ac55e0c0711227f9befc872a9f758458eaefd"]},
18 | "number": {:hex, :number, "1.0.3", "932c8a2d478a181c624138958ca88a78070332191b8061717270d939778c9857", [:mix], [{:decimal, "~> 1.5 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}], "hexpm", "dd397bbc096b2ca965a6a430126cc9cf7b9ef7421130def69bcf572232ca0f18"},
19 | "phoenix": {:hex, :phoenix, "1.5.8", "71cfa7a9bb9a37af4df98939790642f210e35f696b935ca6d9d9c55a884621a4", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_html, "~> 2.13", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.0", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:plug, "~> 1.10", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 1.0 or ~> 2.2", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:plug_crypto, "~> 1.1.2 or ~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "35ded0a32f4836168c7ab6c33b88822eccd201bcd9492125a9bea4c54332d955"},
20 | "phoenix_ecto": {:hex, :phoenix_ecto, "4.2.1", "13f124cf0a3ce0f1948cf24654c7b9f2347169ff75c1123f44674afee6af3b03", [:mix], [{:ecto, "~> 3.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.14.2 or ~> 2.15", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "478a1bae899cac0a6e02be1deec7e2944b7754c04e7d4107fc5a517f877743c0"},
21 | "phoenix_html": {:hex, :phoenix_html, "2.14.3", "51f720d0d543e4e157ff06b65de38e13303d5778a7919bcc696599e5934271b8", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "efd697a7fff35a13eeeb6b43db884705cba353a1a41d127d118fda5f90c8e80f"},
22 | "phoenix_live_dashboard": {:hex, :phoenix_live_dashboard, "0.4.0", "87990e68b60213d7487e65814046f9a2bed4a67886c943270125913499b3e5c3", [:mix], [{:ecto_psql_extras, "~> 0.4.1 or ~> 0.5", [hex: :ecto_psql_extras, repo: "hexpm", optional: true]}, {:phoenix_html, "~> 2.14.1 or ~> 2.15", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:phoenix_live_view, "~> 0.15.0", [hex: :phoenix_live_view, repo: "hexpm", optional: false]}, {:telemetry_metrics, "~> 0.4.0 or ~> 0.5.0 or ~> 0.6.0", [hex: :telemetry_metrics, repo: "hexpm", optional: false]}], "hexpm", "8d52149e58188e9e4497cc0d8900ab94d9b66f96998ec38c47c7a4f8f4f50e57"},
23 | "phoenix_live_reload": {:hex, :phoenix_live_reload, "1.3.1", "9eba6ad16bd80c45f338b2059c7b255ce30784d76f4181304e7b78640e5a7513", [:mix], [{:file_system, "~> 0.2.1 or ~> 0.3", [hex: :file_system, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.4", [hex: :phoenix, repo: "hexpm", optional: false]}], "hexpm", "f3ae26b5abb85a1cb2bc8bb199e29fbcefb34259e469b31fe0c6323f2175a5ef"},
24 | "phoenix_live_view": {:hex, :phoenix_live_view, "0.15.5", "153f15022ff03162201cfbd3de73115f3a6e868bc8a3c07b86a8e984de6a57e2", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix, "~> 1.5.7", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.14", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.2 or ~> 0.5", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "00c80cf27365bdeb44c694b1dc8cf950b4b26141307df340d39a9be47d8dc1ef"},
25 | "phoenix_pubsub": {:hex, :phoenix_pubsub, "2.0.0", "a1ae76717bb168cdeb10ec9d92d1480fec99e3080f011402c0a2d68d47395ffb", [:mix], [], "hexpm", "c52d948c4f261577b9c6fa804be91884b381a7f8f18450c5045975435350f771"},
26 | "plug": {:hex, :plug, "1.11.1", "f2992bac66fdae679453c9e86134a4201f6f43a687d8ff1cd1b2862d53c80259", [:mix], [{:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "23524e4fefbb587c11f0833b3910bfb414bf2e2534d61928e920f54e3a1b881f"},
27 | "plug_cowboy": {:hex, :plug_cowboy, "2.5.0", "51c998f788c4e68fc9f947a5eba8c215fbb1d63a520f7604134cab0270ea6513", [:mix], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:cowboy_telemetry, "~> 0.3", [hex: :cowboy_telemetry, repo: "hexpm", optional: false]}, {:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "5b2c8925a5e2587446f33810a58c01e66b3c345652eeec809b76ba007acde71a"},
28 | "plug_crypto": {:hex, :plug_crypto, "1.2.2", "05654514ac717ff3a1843204b424477d9e60c143406aa94daf2274fdd280794d", [:mix], [], "hexpm", "87631c7ad914a5a445f0a3809f99b079113ae4ed4b867348dd9eec288cecb6db"},
29 | "postgrex": {:hex, :postgrex, "0.15.9", "46f8fe6f25711aeb861c4d0ae09780facfdf3adbd2fb5594ead61504dd489bda", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "610719103e4cb2223d4ab78f9f0f3e720320eeca6011415ab4137ddef730adee"},
30 | "ranch": {:hex, :ranch, "1.7.1", "6b1fab51b49196860b733a49c07604465a47bdb78aa10c1c16a3d199f7f8c881", [:rebar3], [], "hexpm", "451d8527787df716d99dc36162fca05934915db0b6141bbdac2ea8d3c7afc7d7"},
31 | "stream_data": {:hex, :stream_data, "0.5.0", "b27641e58941685c75b353577dc602c9d2c12292dd84babf506c2033cd97893e", [:mix], [], "hexpm", "012bd2eec069ada4db3411f9115ccafa38540a3c78c4c0349f151fc761b9e271"},
32 | "telemetry": {:hex, :telemetry, "0.4.3", "a06428a514bdbc63293cd9a6263aad00ddeb66f608163bdec7c8995784080818", [:rebar3], [], "hexpm", "eb72b8365ffda5bed68a620d1da88525e326cb82a75ee61354fc24b844768041"},
33 | "telemetry_metrics": {:hex, :telemetry_metrics, "0.6.0", "da9d49ee7e6bb1c259d36ce6539cd45ae14d81247a2b0c90edf55e2b50507f7b", [:mix], [{:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "5cfe67ad464b243835512aa44321cee91faed6ea868d7fb761d7016e02915c3d"},
34 | "telemetry_poller": {:hex, :telemetry_poller, "0.5.1", "21071cc2e536810bac5628b935521ff3e28f0303e770951158c73eaaa01e962a", [:rebar3], [{:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "4cab72069210bc6e7a080cec9afffad1b33370149ed5d379b81c7c5f0c663fd4"},
35 | }
36 |
--------------------------------------------------------------------------------
/lib/easy_wire_web/live/page_live.html.leex:
--------------------------------------------------------------------------------
1 |
26 |
27 |
28 |
29 |
39 |
40 |
41 |
51 |
52 |
62 |
63 |
70 |
71 |
72 |
73 |

74 |
75 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |

101 |
102 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
127 |
128 |
129 |
143 |
144 |
151 |
152 |
153 |
154 |
155 |
166 |
167 |
168 |
178 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 | <%= if assigns[:profile] do %>
203 |
204 |
205 |

206 |
207 |
208 |

209 |
210 | Good morning, <%= @profile.name %>
211 |
212 |
213 |
214 | - Company
215 | -
216 |
217 |
220 | <%= @profile.company %>
221 |
222 | - Account status
223 | -
224 | <%= case @profile.trust do %>
225 | <%= :verified -> %>
226 |
227 |
230 | Verified account
231 | <% :unverified -> %>
232 |
233 |
236 | Unverified account
237 | <% end %>
238 |
239 |
240 |
241 |
242 | <% end %>
243 |
244 |
245 |
248 |
251 |
252 |
253 |
254 |
255 |
256 |
257 |
258 |
Overview
259 |
260 |
261 | <%= if assigns[:account] do %>
262 |
263 |
264 |
265 |
266 |
267 |
268 |
271 |
272 |
273 |
274 | -
275 | Account balance
276 |
277 | -
278 |
279 | <%= Number.Currency.number_to_currency(@account.balance) %>
280 |
281 |
282 |
283 |
284 |
285 |
286 |
287 | <% end %>
288 |
289 | <%= if assigns[:pending] do %>
290 |
291 |
292 |
293 |
294 |
295 |
298 |
299 |
300 |
301 | -
302 | Pending
303 |
304 | -
305 |
306 | <%= Number.Currency.number_to_currency(@pending) %>
307 |
308 |
309 |
310 |
311 |
312 |
313 |
314 | <% end %>
315 |
316 | <%= if assigns[:processed] do %>
317 |
318 |
319 |
320 |
321 |
322 |
325 |
326 |
327 |
328 | -
329 | Processed
330 |
331 | -
332 |
333 | <%= Number.Currency.number_to_currency(@processed) %>
334 |
335 |
336 |
337 |
338 |
339 |
340 |
341 | <% end %>
342 |
343 |
344 |
345 |
346 |
347 | <%= if assigns[:transactions] do %>
348 |
349 | Recent activity
350 |
351 |
352 |
353 |
354 |
379 |
380 |
390 |
391 |
392 |
393 |
394 |
395 |
396 |
397 |
398 |
399 |
400 | |
401 | Transaction
402 | |
403 |
404 | Amount
405 | |
406 |
407 | Description
408 | |
409 |
410 | Status
411 | |
412 |
413 | Date
414 | |
415 |
416 |
417 |
418 | <%= for transaction <- @transactions.entries do %>
419 |
420 | |
421 |
432 | |
433 |
434 | <%= Number.Currency.number_to_currency(transaction.amount) %>
435 | USD
436 | |
437 |
438 |
439 | <%= transaction.description %>
440 |
441 | |
442 |
443 |
444 | <%= transaction.status %>
445 |
446 | |
447 |
448 | <%= Calendar.strftime(transaction.date, "%B %d, %Y") %>
449 | |
450 |
451 | <% end %>
452 |
453 |
454 |
455 |
476 |
477 |
478 |
479 |
480 |
481 | <% end %>
482 |
483 |
484 |
485 |
--------------------------------------------------------------------------------