|
@@ -1,5 +1,5 @@
|
|
|
import API from '@/api'
|
|
|
-import Web3 from 'web3'
|
|
|
+// import Web3 from 'web3'
|
|
|
import { showError } from '@/util/util'
|
|
|
|
|
|
let ethHelper = {
|
|
@@ -18,37 +18,26 @@ let ethHelper = {
|
|
|
return Promise.reject(new Error(''))
|
|
|
}
|
|
|
|
|
|
- if (!this.isInitEth) {
|
|
|
- if (window.ethereum) {
|
|
|
- window.web3 = new Web3(window.ethereum)
|
|
|
- try {
|
|
|
- await window.ethereum.enable()
|
|
|
- } catch (error) {
|
|
|
- }
|
|
|
- } else if (window.web3) {
|
|
|
- window.web3 = new Web3(window.web3.currentProvider)
|
|
|
- }
|
|
|
-
|
|
|
- let networkType = await window.web3.eth.net.getNetworkType()
|
|
|
- if (networkType != 'main') {
|
|
|
- showError('eth不是主网')
|
|
|
- return Promise.reject(new Error('eth不是主网'))
|
|
|
- }
|
|
|
-
|
|
|
- this.isInitEth = true
|
|
|
+ if (window.ethereum) {
|
|
|
+ await window.ethereum.enable()
|
|
|
}
|
|
|
|
|
|
- let accounts = await window.web3.eth.getAccounts()
|
|
|
+ // let networkType = await window.web3.eth.net.getNetworkType()
|
|
|
+ // if (networkType != 'main') {
|
|
|
+ // showError('eth不是主网')
|
|
|
+ // return Promise.reject(new Error('eth不是主网'))
|
|
|
+ // }
|
|
|
+
|
|
|
+ let accounts = window.web3.eth.accounts
|
|
|
let account = this.account = accounts[0]
|
|
|
|
|
|
if (account) {
|
|
|
this.curAccount = account
|
|
|
let randomRes = await API.user.getRandom2({ account: account })
|
|
|
- let str = window.web3.utils.sha3(randomRes.data.data.random)
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
try {
|
|
|
- window.web3.eth.sign(str, account, (err, rs) => {
|
|
|
+ window.web3.personal.sign(window.web3.fromUtf8(randomRes.data.data.random), window.web3.eth.coinbase, (err, rs) => {
|
|
|
if (err) {
|
|
|
reject(err)
|
|
|
} else {
|