diff options
builds smoothly + forwards txs to extension
Diffstat (limited to 'app/scripts/background.js')
-rw-r--r-- | app/scripts/background.js | 56 |
1 files changed, 34 insertions, 22 deletions
diff --git a/app/scripts/background.js b/app/scripts/background.js index 1557814b4..2dd5c88c7 100644 --- a/app/scripts/background.js +++ b/app/scripts/background.js @@ -1,8 +1,7 @@ -const web3 = require('web3') - const identitiesUrl = 'https://alpha.metamask.io/identities/' const messagingChannelName = 'metamask' +var pendingTxs = [] // setup badge click handler chrome.browserAction.onClicked.addListener(function(activeTab) { @@ -13,29 +12,42 @@ chrome.browserAction.onClicked.addListener(function(activeTab) { chrome.runtime.onConnect.addListener(function(port) { console.assert(port.name == messagingChannelName) port.onMessage.addListener(function(msg) { - console.log(msg) - port.postMessage({answer: 'Madame'}) + addTransaction(msg.payload) }) }) +// listen to storage changes +// chrome.storage.onChanged.addListener(function(changes, namespace) { +// for (key in changes) { +// var storageChange = changes[key] +// console.log('Storage key "%s" in namespace "%s" changed. ' + +// 'Old value was "%s", new value is "%s".', +// key, +// namespace, +// storageChange.oldValue, +// storageChange.newValue) +// } +// }) + +// // Save it using the Chrome extension storage API. +// chrome.storage.sync.set({'zzz': 22}, function() { +// // Notify that we saved. +// console.log('Settings saved') +// }) + // update badge text -chrome.browserAction.setBadgeText({text: '2'}) +updateBadge() -// listen to storage changes -chrome.storage.onChanged.addListener(function(changes, namespace) { - for (key in changes) { - var storageChange = changes[key] - console.log('Storage key "%s" in namespace "%s" changed. ' + - 'Old value was "%s", new value is "%s".', - key, - namespace, - storageChange.oldValue, - storageChange.newValue) - } -}) -// Save it using the Chrome extension storage API. -chrome.storage.sync.set({'zzz': 22}, function() { - // Notify that we saved. - console.log('Settings saved') -})
\ No newline at end of file +function addTransaction(tx){ + pendingTxs.push(tx) + updateBadge() +} + +function updateBadge(){ + var label = '' + if (pendingTxs.length) { + label = String(pendingTxs.length) + } + chrome.browserAction.setBadgeText({text: label}) +}
\ No newline at end of file |