|
|
@ -182,44 +182,81 @@ console.log(password,'password') |
|
|
|
this.updateBalance(); |
|
|
|
}, |
|
|
|
updateBalance:function() { |
|
|
|
|
|
|
|
let wallet = uni.getStorageSync('wallet'); |
|
|
|
switch (wallet.type) { |
|
|
|
case 'BTC': |
|
|
|
BtcUtil.getBalance(wallet.address,function(balance){ |
|
|
|
wallet.balance=balance; |
|
|
|
wallet.coinList[0].balance=balance |
|
|
|
uni.setStorageSync('wallet', wallet); |
|
|
|
}) |
|
|
|
break; |
|
|
|
case 'ETH': |
|
|
|
EthUtil.getBalance(wallet.address,function(balance){ |
|
|
|
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; |
|
|
|
let that=this |
|
|
|
this.getPrice(wallet.type,function(rr){ |
|
|
|
that.getPrice('USDT',function(usdt){ |
|
|
|
switch (wallet.type) { |
|
|
|
case 'BTC': |
|
|
|
BtcUtil.getBalance(wallet.address,function(balance){ |
|
|
|
wallet.balance=balance; |
|
|
|
wallet.balancePrice=(balance*rr).toFixed(2); |
|
|
|
wallet.coinList[0].balance=balance |
|
|
|
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 |
|
|
|
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; |
|
|
|
case 'TRX': |
|
|
|
|
|
|
|
TronUtil.getTronBalance(wallet.address).then((res) => { |
|
|
|
wallet.balance=res; |
|
|
|
wallet.coinList[0].balance=res |
|
|
|
TronUtil.getContract('TWgEuYRuXgwfDbcfzZsteu5w5dq1nFR35w',wallet.coinList,function(list){ |
|
|
|
wallet.coinList=list; |
|
|
|
wallet.coinList[1].balancePrice=(wallet.coinList[1].balance*usdt).toFixed(2); |
|
|
|
console.log(wallet.coinList) |
|
|
|
uni.setStorageSync('wallet', wallet); |
|
|
|
}) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
case 'TRX': |
|
|
|
}) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
}, |
|
|
|
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) |
|
|
|
|
|
|
|
TronUtil.getTronBalance(wallet.address).then((res) => { |
|
|
|
wallet.balance=res; |
|
|
|
wallet.coinList[0].balance=res |
|
|
|
TronUtil.getContract(wallet.address,wallet.coinList,function(list){ |
|
|
|
wallet.coinList=list; |
|
|
|
console.log(wallet.coinList) |
|
|
|
uni.setStorageSync('wallet', wallet); |
|
|
|
}) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
break; |
|
|
|
// coinList: [{
|
|
|
|
// name: "ETH",
|
|
|
|
// xname: 'Ethereum',
|
|
|
|
// balance: 0,
|
|
|
|
// icon: require('@/static/tongyonh/Frame3299.png')
|
|
|
|
// },
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
export default WalletUtil |
|
|
|