Dread 4 years ago
parent
commit
da69f438df
  1. 2
      main.js
  2. 5
      pages/menu/backUp/index.vue
  3. 1
      pages/menu/backUp/transPaw/index.vue
  4. 48
      pages/menu/wallet/index.vue
  5. 29
      utils/BtcUtil.js
  6. 4
      utils/SystemConfiguration.js
  7. 3
      utils/WalletUtil.js

2
main.js

@ -53,11 +53,13 @@ const i18n = new VueI18n({
import TokenUtil from './utils/TokenUtil.js'
import EthUtil from './utils/EthUtil.js'
import TronUtil from './utils/TronUtil.js'
import BtcUtil from './utils/BtcUtil.js'
import api from './utils/api.js'
import SystemConfiguration from './utils/SystemConfiguration.js'
Vue.prototype.$Token = TokenUtil
Vue.prototype.$EthUtil = EthUtil
Vue.prototype.$BtcUtil = BtcUtil
Vue.prototype.$TronUtil = TronUtil
Vue.prototype.$api = api
Vue.prototype.$SystemConfiguration = SystemConfiguration

5
pages/menu/backUp/index.vue

@ -103,10 +103,9 @@
}
},
onLoad(item){
console.log("item",item)
if(item!=''||item!=undefined){
var word=this.$Token.creatingWallets();
var word2=word.mnemonic
var word2=this.$Token.generateMnemonic();
// ,
uni.setStorage({
key: 'word',

1
pages/menu/backUp/transPaw/index.vue

@ -105,6 +105,7 @@
}
}else{
this.setWalletInfo();
uni.showToast({
title: this.$t('index').Setsuccessfully,

48
pages/menu/wallet/index.vue

@ -46,7 +46,7 @@
</image>
</view>
<!-- <view class="scroll"> -->
<scroll-view :scroll-y="true" style="max-height: 880rpx;" lower-threshold="50">
<scroll-view :scroll-y="true" style="max-height: 880rpx;" lower-threshold="50">
<view class="item flexx" @click="goTrans(item,index)" v-for="item,index in this.userObj.coinList">
<view class="left flex ">
<view class="img1">
@ -76,8 +76,8 @@
</view>
</view>
</view>
<!-- </view> -->
</scroll-view>
<!-- </view> -->
</scroll-view>
</view>
@ -104,27 +104,45 @@
showMoney1: true,
showMoney2: false,
btcBalance: 0,
isStop: false
isStop: false,
timer: null
}
},
onUnload: function() {
this.isStop = true
console.log("停止了")
uni.setStorageSync('isWallet', false);
if (this.timer) {
console.log("停止了")
clearInterval(this.timer);
this.timer = null;
}
},
onShow() {
this.timer = setInterval(() => {
this.updateBalance();
}, 5000)
},
onHide() {
if (this.timer) {
console.log("停止了")
clearInterval(this.timer);
this.timer = null;
}
},
onLoad() {
let currency = uni.getStorageSync('currency');
if (currency) {
this.currency = currency;
}
//
//console.log(this.$TronUtil.decode("TBk72yKTJWppCsa7XrsU7Qhfo4yNvbm8rE"))
this.userObj = uni.getStorageSync('wallet');
console.log('eth有走这吗')
this.updateBalance();
},
computed: {
@ -134,17 +152,17 @@
},
onPullDownRefresh() {
this.updateBalance();
setTimeout(function() {
uni.stopPullDownRefresh();
}, 500);
},
methods: {
async updateBalance(){
async updateBalance() {
this.userObj = await this.$walletUtil.updateBalance();
},
goOther() {
uni.navigateTo({
@ -179,12 +197,12 @@
var _this = this
uni.scanCode({
success: function(res) {
uni.setStorageSync('address',res.result)
uni.setStorageSync('address', res.result)
uni.navigateTo({
url: '/pages/menu/sendToken/transfer/index?item=index'
})
}
});
});
},
goCwallet() {

29
utils/BtcUtil.js

@ -1,3 +1,6 @@
import systemConfiguration from 'utils/SystemConfiguration.js'
const bitcoin = require('bitcoinjs-lib')
let BtcUtil = {
getBalance:async function(address,success) {
let balance=0;
@ -21,6 +24,32 @@ let BtcUtil = {
//TODO handle the exception
}
return balance;
},
sendTransaction:async function(fromAddress, toAddress, value, privateKey){
let bob = new bitcoin.ECPair.fromWIF(privateKey);
const txb = new bitcoin.TransactionBuilder(systemConfiguration.constant.btcNetwork);
txb.setVersion(1);
// 在这个交易中, bob在第0个位置,上图所示
txb.addInput("5799a647d6b89a9f73122d75faee6f5a0210bd3cb22c48a70d35eac33ce5d426", 0);
txb.addOutput(toAddress, 2000000);
console.log(txb,1111111111)
// 签名交易,0代表索引,输入排序,这里只有一个输入,所以是第0位。
txb.sign(0, bob);
// 序列化成一串字符
const tx = txb.build().toHex();
console.log(tx);
const result = await fetch('https://api.blockcypher.com/v1/btc/test3/txs/push',{
method:'post',
headers:{'Content-Type':'application/json'},
body:JSON.stringify({tx})
});
// 打印结果
console.log(result);
}
}
export default BtcUtil

4
utils/SystemConfiguration.js

@ -6,7 +6,7 @@ const constant = isTest ? {
coinTickerWs:'ws://wallet-quartz.weirui0755.com/websocket',
ethNode:'http://47.245.25.82:8545',
ethChainId:1,
btcNetwork:'',
btcNetwork:'https://api.blockcypher.com',
ethTransctionDetail:'https://cn.etherscan.com/tx/',
trxTransctionDetail:'https://tronscan.io/#/transaction/',
checkIp:'https://app.bilibili.com'
@ -16,7 +16,7 @@ const constant = isTest ? {
coinTickerWs:'wss://quartz.bitcooo.com/websocket',
ethNode:'http://47.245.25.82:8545',
ethChainId:1,
btcNetwork:'',
btcNetwork:'https://api.blockcypher.com',
ethTransctionDetail:'https://cn.etherscan.com/tx/',
trxTransctionDetail:'https://tronscan.io/#/transaction/'
}

3
utils/WalletUtil.js

@ -135,6 +135,9 @@ let WalletUtil = {
wallet.privateKey = walletdec.privateKey;
wallet.mnemonic = mnemonic;
wallet.address = walletdec.address;
wallet.ellipsisAddress = wallet.address.substring(0, 6) + '...' + wallet.address.substring(
wallet.address.length - 6,
wallet.address.length);
console.log(wallet)
walletInfo[type].push(wallet);
console.log(walletInfo, 1111111)

Loading…
Cancel
Save