diff --git a/main.js b/main.js index b5d5420..6424269 100644 --- a/main.js +++ b/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 diff --git a/pages/menu/backUp/index.vue b/pages/menu/backUp/index.vue index 379e78d..016efc5 100644 --- a/pages/menu/backUp/index.vue +++ b/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', diff --git a/pages/menu/backUp/transPaw/index.vue b/pages/menu/backUp/transPaw/index.vue index 16fa747..32299d0 100644 --- a/pages/menu/backUp/transPaw/index.vue +++ b/pages/menu/backUp/transPaw/index.vue @@ -105,6 +105,7 @@ } }else{ + this.setWalletInfo(); uni.showToast({ title: this.$t('index').Setsuccessfully, diff --git a/pages/menu/wallet/index.vue b/pages/menu/wallet/index.vue index a1a0008..abe72e8 100644 --- a/pages/menu/wallet/index.vue +++ b/pages/menu/wallet/index.vue @@ -46,7 +46,7 @@ - + @@ -76,8 +76,8 @@ - - + + @@ -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() { diff --git a/utils/BtcUtil.js b/utils/BtcUtil.js index c8d0759..3dc84b2 100644 --- a/utils/BtcUtil.js +++ b/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 \ No newline at end of file diff --git a/utils/SystemConfiguration.js b/utils/SystemConfiguration.js index c61c23d..c4d9e09 100644 --- a/utils/SystemConfiguration.js +++ b/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/' } diff --git a/utils/WalletUtil.js b/utils/WalletUtil.js index 3b1f605..704850c 100644 --- a/utils/WalletUtil.js +++ b/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)