OSDN Git Service

update the bytom.transfer
authorZhiting Lin <zlin035@uottawa.ca>
Tue, 26 Mar 2019 07:00:29 +0000 (15:00 +0800)
committerZhiting Lin <zlin035@uottawa.ca>
Tue, 26 Mar 2019 07:00:29 +0000 (15:00 +0800)
dapp-example/index.html
src/background.js
src/views/sendTransaction/transfer.vue
src/views/sendTransaction/transferConfirm.vue

index 8176cab..e2d55e4 100644 (file)
 
       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插件加载成功事件
index 1a84392..cd924e4 100644 (file)
@@ -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)
       }
     )
   }
index bb1be2f..09f04fe 100644 (file)
@@ -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({
index 53d61c9..4a4f1fb 100644 (file)
 </template>
 
 <script>
-import address from "@/utils/address";
 import transaction from "@/models/transaction";
 import modalPasswd from "@/components/modal-passwd";
 import getLang from "@/assets/language/sdk";
+import { LocalStream } from 'extension-streams';
 export default {
     components: {
         modalPasswd
@@ -194,6 +194,9 @@ export default {
             transaction.transfer(this.account.guid, this.rawData, this.password)
                 .then(ret => {
                     loader.hide();
+                    if(this.$route.params.type == 'popup'){
+                      LocalStream.send({method:'transfer',action:'success', message:ret});
+                    }
                     this.$dialog.show({
                       type: 'success',
                       body: this.$t("transfer.success")