• R/O
  • HTTP
  • SSH
  • HTTPS

Byone: Commit

Bytom Wallet for Chrome


Commit MetaInfo

Révision91ee91deae876f18694272541dcfdc0249ae9a4d (tree)
l'heure2020-02-26 11:18:57
AuteurZhiting Lin <zlin035@uott...>
CommiterZhiting Lin

Message de Log

add the sign transaction pop up and function.

Change Summary

Modification

--- a/src/background.js
+++ b/src/background.js
@@ -36,6 +36,9 @@ export default class Background {
3636 case MsgTypes.SEND:
3737 this.send(sendResponse, message.payload)
3838 break
39+ case MsgTypes.SIGNTRANSACTION:
40+ this.signTransaction(sendResponse, message.payload)
41+ break
3942 case MsgTypes.SIGNMESSAGE:
4043 this.signMessage(sendResponse, message.payload)
4144 break
@@ -174,6 +177,13 @@ export default class Background {
174177
175178 }
176179
180+ signTransaction(sendResponse, payload) {
181+ NotificationService.open(new Prompt(PromptTypes.REQUEST_SIGN_TRANSACTION, '', payload ,approved => {
182+ sendResponse(approved);
183+ }));
184+
185+ }
186+
177187 requestCurrentAccount(sendResponse, payload){
178188 Background.load(bytom => {
179189 const domain = payload.domain;
--- a/src/content.js
+++ b/src/content.js
@@ -100,6 +100,7 @@ class Content {
100100 this.sync(msg)
101101 break
102102 case MsgTypes.TRANSFER:
103+ case MsgTypes.SIGNTRANSACTION:
103104 case MsgTypes.ADVTRANSFER:
104105 case MsgTypes.SIGNMESSAGE:
105106 case MsgTypes.SEND:
--- a/src/dapp.js
+++ b/src/dapp.js
@@ -79,6 +79,10 @@ export default class Bytomdapp {
7979 return _send(MsgTypes.TRANSFER, params)
8080 }
8181
82+ sign_transaction(params) {
83+ return _send(MsgTypes.SIGNTRANSACTION, params)
84+ }
85+
8286 send_advanced_transaction(params) {
8387 return _send(MsgTypes.ADVTRANSFER, params)
8488 }
--- a/src/messages/types.js
+++ b/src/messages/types.js
@@ -6,6 +6,7 @@ export const AUTHENTICATE = 'authenticate'
66 export const TRANSFER = 'transfer'
77 export const ENABLE = 'enable'
88 export const ADVTRANSFER = 'advTransfer'
9+export const SIGNTRANSACTION = 'signTransaction'
910 export const SIGNMESSAGE = 'signMessage'
1011 export const SEND = 'send'
1112 export const LOAD = 'load';
--- a/src/models/transaction.js
+++ b/src/models/transaction.js
@@ -100,6 +100,20 @@ transaction.buildTransaction = function(guid, inputs, outputs, gas, confirmation
100100 return retPromise;
101101 };
102102
103+transaction.signTransaction = function(guid, transaction, password) {
104+ let retPromise = new Promise((resolve, reject) => {
105+ bytom.transaction
106+ .signTransaction(guid, JSON.stringify(transaction), password)
107+ .then(res => {
108+ resolve(res);
109+ })
110+ .catch(error => {
111+ reject(error);
112+ });
113+ });
114+ return retPromise;
115+};
116+
103117 transaction.transfer = function(guid, transaction, password) {
104118 let retPromise = new Promise((resolve, reject) => {
105119 bytom.transaction
--- a/src/prompts/PromptTypes.js
+++ b/src/prompts/PromptTypes.js
@@ -1,5 +1,6 @@
11 export const REQUEST_AUTH = 'enable';
22 export const REQUEST_SIGN = 'signMessage';
3+export const REQUEST_SIGN_TRANSACTION = 'signTransaction';
34 export const REQUEST_ADVANCED_TRANSFER = 'advancedTransfer';
45 export const REQUEST_TRANSFER = 'transfer';
56 export const REQUEST_ADD_NETWORK = 'requestAddNetwork';
--- a/src/router.js
+++ b/src/router.js
@@ -114,6 +114,14 @@ const routers = [
114114 }
115115 },
116116 {
117+ path: '/signTransaction',
118+ name: 'sign-transaction',
119+ meta: { title: '签名交易' },
120+ component: resolve => {
121+ require(['@/views/sendTransaction/signTransaction.vue'], resolve)
122+ }
123+ },
124+ {
117125 path: '/enable',
118126 name: 'enable',
119127 meta: { title: '授权' },
--- a/src/utils/Number.js
+++ b/src/utils/Number.js
@@ -49,13 +49,13 @@ export class Number {
4949 let n = new BigNumber(num);
5050 switch(type){
5151 case "in_cny":
52- return `¥ ${n.toFormat()}`
52+ return `¥ ${n.toFormat(2)}`
5353 case "in_usd":
5454 return `$ ${n.toFormat()}`
5555 case "in_btc":
5656 return `₿ ${n.toFormat()}`
5757 default:
58- return `¥ ${n.toFormat()}`
58+ return `¥ ${n.toFormat(2)}`
5959 }
6060 }
6161
--- /dev/null
+++ b/src/views/sendTransaction/signTransaction.vue
@@ -0,0 +1,274 @@
1+<style lang="" scoped>
2+ .warp {
3+ position: absolute;
4+ top: 0;
5+ left: 0;
6+ right: 0;
7+ height: 600px;
8+ z-index: 2;
9+ overflow: scroll;
10+ }
11+ .header {
12+ display: flex;
13+ }
14+ .header p{
15+ text-align: center;
16+ width: 280px;
17+ padding-top: 17px;
18+ }
19+
20+ .content {
21+ margin: 20px;
22+ padding: 20px;
23+ overflow: hidden;
24+ border-radius:4px;
25+ width: 280px;
26+ }
27+ .divider {
28+ margin: 12px 0;
29+ }
30+
31+ .value .uint {
32+ font-size: 12px;
33+ margin-left: 3px;
34+ }
35+ .btn-inline .btn {
36+ margin: 10px 15px;
37+ }
38+ .row{
39+ word-break: break-all;
40+ }
41+ .col{
42+ font-size: 14px;
43+ width: 35%;
44+ }
45+ .label{
46+ color: #7B7B7B;
47+ }
48+ .value{
49+ color: #282828;
50+ width: 60%;
51+ }
52+ table{
53+ width: 100%;
54+ }
55+ .form-item{
56+ padding:0;
57+ margin:0;
58+ margin-bottom: 10px;
59+ }
60+ .hide{
61+ width: 175px;
62+ overflow: hidden;
63+ text-overflow: ellipsis;
64+ white-space: nowrap;
65+ }
66+ .view-link{
67+ font-size: 14px;
68+ color: #035BD4;
69+ width: 275px;
70+ display: block;
71+ }
72+</style>
73+
74+<template>
75+ <div class="warp bg-gray">
76+ <section class="header bg-header">
77+ <i class="iconfont icon-back" @click="close"></i>
78+ <p>{{ $t('transfer.confirmTransaction') }}</p>
79+ </section>
80+
81+ <section class="content bg-white">
82+ <table>
83+ <tbody>
84+ <tr class="row">
85+ <td class="col label">{{ $t('transfer.from') }}</td>
86+ <td class="col value">{{currentAccount.alias}}</td>
87+ </tr>
88+ <div class="divider"></div>
89+ <tr class="row">
90+ <td class="col label">Input</td>
91+ <td class="col value" v-bind:class="{ hide: !full }" >{{transaction.input}}</td>
92+ </tr>
93+ <tr class="row">
94+ <td class="col label">Output</td>
95+ <td class="col value" v-bind:class="{ hide: !full }" >{{transaction.output}}</td>
96+ </tr>
97+ <tr v-if="transaction.args" class="row">
98+ <td class="col label">Args</td>
99+ <td class="col value" v-bind:class="{ hide: !full }" >{{transaction.args}}</td>
100+ </tr>
101+ <tr class="row">
102+ <td colspan="2" class="center-text">
103+ <a v-on:click="full = !full" class="view-link">
104+ {{ full? $t('transfer.hideAll'): $t('transfer.viewAll') }} >>
105+ </a>
106+ </td>
107+ </tr>
108+
109+ <div class="divider"></div>
110+
111+ <tr v-for="(amountInput, index) in transaction.amounts" :key="index" class="row">
112+ <td class="col label">{{index ==0 && $t('transfer.transferAmount') }}</td>
113+ <td class="col value">{{amountInput.amount}}<span class="uint uppercase">{{amountInput.alias || amountInput.asset}}</span></td>
114+ </tr>
115+
116+ <tr class="row">
117+ <td class="col label">{{ $t('transfer.fee') }}</td>
118+ <td class="col value">{{transaction.fee}}<span class="uint">BTM</span></td>
119+ </tr>
120+
121+ </tbody>
122+ </table>
123+ </section>
124+ <section class="content bg-white">
125+ <div class="form">
126+ <div class="form-item">
127+ <label class="form-item-label">{{ $t('transfer.confirmPassword') }}</label>
128+ <div class="form-item-content">
129+ <input type="password" v-model="password" autofocus>
130+ </div>
131+ </div>
132+ </div>
133+ </section>
134+
135+ <div class="row" style="margin: 20px;">
136+ <div class="btn bg-green" @click="transfer">{{ $t('transfer.confirm') }}</div>
137+ </div>
138+
139+ </div>
140+</template>
141+
142+<script>
143+import transaction from "@/models/transaction";
144+import getLang from "@/assets/language/sdk";
145+import { LocalStream } from 'extension-streams';
146+import {apis} from '@/utils/BrowserApis';
147+import NotificationService from '../../services/NotificationService'
148+import { mapActions, mapGetters, mapState } from 'vuex'
149+import _ from 'lodash';
150+import account from "@/models/account";
151+import { Number as Num } from "@/utils/Number"
152+
153+
154+
155+export default {
156+ data() {
157+ return {
158+ full: false,
159+ transaction: {
160+ input: "",
161+ output: "",
162+ args: "",
163+ fee: "",
164+ confirmations:1,
165+ amounts: []
166+ },
167+ password:'',
168+ prompt:''
169+ };
170+ },
171+ computed: {
172+ ...mapGetters([
173+ 'currentAccount',
174+ 'net',
175+ 'netType',
176+ ])
177+ },
178+ watch: {
179+ },
180+ methods: {
181+ close: function () {
182+ NotificationService.close();
183+ },
184+ transfer: function () {
185+ let loader = this.$loading.show({
186+ // Optional parameters
187+ container: null,
188+ canCancel: true,
189+ onCancel: this.onCancel
190+ });
191+
192+ if(Array.isArray(this.prompt.data)){
193+ Promise.all(this.prompt.data.map( (rawdata) => transaction.signTransaction(this.currentAccount.guid, rawdata, this.password)))
194+ .then( (result) => {
195+ loader.hide();
196+ this.prompt.responder(result);
197+ this.$dialog.show({
198+ type: 'success',
199+ body: this.$t("transfer.success")
200+ });
201+ NotificationService.close();
202+ }).catch(error => {
203+ loader.hide();
204+
205+ this.$dialog.show({
206+ body: getLang(error.message)
207+ });
208+ });
209+ }else{
210+ transaction.signTransaction(this.currentAccount.guid, this.prompt.data, this.password).then( (result) => {
211+ loader.hide();
212+ this.prompt.responder(result);
213+ this.$dialog.show({
214+ type: 'success',
215+ body: this.$t("transfer.success")
216+ });
217+ NotificationService.close();
218+ }).catch(error => {
219+ loader.hide();
220+
221+ this.$dialog.show({
222+ body: getLang(error.message)
223+ });
224+ });
225+ }
226+
227+ },
228+ queryAsset: function(assetID){
229+ return transaction.asset(assetID)
230+ }
231+ }, mounted() {
232+ this.prompt = window.data || apis.extension.getBackgroundPage().notification || null;
233+
234+ if(this.prompt.data !== undefined){
235+ const param = Array.isArray(this.prompt.data)? this.prompt.data[0].tx : this.prompt.data.tx
236+ if(param.inputs !== undefined){
237+ this.transaction.input = param.inputs
238+ }
239+ if(param.outputs !== undefined){
240+ this.transaction.output = param.outputs
241+ }
242+ if(param.fee !== undefined){
243+ this.transaction.fee = param.fee/100000000
244+ }
245+
246+ const array = param.inputs.filter(action => action.type ==='spend')
247+
248+ if(array.length>0){
249+ account.setupNet(`${this.net}${this.netType}`)
250+ const promise =
251+ _(array)
252+ .groupBy('asset')
253+ .map((objs, key) => {
254+ return this.queryAsset(key).then(resp =>{
255+ return {
256+ 'asset': key,
257+ 'alias':resp.alias,
258+ 'amount':Num.formatNue( _.sumBy(objs, 'amount'), resp.decimals)
259+ }
260+ })
261+ })
262+
263+ let that = this;
264+ Promise.all(promise).then(function(output) {
265+ that.transaction.amounts = output
266+ })
267+
268+ }
269+
270+
271+ }
272+ }
273+};
274+</script>
Afficher sur ancien navigateur de dépôt.