龚成明 2 жил өмнө
parent
commit
58b6047b10

+ 3 - 3
src/components/History.vue

@@ -11,7 +11,7 @@
 <script>
 import Top from '@/components/viewer/Top'
 import Table from '@/components/viewer/Table'
-import Tx from '@/plugins/model/Tx'
+import BaseModel from '@/plugins/model/BaseModel'
 
 export default {
   name: 'History',
@@ -67,7 +67,7 @@ export default {
       const rst = await this.tx.findByPaginate(this.table.pageNum, this.table.pageSize)
 
       if (rst.state) {
-        this.table.data = Tx.parseLocalRecordList(rst.data)
+        this.table.data = BaseModel.parseLocalRecordList(rst.data)
         this.$msgkit.success(rst.msg)
       } else {
         this.$msgkit.error(rst.msg)
@@ -76,7 +76,7 @@ export default {
       this.table.loading = false
     },
     createTx() {
-      this.tx = new Tx(this.chain.id, Tx.MODULES.HISTORY)
+      this.tx = new BaseModel(this.chain.id, BaseModel.MODULES.HISTORY)
     }
   },
   provide() {

+ 3 - 3
src/components/Pending.vue

@@ -11,7 +11,7 @@
 <script>
 import Top from '@/components/viewer/Top'
 import Table from '@/components/viewer/Table'
-import Tx from '@/plugins/model/Tx'
+import BaseModel from '@/plugins/model/BaseModel'
 
 export default {
   name: 'Pending',
@@ -66,7 +66,7 @@ export default {
       const rst = await this.tx.findByPaginate(this.table.pageNum, this.table.pageSize)
 
       if (rst.state) {
-        this.table.data = Tx.parseLocalRecordList(rst.data)
+        this.table.data = BaseModel.parseLocalRecordList(rst.data)
         this.$msgkit.success(rst.msg)
       } else {
         this.$msgkit.error(rst.msg)
@@ -75,7 +75,7 @@ export default {
       this.table.loading = false
     },
     createTx() {
-      this.tx = new Tx(this.chain.id, Tx.MODULES.PENDING)
+      this.tx = new BaseModel(this.chain.id, BaseModel.MODULES.PENDING)
     }
   },
   provide() {

+ 8 - 4
src/plugins/model/Tx.js → src/plugins/model/BaseModel.js

@@ -1,6 +1,6 @@
 import http from 'axios'
 
-export default class Tx {
+export default class BaseModel {
   static MODULES = {
     HISTORY: 'history',
     PENDING: 'pending'
@@ -37,7 +37,7 @@ export default class Tx {
   static parseLocalRecordList(remoteRecordList) {
     let localRecordList = []
     for (let remoteRecord of remoteRecordList) {
-      let localRecord = Tx.parseLocalRecord(remoteRecord)
+      let localRecord = BaseModel.parseLocalRecord(remoteRecord)
 
       if (localRecord) localRecordList.push(localRecord)
     }
@@ -54,13 +54,17 @@ export default class Tx {
       localRecord.comment= remoteRecord.comment
       localRecord.from = remoteRecord.fromAddress
       localRecord.to = remoteRecord.toAddress
-      localRecord.gasPrice = Tx.parseGasPrice(remoteRecord.gasPriceStr)
+      localRecord.gasPrice = BaseModel.parseGasPrice(remoteRecord.gasPriceStr)
       localRecord.timestamp = remoteRecord.timestamp
       localRecord.transferList = remoteRecord.transferList
 
       // transferList的format
       for (const transfer of localRecord.transferList) {
-        transfer.amount = parseInt(transfer.amountStr)
+        try {
+          transfer.amount = parseInt(transfer.amountStr) / (10 ** transfer.tokenDecimals)
+        } catch (e) {
+          transfer.amount = parseInt(transfer.amountStr)
+        }
       }
       localRecord.isMev = remoteRecord.isMev === true
       localRecord.isBot = remoteRecord.isBot === true

+ 0 - 1
src/plugins/model/Chain.js

@@ -1,5 +1,4 @@
 import http from 'axios'
-import NumKit from '@/plugins/kit/NumKit'
 
 export default class EthMev {
   static async getAll() {

+ 0 - 83
src/plugins/model/EthMev.js

@@ -1,83 +0,0 @@
-import http from 'axios'
-import NumKit from '@/plugins/kit/NumKit'
-
-export default class EthMev {
-  static async getEthMevData(block, hash, dataVague, page=1, size=200) {
-    const url = '/ethmev/findByHashOrBlockOrDataVague'
-    const rst = await http.post(url, {
-      block: block,
-      hash: hash,
-      dataVague: dataVague,
-      limit1: (page - 1) * size,
-      limit2: size
-    })
-
-    return rst.data
-  }
-
-  static async getEthMevPendingData(block, hash, dataVague, page=1, size=200) {
-    if (!isNaN(parseInt(block)) && block.charAt(0) !== '-') block = '-' + block
-
-    const url = '/ethmev/findByHashOrBlockOrDataVaguePending'
-    const rst = await http.post(url, {
-      block: block,
-      hash: hash,
-      dataVague: dataVague,
-      limit1: (page - 1) * size,
-      limit2: size
-    })
-
-    return rst.data
-  }
-
-  static async deleteByHash(hash) {
-    const url = '/ethmev/deleteByHash'
-    const rst = await http.post(url, {
-      hash: hash
-    })
-
-    return rst.data
-  }
-
-  static async appendOrUpdate(block, hash, dataVague) {
-    const url = '/ethmev/appendOrUpdate'
-    const rst = await http.post(url, {
-      block: block,
-      hash: hash,
-      dataVague: dataVague
-    })
-
-    return rst.data
-  }
-
-  static generateTableDataByDbData(historyList) {
-    historyList.map(function (history) {
-      try {
-        let dataObj = history.dataObj
-
-        history.from = dataObj.fromAdd
-        history.to = dataObj.toAdd
-        history.gasPrice = NumKit.getSubFloat(parseInt(dataObj.gasPrice) / (1E9), 2)
-        history.index = dataObj.index
-        history.type = dataObj.type
-        history.state = dataObj.status
-        history.pending = dataObj.pending
-        history.mev = dataObj.mev
-        history.tradeInfoList = dataObj.tradeInfo
-        history.memo = dataObj.memo
-
-        // hash异常处理
-        if (history.hash.indexOf('0x') === -1 && history.hash.length === 64) history.hash = '0x' + history.hash
-
-        // token处理
-        history.tokenMap = {}
-        history.tradeInfoList.map(function (tradeInfo) {
-          if (!history.tokenMap[tradeInfo.token]) history.tokenMap[tradeInfo.token] = tradeInfo.tokenSymbol
-        })
-        history.tokenAddressList = Object.keys(history.tokenMap)
-      } catch (e) {
-        history.tradeInfo = []
-      }
-    })
-  }
-}

+ 28 - 28
src/plugins/network.js

@@ -7,38 +7,38 @@ import md5 from "md5-node"
 axios.defaults.baseURL = process.env.VUE_APP_BASE_URL
 
 axios.interceptors.request.use(
-    function(config) {
-      // auth
-      let timestamp = parseInt((new Date().getTime()) / 1000) + ''
-      let baseStr = '410410' + timestamp
-      let splitStrList = baseStr.split("")
-      let replacedStr = baseStr.replaceAll(splitStrList[splitStrList.length - 1], "")
-      let authStr = md5(replacedStr)
-
-      config.data.timestamp = timestamp
-      config.data.auth = authStr
-
-      // headers处理
-      config.headers['content-type'] = 'application/json'
-
-      return config;
-    },
-    function(error) {
-      // Do something with request error
-      return Promise.reject(error);
-    }
+  function (config) {
+    // auth
+    let timestamp = parseInt((new Date().getTime()) / 1000) + ''
+    let baseStr = '410410' + timestamp
+    let splitStrList = baseStr.split("")
+    let replacedStr = baseStr.replaceAll(splitStrList[splitStrList.length - 1], "")
+    let authStr = md5(replacedStr)
+
+    config.data.timestamp = timestamp
+    config.data.auth = authStr
+
+    // headers处理
+    config.headers['content-type'] = 'application/json'
+
+    return config;
+  },
+  function (error) {
+    // Do something with request error
+    return Promise.reject(error);
+  }
 );
 
 // Add a response interceptor
 axios.interceptors.response.use(
-    function(response) {
-      // Do something with response data
-      return response;
-    },
-    function(error) {
-      // Do something with response error
-      return Promise.reject(error);
-    }
+  function (response) {
+    // Do something with response data
+    return response;
+  },
+  function (error) {
+    // Do something with response error
+    return Promise.reject(error);
+  }
 );
 
 Vue.prototype.$http = axios

+ 1 - 1
vue.config.js

@@ -6,7 +6,7 @@ module.exports = {
   devServer: {
     proxy: {
       '/api': {
-        target:'http://192.168.101.42:8888',
+        target:'http://127.0.0.1:8888',
         changeOrigin:true,
         pathRewrite:{
           '^/api': ''