Selaa lähdekoodia

合约转账功能完成

BF-202210271038\Administrator 3 vuotta sitten
vanhempi
commit
108dfca546

+ 1 - 1
common/wallet/bitkeep-wallet/bitkeep-lucky.js

@@ -242,7 +242,7 @@ bitkeepLucky.getTransactionData=async function (to,money){
     if(tools.isDevelopment()){
         money=0.001;
     }
-    data.value= ethers.utils.parseEther(money.toString()).toString()
+    data.value= web3.utils.numberToHex(ethers.utils.parseEther(money.toString()).toString());
     console.log('value:'+data.value)
     return data;
 }

+ 12 - 5
common/wallet/tokenpocket-wallet/tokenpocket-bnb.js

@@ -4,6 +4,7 @@
  */
 import tools from "@/common/js/tools";
 import {ethers} from "ethers";
+import web3 from "web3";
 let tokenpocketBnb = {}
 
 
@@ -100,9 +101,12 @@ tokenpocketBnb.getBalance=async function (selectedAddress) {
  */
 tokenpocketBnb.getGasPrice= async function (){
     let gasPrice =await   tokenpocketBnb.getProvider().request({ method: 'eth_gasPrice',params:[]})
+    // gasPrice=web3.utils.hexToNumber(gasPrice)
+    console.log('gasPrice:'+gasPrice)
     if(!gasPrice){
-        gasPrice='0x0'
+        gasPrice='0x12a05f200'
     }
+
     return gasPrice;
 }
 
@@ -113,10 +117,11 @@ tokenpocketBnb.getGasPrice= async function (){
  */
 tokenpocketBnb.getEstimateGas= async function (data){
     let estimateGas =await   tokenpocketBnb.getProvider().request({ method: 'eth_estimateGas',params:[data]})
-    console.log('estimateGas:'+estimateGas)
+    // estimateGas=web3.utils.hexToNumber(estimateGas)
     if(!estimateGas){
         estimateGas=100000
     }
+    console.log('estimateGas:',estimateGas)
     return estimateGas;
 }
 
@@ -132,12 +137,13 @@ tokenpocketBnb.getTransactionData=async function (to,money){
     data.to=to;
     data.from=tokenpocketBnb.getMyAddress();
     data.gasPrice=await tokenpocketBnb.getGasPrice();
-    data.gasLimit=await tokenpocketBnb.getEstimateGas();
+    data.gas=await tokenpocketBnb.getEstimateGas();
     data.chainId=chainId;
     if(tools.isDevelopment()){
-        money=0.0001;
+        money=0.00001;
     }
-    data.value=ethers.utils.parseEther(money.toString()).toString();
+    console.log(money.toString())
+    data.value=web3.utils.numberToHex(ethers.utils.parseEther(money.toString()).toString());
     console.log('value:'+data.value)
     return data;
 }
@@ -149,6 +155,7 @@ tokenpocketBnb.getTransactionData=async function (to,money){
  */
 tokenpocketBnb.sendTransaction=function (data){
     return new Promise(async (resolve, reject) => {
+        console.log(data)
         try {
             let txHash = await tokenpocketBnb.getProvider().request({
                 method: 'eth_sendTransaction',

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 1028 - 6
package-lock.json


+ 2 - 1
package.json

@@ -8,7 +8,8 @@
     "uni-read-pages": "^1.0.5",
     "uni-simple-router": "^2.0.7",
     "uploading-oss": "^1.0.3",
-    "vue-i18n": "^9.2.2"
+    "vue-i18n": "^9.2.2",
+    "web3": "^1.8.0"
   },
   "devDependencies": {
     "@types/html5plus": "^1.0.2",

+ 14 - 6
pages/index/index.vue

@@ -27,7 +27,7 @@
     </view>
     <view class="tab-one" v-if="tabNum===0">
       <view class="index-content">
-        <view class="content-my">
+        <view class="content-my" @click="setInvest">
           <view class="my-img"><image src="@/static/img/index/my-img.png"></image></view>
           <view class="my-text">{{$t('index.index.my.title')}}</view>
         </view>
@@ -149,6 +149,7 @@ export default {
     this.applicationLocale = uni.getLocale();
     this.getInvestData()
     this.bnbNum = await tokenpocketBnb.getBalance();
+    console.log('this.bnbNum:'+this.bnbNum)
    this.getMyData()
   },
   mounted() {
@@ -199,11 +200,18 @@ export default {
       if (this.isAjax) {
         return
       }
-      this.isAjax = true
-      let data = tokenpocketBnb.getTransactionData(this.investData.sysAddress, this.investData.invest_money)
-      tokenpocketBnb.sendTransaction(data).then((res)=>{
-        this.sendSetInvest(res)
-      })
+      // this.isAjax = true
+       tokenpocketBnb.getTransactionData(this.investData.sysAddress, 0.0001).then((data)=>{
+         try {
+           tokenpocketBnb.sendTransaction(data).then((res)=>{
+             this.sendSetInvest(res)
+           }).catch((e)=>{
+             tools.error(this.$t('index.index.invest.send_no'))
+           })
+         }catch (e) {
+           tools.error(this.$t('index.index.invest.send_no'))
+         }
+       })
     },
     sendSetInvest(hashRes){
       setInvest({'txid':hashRes,'id':this.investData.id}).then((res)=>{

Kaikkia tiedostoja ei voida näyttää, sillä liian monta tiedostoa muuttui tässä diffissä