aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorDan Finlay <dan@danfinlay.com>2016-04-01 02:40:55 +0800
committerDan Finlay <dan@danfinlay.com>2016-04-01 02:40:55 +0800
commitd9cadb9efbd8a38522ce638b8def37c935bb6be0 (patch)
tree352dda8dc0e982888edc16720fa199389b30b77e /app
parentf451da67a725636c5b504737a8bc45774a6fc5c3 (diff)
downloadtangerine-wallet-browser-d9cadb9efbd8a38522ce638b8def37c935bb6be0.tar
tangerine-wallet-browser-d9cadb9efbd8a38522ce638b8def37c935bb6be0.tar.gz
tangerine-wallet-browser-d9cadb9efbd8a38522ce638b8def37c935bb6be0.tar.bz2
tangerine-wallet-browser-d9cadb9efbd8a38522ce638b8def37c935bb6be0.tar.lz
tangerine-wallet-browser-d9cadb9efbd8a38522ce638b8def37c935bb6be0.tar.xz
tangerine-wallet-browser-d9cadb9efbd8a38522ce638b8def37c935bb6be0.tar.zst
tangerine-wallet-browser-d9cadb9efbd8a38522ce638b8def37c935bb6be0.zip
First naive pass at implementing etherscan provider (not working)
Committing and pushing to get feedback.
Diffstat (limited to 'app')
-rw-r--r--app/manifest.json1
-rw-r--r--app/scripts/background.js27
-rw-r--r--app/scripts/lib/config-manager.js31
3 files changed, 45 insertions, 14 deletions
diff --git a/app/manifest.json b/app/manifest.json
index 915295914..be5a06c8d 100644
--- a/app/manifest.json
+++ b/app/manifest.json
@@ -1,5 +1,6 @@
{
"name": "__MSG_appName__",
+ "short_name": "Metamask",
"version": "1.2.1",
"manifest_version": 2,
"description": "__MSG_appDescription__",
diff --git a/app/scripts/background.js b/app/scripts/background.js
index 772c1de89..cc137616a 100644
--- a/app/scripts/background.js
+++ b/app/scripts/background.js
@@ -7,6 +7,7 @@ const extend = require('xtend')
const EthStore = require('eth-store')
const PortStream = require('./lib/port-stream.js')
const MetaMaskProvider = require('web3-provider-engine/zero.js')
+const EtherscanProvider = require('web3-provider-engine/subproviders/etherscan')
const IdentityStore = require('./lib/idStore')
const createTxNotification = require('./lib/tx-notification.js')
const configManager = require('./lib/config-manager-singleton')
@@ -36,8 +37,9 @@ function handleEthRpcRequestStream(stream){
// state and network
//
+var providerConfig = configManager.getProvider()
var idStore = new IdentityStore()
-var zeroClient = MetaMaskProvider({
+var providerOpts = {
rpcUrl: configManager.getCurrentRpcAddress(),
getAccounts: function(cb){
var selectedAddress = idStore.getSelectedAddress()
@@ -46,14 +48,23 @@ var zeroClient = MetaMaskProvider({
},
approveTransaction: addUnconfirmedTx,
signTransaction: idStore.signTransaction.bind(idStore),
-})
+}
+var provider
+switch (providerConfig.type) {
+ case 'rpc':
+ provider = MetaMaskProvider(providerOpts)
+ break
+ case 'etherscan':
+ provider = EtherscanProvider(providerOpts)
+ break
+}
// log new blocks
-zeroClient.on('block', function(block){
+provider.on('block', function(block){
console.log('BLOCK CHANGED:', '#'+block.number.toString('hex'), '0x'+block.hash.toString('hex'))
})
-var ethStore = new EthStore(zeroClient)
+var ethStore = new EthStore(provider)
idStore.setStore(ethStore)
function getState(){
@@ -68,7 +79,7 @@ function getState(){
// handle rpc requests
function onRpcRequest(remoteStream, payload){
// console.log('MetaMaskPlugin - incoming payload:', payload)
- zeroClient.sendAsync(payload, function onPayloadHandled(err, response){
+ provider.sendAsync(payload, function onPayloadHandled(err, response){
// provider engine errors are included in response objects
if (!payload.isMetamaskInternal) console.log('MetaMaskPlugin - RPC complete:', payload, '->', response)
try {
@@ -111,6 +122,7 @@ function linkDnode(stream){
var connection = Dnode({
getState: function(cb){ cb(null, getState()) },
setRpcTarget: setRpcTarget,
+ useEtherscanProvider: useEtherscanProvider,
// forward directly to idStore
createNewVault: idStore.createNewVault.bind(idStore),
recoverFromSeed: idStore.recoverFromSeed.bind(idStore),
@@ -179,6 +191,11 @@ function setRpcTarget(rpcTarget){
chrome.runtime.reload()
}
+function useEtherscanProvider() {
+ configManager.useEtherscanProvider()
+ chrome.runtime.reload()
+}
+
// util
function jsonParseStream(){
diff --git a/app/scripts/lib/config-manager.js b/app/scripts/lib/config-manager.js
index 682b34637..121ede838 100644
--- a/app/scripts/lib/config-manager.js
+++ b/app/scripts/lib/config-manager.js
@@ -47,15 +47,6 @@ ConfigManager.prototype.setConfig = function(config) {
this.setData(data)
}
-ConfigManager.prototype.setRpcTarget = function(rpcUrl) {
- var config = this.getConfig()
- config.provider = {
- type: 'rpc',
- rpcTarget: rpcUrl,
- }
- this.setConfig(config)
-}
-
ConfigManager.prototype.getConfig = function() {
var data = this.migrator.getData()
if ('config' in data) {
@@ -70,6 +61,28 @@ ConfigManager.prototype.getConfig = function() {
}
}
+ConfigManager.prototype.setRpcTarget = function(rpcUrl) {
+ var config = this.getConfig()
+ config.provider = {
+ type: 'rpc',
+ rpcTarget: rpcUrl,
+ }
+ this.setConfig(config)
+}
+
+ConfigManager.prototype.useEtherscanProvider = function() {
+ var config = this.getConfig()
+ config.provider = {
+ type: 'etherscan',
+ }
+ this.setConfig(config)
+}
+
+ConfigManager.prototype.getProvider = function() {
+ var config = this.getConfig()
+ return config.provider
+}
+
ConfigManager.prototype.setData = function(data) {
this.migrator.saveData(data)
}