From 23a144fb8b0b214b9c352ee523405d5ecd03046e Mon Sep 17 00:00:00 2001 From: kumavis Date: Fri, 26 Aug 2016 11:08:23 -0700 Subject: library - popup handler demo --- library/example/index.js | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 library/example/index.js (limited to 'library/example/index.js') diff --git a/library/example/index.js b/library/example/index.js new file mode 100644 index 000000000..d24c26f87 --- /dev/null +++ b/library/example/index.js @@ -0,0 +1,42 @@ + +window.addEventListener('load', web3Detect) + +function web3Detect() { + if (global.web3) { + document.body.innerHTML += 'web3 detected!' + } else { + document.body.innerHTML += 'no web3 detected!' + } + startApp() +} + +var primaryAccount = null +web3.eth.getAccounts(function(err, addresses){ + if (err) throw err + primaryAccount = addresses[0] +}) + + +function startApp(){ + document.querySelector('.action-button-1').addEventListener('click', function(){ + web3.eth.sendTransaction({ + from: primaryAccount, + value: 0, + }, function(err, txHash){ + if (err) throw err + console.log('sendTransaction result:', err || txHash) + }) + }) + document.querySelector('.action-button-2').addEventListener('click', function(){ + setTimeout(function(){ + web3.eth.sendTransaction({ + from: primaryAccount, + value: 0, + }, function(err, txHash){ + if (err) throw err + console.log('sendTransaction result:', err || txHash) + }) + }) + }) + +} -- cgit v1.2.3 From b7aab955196a7cef2705e8546814b5c6c1830da7 Mon Sep 17 00:00:00 2001 From: kumavis Date: Fri, 26 Aug 2016 17:39:19 -0700 Subject: library - basic test server + partial safari fixes --- library/example/index.js | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'library/example/index.js') diff --git a/library/example/index.js b/library/example/index.js index d24c26f87..bdde2b47f 100644 --- a/library/example/index.js +++ b/library/example/index.js @@ -4,8 +4,10 @@ window.addEventListener('load', web3Detect) function web3Detect() { if (global.web3) { document.body.innerHTML += 'web3 detected!' + console.log('web3 detected!') } else { document.body.innerHTML += 'no web3 detected!' + console.log('no web3 detected!') } startApp() } @@ -13,12 +15,17 @@ function web3Detect() { var primaryAccount = null web3.eth.getAccounts(function(err, addresses){ if (err) throw err + console.log('set address') primaryAccount = addresses[0] }) function startApp(){ + console.log('app started') + document.querySelector('.action-button-1').addEventListener('click', function(){ + console.log('saw click') + console.log('sending tx') web3.eth.sendTransaction({ from: primaryAccount, value: 0, @@ -28,7 +35,9 @@ function startApp(){ }) }) document.querySelector('.action-button-2').addEventListener('click', function(){ + console.log('saw click') setTimeout(function(){ + console.log('sending tx') web3.eth.sendTransaction({ from: primaryAccount, value: 0, -- cgit v1.2.3 From a3330568d9aa68e2609ce875a96e784c2e77c20c Mon Sep 17 00:00:00 2001 From: kumavis Date: Wed, 31 Aug 2016 15:33:24 -0700 Subject: various things --- library/example/index.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'library/example/index.js') diff --git a/library/example/index.js b/library/example/index.js index bdde2b47f..91d2237c2 100644 --- a/library/example/index.js +++ b/library/example/index.js @@ -5,24 +5,24 @@ function web3Detect() { if (global.web3) { document.body.innerHTML += 'web3 detected!' console.log('web3 detected!') + startApp() } else { document.body.innerHTML += 'no web3 detected!' console.log('no web3 detected!') } - startApp() } -var primaryAccount = null -web3.eth.getAccounts(function(err, addresses){ - if (err) throw err - console.log('set address') - primaryAccount = addresses[0] -}) - - function startApp(){ console.log('app started') + var primaryAccount = null + console.log('getting main account...') + web3.eth.getAccounts(function(err, addresses){ + if (err) throw err + console.log('set address') + primaryAccount = addresses[0] + }) + document.querySelector('.action-button-1').addEventListener('click', function(){ console.log('saw click') console.log('sending tx') -- cgit v1.2.3 From 4cfcb4452a3278cfa775e247271053e82f238fb5 Mon Sep 17 00:00:00 2001 From: kumavis Date: Mon, 12 Sep 2016 18:30:45 -0700 Subject: bugfix - prevent iframe restart restart --- library/example/index.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'library/example/index.js') diff --git a/library/example/index.js b/library/example/index.js index 91d2237c2..a3f4b9859 100644 --- a/library/example/index.js +++ b/library/example/index.js @@ -3,12 +3,10 @@ window.addEventListener('load', web3Detect) function web3Detect() { if (global.web3) { - document.body.innerHTML += 'web3 detected!' - console.log('web3 detected!') + logToDom('web3 detected!') startApp() } else { - document.body.innerHTML += 'no web3 detected!' - console.log('no web3 detected!') + logToDom('no web3 detected!') } } @@ -49,3 +47,8 @@ function startApp(){ }) } + +function logToDom(message){ + document.body.appendChild(document.createTextNode(message)) + console.log(message) +} \ No newline at end of file -- cgit v1.2.3