Browse Source

钱包工具类

master
vee 4 years ago
parent
commit
ffe4e336f7
  1. 61
      utils/WalletUtil.js

61
utils/WalletUtil.js

@ -10,8 +10,8 @@ let fullWallet = {
icon: require('@/static/tongyonh/bye.png') icon: require('@/static/tongyonh/bye.png')
}] }]
}], }],
"ETH": [ "ETH": [{
{balance: 0, balance: 0,
name: "ETH", name: "ETH",
coinList: [{ coinList: [{
name: "ETH", name: "ETH",
@ -26,10 +26,10 @@ let fullWallet = {
contractAddress: '0xdac17f958d2ee523a2206206994597c13d831ec7', contractAddress: '0xdac17f958d2ee523a2206206994597c13d831ec7',
icon: require('@/static/tongyonh/img500.png') icon: require('@/static/tongyonh/img500.png')
} }
]} ]
], }],
"TRON": [ "TRON": [{
{balance: 0, balance: 0,
name: "TRON", name: "TRON",
coinList: [{ coinList: [{
name: "TRX", name: "TRX",
@ -44,8 +44,8 @@ let fullWallet = {
contractAddress: 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t', contractAddress: 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t',
icon: require('@/static/tongyonh/tether_usd.png') icon: require('@/static/tongyonh/tether_usd.png')
} }
]}
] ]
}]
} }
let WalletUtil = { let WalletUtil = {
@ -67,7 +67,9 @@ let WalletUtil = {
walletInfo.TRON[0].password = password; walletInfo.TRON[0].password = password;
walletInfo.TRON[0].privateKey = tron.privateKey; walletInfo.TRON[0].privateKey = tron.privateKey;
walletInfo.TRON[0].address = tron.mnemonic; walletInfo.TRON[0].address = tron.mnemonic;
let wallet = walletInfo.BTC[0];
uni.setStorageSync('walletInfo', walletInfo); uni.setStorageSync('walletInfo', walletInfo);
uni.setStorageSync('wallet', wallet);
}, },
//修改钱包名称 //修改钱包名称
updateWalletName: function(type, address, name) { updateWalletName: function(type, address, name) {
@ -79,6 +81,51 @@ let WalletUtil = {
} }
} }
uni.setStorageSync('walletInfo', walletInfo); uni.setStorageSync('walletInfo', walletInfo);
},
mnemonicEstablishWallet: function(type, mnemonic, password) {
let walletInfo = uni.getStorageSync('walletInfo');
let wallet;
switch (type) {
case 'BTC':
wallet = TokenUtil.generateBtc(mnemonic);
break;
case 'ETH':
wallet = TokenUtil.generateTron(mnemonic);
break;
case 'TRON':
wallet = TokenUtil.generateEth(mnemonic);
break;
}
let walletInfo=walletInfo[type];
walletInfo.password = password;
walletInfo.privateKey = wallet.privateKey;
walletInfo.mnemonic = mnemonic;
walletInfo.address = wallet.address;
walletInfo.push(walletInfo);
uni.setStorageSync('walletInfo', walletInfo);
uni.setStorageSync('wallet', walletInfo);
},
privateKeyEstablishWallet: function(type, privateKey, password) {
let walletInfo = uni.getStorageSync('walletInfo');
let wallet;
switch (type) {
case 'BTC':
wallet = TokenUtil.importBtcPrivateKey(privateKey);
break;
case 'ETH':
wallet = TokenUtil.importEthPrivateKey(privateKey);
break;
case 'TRON':
wallet = TokenUtil.importTronPrivateKey(privateKey);
break;
}
let walletInfo=walletInfo[type];
walletInfo.password = password;
walletInfo.privateKey = wallet.privateKey;
walletInfo.address = wallet.address;
walletInfo.push(walletInfo);
uni.setStorageSync('walletInfo', walletInfo);
uni.setStorageSync('wallet', walletInfo);
} }
} }
export default WalletUtil export default WalletUtil

Loading…
Cancel
Save