|
|
@ -67,7 +67,7 @@ let WalletUtil = { |
|
|
|
walletInfo.BTC[0].privateKey = btc.privateKey; |
|
|
|
walletInfo.BTC[0].address = btc.address; |
|
|
|
walletInfo.BTC[0].ellipsisAddress = walletInfo.BTC[0].address.substring(0, 6) + '...' + walletInfo.BTC[ |
|
|
|
0].address.substring(walletInfo.BTC[0].address.length-6, |
|
|
|
0].address.substring(walletInfo.BTC[0].address.length - 6, |
|
|
|
walletInfo.BTC[0].address.length) |
|
|
|
let eth = TokenUtil.generateEth(mnemonic) |
|
|
|
walletInfo.ETH[0].password = password; |
|
|
@ -88,13 +88,13 @@ let WalletUtil = { |
|
|
|
updateWalletName: function(type, address, name) { |
|
|
|
let walletInfo = uni.getStorageSync('walletInfo'); |
|
|
|
let walletList = walletInfo[type]; |
|
|
|
let wallet =uni.getStorageSync('wallet'); |
|
|
|
let wallet = uni.getStorageSync('wallet'); |
|
|
|
for (var k = 0, length = walletList.length; k < length; k++) { |
|
|
|
if (walletList[k].address === address) { |
|
|
|
walletList[k].name = name |
|
|
|
if(wallet.address==walletList[k].address){ |
|
|
|
wallet.name=name |
|
|
|
uni.setStorageSync('wallet',wallet); |
|
|
|
if (wallet.address == walletList[k].address) { |
|
|
|
wallet.name = name |
|
|
|
uni.setStorageSync('wallet', wallet); |
|
|
|
} |
|
|
|
break; |
|
|
|
} |
|
|
@ -181,7 +181,8 @@ let WalletUtil = { |
|
|
|
walletList = walletInfo[type] |
|
|
|
for (var k = 0, length = walletList.length; k < length; k++) { |
|
|
|
let address = walletList[k].address; |
|
|
|
walletList[k].ellipsisAddress = address.substring(0, 6) + '...' + address.substring(address.length - 6, |
|
|
|
walletList[k].ellipsisAddress = address.substring(0, 6) + '...' + address.substring(address |
|
|
|
.length - 6, |
|
|
|
address.length) |
|
|
|
} |
|
|
|
} else { |
|
|
@ -207,7 +208,8 @@ let WalletUtil = { |
|
|
|
console.log() |
|
|
|
for (var k = 0, length = walletList.length; k < length; k++) { |
|
|
|
if (walletList[k].address == address) { |
|
|
|
walletList[k].ellipsisAddress = address.substring(0, 6) + '...' + address.substring(address.length - 6, |
|
|
|
walletList[k].ellipsisAddress = address.substring(0, 6) + '...' + address.substring(address |
|
|
|
.length - 6, |
|
|
|
address.length) |
|
|
|
uni.setStorageSync('wallet', walletList[k]); |
|
|
|
break; |
|
|
@ -225,7 +227,7 @@ let WalletUtil = { |
|
|
|
params.coinName = 'USDT'; |
|
|
|
const usdtU = await api.getCoinRate(params); |
|
|
|
wallet.totalBalancePrice = 0 |
|
|
|
wallet.totalBalanceCnyPrice=0 |
|
|
|
wallet.totalBalanceCnyPrice = 0 |
|
|
|
console.log(usdtU, 8888) |
|
|
|
switch (wallet.type) { |
|
|
|
case 'BTC': |
|
|
@ -233,17 +235,20 @@ let WalletUtil = { |
|
|
|
wallet.balance = await BtcUtil.getBalance(wallet.address) |
|
|
|
break; |
|
|
|
case 'ETH': |
|
|
|
console.log("进来ETH",wallet.balance ) |
|
|
|
console.log("进来ETH", wallet.balance) |
|
|
|
wallet.balance = await EthUtil.getBalance(wallet.address); |
|
|
|
wallet.balance=wallet.balance>0?wallet.balance.toFixed(6):wallet.balance |
|
|
|
console.log("进来ETH",wallet.balance ) |
|
|
|
wallet.balance = wallet.balance > 0 ? wallet.balance.toFixed(6) : wallet.balance |
|
|
|
console.log("进来ETH", wallet.balance) |
|
|
|
for (let i = 1; i < wallet.coinList.length; i++) { |
|
|
|
wallet.coinList[i].balance = await EthUtil.getTokenBalance(wallet.address, wallet.coinList[i].contractAddress); |
|
|
|
console.log("进来ETH",wallet.coinList[i].balance) |
|
|
|
wallet.coinList[i].balance = await EthUtil.getTokenBalance(wallet.address, wallet.coinList[ |
|
|
|
i].contractAddress); |
|
|
|
console.log("进来ETH", wallet.coinList[i].balance) |
|
|
|
|
|
|
|
} |
|
|
|
wallet.totalBalancePrice = wallet.coinList[1].balancePrice?wallet.coinList[1].balancePrice:0; |
|
|
|
wallet.totalBalanceCnyPrice=wallet.coinList[1].balanceCnyPrice?wallet.coinList[1].balanceCnyPrice:0; |
|
|
|
wallet.totalBalancePrice = wallet.coinList[1].balancePrice ? wallet.coinList[1].balancePrice : |
|
|
|
0; |
|
|
|
wallet.totalBalanceCnyPrice = wallet.coinList[1].balanceCnyPrice ? wallet.coinList[1] |
|
|
|
.balanceCnyPrice : 0; |
|
|
|
wallet.coinList[1].balancePrice = (wallet |
|
|
|
.coinList[1].balance * usdtU.data.priceInUsd).toFixed(2); |
|
|
|
wallet.coinList[1].balanceCnyPrice = (wallet |
|
|
@ -255,17 +260,21 @@ let WalletUtil = { |
|
|
|
params.address = wallet.address; |
|
|
|
params.chainName = wallet.type; |
|
|
|
const tronCoin = await api.getBalance(params); |
|
|
|
var newList=[]; |
|
|
|
var newList = []; |
|
|
|
|
|
|
|
newList.push(wallet.coinList[0]) |
|
|
|
newList.push(wallet.coinList[1]) |
|
|
|
newList[0].tokenType = "trc10" |
|
|
|
newList[0].contractAddress='_'; |
|
|
|
for (let i = 1; i < tronCoin.data.length; i++) { |
|
|
|
if (tronCoin.data[i].tokenAbbr === 'USDT') { |
|
|
|
newList[1].balance = (Number(tronCoin.data[i].balance) / Math.pow(10, tronCoin |
|
|
|
.data[i].tokenDecimal)); |
|
|
|
newList[1].tokenType = "trc20" |
|
|
|
newList[1].balanceCnyPrice = (newList[1].balance * usdtU.data.priceCny).toFixed(2); |
|
|
|
newList[1].balancePrice = (newList[1].balance * usdtU.data.priceInUsd).toFixed(2); |
|
|
|
wallet.totalBalancePrice = newList[1].balancePrice |
|
|
|
wallet.totalBalanceCnyPrice=newList[1].balanceCnyPrice |
|
|
|
wallet.totalBalanceCnyPrice = newList[1].balanceCnyPrice |
|
|
|
} else { |
|
|
|
console.log(Number(tronCoin.data[i].balance) / Math.pow(10, tronCoin.data[i] |
|
|
|
.tokenDecimal)) |
|
|
@ -275,36 +284,34 @@ let WalletUtil = { |
|
|
|
balance: (Number(tronCoin.data[i].balance) / Math.pow(10, tronCoin.data[i] |
|
|
|
.tokenDecimal)), |
|
|
|
icon: tronCoin.data[i].tokenLogo, |
|
|
|
|
|
|
|
} |
|
|
|
if (tronCoin.data[i].tokenType === 'trc20') { |
|
|
|
coin.contractAddress = tronCoin.data[i].tokenId |
|
|
|
} else { |
|
|
|
coin.contractAddress = tronCoin.data[i].owner_address |
|
|
|
contractAddress: tronCoin.data[i].tokenId, |
|
|
|
tokenType: tronCoin.data[i].tokenType |
|
|
|
} |
|
|
|
|
|
|
|
newList.push(coin) |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
wallet.coinList=newList; |
|
|
|
wallet.coinList = newList; |
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
wallet.ellipsisAddress=wallet.address.substring(0, 6) + '...' + wallet.address.substring( |
|
|
|
wallet.ellipsisAddress = wallet.address.substring(0, 6) + '...' + wallet.address.substring( |
|
|
|
wallet.address.length - 6, |
|
|
|
wallet.address.length); |
|
|
|
wallet.balancePrice = (wallet.balance * mainCoinP.data.priceInUsd).toFixed(2); |
|
|
|
wallet.balanceCnyPrice = (wallet.balance * mainCoinP.data.priceCny).toFixed(2); |
|
|
|
wallet.totalBalancePrice=(Number(wallet.totalBalancePrice)+Number(wallet.balancePrice)).toFixed(2); |
|
|
|
wallet.totalBalanceCnyPrice=(Number(wallet.totalBalanceCnyPrice)+Number(wallet.balanceCnyPrice)).toFixed(2); |
|
|
|
console.log("wallet.balancePrice",Number(wallet.totalBalancePrice)) |
|
|
|
console.log("wallet.balanceCnyPrice",wallet.totalBalancePrice) |
|
|
|
wallet.totalBalancePrice = (Number(wallet.totalBalancePrice) + Number(wallet.balancePrice)).toFixed(2); |
|
|
|
wallet.totalBalanceCnyPrice = (Number(wallet.totalBalanceCnyPrice) + Number(wallet.balanceCnyPrice)) |
|
|
|
.toFixed(2); |
|
|
|
console.log("wallet.balancePrice", Number(wallet.totalBalancePrice)) |
|
|
|
console.log("wallet.balanceCnyPrice", wallet.totalBalancePrice) |
|
|
|
wallet.coinList[0].balance = wallet.balance |
|
|
|
wallet.coinList[0].balancePrice = wallet.balancePrice |
|
|
|
wallet.coinList[0].balanceCnyPrice = wallet.balanceCnyPrice |
|
|
|
uni.setStorageSync('wallet',wallet); |
|
|
|
uni.setStorageSync('wallet', wallet); |
|
|
|
const walletInfo = uni.getStorageSync('walletInfo'); |
|
|
|
for (var k = 0, length = walletInfo[wallet.type].length; k < length; k++) { |
|
|
|
if (walletInfo[wallet.type][k].address === wallet.address) { |
|
|
|