aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorkumavis <aaron@kumavis.me>2015-08-02 11:50:29 +0800
committerkumavis <aaron@kumavis.me>2015-08-02 11:50:29 +0800
commitfd9871acaef0ffab3277c65da4dade99323c4c7a (patch)
treeaa6c70e783a3637261119895c1aafc820c37406e /app
parentcc1bb92f9d842f4d8a757358bf31c5de6c32592d (diff)
downloadtangerine-wallet-browser-fd9871acaef0ffab3277c65da4dade99323c4c7a.tar
tangerine-wallet-browser-fd9871acaef0ffab3277c65da4dade99323c4c7a.tar.gz
tangerine-wallet-browser-fd9871acaef0ffab3277c65da4dade99323c4c7a.tar.bz2
tangerine-wallet-browser-fd9871acaef0ffab3277c65da4dade99323c4c7a.tar.lz
tangerine-wallet-browser-fd9871acaef0ffab3277c65da4dade99323c4c7a.tar.xz
tangerine-wallet-browser-fd9871acaef0ffab3277c65da4dade99323c4c7a.tar.zst
tangerine-wallet-browser-fd9871acaef0ffab3277c65da4dade99323c4c7a.zip
builds smoothly + forwards txs to extension
Diffstat (limited to 'app')
-rw-r--r--app/manifest.json2
-rw-r--r--app/scripts/background.js56
-rw-r--r--app/scripts/contentscript.js29
-rw-r--r--app/scripts/inpage.js10
4 files changed, 62 insertions, 35 deletions
diff --git a/app/manifest.json b/app/manifest.json
index 3a5456cce..cd23eee87 100644
--- a/app/manifest.json
+++ b/app/manifest.json
@@ -38,6 +38,6 @@
"storage"
],
"web_accessible_resources": [
- "scripts/web3.js"
+ "scripts/inpage.js"
]
} \ No newline at end of file
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
diff --git a/app/scripts/contentscript.js b/app/scripts/contentscript.js
index 2e50ae3a5..53ec9eef5 100644
--- a/app/scripts/contentscript.js
+++ b/app/scripts/contentscript.js
@@ -1,16 +1,25 @@
-const web3 = require('web3')
+const messageType = 'metamaskMessage'
-// inject script tag
+
+// inject in-page script
var scriptTag = document.createElement('script')
-scriptTag.src = chrome.extension.getURL('scripts/web3.js')
-scriptTag.onload = function() { debugger; this.parentNode.removeChild(this) }
+scriptTag.src = chrome.extension.getURL('scripts/inpage.js')
+scriptTag.onload = function() { this.parentNode.removeChild(this) }
var container = document.head || document.documentElement
container.appendChild(scriptTag)
// listen for messages
-var port = chrome.runtime.connect({name: 'metamask'})
-port.postMessage({joke: 'Knock knock'})
-port.onMessage.addListener(function(msg) {
- console.log(msg)
- // port.postMessage({answer: 'Madame'})
-}) \ No newline at end of file
+var metamaskPlugin = chrome.runtime.connect({name: 'metamask'})
+// metamaskPlugin.onMessage.addListener(function(msg) {
+// console.log(msg)
+// })
+
+window.addEventListener('message', receiveMessage, false);
+function receiveMessage(event){
+ var msg = event.data
+ // validate message type
+ if (typeof msg !== 'object') return
+ if (msg.type !== messageType) return
+ // forward message
+ metamaskPlugin.postMessage(msg)
+} \ No newline at end of file
diff --git a/app/scripts/inpage.js b/app/scripts/inpage.js
index 02bf226cb..006a8e0bb 100644
--- a/app/scripts/inpage.js
+++ b/app/scripts/inpage.js
@@ -2,14 +2,20 @@ const web3 = require('web3')
const MetamaskProvider = require('./lib/metamask-provider.js')
const rpcUrl = 'https://rpc.metamask.io'
+const messageType = 'metamaskMessage'
+const documentOrigin = window.location.origin
var provider = new MetamaskProvider(forwardPayload, rpcUrl)
web3.setProvider(provider)
// injecting web3
+console.log('Metamask injected web3')
window.web3 = web3
-function forwardPayload(){
- debugger
+function forwardPayload(payload){
+ window.postMessage({
+ type: messageType,
+ payload: payload,
+ }, documentOrigin)
} \ No newline at end of file