From: Zhiting Lin Date: Wed, 26 Feb 2020 02:18:57 +0000 (+0800) Subject: add the sign transaction pop up and function. X-Git-Tag: 2.2.0~2 X-Git-Url: http://git.osdn.net/view?p=bytom%2FByone.git;a=commitdiff_plain;h=91ee91deae876f18694272541dcfdc0249ae9a4d;hp=a6eda9b675d0b5eb221a65f928bfd130f773173f add the sign transaction pop up and function. --- diff --git a/src/background.js b/src/background.js index 00a71af..6461fbb 100644 --- a/src/background.js +++ b/src/background.js @@ -36,6 +36,9 @@ export default class Background { case MsgTypes.SEND: this.send(sendResponse, message.payload) break + case MsgTypes.SIGNTRANSACTION: + this.signTransaction(sendResponse, message.payload) + break case MsgTypes.SIGNMESSAGE: this.signMessage(sendResponse, message.payload) break @@ -174,6 +177,13 @@ export default class Background { } + signTransaction(sendResponse, payload) { + NotificationService.open(new Prompt(PromptTypes.REQUEST_SIGN_TRANSACTION, '', payload ,approved => { + sendResponse(approved); + })); + + } + requestCurrentAccount(sendResponse, payload){ Background.load(bytom => { const domain = payload.domain; diff --git a/src/content.js b/src/content.js index 888c3c4..e70a4f3 100644 --- a/src/content.js +++ b/src/content.js @@ -100,6 +100,7 @@ class Content { this.sync(msg) break case MsgTypes.TRANSFER: + case MsgTypes.SIGNTRANSACTION: case MsgTypes.ADVTRANSFER: case MsgTypes.SIGNMESSAGE: case MsgTypes.SEND: diff --git a/src/dapp.js b/src/dapp.js index dcc13d1..f99d089 100644 --- a/src/dapp.js +++ b/src/dapp.js @@ -79,6 +79,10 @@ export default class Bytomdapp { return _send(MsgTypes.TRANSFER, params) } + sign_transaction(params) { + return _send(MsgTypes.SIGNTRANSACTION, params) + } + send_advanced_transaction(params) { return _send(MsgTypes.ADVTRANSFER, params) } diff --git a/src/messages/types.js b/src/messages/types.js index d2825c2..6523048 100644 --- a/src/messages/types.js +++ b/src/messages/types.js @@ -6,6 +6,7 @@ export const AUTHENTICATE = 'authenticate' export const TRANSFER = 'transfer' export const ENABLE = 'enable' export const ADVTRANSFER = 'advTransfer' +export const SIGNTRANSACTION = 'signTransaction' export const SIGNMESSAGE = 'signMessage' export const SEND = 'send' export const LOAD = 'load'; diff --git a/src/models/transaction.js b/src/models/transaction.js index 35bc544..7eef434 100644 --- a/src/models/transaction.js +++ b/src/models/transaction.js @@ -100,6 +100,20 @@ transaction.buildTransaction = function(guid, inputs, outputs, gas, confirmation return retPromise; }; +transaction.signTransaction = function(guid, transaction, password) { + let retPromise = new Promise((resolve, reject) => { + bytom.transaction + .signTransaction(guid, JSON.stringify(transaction), password) + .then(res => { + resolve(res); + }) + .catch(error => { + reject(error); + }); + }); + return retPromise; +}; + transaction.transfer = function(guid, transaction, password) { let retPromise = new Promise((resolve, reject) => { bytom.transaction diff --git a/src/prompts/PromptTypes.js b/src/prompts/PromptTypes.js index b865426..d55de7f 100644 --- a/src/prompts/PromptTypes.js +++ b/src/prompts/PromptTypes.js @@ -1,5 +1,6 @@ export const REQUEST_AUTH = 'enable'; export const REQUEST_SIGN = 'signMessage'; +export const REQUEST_SIGN_TRANSACTION = 'signTransaction'; export const REQUEST_ADVANCED_TRANSFER = 'advancedTransfer'; export const REQUEST_TRANSFER = 'transfer'; export const REQUEST_ADD_NETWORK = 'requestAddNetwork'; diff --git a/src/router.js b/src/router.js index 51506bd..4339f6c 100644 --- a/src/router.js +++ b/src/router.js @@ -114,6 +114,14 @@ const routers = [ } }, { + path: '/signTransaction', + name: 'sign-transaction', + meta: { title: '签名交易' }, + component: resolve => { + require(['@/views/sendTransaction/signTransaction.vue'], resolve) + } + }, + { path: '/enable', name: 'enable', meta: { title: '授权' }, diff --git a/src/utils/Number.js b/src/utils/Number.js index 7c5fa5e..301e60f 100644 --- a/src/utils/Number.js +++ b/src/utils/Number.js @@ -49,13 +49,13 @@ export class Number { let n = new BigNumber(num); switch(type){ case "in_cny": - return `¥ ${n.toFormat()}` + return `¥ ${n.toFormat(2)}` case "in_usd": return `$ ${n.toFormat()}` case "in_btc": return `₿ ${n.toFormat()}` default: - return `¥ ${n.toFormat()}` + return `¥ ${n.toFormat(2)}` } } diff --git a/src/views/sendTransaction/signTransaction.vue b/src/views/sendTransaction/signTransaction.vue new file mode 100644 index 0000000..b11639f --- /dev/null +++ b/src/views/sendTransaction/signTransaction.vue @@ -0,0 +1,274 @@ + + + + +