|
|
@ -7,7 +7,7 @@ let fullWallet = { |
|
|
|
"BTC": [{ |
|
|
|
balance: 0, |
|
|
|
name: "BTC", |
|
|
|
type:'BTC', |
|
|
|
type: 'BTC', |
|
|
|
coinList: [{ |
|
|
|
name: "BTC", |
|
|
|
xname: 'Bitcoin', |
|
|
@ -18,7 +18,7 @@ let fullWallet = { |
|
|
|
"ETH": [{ |
|
|
|
balance: 0, |
|
|
|
name: "ETH", |
|
|
|
type:'ETH', |
|
|
|
type: 'ETH', |
|
|
|
coinList: [{ |
|
|
|
name: "ETH", |
|
|
|
xname: 'Ethereum', |
|
|
@ -37,7 +37,7 @@ let fullWallet = { |
|
|
|
"TRX": [{ |
|
|
|
balance: 0, |
|
|
|
name: "TRX", |
|
|
|
type:'TRX', |
|
|
|
type: 'TRX', |
|
|
|
coinList: [{ |
|
|
|
name: "TRX", |
|
|
|
xname: 'TRON', |
|
|
@ -58,7 +58,7 @@ let fullWallet = { |
|
|
|
let WalletUtil = { |
|
|
|
//初次创建钱包
|
|
|
|
initialWallet: function(mnemonic, password) { |
|
|
|
console.log(password,'password') |
|
|
|
console.log(password, 'password') |
|
|
|
let walletInfo = fullWallet; |
|
|
|
let btc = TokenUtil.generateBtc(mnemonic); |
|
|
|
walletInfo.BTC[0].password = password; |
|
|
@ -95,28 +95,28 @@ let WalletUtil = { |
|
|
|
//助记词新建
|
|
|
|
mnemonicEstablishWallet: function(type, mnemonic, password) { |
|
|
|
let walletInfo = uni.getStorageSync('walletInfo'); |
|
|
|
console.log(password,'password',type) |
|
|
|
console.log(password, 'password', type) |
|
|
|
let walletdec; |
|
|
|
switch (type) { |
|
|
|
case 'BTC': |
|
|
|
walletdec = TokenUtil.generateBtc(mnemonic); |
|
|
|
if(uni.getStorageSync('walletInfo')){ |
|
|
|
uni.setStorageSync('walleti',walletdec.address) |
|
|
|
if (uni.getStorageSync('walletInfo')) { |
|
|
|
uni.setStorageSync('walleti', walletdec.address) |
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
case 'ETH': |
|
|
|
walletdec = TokenUtil.generateEth(mnemonic); |
|
|
|
if(uni.getStorageSync('walletInfo')){ |
|
|
|
uni.setStorageSync('walleti',walletdec.address) |
|
|
|
if (uni.getStorageSync('walletInfo')) { |
|
|
|
uni.setStorageSync('walleti', walletdec.address) |
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
case 'TRX': |
|
|
|
|
|
|
|
walletdec = TokenUtil.generateTron(mnemonic); |
|
|
|
if(uni.getStorageSync('walletInfo')){ |
|
|
|
uni.setStorageSync('walleti',walletdec.address) |
|
|
|
if (uni.getStorageSync('walletInfo')) { |
|
|
|
uni.setStorageSync('walleti', walletdec.address) |
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
@ -138,7 +138,7 @@ let WalletUtil = { |
|
|
|
privateKeyEstablishWallet: function(type, privateKey, password) { |
|
|
|
let walletInfo = uni.getStorageSync('walletInfo'); |
|
|
|
console.log(type) |
|
|
|
console.log(password,'password') |
|
|
|
console.log(password, 'password') |
|
|
|
let walletdec; |
|
|
|
switch (type) { |
|
|
|
case 'BTC': |
|
|
@ -156,7 +156,7 @@ let WalletUtil = { |
|
|
|
wallet.privateKey = walletdec.privateKey; |
|
|
|
wallet.address = walletdec.address; |
|
|
|
walletInfo[type].push(wallet); |
|
|
|
console.log(walletInfo,'当前私钥建的') |
|
|
|
console.log(walletInfo, '当前私钥建的') |
|
|
|
uni.setStorageSync('walletInfo', walletInfo); |
|
|
|
uni.setStorageSync('wallet', wallet); |
|
|
|
uni.setStorageSync('walleti', wallet.address); |
|
|
@ -177,7 +177,8 @@ let WalletUtil = { |
|
|
|
for (var k = 0, length = walletInfo[obj].length; k < length; k++) { |
|
|
|
let address = walletInfo[obj][k].address; |
|
|
|
|
|
|
|
walletInfo[obj][k].ellipsisAddress = address.substring(0, 6) + '...' + address.substring(address.length-6, |
|
|
|
walletInfo[obj][k].ellipsisAddress = address.substring(0, 6) + '...' + address.substring( |
|
|
|
address.length - 6, |
|
|
|
address.length); |
|
|
|
walletInfo[obj][k].type = obj; |
|
|
|
walletList.push(walletInfo[obj][k]); |
|
|
@ -202,43 +203,48 @@ let WalletUtil = { |
|
|
|
|
|
|
|
} |
|
|
|
}, |
|
|
|
updateBalance:function() { |
|
|
|
updateBalance: function(success) { |
|
|
|
const wallet = uni.getStorageSync('wallet'); |
|
|
|
console.log(wallet,'更新余额') |
|
|
|
console.log(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; |
|
|
|
walletInfo[wallet.type][k] = wallet; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
uni.setStorageSync('walletInfo', walletInfo); |
|
|
|
let that=this |
|
|
|
this.getPrice(wallet.type,function(rr){ |
|
|
|
that.getPrice('USDT',function(usdt){ |
|
|
|
let that = this |
|
|
|
this.getPrice(wallet.type, function(rr) { |
|
|
|
that.getPrice('USDT', function(usdt) { |
|
|
|
switch (wallet.type) { |
|
|
|
case 'BTC': |
|
|
|
console.log("进来BTC") |
|
|
|
BtcUtil.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 |
|
|
|
BtcUtil.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 |
|
|
|
uni.setStorageSync('wallet', wallet); |
|
|
|
success() |
|
|
|
}) |
|
|
|
break; |
|
|
|
case 'ETH': |
|
|
|
console.log("进来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); |
|
|
|
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); |
|
|
|
success() |
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
@ -248,15 +254,18 @@ let WalletUtil = { |
|
|
|
case 'TRX': |
|
|
|
console.log("进来TRX") |
|
|
|
TronUtil.getTronBalance(wallet.address).then((res) => { |
|
|
|
wallet.balance=res; |
|
|
|
wallet.balancePrice=(res*rr).toFixed(2); |
|
|
|
wallet.coinList[0].balance=res |
|
|
|
wallet.coinList[0].balancePrice=wallet.balancePrice |
|
|
|
TronUtil.getContract(wallet.address,wallet.coinList,function(list){ |
|
|
|
wallet.coinList=list; |
|
|
|
wallet.coinList[1].balancePrice=(wallet.coinList[1].balance*usdt).toFixed(2); |
|
|
|
wallet.balance = res; |
|
|
|
wallet.balancePrice = (res * rr).toFixed(2); |
|
|
|
wallet.coinList[0].balance = res |
|
|
|
wallet.coinList[0].balancePrice = wallet.balancePrice |
|
|
|
TronUtil.getContract(wallet.address, 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); |
|
|
|
success() |
|
|
|
}) |
|
|
|
|
|
|
|
}) |
|
|
@ -270,7 +279,7 @@ let WalletUtil = { |
|
|
|
}) |
|
|
|
|
|
|
|
}, |
|
|
|
getPrice:function(type,success){ |
|
|
|
getPrice: function(type, success) { |
|
|
|
uni.request({ |
|
|
|
url: 'https://apilist.tronscan.org/api/token/price?token=' + type.toLowerCase(), //请求接口
|
|
|
|
header: { |
|
|
@ -289,8 +298,8 @@ let WalletUtil = { |
|
|
|
|
|
|
|
|
|
|
|
// 封装地址方法
|
|
|
|
updateAddress:function(type,value,bigAddress,addressName) { |
|
|
|
let that=this |
|
|
|
updateAddress: function(type, value, bigAddress, addressName) { |
|
|
|
let that = this |
|
|
|
switch (wallet.type) { |
|
|
|
case 'BTC': |
|
|
|
|
|
|
@ -300,30 +309,30 @@ let WalletUtil = { |
|
|
|
|
|
|
|
break; |
|
|
|
case 'TRX': |
|
|
|
if(value=='ETH'){ |
|
|
|
if (value == 'ETH') { |
|
|
|
const gai = uni.getStorageSync('ETHAddressInfo') |
|
|
|
const gai2 = uni.getStorageSync('TRXAddressInfo') |
|
|
|
const index=uni.getStorageSync('editIndex') |
|
|
|
let eth=new Object; |
|
|
|
eth.address=bigAddress; |
|
|
|
eth.name=addressName |
|
|
|
eth.coinList=[{ |
|
|
|
name:"ETH", |
|
|
|
name2:"ETH", |
|
|
|
xname:'Ethereum', |
|
|
|
icon:require('@/static/tongyonh/Frame3299.png') |
|
|
|
const index = uni.getStorageSync('editIndex') |
|
|
|
let eth = new Object; |
|
|
|
eth.address = bigAddress; |
|
|
|
eth.name = addressName |
|
|
|
eth.coinList = [{ |
|
|
|
name: "ETH", |
|
|
|
name2: "ETH", |
|
|
|
xname: 'Ethereum', |
|
|
|
icon: require('@/static/tongyonh/Frame3299.png') |
|
|
|
}]; |
|
|
|
gai2.splice(index,1) |
|
|
|
uni.setStorageSync('TRXAddressInfo',gai2) |
|
|
|
gai2.splice(index, 1) |
|
|
|
uni.setStorageSync('TRXAddressInfo', gai2) |
|
|
|
gai.push(eth); |
|
|
|
uni.setStorageSync('ETHAddressInfo',gai) |
|
|
|
uni.setStorageSync('ETHAddressInfo', gai) |
|
|
|
uni.showToast({ |
|
|
|
title: 'Successfully', |
|
|
|
icon: 'success', |
|
|
|
duration: 1500 |
|
|
|
}) |
|
|
|
uni.navigateTo({ |
|
|
|
url:'../address/index' |
|
|
|
url: '../address/index' |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
@ -333,7 +342,7 @@ let WalletUtil = { |
|
|
|
|
|
|
|
}, |
|
|
|
// 指纹识别
|
|
|
|
finger(){ |
|
|
|
finger() { |
|
|
|
// #ifdef APP-PLUS
|
|
|
|
if (!plus.fingerprint.isSupport()) { |
|
|
|
this.result = '此设备不支持指纹识别'; |
|
|
@ -359,7 +368,7 @@ let WalletUtil = { |
|
|
|
}, |
|
|
|
|
|
|
|
fingerprint: function(sett) { |
|
|
|
let bltype=true; |
|
|
|
let bltype = true; |
|
|
|
// #ifdef APP-PLUS
|
|
|
|
if (!plus.fingerprint.isSupport()) { |
|
|
|
uni.showToast({ |
|
|
@ -402,8 +411,8 @@ let WalletUtil = { |
|
|
|
// #endif
|
|
|
|
|
|
|
|
|
|
|
|
let that=this; |
|
|
|
let forSett=true; |
|
|
|
let that = this; |
|
|
|
let forSett = true; |
|
|
|
// #ifdef APP-PLUS
|
|
|
|
plus.fingerprint.authenticate(function() { |
|
|
|
plus.nativeUI.closeWaiting(); //兼容Android平台关闭等待框
|
|
|
@ -413,10 +422,10 @@ let WalletUtil = { |
|
|
|
// duration: 1500,
|
|
|
|
// })
|
|
|
|
// 存储设置里开启指纹后的状态,隐藏使用密码
|
|
|
|
console.log(forSett,12121) |
|
|
|
if(sett){ |
|
|
|
uni.setStorageSync('fingerPass',true) |
|
|
|
console.log(forSett,12121) |
|
|
|
console.log(forSett, 12121) |
|
|
|
if (sett) { |
|
|
|
uni.setStorageSync('fingerPass', true) |
|
|
|
console.log(forSett, 12121) |
|
|
|
|
|
|
|
} |
|
|
|
//plus.nativeUI.alert('Fingerprint identification succeeded');
|
|
|
@ -427,7 +436,9 @@ let WalletUtil = { |
|
|
|
break; |
|
|
|
case e.AUTHENTICATE_OVERLIMIT: |
|
|
|
plus.nativeUI.closeWaiting(); //兼容Android平台关闭等待框
|
|
|
|
plus.nativeUI.alert('The number of fingerprint identification failures exceeds the limit. Please use other methods for authentication'); |
|
|
|
plus.nativeUI.alert( |
|
|
|
'The number of fingerprint identification failures exceeds the limit. Please use other methods for authentication' |
|
|
|
); |
|
|
|
break; |
|
|
|
case e.CANCEL: |
|
|
|
plus.nativeUI.toast('Recognition has been cancelled'); |
|
|
@ -440,7 +451,7 @@ let WalletUtil = { |
|
|
|
}); |
|
|
|
// Android平台手动弹出等待提示框
|
|
|
|
if ('Android' == plus.os.name) { |
|
|
|
this.show=true; |
|
|
|
this.show = true; |
|
|
|
/* plus.nativeUI.showWaiting('指纹识别中...').onclose = function() { |
|
|
|
plus.fingerprint.cancel(); |
|
|
|
} */ |
|
|
@ -466,7 +477,7 @@ let WalletUtil = { |
|
|
|
|
|
|
|
|
|
|
|
}, |
|
|
|
printCancel:function(){ |
|
|
|
printCancel: function() { |
|
|
|
plus.fingerprint.cancel(); |
|
|
|
// this.result="停止指纹识别"
|
|
|
|
}, |
|
|
|