diff --git a/utils/WalletUtil.js b/utils/WalletUtil.js index 1f4002b..c609a82 100644 --- a/utils/WalletUtil.js +++ b/utils/WalletUtil.js @@ -10,8 +10,8 @@ let fullWallet = { icon: require('@/static/tongyonh/bye.png') }] }], - "ETH": [ - {balance: 0, + "ETH": [{ + balance: 0, name: "ETH", coinList: [{ name: "ETH", @@ -26,10 +26,10 @@ let fullWallet = { contractAddress: '0xdac17f958d2ee523a2206206994597c13d831ec7', icon: require('@/static/tongyonh/img500.png') } - ]} - ], - "TRON": [ - {balance: 0, + ] + }], + "TRON": [{ + balance: 0, name: "TRON", coinList: [{ name: "TRX", @@ -44,8 +44,8 @@ let fullWallet = { contractAddress: 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t', icon: require('@/static/tongyonh/tether_usd.png') } - ]} - ] + ] + }] } let WalletUtil = { @@ -67,7 +67,9 @@ let WalletUtil = { walletInfo.TRON[0].password = password; walletInfo.TRON[0].privateKey = tron.privateKey; walletInfo.TRON[0].address = tron.mnemonic; + let wallet = walletInfo.BTC[0]; uni.setStorageSync('walletInfo', walletInfo); + uni.setStorageSync('wallet', wallet); }, //修改钱包名称 updateWalletName: function(type, address, name) { @@ -79,6 +81,51 @@ let WalletUtil = { } } 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