1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

Generate explorer link to match current blockchain

This commit is contained in:
Dan Finlay 2016-04-19 18:21:28 -07:00
parent b8c57433ce
commit f79601ee58
5 changed files with 35 additions and 40 deletions

View File

@ -17,7 +17,7 @@ injectCss(css)
async.parallel({ async.parallel({
currentDomain: getCurrentDomain, currentDomain: getCurrentDomain,
accountManager: connectToAccountManager, accountManager: connectToAccountManager,
}, setupApp) }, getNetworkVersion)
function connectToAccountManager(cb){ function connectToAccountManager(cb){
// setup communication with background // setup communication with background
@ -65,6 +65,13 @@ function getCurrentDomain(cb){
}) })
} }
function getNetworkVersion(cb, results) {
web3.version.getNetwork(function(err, result) {
results.networkVersion = result
setupApp(err, results)
})
}
function setupApp(err, opts){ function setupApp(err, opts){
if (err) { if (err) {
alert(err.stack) alert(err.stack)
@ -78,6 +85,6 @@ function setupApp(err, opts){
container: container, container: container,
accountManager: opts.accountManager, accountManager: opts.accountManager,
currentDomain: opts.currentDomain, currentDomain: opts.currentDomain,
networkVersion: opts.networkVersion,
}) })
} }

View File

@ -17,6 +17,7 @@ function mapStateToProps(state) {
address: state.appState.currentView.context, address: state.appState.currentView.context,
accountDetail: accountDetail, accountDetail: accountDetail,
transactions: state.metamask.transactions, transactions: state.metamask.transactions,
networkVersion: state.networkVersion,
} }
} }
@ -74,7 +75,9 @@ AccountDetailScreen.prototype.render = function() {
]), ]),
]), ]),
transactionList(transactions), transactionList(transactions
.filter(tx => tx.txParams.from === state.address)
.sort((a, b) => b.time - a.time), state.networkVersion),
this.exportedAccount(accountDetail), this.exportedAccount(accountDetail),
// transaction table // transaction table

View File

@ -1,39 +1,9 @@
/*
transactions
:
Array[3]
0
:
Object
id
:
1461025348948185
status
:
"confirmed"
time
:
1461025348948
txParams
:
Object
data
:
"0x90b98a11000000000000000000000000c5b8dbac4c1d3f152cdeb400e2313f309c410acb00000000000000000000000000000000000000000000000000000000000003e8"
from
:
"0xfdea65c8e26263f6d9a1b5de9555d2931a33b825"
to
:
"0xcd1ca6275b45065c4db4ec024859f8fd9d8d44ba"
__proto__
:
Object
*/
const h = require('react-hyperscript') const h = require('react-hyperscript')
const formatBalance = require('../util').formatBalance const formatBalance = require('../util').formatBalance
const addressSummary = require('../util').addressSummary
const explorerLink = require('../../lib/explorer-link')
module.exports = function(transactions) { module.exports = function(transactions, network) {
return h('details', [ return h('details', [
h('summary', [ h('summary', [
@ -41,7 +11,7 @@ module.exports = function(transactions) {
]), ]),
h('.flex-row.flex-space-around', [ h('.flex-row.flex-space-around', [
h('div.font-small','Transaction'), h('div.font-small','To'),
h('div.font-small','Amount'), h('div.font-small','Amount'),
]), ]),
@ -56,10 +26,10 @@ module.exports = function(transactions) {
return h('.tx.flex-row.flex-space-around', [ return h('.tx.flex-row.flex-space-around', [
h('a.font-small', h('a.font-small',
{ {
href: 'http://testnet.etherscan.io/tx/0xfc37bda95ce571bd0a393e8e7f6da394f1420a57b7d53f7c93821bff61f9b580', href: explorerLink(transaction.hash, parseInt(network)),
target: '_blank', target: '_blank',
}, },
'0xfc37bda...b580'), addressSummary(transaction.txParams.to)),
h('div.font-small', formatBalance(transaction.txParams.value)) h('div.font-small', formatBalance(transaction.txParams.value))
]) ])
}) })

View File

@ -32,7 +32,10 @@ function startApp(metamaskState, accountManager, opts){
// appState represents the current tab's popup state // appState represents the current tab's popup state
appState: { appState: {
currentDomain: opts.currentDomain, currentDomain: opts.currentDomain,
} },
// Which blockchain we are using:
networkVersion: opts.networkVersion,
}) })
// if unconfirmed txs, start on txConf page // if unconfirmed txs, start on txConf page

12
ui/lib/explorer-link.js Normal file
View File

@ -0,0 +1,12 @@
module.exports = function(hash, network) {
let prefix
switch (network) {
case 1: // main net
prefix = ''
case 2: // morden test net
prefix = 'testnet.'
default:
prefix = ''
}
return `http://${prefix}etherscan.io/tx/${hash}`
}