Merge pull request #6017 from blockscout/vb-contract-interaction-vars-to-runtime

Move "contract interaction" and "Add chain to MM" env vars to runtime
pull/5921/head
Victor Baranov 2 years ago committed by GitHub
commit e303d72f67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      .github/workflows/publish-docker-image-every-push.yml
  2. 4
      .github/workflows/publish-docker-image-release.yml
  3. 1
      CHANGELOG.md
  4. 30
      apps/block_scout_web/assets/js/lib/add_chain_to_mm.js
  5. 6
      apps/block_scout_web/assets/js/lib/smart_contract/connect.js
  6. 6
      apps/block_scout_web/assets/webpack.config.js
  7. 2
      apps/block_scout_web/lib/block_scout_web/templates/address_token/_tokens.html.eex
  8. 2
      apps/block_scout_web/lib/block_scout_web/templates/address_token_balance/_tokens.html.eex
  9. 13
      apps/block_scout_web/lib/block_scout_web/templates/layout/_add_chain_to_mm.html.eex
  10. 4
      apps/block_scout_web/lib/block_scout_web/templates/layout/_footer.html.eex
  11. 2
      apps/block_scout_web/lib/block_scout_web/templates/layout/_search.html.eex
  12. 2
      apps/block_scout_web/lib/block_scout_web/templates/search/_tile.html.eex
  13. 2
      apps/block_scout_web/lib/block_scout_web/templates/search/results.html.eex
  14. 2
      apps/block_scout_web/lib/block_scout_web/templates/tokens/_tile.html.eex
  15. 2
      apps/block_scout_web/lib/block_scout_web/templates/tokens/index.html.eex
  16. 2
      apps/block_scout_web/lib/block_scout_web/templates/tokens/overview/_details.html.eex
  17. 10
      apps/block_scout_web/priv/gettext/default.pot
  18. 10
      apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po
  19. 4
      config/runtime.exs
  20. 1
      docker-compose/docker-compose-no-build-ganache.yml
  21. 3
      docker-compose/docker-compose.yml
  22. 6
      docker-compose/envs/common-blockscout.env
  23. 4
      docker/Dockerfile

@ -70,10 +70,6 @@ jobs:
DISABLE_BRIDGE_MARKET_CAP_UPDATER=false
CACHE_BRIDGE_MARKET_CAP_UPDATE_INTERVAL=
SOCKET_ROOT=
CHAIN_ID=
JSON_RPC=
COIN_NAME=
SUBNETWORK=
tests:
needs: push_to_registry
uses: blockscout/blockscout-ci-cd/.github/workflows/e2e_k8s.yaml@master

@ -65,10 +65,6 @@ jobs:
ADMIN_PANEL_ENABLED=""
CACHE_ADDRESS_WITH_BALANCES_UPDATE_INTERVAL=""
SOCKET_ROOT=""
CHAIN_ID=""
JSON_RPC=""
SUBNETWORK=""
COIN_NAME=""
merge-master-after-release:
name: Merge 'master' to specific branch after release

