浏览代码

no message

DESKTOP-70VPDLK\Administrator 6 月之前
父节点
当前提交
05625b9851
共有 3 个文件被更改,包括 95 次插入11 次删除
  1. 1 0
      api/pledge.js
  2. 6 2
      common/wallet/tokenpocket-wallet/tokenpocket-bnb.js
  3. 88 9
      pages/home/home-index.vue

+ 1 - 0
api/pledge.js

@@ -5,4 +5,5 @@ const commonUrl = '/api/pledge/'
 export const getDividendList = (data) => request(commonUrl + 'dividend', 'post', { ...data })
 export const getPledgeList = (data) => request(commonUrl + 'list', 'post', { ...data })
 export const addPledge = (data) => request(commonUrl + 'add', 'post', { ...data })
+export const getPledgeConfig = (data) => request(commonUrl + 'config', 'post', { ...data })
 

+ 6 - 2
common/wallet/tokenpocket-wallet/tokenpocket-bnb.js

@@ -175,19 +175,23 @@ tokenpocketBnb.getEstimateGas= async function (data){
  * @returns {{}}
  */
 tokenpocketBnb.getTransactionData=async function (to,money){
+    console.log('-------------------------aaaaaaaaaaaaaaaaaaaaaa')
     let data={};
-    data.data='0x0';
+
     data.to=to;
     data.from=tokenpocketBnb.getMyAddress();
     data.gasPrice=await tokenpocketBnb.getGasPrice();
+    data.gas=await tokenpocketBnb.getEstimateGas(data);
+    console.log('-------------------------aaaaaaaaaaaaaaaaaaaaaa')
     data.chainId=chainId;
     if(tools.isDevelopment()){
         money=0.00001;
     }
+    data.data='0x0';
     console.log(money.toString())
     data.value=web3.utils.numberToHex(ethers.utils.parseEther(money.toString()).toString());
     console.log('value:'+data.value)
-    data.gas=await tokenpocketBnb.getEstimateGas(data);
+
     return data;
 }
 

+ 88 - 9
pages/home/home-index.vue

@@ -3,10 +3,14 @@
 	import {
 		getTotalMoney
 	} from "@/api/money";
-	import {
-		getDividendList
-	} from "@/api/pledge";
+  import {
+    addPledge,
+    getDividendList, getPledgeConfig
+  } from "@/api/pledge";
 	import blank from "@/components/en-utils/en-blank/en-blank.vue"
+  import web3 from "web3";
+  import {ethers} from "ethers";
+  import tools from "@/common/js/tools";
 	export default {
 		name: "home-index",
 		props: {
@@ -20,7 +24,22 @@
 		watch: {
 			'address': function() {
 				this.getIconNum()
-			}
+			},
+      'pledgeNUm':function () {
+        console.log(this.pledgeNUm)
+        if(this.pledgeNUm===''){
+          return
+        }
+        if(this.listTab===1){
+          if(this.coinNum<this.pledgeNUm){
+            this.pledgeNUm=this.coinNum
+          }
+        }else {
+          if(this.pledgeTotal<this.pledgeNUm){
+            this.pledgeNUm=this.pledgeTotal
+          }
+        }
+      }
 		},
 		data() {
 			return {
@@ -32,18 +51,31 @@
 				page: 1,
 				total: '',
         pledgeNUm: '',
+        bnb_num: '',
+        pledgeAddress: '',
 				list: []
 			};
 		},
+
 		mounted() {
 			this.getIconNum()
 			this.getTotalMoney()
 			this.getDividendList()
+			this.getPledgeConfig()
 		},
 		methods: {
+      getPledgeConfig(){
+        getPledgeConfig().then(res=>{
+          if(res.code===1){
+            this.bnb_num=res.data.bnb_num
+            this.pledgeAddress=res.data.address
+          }
+        })
+      },
       setListTab(listTab) {
         if (this.listTab !== listTab) {
           this.listTab = listTab
+          this.pledgeNUm=''
         }
       },
 			getDividendList() {
@@ -56,6 +88,53 @@
 					}
 				})
 			},
+      async addPledge(){
+        if(this.listTab===1){
+          if(this.coinNum<this.pledgeNUm){
+            tools.error('DAO不足')
+            return
+          }
+        }else {
+          if(this.pledgeTotal<this.pledgeNUm){
+            tools.error('贡献不足')
+            return
+          }
+          let bnbNUm=tokenpocketBnb.getBalance(this.address)
+          if (bnbNUm<this.bnb_num){
+            tools.error('BNB不足')
+            return
+          }
+        }
+        let data=''
+        let transactionData
+        if(this.listTab===1){
+          data='0xa9059cbb'
+          //icon转账
+          let formHex=web3.utils.numberToHex(ethers.utils.parseEther(this.pledgeNUm.toString()).toString());
+          data=data+tools.replenishZero(this.pledgeAddress)+tools.replenishZero(formHex)
+           transactionData=await tokenpocketBnb.getContractTransaction(data, 0);
+        }else {
+          //bnb转账
+          transactionData=await tokenpocketBnb.getTransactionData(this.pledgeAddress, this.bnb_num);
+        }
+        tokenpocketBnb.sendTransaction(transactionData).then(res=>{
+          if(res){
+            addPledge({'type':this.listTab,'money':this.pledgeNUm,'hash':res}).then(res=>{
+              if(res.code===0){
+                this.pledgeNUm=''
+                tools.success(res.msg)
+                this.getTotalMoney()
+              }else {
+                tools.error(res.msg)
+              }
+            })
+          }else {
+            tools.error('发起失败')
+          }
+          console.log(res)
+        })
+
+      },
 			scrolltolower() {
 				if (this.list.length < this.total) {
 					++this.page
@@ -84,10 +163,10 @@
 
 			},
       setMax(){
-        if(this.type===1){
-          this.formNUm=this.usdtNum
+        if(this.listTab===1){
+          this.pledgeNUm=this.coinNum
         }else {
-          this.formNUm=this.iconNum
+          this.pledgeNUm=this.pledgeTotal
         }
       },
 		},
@@ -156,10 +235,10 @@
             </view>
           </view>
           <view>
-            <input v-model="pledgeNUm" :placeholder="'输入要'+(listTab===1 ?'质押':'解压')+'的DAO数量'" placeholder-class="fs-28"></input>
+            <input v-model="pledgeNUm"  :placeholder="'输入要'+(listTab===1 ?'质押':'解压')+'的DAO数量'" placeholder-class="fs-28"></input>
           </view>
         </view>
-        <view class="convent-but b-rad-20 text-align-center fs-28 fc-f" @click="">
+        <view class="convent-but b-rad-20 text-align-center fs-28 fc-f" @click="addPledge">
           确定
         </view>
       </view>