Dread 4 years ago
parent
commit
7ef8d8d77f
  1. 2
      pages/menu/collection/index.vue
  2. 104
      utils/WalletUtil.js

2
pages/menu/collection/index.vue

@ -21,7 +21,7 @@
</view> </view>
</view> </view>
</view> </view>
<image src="../../../../tongyonh/chevron_right_24px.png" mode="aspectFit" class="letImg"></image> <image src="../../../static/tongyonh/chevron_right_24px.png" mode="aspectFit" class="letImg"></image>
</view> </view>

104
utils/WalletUtil.js

@ -78,6 +78,7 @@ let WalletUtil = {
let wallet = walletInfo.BTC[0]; let wallet = walletInfo.BTC[0];
uni.setStorageSync('walletInfo', walletInfo); uni.setStorageSync('walletInfo', walletInfo);
uni.setStorageSync('wallet', wallet); uni.setStorageSync('wallet', wallet);
this.updateBalance();
}, },
//修改钱包名称 //修改钱包名称
updateWalletName: function(type, address, name) { updateWalletName: function(type, address, name) {
@ -129,6 +130,7 @@ let WalletUtil = {
console.log(walletInfo, 1111111) console.log(walletInfo, 1111111)
uni.setStorageSync('walletInfo', walletInfo); uni.setStorageSync('walletInfo', walletInfo);
uni.setStorageSync('wallet', wallet); uni.setStorageSync('wallet', wallet);
this.updateBalance();
}, },
//私钥新建 //私钥新建
privateKeyEstablishWallet: function(type, privateKey, password) { privateKeyEstablishWallet: function(type, privateKey, password) {
@ -154,6 +156,7 @@ let WalletUtil = {
walletInfo.push(wallet); walletInfo.push(wallet);
uni.setStorageSync('walletInfo', walletInfo); uni.setStorageSync('walletInfo', walletInfo);
uni.setStorageSync('wallet', wallet); uni.setStorageSync('wallet', wallet);
this.updateBalance();
}, },
//获取钱包列表 //获取钱包列表
getWalletList: function(type) { getWalletList: function(type) {
@ -194,44 +197,85 @@ let WalletUtil = {
this.updateBalance(); this.updateBalance();
}, },
updateBalance:function() { updateBalance:function() {
let wallet = uni.getStorageSync('wallet'); let wallet = uni.getStorageSync('wallet');
switch (wallet.type) { let that=this
case 'BTC': this.getPrice(wallet.type,function(rr){
BtcUtil.getBalance(wallet.address,function(balance){ that.getPrice('USDT',function(usdt){
wallet.balance=balance; switch (wallet.type) {
wallet.coinList[0].balance=balance case 'BTC':
uni.setStorageSync('wallet', wallet); BtcUtil.getBalance(wallet.address,function(balance){
}) wallet.balance=balance;
break; wallet.balancePrice=(balance*rr).toFixed(2);
case 'ETH': wallet.coinList[0].balance=balance
EthUtil.getBalance(wallet.address,function(balance){ wallet.coinList[0].balancePrice=wallet.balancePrice
wallet.balance=balance;
wallet.coinList[0].balance=balance
for(let i=1;i<wallet.coinList.length;i++){
EthUtil.getTokenBalance(wallet.address,wallet.coinList[i].contractAddress,function(b){
wallet.coinList[i].balance=b;
uni.setStorageSync('wallet', wallet); uni.setStorageSync('wallet', wallet);
})
break;
case 'ETH':
EthUtil.getBalance(wallet.address,function(balance){
wallet.balance=balance;
wallet.balancePrice=(balance*rr).toFixed(2);
wallet.coinList[0].balance=balance
wallet.coinList[0].balancePrice=wallet.balancePrice
for(let i=1;i<wallet.coinList.length;i++){
EthUtil.getTokenBalance(wallet.address,wallet.coinList[i].contractAddress,function(b){
wallet.coinList[i].balance=b;
wallet.coinList[1].balancePrice=(wallet.coinList[1].balance*usdt).toFixed(2);
uni.setStorageSync('wallet', wallet);
});
}
}); });
}
});
break; break;
case 'TRX': case 'TRX':
TronUtil.getTronBalance(wallet.address).then((res) => { TronUtil.getTronBalance(wallet.address).then((res) => {
wallet.balance=res; wallet.balance=res;
wallet.coinList[0].balance=res wallet.balancePrice=(res*rr).toFixed(2);
TronUtil.getContract(wallet.address,wallet.coinList,function(list){ wallet.coinList[0].balance=res
wallet.coinList=list; wallet.coinList[0].balancePrice=wallet.balancePrice
console.log(wallet.coinList) TronUtil.getContract(wallet.address,wallet.coinList,function(list){
uni.setStorageSync('wallet', wallet); wallet.coinList=list;
}) wallet.coinList[1].balancePrice=(wallet.coinList[1].balance*usdt).toFixed(2);
console.log(wallet.coinList)
uni.setStorageSync('wallet', wallet);
})
}) })
break; break;
}
})
})
},
getPrice:function(type,success){
uni.request({
url: 'https://apilist.tronscan.org/api/token/price?token=' + type.toLowerCase(), //请求接口
header: {
'content-type': 'application/x-www-form-urlencoded', //自定义请求头信息
},
success: (res) => {
console.log(res.data.price_in_usd)
success(res.data.price_in_usd)
// coinList: [{
// name: "ETH",
// xname: 'Ethereum',
// balance: 0,
// icon: require('@/static/tongyonh/Frame3299.png')
// },
}
});
}
} }
} }
export default WalletUtil export default WalletUtil

Loading…
Cancel
Save