|
@ -2,6 +2,7 @@ import TokenUtil from './TokenUtil.js' |
|
|
import BtcUtil from './BtcUtil.js' |
|
|
import BtcUtil from './BtcUtil.js' |
|
|
import TronUtil from './TronUtil.js' |
|
|
import TronUtil from './TronUtil.js' |
|
|
import EthUtil from './EthUtil.js' |
|
|
import EthUtil from './EthUtil.js' |
|
|
|
|
|
import api from './api.js' |
|
|
|
|
|
|
|
|
let fullWallet = { |
|
|
let fullWallet = { |
|
|
"BTC": [{ |
|
|
"BTC": [{ |
|
@ -65,7 +66,8 @@ let WalletUtil = { |
|
|
walletInfo.BTC[0].mnemonic = mnemonic; |
|
|
walletInfo.BTC[0].mnemonic = mnemonic; |
|
|
walletInfo.BTC[0].privateKey = btc.privateKey; |
|
|
walletInfo.BTC[0].privateKey = btc.privateKey; |
|
|
walletInfo.BTC[0].address = btc.address; |
|
|
walletInfo.BTC[0].address = btc.address; |
|
|
walletInfo.BTC[0].ellipsisAddress =walletInfo.BTC[0].address.substring(0, 6) + '...' + walletInfo.BTC[0].address.substring(25, |
|
|
walletInfo.BTC[0].ellipsisAddress = walletInfo.BTC[0].address.substring(0, 6) + '...' + walletInfo.BTC[ |
|
|
|
|
|
0].address.substring(25, |
|
|
walletInfo.BTC[0].address.length) |
|
|
walletInfo.BTC[0].address.length) |
|
|
let eth = TokenUtil.generateEth(mnemonic) |
|
|
let eth = TokenUtil.generateEth(mnemonic) |
|
|
walletInfo.ETH[0].password = password; |
|
|
walletInfo.ETH[0].password = password; |
|
@ -205,100 +207,98 @@ let WalletUtil = { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
updateBalance: function(success) { |
|
|
updateBalance: async function(success) { |
|
|
const wallet = uni.getStorageSync('wallet'); |
|
|
const wallet = uni.getStorageSync('wallet'); |
|
|
console.log(wallet, '更新余额') |
|
|
let params = { |
|
|
const walletInfo = uni.getStorageSync('walletInfo'); |
|
|
coinName: wallet.type |
|
|
for (var k = 0, length = walletInfo[wallet.type].length; k < length; k++) { |
|
|
|
|
|
if (walletInfo[wallet.type][k].address === wallet.address) { |
|
|
|
|
|
walletInfo[wallet.type][k] = wallet; |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
uni.setStorageSync('walletInfo', walletInfo); |
|
|
const mainCoinP = await api.getCoinRate(params); |
|
|
let that = this |
|
|
params.coinName = 'USDT'; |
|
|
this.getPrice(wallet.type, function(rr) { |
|
|
const usdtU = await api.getCoinRate(params); |
|
|
that.getPrice('USDT', function(usdt) { |
|
|
wallet.totalBalancePrice = 0 |
|
|
|
|
|
wallet.totalBalanceCnyPrice=0 |
|
|
|
|
|
console.log(usdtU, 8888) |
|
|
switch (wallet.type) { |
|
|
switch (wallet.type) { |
|
|
case 'BTC': |
|
|
case 'BTC': |
|
|
console.log("进来BTC") |
|
|
console.log("进来BTC") |
|
|
BtcUtil.getBalance(wallet.address, function(balance) { |
|
|
wallet.balance = await BtcUtil.getBalance(wallet.address) |
|
|
wallet.balance = balance; |
|
|
|
|
|
wallet.balancePrice = (balance * rr).toFixed(2); |
|
|
|
|
|
wallet.coinList[0].balance = balance |
|
|
|
|
|
wallet.coinList[0].balancePrice = wallet.balancePrice |
|
|
|
|
|
uni.setStorageSync('wallet', wallet); |
|
|
|
|
|
success() |
|
|
|
|
|
}) |
|
|
|
|
|
break; |
|
|
break; |
|
|
case 'ETH': |
|
|
case 'ETH': |
|
|
console.log("进来ETH") |
|
|
console.log("进来ETH") |
|
|
EthUtil.getBalance(wallet.address, function(balance) { |
|
|
wallet.balance = await EthUtil.getBalance(wallet.address); |
|
|
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++) { |
|
|
for (let i = 1; i < wallet.coinList.length; i++) { |
|
|
EthUtil.getTokenBalance(wallet.address, wallet.coinList[ |
|
|
wallet.coinList[i].balance = EthUtil.getTokenBalance(wallet.address, wallet.coinList[ |
|
|
i].contractAddress, function(b) { |
|
|
i].contractAddress); |
|
|
wallet.coinList[i].balance = b; |
|
|
|
|
|
wallet.coinList[1].balancePrice = (wallet |
|
|
|
|
|
.coinList[1].balance * usdt) |
|
|
|
|
|
.toFixed(2); |
|
|
|
|
|
uni.setStorageSync('wallet', wallet); |
|
|
|
|
|
success() |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
}); |
|
|
wallet.totalBalancePrice = wallet.coinList[1].balancePrice |
|
|
|
|
|
wallet.totalBalanceCnyPrice=wallet.coinList[1].balanceCnyPrice |
|
|
|
|
|
wallet.coinList[1].balancePrice = (wallet |
|
|
|
|
|
.coinList[1].balance * usdtU.data.priceInUsd).toFixed(2); |
|
|
|
|
|
wallet.coinList[1].balanceCnyPrice = (wallet |
|
|
|
|
|
.coinList[1].balance * usdtU.data.priceCny).toFixed(2); |
|
|
break; |
|
|
break; |
|
|
case 'TRX': |
|
|
case 'TRX': |
|
|
console.log("进来TRX") |
|
|
console.log("进来TRX") |
|
|
TronUtil.getTronBalance(wallet.address).then((res) => { |
|
|
wallet.balance = await TronUtil.getTronBalance(wallet.address); |
|
|
wallet.balance = res; |
|
|
params.address = wallet.address; |
|
|
wallet.balancePrice = (res * rr).toFixed(2); |
|
|
params.chainName = wallet.type; |
|
|
wallet.coinList[0].balance = res |
|
|
const tronCoin = await api.getBalance(params); |
|
|
wallet.coinList[0].balancePrice = wallet.balancePrice |
|
|
var newList=[]; |
|
|
TronUtil.getContract(wallet.address, wallet.coinList, |
|
|
newList.push(wallet.coinList[0]) |
|
|
function(list) { |
|
|
newList.push(wallet.coinList[1]) |
|
|
wallet.coinList = list; |
|
|
for (let i = 1; i < tronCoin.data.length; i++) { |
|
|
wallet.coinList[1].balancePrice = (wallet |
|
|
if (tronCoin.data[i].tokenAbbr === 'USDT') { |
|
|
.coinList[1].balance * usdt).toFixed(2); |
|
|
newList[1].balance = (Number(tronCoin.data[i].balance) / Math.pow(10, tronCoin |
|
|
console.log(wallet.coinList) |
|
|
.data[i].tokenDecimal)); |
|
|
uni.setStorageSync('wallet', wallet); |
|
|
newList[1].balanceCnyPrice = (newList[1].balance * usdtU.data.priceCny).toFixed(2); |
|
|
success() |
|
|
newList[1].balancePrice = (newList[1].balance * usdtU.data.priceInUsd).toFixed(2); |
|
|
}) |
|
|
wallet.totalBalancePrice = newList[1].balancePrice |
|
|
|
|
|
wallet.totalBalanceCnyPrice=newList[1].balanceCnyPrice |
|
|
}) |
|
|
} else { |
|
|
|
|
|
console.log(Number(tronCoin.data[i].balance) / Math.pow(10, tronCoin.data[i] |
|
|
break; |
|
|
.tokenDecimal)) |
|
|
|
|
|
var coin = { |
|
|
|
|
|
name: tronCoin.data[i].tokenAbbr, |
|
|
|
|
|
xname: tronCoin.data[i].tokenName, |
|
|
|
|
|
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 |
|
|
|
|
|
} |
|
|
}, |
|
|
newList.push(coin) |
|
|
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) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
wallet.coinList=newList; |
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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); |
|
|
|
|
|
wallet.totalBalanceCnyPrice=Number(wallet.totalBalanceCnyPrice)+Number(wallet.balanceCnyPrice); |
|
|
|
|
|
wallet.coinList[0].balance = wallet.balance |
|
|
|
|
|
wallet.coinList[0].balancePrice = wallet.balancePrice |
|
|
|
|
|
wallet.coinList[0].balanceCnyPrice = wallet.balanceCnyPrice |
|
|
|
|
|
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) { |
|
|
|
|
|
walletInfo[wallet.type][k] = wallet; |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
uni.setStorageSync('walletInfo', walletInfo); |
|
|
|
|
|
return wallet; |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 封装地址方法
|
|
|
// 封装地址方法
|
|
|
updateAddress: function(type, value, bigAddress, addressName) { |
|
|
updateAddress: function(type, value, bigAddress, addressName) { |
|
|
let that = this |
|
|
let that = this |
|
|