aboutsummaryrefslogtreecommitdiffstats
path: root/mascara
diff options
context:
space:
mode:
authorfrankiebee <frankie.diamond@gmail.com>2017-10-05 13:09:37 +0800
committerfrankiebee <frankie.diamond@gmail.com>2017-10-05 13:09:37 +0800
commite7589a099fa592b930458a16d7346ff20070a6e8 (patch)
treeff31066a573114e2aca824f74e5a504caa466334 /mascara
parenta142f8913d6807966737572ad43fdcbbdbb5d79e (diff)
downloadtangerine-wallet-browser-e7589a099fa592b930458a16d7346ff20070a6e8.tar
tangerine-wallet-browser-e7589a099fa592b930458a16d7346ff20070a6e8.tar.gz
tangerine-wallet-browser-e7589a099fa592b930458a16d7346ff20070a6e8.tar.bz2
tangerine-wallet-browser-e7589a099fa592b930458a16d7346ff20070a6e8.tar.lz
tangerine-wallet-browser-e7589a099fa592b930458a16d7346ff20070a6e8.tar.xz
tangerine-wallet-browser-e7589a099fa592b930458a16d7346ff20070a6e8.tar.zst
tangerine-wallet-browser-e7589a099fa592b930458a16d7346ff20070a6e8.zip
mascara:exampl/app - add a send tx button
Diffstat (limited to 'mascara')
-rw-r--r--mascara/example/app.js28
-rw-r--r--mascara/example/app/index.html2
2 files changed, 22 insertions, 8 deletions
diff --git a/mascara/example/app.js b/mascara/example/app.js
index d0cb6ba83..598e2c84c 100644
--- a/mascara/example/app.js
+++ b/mascara/example/app.js
@@ -7,20 +7,32 @@ async function loadProvider() {
const ethereumProvider = window.metamask.createDefaultProvider({ host: 'http://localhost:9001' })
const ethQuery = new EthQuery(ethereumProvider)
const accounts = await ethQuery.accounts()
- logToDom(accounts.length ? accounts[0] : 'LOCKED or undefined')
- setupButton(ethQuery)
+ window.METAMASK_ACCOUNT = accounts[0] || 'locked'
+ logToDom(accounts.length ? accounts[0] : 'LOCKED or undefined', 'account')
+ setupButtons(ethQuery)
}
-function logToDom(message){
- document.getElementById('account').innerText = message
+function logToDom(message, context){
+ document.getElementById(context).innerText = message
console.log(message)
}
-function setupButton (ethQuery) {
- const button = document.getElementById('action-button-1')
- button.addEventListener('click', async () => {
+function setupButtons (ethQuery) {
+ const accountButton = document.getElementById('action-button-1')
+ accountButton.addEventListener('click', async () => {
const accounts = await ethQuery.accounts()
- logToDom(accounts.length ? accounts[0] : 'LOCKED or undefined')
+ window.METAMASK_ACCOUNT = accounts[0] || 'locked'
+ logToDom(accounts.length ? accounts[0] : 'LOCKED or undefined', 'account')
+ })
+ const txButton = document.getElementById('action-button-2')
+ txButton.addEventListener('click', async () => {
+ if (!window.METAMASK_ACCOUNT || window.METAMASK_ACCOUNT === 'locked') return
+ const txHash = await ethQuery.sendTransaction({
+ from: window.METAMASK_ACCOUNT,
+ to: window.METAMASK_ACCOUNT,
+ data: '',
+ })
+ logToDom(txHash, 'cb-value')
})
} \ No newline at end of file
diff --git a/mascara/example/app/index.html b/mascara/example/app/index.html
index f3e38877c..8afb6f3f2 100644
--- a/mascara/example/app/index.html
+++ b/mascara/example/app/index.html
@@ -10,6 +10,8 @@
<body>
<button id="action-button-1">GET ACCOUNT</button>
<div id="account"></div>
+ <button id="action-button-2">SEND TRANSACTION</button>
+ <div id="cb-value" ></div>
<script src="./app.js"></script>
</body>
</html> \ No newline at end of file