From: Zhiting Lin Date: Tue, 26 Mar 2019 07:00:29 +0000 (+0800) Subject: update the bytom.transfer X-Git-Tag: v1.0.0.1~13 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=fdf0fdf23052923e646b349b22be87986fba9f99;p=bytom%2FByone.git update the bytom.transfer --- diff --git a/dapp-example/index.html b/dapp-example/index.html index 8176cab..e2d55e4 100644 --- a/dapp-example/index.html +++ b/dapp-example/index.html @@ -15,7 +15,11 @@ var bytom getById('transferButton').addEventListener('click', () => { - bytom.transfer(getById('to').value, getById('amount').value) + bytom.transfer(getById('to').value, getById('amount').value).then( + resp =>{ + console.log(resp) + } + ) }) // 监听Bytom插件加载成功事件 diff --git a/src/background.js b/src/background.js index 1a84392..cd924e4 100644 --- a/src/background.js +++ b/src/background.js @@ -48,7 +48,9 @@ export default class Background { transfer(sendResponse, payload) { var promptURL = chrome.extension.getURL('pages/prompt.html') - var queryString = new URLSearchParams(payload).toString() + var requestBody = payload + requestBody.type = "popup" + var queryString = new URLSearchParams(requestBody).toString() console.log(promptURL, queryString) chrome.windows.create( { @@ -59,8 +61,17 @@ export default class Background { top: 0, left: 0 }, - () => { - sendResponse(true) + (window) => { + chrome.runtime.onMessage.addListener(function(request, sender) { + if(sender.tab.windowId === window.id){ + switch (request.method){ + case 'transfer': + sendResponse(request); + break + } + } + }); + console.log(window) } ) } diff --git a/src/views/sendTransaction/transfer.vue b/src/views/sendTransaction/transfer.vue index bb1be2f..09f04fe 100644 --- a/src/views/sendTransaction/transfer.vue +++ b/src/views/sendTransaction/transfer.vue @@ -119,6 +119,8 @@ import account from "@/models/account"; import transaction from "@/models/transaction"; import getLang from "@/assets/language/sdk"; import Confirm from "./transferConfirm"; +import { LocalStream } from 'extension-streams'; + export default { components: { Confirm @@ -193,6 +195,10 @@ export default { this.$router.go(-1) this.transaction.to = ""; this.transaction.amount = ""; + if(this.$route.query.type == 'popup'){ + LocalStream.send({method:'transfer',action:'reject'}); + window.close(); + } }, send: function () { if (this.transaction.to == "") { @@ -218,7 +224,7 @@ export default { transaction.build(this.account.guid, this.transaction.to, this.transaction.asset, this.transaction.amount, this.transaction.fee).then(ret => { loader.hide(); this.transaction.fee = Number(ret.result.data.fee / 100000000); - this.$router.push({ name: 'transfer-confirm', params: { account: this.account, transaction: this.transaction, rawData: ret.result.data } }) + this.$router.push({ name: 'transfer-confirm', params: { account: this.account, transaction: this.transaction, rawData: ret.result.data, type: this.$route.query.type } }) }).catch(error => { loader.hide(); this.$dialog.show({ diff --git a/src/views/sendTransaction/transferConfirm.vue b/src/views/sendTransaction/transferConfirm.vue index 53d61c9..4a4f1fb 100644 --- a/src/views/sendTransaction/transferConfirm.vue +++ b/src/views/sendTransaction/transferConfirm.vue @@ -154,10 +154,10 @@