aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorkumavis <aaron@kumavis.me>2015-08-02 14:36:03 +0800
committerkumavis <aaron@kumavis.me>2015-08-02 14:36:03 +0800
commit6bf98c6923624d565619ecf68c9d4c41d76510ba (patch)
tree21a888b99d6659c1f46576bac3cd0d620c9c04ed /app
parentdcfd89db1b98d6d7235c3a73993d8a495a2aabff (diff)
downloadtangerine-wallet-browser-6bf98c6923624d565619ecf68c9d4c41d76510ba.tar
tangerine-wallet-browser-6bf98c6923624d565619ecf68c9d4c41d76510ba.tar.gz
tangerine-wallet-browser-6bf98c6923624d565619ecf68c9d4c41d76510ba.tar.bz2
tangerine-wallet-browser-6bf98c6923624d565619ecf68c9d4c41d76510ba.tar.lz
tangerine-wallet-browser-6bf98c6923624d565619ecf68c9d4c41d76510ba.tar.xz
tangerine-wallet-browser-6bf98c6923624d565619ecf68c9d4c41d76510ba.tar.zst
tangerine-wallet-browser-6bf98c6923624d565619ecf68c9d4c41d76510ba.zip
load from storage on start and export unsignedTxs on remote connect
Diffstat (limited to 'app')
-rw-r--r--app/manifest.json8
-rw-r--r--app/scripts/background.js56
-rw-r--r--app/scripts/contentscript.js2
-rw-r--r--app/scripts/inpage.js2
4 files changed, 49 insertions, 19 deletions
diff --git a/app/manifest.json b/app/manifest.json
index cd23eee87..d760eea0f 100644
--- a/app/manifest.json
+++ b/app/manifest.json
@@ -39,5 +39,11 @@
],
"web_accessible_resources": [
"scripts/inpage.js"
- ]
+ ],
+ "externally_connectable": {
+ "matches": [
+ "https://metamask.io/*",
+ "https://alpha.metamask.io/*"
+ ]
+ }
} \ No newline at end of file
diff --git a/app/scripts/background.js b/app/scripts/background.js
index fbf80c7a3..ddb867219 100644
--- a/app/scripts/background.js
+++ b/app/scripts/background.js
@@ -1,28 +1,36 @@
const identitiesUrl = 'https://alpha.metamask.io/identities/'
const messagingChannelName = 'metamask'
-var unconfirmedTxs = {}
+var unsignedTxs = {}
// setup badge click handler
chrome.browserAction.onClicked.addListener(function(activeTab) {
chrome.tabs.create({ url: identitiesUrl })
})
-// setup content-background messaging
-chrome.runtime.onConnect.addListener(function(port) {
- port.onMessage.addListener(handleMessage)
+// setup messaging
+chrome.runtime.onConnect.addListener(connectRemote)
+chrome.runtime.onConnectExternal.addListener(connectRemote)
+function connectRemote(remote){
+ remote.onMessage.addListener(handleMessage)
+ exportUnsignedTxs(remote)
+}
+
+// load from storage
+chrome.storage.sync.get(function(data){
+ for (var key in data) {
+ var serialized = data[key]
+ var tx = deserializeTx(serialized)
+ var hash = simpleHash(serialized)
+ unsignedTxs[hash] = tx
+ }
+ 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:',
- key,
- namespace,
- storageChange.oldValue,
- storageChange.newValue)
if (storageChange.oldValue && !storageChange.newValue) {
// was removed
removeTransaction(storageChange.oldValue)
@@ -40,11 +48,11 @@ function handleMessage(msg){
console.log('got message!', msg.type)
switch(msg.type){
- case 'addUnconfirmedTx':
+ case 'addUnsignedTx':
addTransaction(msg.payload)
return
- case 'removeUnconfirmedTx':
+ case 'removeUnsignedTx':
removeTransaction(msg.payload)
return
@@ -54,8 +62,7 @@ function handleMessage(msg){
function addTransaction(tx){
var serialized = serializeTx(tx)
var hash = simpleHash(serialized)
- console.log('add tx: ', tx.id, hash, serializeTx(tx), tx)
- unconfirmedTxs[hash] = tx
+ unsignedTxs[hash] = tx
var data = {}
data[hash] = serialized
chrome.storage.sync.set(data)
@@ -65,7 +72,7 @@ function addTransaction(tx){
function removeTransaction(serialized){
var hash = simpleHash(serialized)
- delete unconfirmedTxs[hash]
+ delete unsignedTxs[hash]
var data = {}
data[hash] = undefined
chrome.storage.sync.set(data)
@@ -73,9 +80,18 @@ function removeTransaction(serialized){
updateBadge()
}
+function exportUnsignedTxs(remote){
+ console.log('exporting txs!', unsignedTxs)
+ var data = {
+ type: 'importUnsignedTxs',
+ payload: getValues(unsignedTxs),
+ }
+ remote.postMessage(data)
+}
+
function updateBadge(){
var label = ''
- var count = Object.keys(unconfirmedTxs).length
+ var count = Object.keys(unsignedTxs).length
if (count) {
label = String(count)
}
@@ -100,4 +116,12 @@ function serializeTx(tx){
function deserializeTx(tx){
return JSON.parse(tx)
+}
+
+function getValues(obj){
+ var output = []
+ for (var key in obj) {
+ output.push(obj[key])
+ }
+ return output
} \ No newline at end of file
diff --git a/app/scripts/contentscript.js b/app/scripts/contentscript.js
index 0493921f0..7a180d9a9 100644
--- a/app/scripts/contentscript.js
+++ b/app/scripts/contentscript.js
@@ -1,5 +1,5 @@
const allowedMessageTarget = 'metamask'
-const allowedMessageType = 'addUnconfirmedTx'
+const allowedMessageType = 'addUnsignedTx'
// inject in-page script
diff --git a/app/scripts/inpage.js b/app/scripts/inpage.js
index 1d264975e..42f2de08a 100644
--- a/app/scripts/inpage.js
+++ b/app/scripts/inpage.js
@@ -4,7 +4,7 @@ const MetamaskProvider = require('./lib/metamask-provider.js')
const rpcUrl = 'https://rpc.metamask.io'
const documentOrigin = window.location.origin
const allowedMessageTarget = 'metamask'
-const allowedMessageType = 'addUnconfirmedTx'
+const allowedMessageType = 'addUnsignedTx'
var provider = new MetamaskProvider(forwardPayload, rpcUrl)