From ffe4e336f75313f13be40cecf18ee14f5e841919 Mon Sep 17 00:00:00 2001 From: vee <897831508@qq.com> Date: Sat, 13 Nov 2021 15:38:12 +0800 Subject: [PATCH] =?UTF-8?q?=E9=92=B1=E5=8C=85=E5=B7=A5=E5=85=B7=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/WalletUtil.js | 63 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 55 insertions(+), 8 deletions(-) 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