Skip to content

Commit

Permalink
Account/Watchlist/Notifications (#13)
Browse files Browse the repository at this point in the history
* Auth for debug

Fix for Auth callback calls endless cycle

* Logout from auth0 and add profile picture

Fix styles in signin/signout

* Add profile

* Update dockerfiles

* Make auth paths dependent of API_PATH

* Change api_path to network_path

* Save identity from auth into DB

* Hardcode urls to make it work again

Style fixes

* Change sign_in icon

* Create Watchlist together with identity

* Add watchlist show

* Add watchlist addresses

Fix creating account on first login

Make address as it should look like

* Associate watchlist with addresses

* Create watchlist address UI

Add balance in coin (need to use right coin)

* Add tokens on watchlist

Fix warnings

Fix topnav styles

* Add watch_ and notify_ fields in WatchlistAddress

* Notifications draft

Style fixes

Removed divider
Watchlist Address Form:
ERC-721 & ERC-1155 -> NFT
Form style -> modal
Move Auth into Account module

Add any valid address to watchlist

Fix profile namespace in router

Fixes in build Notification

Fixed insert notifications

* Send Emails via SendGrid

* Add AUTH0 & SENDGRID API keys to Makefile

* Finish email variables

Fix warnings

Add links to email

* Update & Delete Watchlist Addresses

Fix styles

Fix warnings

* Authorize create/update watchlist_address

Fix credo warnings

* Refactoring and fix UI

* Introduce sender & template ENVs

* Fix credo warns

* Fix formatter & dialyzer

* Make Notifier main entrypoint

* Fix tests

* Fix comments

* Hardcode auth0 callbacks for prod env

Export it in dev env and it should work:
```
export AUTH0_CALLBACK_URL='http://localhost:4000/auth/auth0/callback'
export AUTH0_LOGOUT_RETURN_URL='http://localhost:4000/auth/logout'
```

* Style fixes

* Private tags on address/transaction/token pages

* Add account logger

* fix email subject

* Fix token_transfers notifications

* Prepare for release

* Fix transaction dropdown

* Remoe unwanted changes

* Reset CI cache

* Fix Dialyzer, gettext

* Add logout_return_to_url to :ueberauth config for test env

* Invalidate GA cache

* Redefine sign_in_link for test env

* Fix adding address with disabled checkboxes

Remove testnet hardcode from prod config

CI fix attempt

* Add AUTH0_LOGOUT_URL env

* Fix logger warning

* current_user/1, check that mapping contains :current_user object before executing get_session function

* Fix current_user

* Final fix of current_user/1

* Introduce COIN_NAME env

* Lowercase hashes in email

* Style fix

* Add block_url to email

* Fix creating notifications for NFT

* Add notifier to token_transfers import runner

* Add processing transfer into Notifier

* Fix token transfer summary

* WIP: Account refactoring (#19)

* Move Ueberauth settings to config.exs

* Make AuthController more clear

* Fix error when build_watchlist_notification returns nil

* Set WatchlistAddressForm defaults

* Style fix

* Fix double send email for tokens

* Style fix WatchlistController

* Style fix AddWatchlistAddress

* Style fix UserFromAuth

* Use Logger instead AccountLogger

* Credo fix

* Fix AddWatchlistAddress

* Fix Notifier

Co-authored-by: Oleg Sovetnik <sovetnik@oblaka.biz>
Co-authored-by: nikitosing <nikitosing4@mail.ru>
  • Loading branch information
3 people committed May 13, 2022
1 parent 35d7887 commit 6ed183f
Show file tree
Hide file tree
Showing 96 changed files with 4,012 additions and 404 deletions.
4 changes: 2 additions & 2 deletions .dialyzer-ignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ lib/indexer/fetcher/token_total_supply_on_demand.ex:16
lib/explorer/exchange_rates/source.ex:110
lib/explorer/exchange_rates/source.ex:113
lib/explorer/smart_contract/solidity/verifier.ex:162
lib/block_scout_web/templates/address_contract/index.html.eex:158
lib/block_scout_web/templates/address_contract/index.html.eex:195
lib/block_scout_web/templates/address_contract/index.html.eex:160
lib/block_scout_web/templates/address_contract/index.html.eex:197
lib/explorer/staking/stake_snapshotting.ex:15: Function do_snapshotting/7 has no local return
lib/explorer/staking/stake_snapshotting.ex:147
lib/explorer/third_party_integrations/sourcify.ex:70
Expand Down
32 changes: 18 additions & 14 deletions .github/workflows/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ env:
MIX_ENV: test
OTP_VERSION: '24.3.3'
ELIXIR_VERSION: '1.13.4'
AUTH0_DOMAIN: 'blockscoutcom.us.auth0.com'
AUTH0_CALLBACK_URL: 'https://blockscout.com/auth/auth0/callback'
AUTH0_LOGOUT_URL: 'https://blockscoutcom.us.auth0.com/v2/logout'
AUTH0_LOGOUT_RETURN_URL: 'https://blockscout.com/auth/logout'

jobs:
build-and-cache:
Expand All @@ -35,7 +39,7 @@ jobs:
uses: actions/cache@v2
id: deps-cache
with:
path: |
path: |
deps
_build
key: ${{ runner.os }}-${{ env.ELIXIR_VERSION }}-${{ env.OTP_VERSION }}-${{ env.MIX_ENV }}-deps-mixlockhash_11-${{ hashFiles('mix.lock') }}
Expand Down Expand Up @@ -90,12 +94,12 @@ jobs:
with:
otp-version: ${{ env.OTP_VERSION }}
elixir-version: ${{ env.ELIXIR_VERSION }}

- name: Restore Mix Deps Cache
uses: actions/cache@v2
id: deps-cache
with:
path: |
path: |
deps
_build
key: ${{ runner.os }}-${{ env.ELIXIR_VERSION }}-${{ env.OTP_VERSION }}-${{ env.MIX_ENV }}-deps-mixlockhash_11-${{ hashFiles('mix.lock') }}
Expand All @@ -119,7 +123,7 @@ jobs:
uses: actions/cache@v2
id: deps-cache
with:
path: |
path: |
deps
_build
key: ${{ runner.os }}-${{ env.ELIXIR_VERSION }}-${{ env.OTP_VERSION }}-${{ env.MIX_ENV }}-deps-mixlockhash_11-${{ hashFiles('mix.lock') }}
Expand All @@ -142,7 +146,7 @@ jobs:
uses: actions/cache@v2
id: deps-cache
with:
path: |
path: |
deps
_build
key: ${{ runner.os }}-${{ env.ELIXIR_VERSION }}-${{ env.OTP_VERSION }}-${{ env.MIX_ENV }}-deps-mixlockhash_11-${{ hashFiles('mix.lock') }}
Expand Down Expand Up @@ -182,7 +186,7 @@ jobs:
uses: actions/cache@v2
id: deps-cache
with:
path: |
path: |
deps
_build
key: ${{ runner.os }}-${{ env.ELIXIR_VERSION }}-${{ env.OTP_VERSION }}-${{ env.MIX_ENV }}-deps-mixlockhash_11-${{ hashFiles('mix.lock') }}
Expand All @@ -208,7 +212,7 @@ jobs:
uses: actions/cache@v2
id: deps-cache
with:
path: |
path: |
deps
_build
key: ${{ runner.os }}-${{ env.ELIXIR_VERSION }}-${{ env.OTP_VERSION }}-${{ env.MIX_ENV }}-deps-mixlockhash_11-${{ hashFiles('mix.lock') }}
Expand Down Expand Up @@ -236,7 +240,7 @@ jobs:
uses: actions/cache@v2
id: deps-cache
with:
path: |
path: |
deps
_build
key: ${{ runner.os }}-${{ env.ELIXIR_VERSION }}-${{ env.OTP_VERSION }}-${{ env.MIX_ENV }}-deps-mixlockhash_11-${{ hashFiles('mix.lock') }}
Expand Down Expand Up @@ -282,7 +286,7 @@ jobs:
uses: actions/cache@v2
id: deps-cache
with:
path: |
path: |
deps
_build
key: ${{ runner.os }}-${{ env.ELIXIR_VERSION }}-${{ env.OTP_VERSION }}-${{ env.MIX_ENV }}-deps-mixlockhash_11-${{ hashFiles('mix.lock') }}
Expand Down Expand Up @@ -341,7 +345,7 @@ jobs:
uses: actions/cache@v2
id: deps-cache
with:
path: |
path: |
deps
_build
key: ${{ runner.os }}-${{ env.ELIXIR_VERSION }}-${{ env.OTP_VERSION }}-${{ env.MIX_ENV }}-deps-mixlockhash_11-${{ hashFiles('mix.lock') }}
Expand Down Expand Up @@ -397,7 +401,7 @@ jobs:
uses: actions/cache@v2
id: deps-cache
with:
path: |
path: |
deps
_build
key: ${{ runner.os }}-${{ env.ELIXIR_VERSION }}-${{ env.OTP_VERSION }}-${{ env.MIX_ENV }}-deps-mixlockhash_11-${{ hashFiles('mix.lock') }}
Expand Down Expand Up @@ -464,7 +468,7 @@ jobs:
uses: actions/cache@v2
id: deps-cache
with:
path: |
path: |
deps
_build
key: ${{ runner.os }}-${{ env.ELIXIR_VERSION }}-${{ env.OTP_VERSION }}-${{ env.MIX_ENV }}-deps-mixlockhash_11-${{ hashFiles('mix.lock') }}
Expand Down Expand Up @@ -525,7 +529,7 @@ jobs:
uses: actions/cache@v2
id: deps-cache
with:
path: |
path: |
deps
_build
key: ${{ runner.os }}-${{ env.ELIXIR_VERSION }}-${{ env.OTP_VERSION }}-${{ env.MIX_ENV }}-deps-mixlockhash_11-${{ hashFiles('mix.lock') }}
Expand Down Expand Up @@ -572,4 +576,4 @@ jobs:
ETHEREUM_JSONRPC_CASE: "EthereumJSONRPC.Case.Parity.Mox"
ETHEREUM_JSONRPC_WEB_SOCKET_CASE: "EthereumJSONRPC.WebSocket.Case.Mox"
CHAIN_ID: "77"
ADMIN_PANEL_ENABLED: "true"
ADMIN_PANEL_ENABLED: "true"
2 changes: 2 additions & 0 deletions apps/block_scout_web/assets/css/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ $fa-font-path: "~@fortawesome/fontawesome-free/webfonts";
@import "components/_dropzone";
@import "components/_search";
@import "components/_ad";
@import "components/_account";

// Font Awesome
@import "components/_fontawesome_icon";

Expand Down
69 changes: 69 additions & 0 deletions apps/block_scout_web/assets/css/components/_account.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
div.divider {
height: inherit;
width: 1px;
background: #828ba0;
margin-left: 10px;
margin-right: 10px;
}

input.profile-item {
margin-left: 10px;
color: #828ba0;
outline: none;
}

.header-account {
font-size: 18px;
}

.label-account {
font-size: 1rem;
}

.white {
color: #fff;
}

.card-body-account {
max-width: none !important;
}

.form-input {
display: flex;
margin-bottom: 1rem;
}

.form-checkbox {
margin-right: 0.5rem;
align-self: center;
}

.label-checkbox {
font-size: 14px;
margin-bottom: 0;
}

.o-flow-x {
overflow-x: auto;
}

.fs-14 {
font-size: 14px;
}

.acc-link-active {
&:hover, &:focus {
background-color: $primary !important;
color: #fff !important;
}
background-color: $primary;
color: #fff;
}

.table-watchlist {
margin: 30px;

@include media-breakpoint-down(md) {
margin: 0;
}
}
17 changes: 17 additions & 0 deletions apps/block_scout_web/config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,23 @@ config :block_scout_web, BlockScoutWeb.ApiRouter,

config :block_scout_web, BlockScoutWeb.WebRouter, enabled: System.get_env("DISABLE_WEBAPP") != "true"

# Configures Ueberauth's Auth0 auth provider
config :ueberauth, Ueberauth.Strategy.Auth0.OAuth,
domain: System.get_env("AUTH0_DOMAIN"),
client_id: System.get_env("AUTH0_CLIENT_ID"),
client_secret: System.get_env("AUTH0_CLIENT_SECRET")

# Configures Ueberauth local settings
config :ueberauth, Ueberauth,
providers: [
auth0: {
Ueberauth.Strategy.Auth0,
[callback_url: System.get_env("AUTH0_CALLBACK_URL")]
}
],
logout_url: System.get_env("AUTH0_LOGOUT_URL"),
logout_return_to_url: System.get_env("AUTH0_LOGOUT_RETURN_URL")

config :hammer,
backend: {Hammer.Backend.ETS, [expiry_ms: 60_000 * 60 * 4, cleanup_interval_ms: 60_000 * 10]}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
defmodule BlockScoutWeb.Account.AuthController do
use BlockScoutWeb, :controller

plug(Ueberauth)

def logout(conn, _params) do
conn
# |> put_flash(:info, "You have been logged out!")
|> configure_session(drop: true)
|> redirect(to: root())
end

def profile(conn, _params),
do: conn |> get_session(:current_user) |> do_profile(conn)

defp do_profile(nil, conn),
do: redirect(conn, to: root())

defp do_profile(%{} = user, conn),
do: render(conn, :profile, user: user)

def callback(%{assigns: %{ueberauth_failure: _fails}} = conn, _params) do
conn
|> put_flash(:error, "Failed to authenticate.")
|> redirect(to: root())
end

def callback(%{assigns: %{ueberauth_auth: auth}} = conn, _params) do
case UserFromAuth.find_or_create(auth) do
{:ok, user} ->
conn
# |> put_flash(:info, "Successfully authenticated as " <> user.name <> ".")
|> put_session(:current_user, user)
|> redirect(to: root())

{:error, reason} ->
conn
|> put_flash(:error, reason)
|> redirect(to: root())
end
end

# for importing in other controllers
def authenticate!(conn) do
current_user(conn) || redirect(conn, to: root())
end

def current_user(%{private: %{plug_session: %{"current_user" => _}}} = conn),
do: get_session(conn, :current_user)

def current_user(_), do: nil

defp root do
System.get_env("NETWORK_PATH") || "/"
end
end

0 comments on commit 6ed183f

Please sign in to comment.