/
trade_out.html
152 lines (151 loc) · 4.96 KB
/
trade_out.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="initial-scale=1,maximum-scale=1, minimum-scale=1">
<link rel="stylesheet" href="css/mui.min.css">
<link rel="stylesheet" href="css/unified.css">
<link rel="stylesheet" href="css/walletCurr.css">
<script src="js/jquery-3.3.1.min.js" type="text/javascript" charset="utf-8"></script>
<script src="js/rem.js"></script>
<script src="js/mui.min.js" type="text/javascript" charset="utf-8"></script>
<script src="js/vue.min.js" type="text/javascript" charset="utf-8"></script>
<script src="js/public.js" type="text/javascript" charset="utf-8"></script>
<title>转账</title>
<style type="text/css">
.mui-input-range .mui-tooltip{
display: none;
}
</style>
</head>
<body>
<div class="setEalletWrapper" id="app">
<div class="unContent">
<div class="content">
<ul>
<li class="flex-box">
<span>收款地址</span>
<input class="box-1" type="text" v-model="address" placeholder="请输入收款人地址">
</li>
<li class="flex-box">
<span>转账金额</span>
<input class="box-1" type="number" v-model="num" placeholder="请输入转账金额">
</li>
<li class="flex-box">
<span>钱包密码</span>
<input class="box-1" type="password" v-model="pwd" placeholder="请输入钱包密码">
</li>
<li class="flex-box" style="justify-content: space-between;">
<span>交易费用</span>
<div class="mui-input-row mui-input-range">
<input type="range" :min='gas_min' v-model="gas_price" :max='gas_max' id='block-range'>
</div>
<div style="width: 2.2rem;">{{tx_fee}} BCS</div>
</li>
</ul>
<div class="swBtn" style="margin-top: 1rem;">
<a class="btn-ui sw-btn-1" @tap="soSub">确认转账</a>
</div>
</div>
</div>
</div>
<script src="wallet/web3.min.js" type="text/javascript" charset="utf-8"></script>
</body>
<script type="text/javascript">
var vm = new Vue({
el: '#app',
data: {
address:'',
num:'',
pwd:'',
gas_limit:60000,
gas_price:10,
gas_min:1,
gas_max:30
},
computed:{
tx_fee:function(){
return parseFloat((this.gas_limit*(this.gas_price)/1e9).toFixed(8))
}
},
methods: {
scanInit:function(res){
this.address = res
},
soSub:function(){
if(!this.address){
mui.toast('请输入收款地址');return;
}
if(!this.num){
mui.toast('请输入转账金额');return;
}
if(!this.pwd){
mui.toast('请输入钱包密码');return;
}
var _self = this;
var walletInfo = getItem('walletInfo');
plus.nativeUI.showWaiting();
try{
var web3 = initWeb3();
var account = web3.eth.accounts.decrypt(walletInfo.keystoreV3, _self.pwd);
var value = web3.utils.toWei(_self.num.toString(), 'ether');
web3.eth.accounts.wallet.add(account);
web3.eth.sendTransaction({
from: walletInfo.walletAddress,
to: _self.address,
value: value,
gasPrice: web3.utils.toWei(_self.gas_price.toString(),'gwei'),
gas: _self.gas_limit.toString()
}, function (error, txhash) {
plus.nativeUI.closeWaiting();
if(error){
mui.alert('转账失败'+error);
_self.address = '';
_self.num = '';
_self.pwd = '';
}else{
mui.alert('转账成功,请耐心等待',function(){
mui.openWindow({
url: 'trade_ing.html',
id: 'trade_ing',
styles: {
titleNView: {
autoBackButton:true
}
},
waiting:{
autoShow:false
},
extras:{
addressFrom:walletInfo.walletAddress,
addressTo:_self.address,
value:value,
gas:_self.gas_limit,
hash:txhash
}
});
_self.address = '';
_self.num = '';
_self.pwd = '';
setTimeout(function(){
plus.webview.currentWebview().close('none');
},1000);
});
}
});
}catch(err){
plus.nativeUI.closeWaiting();
mui.alert('转账失败,'+err);
}
},
getGasPrice:function(){
var _self = this;
var web3 = initWeb3();
web3.eth.getGasPrice(function(err,res){
_self.gas_price = res;
});
}
}
})
</script>
</html>