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

Connect to Metamask button #3201

Merged
merged 2 commits into from Jul 17, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -7,6 +7,7 @@
- [#3145](https://github.com/poanetwork/blockscout/pull/3145) - Pending txs per address API endpoint

### Fixes
- [#3201](https://github.com/poanetwork/blockscout/pull/3201) - Connect to Metamask button
- [#3192](https://github.com/poanetwork/blockscout/pull/3192) - Dropdown menu doesn't open at "not found" page
- [#3190](https://github.com/poanetwork/blockscout/pull/3190) - Contract log/method decoded view improvements: eliminate horizontal scroll, remove excess borders, whitespaces
- [#3185](https://github.com/poanetwork/blockscout/pull/3185) - Transaction page: decoding logs from nested contracts calls
Expand Down
4 changes: 4 additions & 0 deletions apps/block_scout_web/assets/css/components/_card.scss
Expand Up @@ -258,6 +258,10 @@ $card-tab-icon-color-active: #fff !default;
}
}

.implementation-container {
margin-top: 10px;
}

.implementation-title {
float: left;
margin-right: 5px;
Expand Down
14 changes: 13 additions & 1 deletion apps/block_scout_web/assets/js/lib/smart_contract/functions.js
@@ -1,6 +1,6 @@
import $ from 'jquery'
import ethNetProps from 'eth-net-props'
import { walletEnabled, getCurrentAccount } from './write.js'
import { walletEnabled, connectToWallet, getCurrentAccount, hideConnectButton } from './write.js'
import { openErrorModal, openWarningModal, openSuccessModal, openModalWithMessage } from '../modals.js'
import '../../pages/address'

Expand All @@ -19,6 +19,18 @@ const loadFunctions = (element) => {
response => $element.html(response)
)
.done(function () {
const $connect = $('[connect-metamask]')

if (hideConnectButton()) {
$connect.addClass('hidden')
} else {
$connect.removeClass('hidden')
}

$connect.on('click', () => {
connectToWallet()
})

$('[data-function]').each((_, element) => {
readWriteFunction(element)
})
Expand Down
29 changes: 27 additions & 2 deletions apps/block_scout_web/assets/js/lib/smart_contract/write.js
Expand Up @@ -3,10 +3,10 @@ import Web3 from 'web3'
export const walletEnabled = () => {
if (window.ethereum) {
window.web3 = new Web3(window.ethereum)
if (window.ethereum._state && window.ethereum._state.isUnlocked) { // Nifty Wallet
if (window.ethereum.isUnlocked && window.ethereum.isNiftyWallet) { // Nifty Wallet
window.web3 = new Web3(window.web3.currentProvider)
return Promise.resolve(true)
} else if (window.ethereum._state && window.ethereum._state.isUnlocked === false) { // Nifty Wallet
} else if (window.ethereum.isUnlocked === false && window.ethereum.isNiftyWallet) { // Nifty Wallet
return Promise.resolve(false)
} else {
window.ethereum.enable()
Expand All @@ -21,9 +21,34 @@ export const walletEnabled = () => {
}
}

export const connectToWallet = () => {
if (window.ethereum) {
window.ethereum.enable()
}
}

export const getCurrentAccount = async () => {
const accounts = await window.web3.eth.getAccounts()
const account = accounts[0] ? accounts[0].toLowerCase() : null

return account
}

export const hideConnectButton = () => {
if (window.ethereum) {
window.web3 = new Web3(window.ethereum)
if (window.ethereum.isNiftyWallet) {
return true
} else if (window.ethereum.isMetaMask) {
if (window.ethereum.selectedAddress) {
return true
} else {
return false
}
} else {
return true
}
} else {
return false
}
}
Expand Up @@ -58,7 +58,8 @@ defmodule BlockScoutWeb.SmartContractController do
contract_abi: contract_abi,
implementation_address: implementation_address_hash_string,
implementation_abi: implementation_abi,
contract_type: contract_type
contract_type: contract_type,
action: action
)
else
:error ->
Expand Down
@@ -1,5 +1,8 @@
<%= if @action== "write" do %>
<button connect-metamask class="button btn-line">Connect to Metamask</button>
<% end %>
<%= if @contract_type == "proxy" do %>
<div>
<div class="implementation-container">
<h2 class="implementation-title">Implementation address: </h2><h3 class="implementation-value"><%= link(
@implementation_address,
to: address_path(@conn, :show, @implementation_address)
Expand Down
10 changes: 5 additions & 5 deletions apps/block_scout_web/priv/gettext/default.pot
Expand Up @@ -562,8 +562,8 @@ msgid "ERC-721 "
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/smart_contract/_functions.html.eex:40
#: lib/block_scout_web/templates/smart_contract/_functions.html.eex:75
#: lib/block_scout_web/templates/smart_contract/_functions.html.eex:43
#: lib/block_scout_web/templates/smart_contract/_functions.html.eex:78
msgid "ETH"
msgstr ""

Expand Down Expand Up @@ -1180,7 +1180,7 @@ msgid "QR Code"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/smart_contract/_functions.html.eex:44
#: lib/block_scout_web/templates/smart_contract/_functions.html.eex:47
msgid "Query"
msgstr ""

Expand Down Expand Up @@ -1631,7 +1631,7 @@ msgid "View transaction %{transaction} on %{subnetwork}"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/smart_contract/_functions.html.eex:74
#: lib/block_scout_web/templates/smart_contract/_functions.html.eex:77
msgid "WEI"
msgstr ""

Expand Down Expand Up @@ -1919,7 +1919,7 @@ msgid "Waiting for transaction's confirmation..."
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/smart_contract/_functions.html.eex:44
#: lib/block_scout_web/templates/smart_contract/_functions.html.eex:47
msgid "Write"
msgstr ""

Expand Down
12 changes: 6 additions & 6 deletions apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po
Expand Up @@ -562,8 +562,8 @@ msgid "ERC-721 "
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/smart_contract/_functions.html.eex:40
#: lib/block_scout_web/templates/smart_contract/_functions.html.eex:75
#: lib/block_scout_web/templates/smart_contract/_functions.html.eex:43
#: lib/block_scout_web/templates/smart_contract/_functions.html.eex:78
msgid "ETH"
msgstr ""

Expand Down Expand Up @@ -1180,7 +1180,7 @@ msgid "QR Code"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/smart_contract/_functions.html.eex:44
#: lib/block_scout_web/templates/smart_contract/_functions.html.eex:47
msgid "Query"
msgstr ""

Expand Down Expand Up @@ -1631,7 +1631,7 @@ msgid "View transaction %{transaction} on %{subnetwork}"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/smart_contract/_functions.html.eex:74
#: lib/block_scout_web/templates/smart_contract/_functions.html.eex:77
msgid "WEI"
msgstr ""

Expand Down Expand Up @@ -1919,7 +1919,7 @@ msgid "Waiting for transaction's confirmation..."
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/smart_contract/_functions.html.eex:44
#: lib/block_scout_web/templates/smart_contract/_functions.html.eex:47
msgid "Write"
msgstr ""

Expand All @@ -1934,7 +1934,7 @@ msgstr ""
msgid "Apps"
msgstr ""

#, elixir-format, fuzzy
#, elixir-format
#: lib/block_scout_web/templates/transaction_raw_trace/index.html.eex:15
msgid "Copy Raw Trace"
msgstr ""