|
@@ -5,30 +5,17 @@ import { showError } from '@/util/util'
|
|
|
let ethHelper = {
|
|
|
isInitEth: false,
|
|
|
curAccount: '',
|
|
|
- checkMainNetwork () {
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
- window.web3.version.getNetwork((err, netId) => {
|
|
|
- console.log(netId, err)
|
|
|
- if (netId != 1) {
|
|
|
- reject(new Error('当前网络类型不是主网'))
|
|
|
- } else {
|
|
|
- resolve()
|
|
|
- }
|
|
|
- })
|
|
|
- })
|
|
|
+ network: 0,
|
|
|
+ getMainNetwork () {
|
|
|
+ return window.web3.eth.net.getNetworkType()
|
|
|
},
|
|
|
/**
|
|
|
* @des 签名认证
|
|
|
*/
|
|
|
async initEth () {
|
|
|
if (!window.ethereum || !window.web3) {
|
|
|
- return Promise.reject(new Error('你还没有安装eth插件'))
|
|
|
- }
|
|
|
-
|
|
|
- try {
|
|
|
- await this.checkMainNetwork()
|
|
|
- } catch (e) {
|
|
|
- return Promise.reject(e)
|
|
|
+ showError('你还没有安装eth插件')
|
|
|
+ return Promise.reject(new Error(''))
|
|
|
}
|
|
|
|
|
|
if (!this.isInitEth) {
|
|
@@ -42,6 +29,12 @@ let ethHelper = {
|
|
|
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
|
|
|
}
|
|
|
|