Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add total blocks counter #1813

Merged
merged 4 commits into from
Apr 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Features

- [#1815](https://github.com/poanetwork/blockscout/pull/1815) - able to search without prefix "0x"
- [#1813](https://github.com/poanetwork/blockscout/pull/1813) - add total blocks counter to the main page
- [#1806](https://github.com/poanetwork/blockscout/pull/1806) - verify contracts with a post request

### Fixes
Expand Down
18 changes: 15 additions & 3 deletions apps/block_scout_web/assets/js/pages/chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ export const initialState = {
transactionsError: false,
transactionsLoading: true,
transactionCount: null,
usdMarketCap: null
usdMarketCap: null,
blockCount: null
}

export const reducer = withMissingBlocks(baseReducer)
Expand All @@ -46,11 +47,13 @@ function baseReducer (state = initialState, action) {
blocks: [
action.msg,
...state.blocks.slice(0, -1)
]
],
blockCount: action.msg.blockNumber + 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@saneery does it handle the case when we have no blocks?

Copy link
Contributor Author

@saneery saneery Apr 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vbaranov do you mean when no blocks in the database? This js code handles only when new block comes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

})
} else {
return Object.assign({}, state, {
blocks: state.blocks.map((block) => block.blockNumber === action.msg.blockNumber ? action.msg : block)
blocks: state.blocks.map((block) => block.blockNumber === action.msg.blockNumber ? action.msg : block),
blockCount: action.msg.blockNumber + 1
})
}
}
Expand Down Expand Up @@ -152,6 +155,15 @@ const elements = {
$el.empty().append(numeral(state.transactionCount).format())
}
},
'[data-selector="block-count"]': {
load ($el) {
return { blockCount: numeral($el.text()).value() }
},
render ($el, state, oldState) {
if (oldState.blockCount === state.blockCount) return
$el.empty().append(numeral(state.blockCount).format())
}
},
'[data-selector="address-count"]': {
render ($el, state, oldState) {
if (oldState.addressCount === state.addressCount) return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ defmodule BlockScoutWeb.ChainController do

def show(conn, _params) do
transaction_estimated_count = Chain.transaction_estimated_count()
block_count = Chain.block_count()

exchange_rate = Market.get_exchange_rate(Explorer.coin()) || Token.null()

Expand All @@ -22,7 +23,8 @@ defmodule BlockScoutWeb.ChainController do
exchange_rate: exchange_rate,
chart_data_path: market_history_chart_path(conn, :show),
transaction_estimated_count: transaction_estimated_count,
transactions_path: recent_transactions_path(conn, :index)
transactions_path: recent_transactions_path(conn, :index),
block_count: block_count
)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@
<%= Cldr.Number.to_string!(@transaction_estimated_count, format: "#,###") %>
</span>
</div>
<div class="dashboard-banner-network-stats-item">
<span class="dashboard-banner-network-stats-label">
<%= gettext "Total blocks" %>
</span>
<span class="dashboard-banner-network-stats-value" data-selector="block-count">
<%= Cldr.Number.to_string!(@block_count, format: "#,###") %>
</span>
</div>
<div class="dashboard-banner-network-stats-item">
<span class="dashboard-banner-network-stats-label">
<%= gettext "Wallet addresses" %>
Expand Down
25 changes: 15 additions & 10 deletions apps/block_scout_web/priv/gettext/default.pot
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ msgid "BlockScout provides analytics data, API, and Smart Contract tools for the
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/chain/show.html.eex:72
#: lib/block_scout_web/templates/chain/show.html.eex:80
#: lib/block_scout_web/templates/layout/_topnav.html.eex:16
#: lib/block_scout_web/templates/layout/_topnav.html.eex:20
msgid "Blocks"
Expand Down Expand Up @@ -560,7 +560,7 @@ msgid "More internal transactions have come in"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/chain/show.html.eex:96
#: lib/block_scout_web/templates/chain/show.html.eex:104
#: lib/block_scout_web/templates/pending_transaction/index.html.eex:14
#: lib/block_scout_web/templates/transaction/index.html.eex:14
msgid "More transactions have come in"
Expand Down Expand Up @@ -957,7 +957,7 @@ msgstr ""
#: lib/block_scout_web/templates/block_transaction/index.html.eex:23
#: lib/block_scout_web/templates/block_transaction/index.html.eex:26
#: lib/block_scout_web/templates/block_transaction/index.html.eex:35
#: lib/block_scout_web/templates/chain/show.html.eex:93
#: lib/block_scout_web/templates/chain/show.html.eex:101
#: lib/block_scout_web/templates/layout/_topnav.html.eex:35
#: lib/block_scout_web/views/address_view.ex:294
msgid "Transactions"
Expand Down Expand Up @@ -1031,12 +1031,12 @@ msgid "Verify & publish"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/chain/show.html.eex:71
#: lib/block_scout_web/templates/chain/show.html.eex:79
msgid "View All Blocks →"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/chain/show.html.eex:92
#: lib/block_scout_web/templates/chain/show.html.eex:100
msgid "View All Transactions →"
msgstr ""

Expand Down Expand Up @@ -1076,7 +1076,7 @@ msgid "WEI"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/chain/show.html.eex:58
#: lib/block_scout_web/templates/chain/show.html.eex:66
msgid "Wallet addresses"
msgstr ""

Expand Down Expand Up @@ -1160,8 +1160,8 @@ msgstr ""
#: lib/block_scout_web/templates/address_token_transfer/index.html.eex:19
#: lib/block_scout_web/templates/address_validation/index.html.eex:63
#: lib/block_scout_web/templates/address_validation/index.html.eex:82
#: lib/block_scout_web/templates/chain/show.html.eex:84
#: lib/block_scout_web/templates/chain/show.html.eex:110
#: lib/block_scout_web/templates/chain/show.html.eex:92
#: lib/block_scout_web/templates/chain/show.html.eex:118
#: lib/block_scout_web/templates/tokens/read_contract/index.html.eex:24
msgid "Loading..."
msgstr ""
Expand Down Expand Up @@ -1371,7 +1371,7 @@ msgstr ""
#: lib/block_scout_web/templates/address_token_transfer/index.html.eex:26
#: lib/block_scout_web/templates/address_transaction/index.html.eex:55
#: lib/block_scout_web/templates/address_validation/index.html.eex:70
#: lib/block_scout_web/templates/chain/show.html.eex:76
#: lib/block_scout_web/templates/chain/show.html.eex:84
#: lib/block_scout_web/templates/pending_transaction/index.html.eex:23
#: lib/block_scout_web/templates/tokens/holder/index.html.eex:22
#: lib/block_scout_web/templates/tokens/transfer/index.html.eex:20
Expand Down Expand Up @@ -1514,7 +1514,7 @@ msgid "Emission Contract"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/chain/show.html.eex:102
#: lib/block_scout_web/templates/chain/show.html.eex:110
msgid "Something went wrong, click to retry."
msgstr ""

Expand Down Expand Up @@ -1744,3 +1744,8 @@ msgstr ""
#: lib/block_scout_web/templates/transaction/overview.html.eex:165
msgid "ERC-721"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/chain/show.html.eex:58
msgid "Total blocks"
msgstr ""
25 changes: 15 additions & 10 deletions apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ msgid "BlockScout provides analytics data, API, and Smart Contract tools for the
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/chain/show.html.eex:72
#: lib/block_scout_web/templates/chain/show.html.eex:80
#: lib/block_scout_web/templates/layout/_topnav.html.eex:16
#: lib/block_scout_web/templates/layout/_topnav.html.eex:20
msgid "Blocks"
Expand Down Expand Up @@ -560,7 +560,7 @@ msgid "More internal transactions have come in"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/chain/show.html.eex:96
#: lib/block_scout_web/templates/chain/show.html.eex:104
#: lib/block_scout_web/templates/pending_transaction/index.html.eex:14
#: lib/block_scout_web/templates/transaction/index.html.eex:14
msgid "More transactions have come in"
Expand Down Expand Up @@ -957,7 +957,7 @@ msgstr ""
#: lib/block_scout_web/templates/block_transaction/index.html.eex:23
#: lib/block_scout_web/templates/block_transaction/index.html.eex:26
#: lib/block_scout_web/templates/block_transaction/index.html.eex:35
#: lib/block_scout_web/templates/chain/show.html.eex:93
#: lib/block_scout_web/templates/chain/show.html.eex:101
#: lib/block_scout_web/templates/layout/_topnav.html.eex:35
#: lib/block_scout_web/views/address_view.ex:294
msgid "Transactions"
Expand Down Expand Up @@ -1031,12 +1031,12 @@ msgid "Verify & publish"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/chain/show.html.eex:71
#: lib/block_scout_web/templates/chain/show.html.eex:79
msgid "View All Blocks →"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/chain/show.html.eex:92
#: lib/block_scout_web/templates/chain/show.html.eex:100
msgid "View All Transactions →"
msgstr ""

Expand Down Expand Up @@ -1076,7 +1076,7 @@ msgid "WEI"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/chain/show.html.eex:58
#: lib/block_scout_web/templates/chain/show.html.eex:66
msgid "Wallet addresses"
msgstr ""

Expand Down Expand Up @@ -1160,8 +1160,8 @@ msgstr ""
#: lib/block_scout_web/templates/address_token_transfer/index.html.eex:19
#: lib/block_scout_web/templates/address_validation/index.html.eex:63
#: lib/block_scout_web/templates/address_validation/index.html.eex:82
#: lib/block_scout_web/templates/chain/show.html.eex:84
#: lib/block_scout_web/templates/chain/show.html.eex:110
#: lib/block_scout_web/templates/chain/show.html.eex:92
#: lib/block_scout_web/templates/chain/show.html.eex:118
#: lib/block_scout_web/templates/tokens/read_contract/index.html.eex:24
msgid "Loading..."
msgstr ""
Expand Down Expand Up @@ -1371,7 +1371,7 @@ msgstr ""
#: lib/block_scout_web/templates/address_token_transfer/index.html.eex:26
#: lib/block_scout_web/templates/address_transaction/index.html.eex:55
#: lib/block_scout_web/templates/address_validation/index.html.eex:70
#: lib/block_scout_web/templates/chain/show.html.eex:76
#: lib/block_scout_web/templates/chain/show.html.eex:84
#: lib/block_scout_web/templates/pending_transaction/index.html.eex:23
#: lib/block_scout_web/templates/tokens/holder/index.html.eex:22
#: lib/block_scout_web/templates/tokens/transfer/index.html.eex:20
Expand Down Expand Up @@ -1514,7 +1514,7 @@ msgid "Emission Contract"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/chain/show.html.eex:102
#: lib/block_scout_web/templates/chain/show.html.eex:110
msgid "Something went wrong, click to retry."
msgstr ""

Expand Down Expand Up @@ -1744,3 +1744,8 @@ msgstr ""
#: lib/block_scout_web/templates/transaction/overview.html.eex:165
msgid "ERC-721"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/chain/show.html.eex:58
msgid "Total blocks"
msgstr ""