|
@@ -5,6 +5,18 @@ 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()
|
|
|
+ }
|
|
|
+ })
|
|
|
+ })
|
|
|
+ },
|
|
|
/**
|
|
|
* @des 签名认证
|
|
|
*/
|
|
@@ -13,6 +25,12 @@ let ethHelper = {
|
|
|
return Promise.reject(new Error('你还没有安装eth插件'))
|
|
|
}
|
|
|
|
|
|
+ try {
|
|
|
+ await this.checkMainNetwork()
|
|
|
+ } catch (e) {
|
|
|
+ return Promise.reject(e)
|
|
|
+ }
|
|
|
+
|
|
|
if (!this.isInitEth) {
|
|
|
if (window.ethereum) {
|
|
|
window.web3 = new Web3(window.ethereum)
|
|
@@ -39,7 +57,6 @@ let ethHelper = {
|
|
|
try {
|
|
|
window.web3.eth.sign(str, account, (err, rs) => {
|
|
|
if (err) {
|
|
|
- console.log('err1', err)
|
|
|
reject(err)
|
|
|
} else {
|
|
|
resolve({
|
|
@@ -49,7 +66,6 @@ let ethHelper = {
|
|
|
}
|
|
|
})
|
|
|
} catch (err) {
|
|
|
- console.log('err2', err)
|
|
|
reject(err)
|
|
|
}
|
|
|
})
|