|
@ -3,6 +3,7 @@ let fullWallet = { |
|
|
"BTC": [{ |
|
|
"BTC": [{ |
|
|
balance: 0, |
|
|
balance: 0, |
|
|
name: "BTC", |
|
|
name: "BTC", |
|
|
|
|
|
type:'BTC', |
|
|
coinList: [{ |
|
|
coinList: [{ |
|
|
name: "BTC", |
|
|
name: "BTC", |
|
|
xname: 'Bitcoin', |
|
|
xname: 'Bitcoin', |
|
@ -13,6 +14,7 @@ let fullWallet = { |
|
|
"ETH": [{ |
|
|
"ETH": [{ |
|
|
balance: 0, |
|
|
balance: 0, |
|
|
name: "ETH", |
|
|
name: "ETH", |
|
|
|
|
|
type:'ETH', |
|
|
coinList: [{ |
|
|
coinList: [{ |
|
|
name: "ETH", |
|
|
name: "ETH", |
|
|
xname: 'Ethereum', |
|
|
xname: 'Ethereum', |
|
@ -31,6 +33,7 @@ let fullWallet = { |
|
|
"TRX": [{ |
|
|
"TRX": [{ |
|
|
balance: 0, |
|
|
balance: 0, |
|
|
name: "TRX", |
|
|
name: "TRX", |
|
|
|
|
|
type:'TRX', |
|
|
coinList: [{ |
|
|
coinList: [{ |
|
|
name: "TRX", |
|
|
name: "TRX", |
|
|
xname: 'TRON', |
|
|
xname: 'TRON', |
|
@ -63,10 +66,10 @@ let WalletUtil = { |
|
|
walletInfo.ETH[0].privateKey = eth.privateKey; |
|
|
walletInfo.ETH[0].privateKey = eth.privateKey; |
|
|
walletInfo.ETH[0].address = eth.address; |
|
|
walletInfo.ETH[0].address = eth.address; |
|
|
let tron = TokenUtil.generateTron(mnemonic); |
|
|
let tron = TokenUtil.generateTron(mnemonic); |
|
|
walletInfo.TRON[0].mnemonic = mnemonic; |
|
|
walletInfo.TRX[0].mnemonic = mnemonic; |
|
|
walletInfo.TRON[0].password = password; |
|
|
walletInfo.TRX[0].password = password; |
|
|
walletInfo.TRON[0].privateKey = tron.privateKey; |
|
|
walletInfo.TRX[0].privateKey = tron.privateKey; |
|
|
walletInfo.TRON[0].address = tron.address; |
|
|
walletInfo.TRX[0].address = tron.address; |
|
|
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); |
|
@ -74,17 +77,19 @@ let WalletUtil = { |
|
|
//修改钱包名称
|
|
|
//修改钱包名称
|
|
|
updateWalletName: function(type, address, name) { |
|
|
updateWalletName: function(type, address, name) { |
|
|
let walletInfo = uni.getStorageSync('walletInfo'); |
|
|
let walletInfo = uni.getStorageSync('walletInfo'); |
|
|
for (var k = 0, length = walletInfo.length; k < length; k++) { |
|
|
let walletList = walletInfo[type]; |
|
|
if (walletInfo[k].address === address) { |
|
|
for (var k = 0, length = walletList.length; k < length; k++) { |
|
|
|
|
|
if (walletList[k].address === address) { |
|
|
walletInfo[k].name = name |
|
|
walletInfo[k].name = name |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
uni.setStorageSync('walletInfo', walletInfo); |
|
|
uni.setStorageSync('walletInfo', walletInfo); |
|
|
}, |
|
|
}, |
|
|
|
|
|
//助记词新建
|
|
|
mnemonicEstablishWallet: function(type, mnemonic, password) { |
|
|
mnemonicEstablishWallet: function(type, mnemonic, password) { |
|
|
let walletInfo = uni.getStorageSync('walletInfo'); |
|
|
let walletInfo = uni.getStorageSync('walletInfo'); |
|
|
|
|
|
|
|
|
let walletdec; |
|
|
let walletdec; |
|
|
switch (type) { |
|
|
switch (type) { |
|
|
case 'BTC': |
|
|
case 'BTC': |
|
@ -97,17 +102,18 @@ let WalletUtil = { |
|
|
walletdec = TokenUtil.generateEth(mnemonic); |
|
|
walletdec = TokenUtil.generateEth(mnemonic); |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
let wallet=fullWallet[type][0]; |
|
|
let wallet = fullWallet[type][0]; |
|
|
wallet.password = password; |
|
|
wallet.password = password; |
|
|
wallet.privateKey = walletdec.privateKey; |
|
|
wallet.privateKey = walletdec.privateKey; |
|
|
wallet.mnemonic = mnemonic; |
|
|
wallet.mnemonic = mnemonic; |
|
|
wallet.address = walletdec.address; |
|
|
wallet.address = walletdec.address; |
|
|
console.log(wallet) |
|
|
console.log(wallet) |
|
|
walletInfo[type].push(wallet); |
|
|
walletInfo[type].push(wallet); |
|
|
console.log(walletInfo,1111111) |
|
|
console.log(walletInfo, 1111111) |
|
|
uni.setStorageSync('walletInfo', walletInfo); |
|
|
uni.setStorageSync('walletInfo', walletInfo); |
|
|
uni.setStorageSync('wallet', wallet); |
|
|
uni.setStorageSync('wallet', wallet); |
|
|
}, |
|
|
}, |
|
|
|
|
|
//私钥新建
|
|
|
privateKeyEstablishWallet: function(type, privateKey, password) { |
|
|
privateKeyEstablishWallet: function(type, privateKey, password) { |
|
|
let walletInfo = uni.getStorageSync('walletInfo'); |
|
|
let walletInfo = uni.getStorageSync('walletInfo'); |
|
|
console.log(type) |
|
|
console.log(type) |
|
@ -123,30 +129,43 @@ let WalletUtil = { |
|
|
walletdec = TokenUtil.importTronPrivateKey(privateKey); |
|
|
walletdec = TokenUtil.importTronPrivateKey(privateKey); |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
let wallet=fullWallet[type][0]; |
|
|
let wallet = fullWallet[type][0]; |
|
|
wallet.password = password; |
|
|
wallet.password = password; |
|
|
wallet.privateKey = walletdec.privateKey; |
|
|
wallet.privateKey = walletdec.privateKey; |
|
|
wallet.address = walletdec.address; |
|
|
wallet.address = walletdec.address; |
|
|
walletInfo.push(wallet); |
|
|
walletInfo.push(wallet); |
|
|
uni.setStorageSync('walletInfo', walletInfo); |
|
|
uni.setStorageSync('walletInfo', walletInfo); |
|
|
uni.setStorageSync('wallet', wallet); |
|
|
uni.setStorageSync('wallet', wallet); |
|
|
} |
|
|
}, |
|
|
, |
|
|
//获取钱包列表
|
|
|
getWalletList: function(type) { |
|
|
getWalletList: function(type) { |
|
|
let walletInfo = uni.getStorageSync('walletInfo'); |
|
|
let walletInfo = uni.getStorageSync('walletInfo'); |
|
|
let walletList=[]; |
|
|
let walletList = []; |
|
|
if(type){ |
|
|
if (type) { |
|
|
walletList=walletInfo[type] |
|
|
walletList = walletInfo[type] |
|
|
}else{ |
|
|
} else { |
|
|
for(let obj in walletInfo){ |
|
|
for (let obj in walletInfo) { |
|
|
for (var k = 0, length = walletInfo[obj].length; k < length; k++) { |
|
|
for (var k = 0, length = walletInfo[obj].length; k < length; k++) { |
|
|
let address=walletInfo[obj][k].address; |
|
|
let address = walletInfo[obj][k].address; |
|
|
walletInfo[obj][k].ellipsisAddress=address.substring(0, 6)+'...'+address.substring(25, address.length); |
|
|
walletInfo[obj][k].ellipsisAddress = address.substring(0, 6) + '...' + address.substring(25, |
|
|
|
|
|
address.length); |
|
|
|
|
|
walletInfo[obj][k].type = obj; |
|
|
walletList.push(walletInfo[obj][k]); |
|
|
walletList.push(walletInfo[obj][k]); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
return walletList; |
|
|
return walletList; |
|
|
|
|
|
}, |
|
|
|
|
|
selectWallet: function(type, address) { |
|
|
|
|
|
let walletInfo = uni.getStorageSync('walletInfo'); |
|
|
|
|
|
let walletList = walletInfo[type]; |
|
|
|
|
|
for (var k = 0, length = walletList.length; k < length; k++) { |
|
|
|
|
|
if (walletList[k].address === address) { |
|
|
|
|
|
uni.setStorageSync('wallet', walletList[k]); |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
export default WalletUtil |
|
|
export default WalletUtil |
|
|