From 59d9a80756ae48ab634e811a916f63fc03bf69ff Mon Sep 17 00:00:00 2001 From: Zhiting Lin Date: Wed, 23 Jan 2019 10:23:23 +0800 Subject: [PATCH] add the Advanced build transaction's function --- src/background.js | 22 +++++ src/content.js | 7 +- src/dapp.js | 7 ++ src/messages/types.js | 1 + src/models/transaction.js | 38 +++++++++ src/router.js | 8 ++ src/views/advancedTransfer.vue | 177 +++++++++++++++++++++++++++++++++++++++++ 7 files changed, 257 insertions(+), 3 deletions(-) create mode 100644 src/views/advancedTransfer.vue diff --git a/src/background.js b/src/background.js index 4e844c8..9f99837 100644 --- a/src/background.js +++ b/src/background.js @@ -21,6 +21,9 @@ export default class Background { case MsgTypes.TRANSFER: this.transfer(sendResponse, message.payload) break + case MsgTypes.ADVTRANSFER: + this.advancedTransfer(sendResponse, message.payload) + break } } @@ -42,6 +45,25 @@ export default class Background { } ) } + + advancedTransfer(sendResponse, payload) { + var promptURL = chrome.extension.getURL('pages/prompt.html') + var queryString = 'object='+JSON.stringify(payload) + console.log(promptURL, queryString) + chrome.windows.create( + { + url: `${promptURL}#advancedTransfer?${queryString}`, + type: 'popup', + width: 350, + height: 623, + top: 0, + left: 0 + }, + () => { + sendResponse(true) + } + ) + } } new Background() diff --git a/src/content.js b/src/content.js index a78875d..b2b5634 100644 --- a/src/content.js +++ b/src/content.js @@ -58,7 +58,8 @@ class Content { this.sync(msg) break case MsgTypes.TRANSFER: - this.transfer(networkMessage) + case MsgTypes.ADVTRANSFER: + this.transfer(msg.type, networkMessage) break default: stream.send(networkMessage.error('errtest'), EventNames.INJECT) @@ -85,10 +86,10 @@ class Content { stream.synced = true } - transfer(message) { + transfer(type, message) { if (!isReady) return - InternalMessage.payload(MsgTypes.TRANSFER, message.payload) + InternalMessage.payload(type, message.payload) .send() .then(res => this.respond(message, res)) } diff --git a/src/dapp.js b/src/dapp.js index 6c01db9..c096e1e 100644 --- a/src/dapp.js +++ b/src/dapp.js @@ -72,4 +72,11 @@ export default class Bytomdapp { amount: amount }) } + + advancedTransfer(input, output) { + return _send(MsgTypes.ADVTRANSFER, { + input, + output + }) + } } diff --git a/src/messages/types.js b/src/messages/types.js index 3405e62..afa22c9 100644 --- a/src/messages/types.js +++ b/src/messages/types.js @@ -3,3 +3,4 @@ export const ERROR = 'error' export const PUSH_BYTOM = 'pushBytom' export const AUTHENTICATE = 'authenticate' export const TRANSFER = 'transfer' +export const ADVTRANSFER = 'advTransfer' diff --git a/src/models/transaction.js b/src/models/transaction.js index 39490df..e507de7 100644 --- a/src/models/transaction.js +++ b/src/models/transaction.js @@ -28,6 +28,20 @@ transaction.build = function(guid, to, asset, amount, fee) { return retPromise; }; +transaction.buildTransaction = function(guid, inputs, outputs) { + let retPromise = new Promise((resolve, reject) => { + bytom.transaction + .buildTransaction(guid, inputs, outputs) + .then(res => { + resolve(res); + }) + .catch(error => { + reject(error); + }); + }); + return retPromise; +}; + transaction.transfer = function(guid, transaction, password) { let retPromise = new Promise((resolve, reject) => { bytom.transaction @@ -50,4 +64,28 @@ transaction.transfer = function(guid, transaction, password) { return retPromise; }; +transaction.advancedTransfer = function(guid, transaction, password, arrayData) { + let retPromise = new Promise((resolve, reject) => { + bytom.transaction + .signTransaction(guid, JSON.stringify(transaction), password) + .then(ret => { + let signatures = ret.signatures + signatures[0] = arrayData + bytom.transaction + .submitPayment(guid, ret.raw_transaction, signatures) + .then(res3 => { + resolve(res3); + }) + .catch(error => { + reject(error); + }); + }) + .catch(error => { + reject(error); + }); + }); + + return retPromise; +}; + export default transaction; diff --git a/src/router.js b/src/router.js index 8b7b711..d1c53b1 100644 --- a/src/router.js +++ b/src/router.js @@ -18,6 +18,14 @@ const routers = [ } }, { + path: '/advancedTransfer', + name: 'advanced-transfer', + meta: { title: '高级转账' }, + component: resolve => { + require(['@/views/advancedTransfer.vue'], resolve) + } + }, + { path: '/transfer/info', name: 'transfer-info', meta: { title: '交易详情' }, diff --git a/src/views/advancedTransfer.vue b/src/views/advancedTransfer.vue new file mode 100644 index 0000000..a94545a --- /dev/null +++ b/src/views/advancedTransfer.vue @@ -0,0 +1,177 @@ + + + + + -- 2.11.0