From f79601ee58a07ec6275d4588845578795f550d84 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Tue, 19 Apr 2016 18:21:28 -0700 Subject: Generate explorer link to match current blockchain --- app/scripts/popup.js | 11 +++++++-- ui/app/account-detail.js | 5 ++++- ui/app/components/transaction-list.js | 42 +++++------------------------------ ui/index.js | 5 ++++- ui/lib/explorer-link.js | 12 ++++++++++ 5 files changed, 35 insertions(+), 40 deletions(-) create mode 100644 ui/lib/explorer-link.js diff --git a/app/scripts/popup.js b/app/scripts/popup.js index 85b3e30f9..6a39da661 100644 --- a/app/scripts/popup.js +++ b/app/scripts/popup.js @@ -17,7 +17,7 @@ injectCss(css) async.parallel({ currentDomain: getCurrentDomain, accountManager: connectToAccountManager, -}, setupApp) +}, getNetworkVersion) function connectToAccountManager(cb){ // 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){ if (err) { alert(err.stack) @@ -78,6 +85,6 @@ function setupApp(err, opts){ container: container, accountManager: opts.accountManager, currentDomain: opts.currentDomain, + networkVersion: opts.networkVersion, }) - } diff --git a/ui/app/account-detail.js b/ui/app/account-detail.js index 871c0e66c..025644efe 100644 --- a/ui/app/account-detail.js +++ b/ui/app/account-detail.js @@ -17,6 +17,7 @@ function mapStateToProps(state) { address: state.appState.currentView.context, accountDetail: accountDetail, 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), // transaction table diff --git a/ui/app/components/transaction-list.js b/ui/app/components/transaction-list.js index e01c8c1f0..865ce5370 100644 --- a/ui/app/components/transaction-list.js +++ b/ui/app/components/transaction-list.js @@ -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 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', [ h('summary', [ @@ -41,7 +11,7 @@ module.exports = function(transactions) { ]), h('.flex-row.flex-space-around', [ - h('div.font-small','Transaction'), + h('div.font-small','To'), h('div.font-small','Amount'), ]), @@ -56,10 +26,10 @@ module.exports = function(transactions) { return h('.tx.flex-row.flex-space-around', [ h('a.font-small', { - href: 'http://testnet.etherscan.io/tx/0xfc37bda95ce571bd0a393e8e7f6da394f1420a57b7d53f7c93821bff61f9b580', + href: explorerLink(transaction.hash, parseInt(network)), target: '_blank', }, - '0xfc37bda...b580'), + addressSummary(transaction.txParams.to)), h('div.font-small', formatBalance(transaction.txParams.value)) ]) }) diff --git a/ui/index.js b/ui/index.js index 05d30d8d3..4ecce2fbe 100644 --- a/ui/index.js +++ b/ui/index.js @@ -32,7 +32,10 @@ function startApp(metamaskState, accountManager, opts){ // appState represents the current tab's popup state appState: { currentDomain: opts.currentDomain, - } + }, + + // Which blockchain we are using: + networkVersion: opts.networkVersion, }) // if unconfirmed txs, start on txConf page diff --git a/ui/lib/explorer-link.js b/ui/lib/explorer-link.js new file mode 100644 index 000000000..a2e7872f9 --- /dev/null +++ b/ui/lib/explorer-link.js @@ -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}` +} -- cgit