@ -6,6 +6,7 @@
- [#6001](https://github.com/blockscout/blockscout/pull/6001) - Add ETHEREUM_JSONRPC_DISABLE_ARCHIVE_BALANCES env var that filters requests and query node only if the block quantity is "latest"
### Fixes
- [#6017](https://github.com/blockscout/blockscout/pull/6017) - Move "contract interaction" and "Add chain to MM" env vars to runtime
- [#6012](https://github.com/blockscout/blockscout/pull/6012) - Fix display of estimated addresses counter on the main page
- [#5978](https://github.com/blockscout/blockscout/pull/5978) - Allow timestamp param in the log of eth_getTransactionReceipt method
- [#5977](https://github.com/blockscout/blockscout/pull/5977) - Fix address overview.html.eex in case of nil implementation address hash

@ -2,29 +2,33 @@ import 'bootstrap'
export async function addChainToMM ({ btn }) {
try {
const chainID = await window.ethereum.request({ method: 'eth_chainId' })
const chainIDFromEnvVar = parseInt(process.env.CHAIN_ID)
const chainIDHex = chainIDFromEnvVar && `0x${chainIDFromEnvVar.toString(16)}`
const chainIDFromWallet = await window.ethereum.request({ method: 'eth_chainId' })
const chainIDFromInstance = getChainIdHex()
const coinName = document.getElementById('js-coin-name').value
const subNetwork = document.getElementById('js-subnetwork').value
const jsonRPC = document.getElementById('js-json-rpc').value
const blockscoutURL = location.protocol + '//' + location.host + process.env.NETWORK_PATH
if (chainID !== chainIDHex) {
if (chainIDFromWallet !== chainIDFromInstance) {
await window.ethereum.request({
method: 'wallet_addEthereumChain',
params: [{
chainId: chainIDHex,
chainName: process.env.SUBNETWORK,
chainId: chainIDFromInstance,
chainName: subNetwork,
nativeCurrency: {
name: process.env.COIN_NAME,
symbol: process.env.COIN_NAME,
name: coinName,
symbol: coinName,
decimals: 18
},
rpcUrls: [process.env.JSON_RPC],
rpcUrls: [jsonRPC],
blockExplorerUrls: [blockscoutURL]
}]
})
} else {
btn.tooltip('dispose')
btn.tooltip({
title: `You're already connected to ${process.env.SUBNETWORK}`,
title: `You're already connected to ${subNetwork}`,
trigger: 'click',
placement: 'bottom'
}).tooltip('show')
@ -37,3 +41,9 @@ export async function addChainToMM ({ btn }) {
console.error(error)
}
}
function getChainIdHex () {
const chainIDFromDOM = document.getElementById('js-chain-id').value
const chainIDFromInstance = parseInt(chainIDFromDOM)
return chainIDFromInstance && `0x${chainIDFromInstance.toString(16)}`
}

@ -4,9 +4,11 @@ import WalletConnectProvider from '@walletconnect/web3-provider'
import { compareChainIDs, formatError, showConnectElements, showConnectedToElements } from './common_helpers'
import { openWarningModal } from '../modals'
const instanceChainId = process.env.CHAIN_ID ? parseInt(`${process.env.CHAIN_ID}`, 10) : 100
const instanceChainIdStr = document.getElementById('js-chain-id').value
const instanceChainId = parseInt(instanceChainIdStr, 10)
const walletConnectOptions = { rpc: {}, chainId: instanceChainId }
walletConnectOptions.rpc[instanceChainId] = process.env.JSON_RPC ? process.env.JSON_RPC : 'https://dai.poa.network'
const jsonRPC = document.getElementById('js-json-rpc').value
walletConnectOptions.rpc[instanceChainId] = jsonRPC
// Chosen wallet provider given by the dialog window
let provider

@ -156,11 +156,7 @@ const appJs =
new ContextReplacementPlugin(/moment[\/\\]locale$/, /en/),
new webpack.DefinePlugin({
'process.env.SOCKET_ROOT': JSON.stringify(process.env.SOCKET_ROOT),
'process.env.NETWORK_PATH': JSON.stringify(process.env.NETWORK_PATH),
'process.env.CHAIN_ID': JSON.stringify(process.env.CHAIN_ID),
'process.env.JSON_RPC': JSON.stringify(process.env.JSON_RPC),
'process.env.SUBNETWORK': JSON.stringify(process.env.SUBNETWORK),
'process.env.COIN_NAME': JSON.stringify(process.env.COIN_NAME)
'process.env.NETWORK_PATH': JSON.stringify(process.env.NETWORK_PATH)
}),
new webpack.ProvidePlugin({
process: 'process/browser',

@ -3,7 +3,7 @@
</td>
<td>
<%= if System.get_env("DISPLAY_TOKEN_ICONS") === "true" do %>
<% chain_id_for_token_icon = System.get_env("CHAIN_ID") %>
<% chain_id_for_token_icon = Application.get_env(:block_scout_web, :chain_id) %>
<% address_hash = @token.contract_address_hash %>
<%=
render BlockScoutWeb.TokensView,

@ -22,7 +22,7 @@
) do %>
<div class="row dropdown-row wh-sp">
<%= if System.get_env("DISPLAY_TOKEN_ICONS") === "true" do %>
<% chain_id_for_token_icon = System.get_env("CHAIN_ID") %>
<% chain_id_for_token_icon = Application.get_env(:block_scout_web, :chain_id) %>
<% address_hash = token.contract_address_hash %>
<%=
render BlockScoutWeb.TokensView,

@ -0,0 +1,13 @@
<input id="js-chain-id" class="d-none" value="<%= Application.get_env(:block_scout_web, :chain_id) %>" />
<input id="js-coin-name" class="d-none" value="<%= Application.get_env(:explorer, :coin_name) %>" />
<% sub_network = Keyword.get(Application.get_env(:block_scout_web, BlockScoutWeb.Chain), :subnetwork) %>
<input id="js-subnetwork" class="d-none" value="<%= sub_network %>" />
<input id="js-json-rpc" class="d-none" value="<%= Application.get_env(:block_scout_web, :json_rpc) %>" />
<li>
<a
class="footer-link js-btn-add-chain-to-mm btn-add-chain-to-mm in-footer"
style="cursor: pointer;"
>
<%= gettext("Add") <> " #{sub_network}" %>
</a>
</li>

@ -40,9 +40,7 @@
<li><a href="<%= Application.get_env(:block_scout_web, :footer)[:github_link] %>" rel="noreferrer" class="footer-link"><%= gettext("Contribute") %></a></li>
<li><a href="<%= Application.get_env(:block_scout_web, :footer)[:chat_link] %>" rel="noreferrer" class="footer-link"><%= gettext("Chat (#blockscout)") %></a></li>
<li><a href="<%= Application.get_env(:block_scout_web, :footer)[:forum_link] %>" rel="noreferrer" class="footer-link"><%= gettext("Forum") %></a></li>
<%= if System.get_env("COIN_NAME") && System.get_env("NETWORK_PATH") && System.get_env("SUBNETWORK") && System.get_env("JSON_RPC") && System.get_env("CHAIN_ID") do %>
<li><a class="footer-link js-btn-add-chain-to-mm btn-add-chain-to-mm in-footer" style="cursor: pointer;"><%= gettext("Add") <> " #{System.get_env("SUBNETWORK")}" %></a></li>
<% end %>
<%= render BlockScoutWeb.LayoutView, "_add_chain_to_mm.html" %>
</ul>
</div>
<% main_nets = main_nets(other_networks()) %>

@ -6,7 +6,7 @@
id="<%= @id %>"
class="main-search-autocomplete"
data-test="search_input"
data-chain-id="<%= System.get_env("CHAIN_ID") %>"
data-chain-id="<%= Application.get_env(:block_scout_web, :chain_id) %>"
data-display-token-icons="<%= System.get_env("DISPLAY_TOKEN_ICONS") %>"
type="text"
tabindex="1"

@ -9,7 +9,7 @@
data-address-hash="<%= @result.address_hash %>"
>
<%= if System.get_env("DISPLAY_TOKEN_ICONS") === "true" do %>
<% chain_id_for_token_icon = System.get_env("CHAIN_ID") %>
<% chain_id_for_token_icon = Application.get_env(:block_scout_web, :chain_id) %>
<% address_hash = @result.address_hash %>
<%=
render BlockScoutWeb.TokensView,

@ -1,7 +1,7 @@
<section
class="container"
data-page="search-results"
data-chain-id="<%= System.get_env("CHAIN_ID") %>"
data-chain-id="<%= Application.get_env(:block_scout_web, :chain_id) %>"
data-display-token-icons="<%= System.get_env("DISPLAY_TOKEN_ICONS") %>"
>
<%= render BlockScoutWeb.Advertisement.TextAdView, "index.html", conn: @conn %>

@ -7,7 +7,7 @@
</td>
<td class="token-icon">
<%= if System.get_env("DISPLAY_TOKEN_ICONS") === "true" do %>
<% chain_id_for_token_icon = System.get_env("CHAIN_ID") %>
<% chain_id_for_token_icon = Application.get_env(:block_scout_web, :chain_id) %>
<% foreign_token_contract_address_hash = nil %>
<% token_hash_for_token_icon = if foreign_token_contract_address_hash, do: foreign_token_contract_address_hash, else: Address.checksum(@token.contract_address_hash) %>
<%=

@ -1,7 +1,7 @@
<section
class="container"
data-page="tokens"
data-chain-id="<%= System.get_env("CHAIN_ID") %>"
data-chain-id="<%= Application.get_env(:block_scout_web, :chain_id) %>"
data-display-token-icons="<%= System.get_env("DISPLAY_TOKEN_ICONS") %>"
>
<%= render BlockScoutWeb.Advertisement.TextAdView, "index.html", conn: @conn %>

@ -25,7 +25,7 @@
<%= if token_name?(@token) do %>
<span
id="token-icon"
data-chain-id="<%= System.get_env("CHAIN_ID") %>"
data-chain-id="<%= Application.get_env(:block_scout_web, :chain_id) %>"
data-address-hash="<%= Address.checksum(@token.contract_address_hash) %>"
data-display-token-icons="<%= System.get_env("DISPLAY_TOKEN_ICONS") %>">
</span>

@ -136,7 +136,7 @@ msgstr ""
msgid "Actual gas amount used by the transaction."
msgstr ""
#: lib/block_scout_web/templates/layout/_footer.html.eex:44
#: lib/block_scout_web/templates/layout/_add_chain_to_mm.html.eex:11
#, elixir-autogen, elixir-format
msgid "Add"
msgstr ""
@ -1329,7 +1329,7 @@ msgstr ""
msgid "Logs"
msgstr ""
#: lib/block_scout_web/templates/layout/_footer.html.eex:52
#: lib/block_scout_web/templates/layout/_footer.html.eex:50
#, elixir-autogen, elixir-format
msgid "Main Networks"
msgstr ""
@ -1548,7 +1548,7 @@ msgstr ""
msgid "Optimization runs"
msgstr ""
#: lib/block_scout_web/templates/layout/_footer.html.eex:76
#: lib/block_scout_web/templates/layout/_footer.html.eex:74
#, elixir-autogen, elixir-format
msgid "Other Explorers"
msgstr ""
@ -1911,7 +1911,7 @@ msgstr ""
msgid "Telegram"
msgstr ""
#: lib/block_scout_web/templates/layout/_footer.html.eex:65
#: lib/block_scout_web/templates/layout/_footer.html.eex:63
#, elixir-autogen, elixir-format
msgid "Test Networks"
msgstr ""
@ -2543,7 +2543,7 @@ msgstr ""
msgid "Verify the contract "
msgstr ""
#: lib/block_scout_web/templates/layout/_footer.html.eex:91
#: lib/block_scout_web/templates/layout/_footer.html.eex:89
#, elixir-autogen, elixir-format
msgid "Version"
msgstr ""

@ -136,7 +136,7 @@ msgstr ""
msgid "Actual gas amount used by the transaction."
msgstr ""
#: lib/block_scout_web/templates/layout/_footer.html.eex:44
#: lib/block_scout_web/templates/layout/_add_chain_to_mm.html.eex:11
#, elixir-autogen, elixir-format
msgid "Add"
msgstr ""
@ -1329,7 +1329,7 @@ msgstr ""
msgid "Logs"
msgstr ""
#: lib/block_scout_web/templates/layout/_footer.html.eex:52
#: lib/block_scout_web/templates/layout/_footer.html.eex:50
#, elixir-autogen, elixir-format
msgid "Main Networks"
msgstr ""
@ -1548,7 +1548,7 @@ msgstr ""
msgid "Optimization runs"
msgstr ""
#: lib/block_scout_web/templates/layout/_footer.html.eex:76
#: lib/block_scout_web/templates/layout/_footer.html.eex:74
#, elixir-autogen, elixir-format
msgid "Other Explorers"
msgstr ""
@ -1911,7 +1911,7 @@ msgstr ""
msgid "Telegram"
msgstr ""
#: lib/block_scout_web/templates/layout/_footer.html.eex:65
#: lib/block_scout_web/templates/layout/_footer.html.eex:63
#, elixir-autogen, elixir-format
msgid "Test Networks"
msgstr ""
@ -2543,7 +2543,7 @@ msgstr ""
msgid "Verify the contract "
msgstr ""
#: lib/block_scout_web/templates/layout/_footer.html.eex:91
#: lib/block_scout_web/templates/layout/_footer.html.eex:89
#, elixir-autogen, elixir-format
msgid "Version"
msgstr ""

@ -72,7 +72,9 @@ config :block_scout_web,
max_size_to_show_array_as_is: Integer.parse(System.get_env("MAX_SIZE_UNLESS_HIDE_ARRAY", "50")),
max_length_to_show_string_without_trimming: System.get_env("MAX_STRING_LENGTH_WITHOUT_TRIMMING", "2040"),
re_captcha_secret_key: System.get_env("RE_CAPTCHA_SECRET_KEY", nil),
re_captcha_client_key: System.get_env("RE_CAPTCHA_CLIENT_KEY", nil)
re_captcha_client_key: System.get_env("RE_CAPTCHA_CLIENT_KEY", nil),
chain_id: System.get_env("CHAIN_ID"),
json_rpc: System.get_env("JSON_RPC")
default_api_rate_limit = 50
default_api_rate_limit_str = Integer.to_string(default_api_rate_limit)

@ -33,6 +33,7 @@ services:
DATABASE_URL: postgresql://postgres:@host.docker.internal:7432/blockscout?ssl=false
ECTO_USE_SSL: 'false'
SECRET_KEY_BASE: '56NtB48ear7+wMSf0IQuWDAAazhpb31qyc7GiyspBP2vh7t5zlCsF5QDv76chXeN'
CHAIN_ID: '1337'
ports:
- 4000:4000

@ -15,7 +15,6 @@ services:
blockscout:
depends_on:
- db
image: blockscout/blockscout:${DOCKER_TAG:-latest}
build:
context: ..
dockerfile: ./docker/Dockerfile
@ -28,6 +27,8 @@ services:
DISABLE_WEBAPP: "false"
DISABLE_WRITE_API: "false"
CACHE_ENABLE_TOTAL_GAS_USAGE_COUNTER: ""
CACHE_ADDRESS_WITH_BALANCES_UPDATE_INTERVAL: ""
SOCKET_ROOT: "/"
WOBSERVER_ENABLED: "false"
ADMIN_PANEL_ENABLED: ""
restart: always

@ -20,7 +20,7 @@ BLOCKSCOUT_PROTOCOL=
# CHECK_ORIGIN=
PORT=4000
# COIN=
# COIN_NAME=
COIN_NAME=
# METADATA_CONTRACT=
# VALIDATORS_CONTRACT=
# KEYS_MANAGER_CONTRACT=
@ -106,7 +106,7 @@ CUSTOM_CONTRACT_ADDRESSES_TEST_TOKEN=
ENABLE_SOURCIFY_INTEGRATION=false
SOURCIFY_SERVER_URL=
SOURCIFY_REPO_URL=
# CHAIN_ID=
CHAIN_ID=
MAX_SIZE_UNLESS_HIDE_ARRAY=50
HIDE_BLOCK_MINER=false
DISPLAY_TOKEN_ICONS=false
@ -115,7 +115,7 @@ TENDERLY_CHAIN_PATH=
MAX_STRING_LENGTH_WITHOUT_TRIMMING=2040
RE_CAPTCHA_SECRET_KEY=
RE_CAPTCHA_CLIENT_KEY=
# JSON_RPC=
JSON_RPC=
API_RATE_LIMIT=50
API_RATE_LIMIT_BY_KEY=50
API_RATE_LIMIT_BY_IP=50

@ -34,10 +34,6 @@ ARG WOBSERVER_ENABLED
ARG ADMIN_PANEL_ENABLED
ARG CACHE_ADDRESS_WITH_BALANCES_UPDATE_INTERVAL
ARG SOCKET_ROOT
ARG CHAIN_ID
ARG JSON_RPC
ARG SUBNETWORK
ARG COIN_NAME
ARG COIN
# Cache elixir deps

Loading…
Cancel
Save