wkw 1 månad sedan
förälder
incheckning
5923fa913d
2 ändrade filer med 12 tillägg och 9 borttagningar
  1. 9 7
      src/pages/trade/index.vue
  2. 3 2
      src/utils/web.js

+ 9 - 7
src/pages/trade/index.vue

@@ -282,7 +282,7 @@ const WGTbalance = ref(0);
 const STTbalance = ref(0);
 const entry_fee = ref(0);
 const wgt_price = ref(0);
-const privateKey = window.android.getPrivateKey();//app
+const privateKey = ref('');
 // const privateKey = "0x4553077da5d773773dad0511c6e5d33142ae2c1bd05a3a8a4a7becbc0d23d9b5";//H5
 
 const bgClass = computed(() => {
@@ -291,8 +291,10 @@ const bgClass = computed(() => {
   return 'bg3';
 });
 const handleAddressUpdate = (addr) => {
+  privateKey.value = window.android.getPrivateKey();//app
   walletAddress.value = addr;
   getGameMatchList();
+  getnum(privateKey.value);
 };
 // 获取游戏赛事列表(三个tab)
 const getGameMatchList = async (type = true) => {
@@ -336,7 +338,7 @@ const openGamePopup = (value) => {
   showType.value=value;
 };
 // 获取余额
-const getnum = async () =>{
+const getnum = async (privateKey) =>{
   try {
     WGTbalance.value = await getBalance(privateKey,'wgt');
     STTbalance.value = await getBalance(privateKey,'stt');
@@ -385,7 +387,7 @@ const handleTokenSignUp = async (signUpFn, price) => {
     mask: true
   });
   try {
-    const result = await signUpFn(privateKey, price);
+    const result = await signUpFn(privateKey.value, price);
     if (result.status === "success") {
       await getMatchEnroll();
     } else {
@@ -442,7 +444,7 @@ const getsendSingleReward = async (prize_money) =>{
     mask: true
   });
   try {
-    const result = await sendSingleReward(privateKey,prize_money);
+    const result = await sendSingleReward(privateKey.value,prize_money);
     if (result.status === "success") {
       await getClaimPrize();
     }else{
@@ -463,9 +465,9 @@ const getsendSingleReward = async (prize_money) =>{
   }
 }
 
-onMounted(async () => {
-  getnum();
-});
+// onMounted(async () => {
+  
+// });
 </script>
   
   <style lang="scss" scoped>

+ 3 - 2
src/utils/web.js

@@ -3,8 +3,6 @@ import jlabiData from "@/utils/abijson/jlabi.json";
 import bmabiData from "@/utils/abijson/bmabi.json";
 import pubData from "@/utils/abijson/pub.json";
 
-const web3 = getWeb3();
-
 const TOKEN_ADDRESSES = {
     wgt: "0xCec9CE45f9E8f41016c89576CD27d74d5103c04c",
     stt: "0x45F07c7Fe9E12518eA0eec109506799384BE0a95"
@@ -19,6 +17,7 @@ function normalizePrivateKey(pk) {
 // 获取余额
 async function getBalance(privateKey, type) {
     try {
+        const web3 = await getWeb3();
         privateKey = normalizePrivateKey(privateKey);
         const { address } = web3.eth.accounts.privateKeyToAccount(privateKey);
         const tokenAddress = TOKEN_ADDRESSES[type.toLowerCase()];
@@ -44,6 +43,7 @@ async function sendSingleReward(privateKey, amount) {
     privateKey = normalizePrivateKey(privateKey);
 
     try {
+        const web3 = await getWeb3();
         const account = web3.eth.accounts.privateKeyToAccount(privateKey);
         const sender = account.address;
         const amountWei = web3.utils.toWei(amount.toString(), "ether");
@@ -86,6 +86,7 @@ async function tokenSignUp(privateKey, amount, type) {
     const tokenAmount = web3.utils.toWei(amount.toString(), "ether");
 
     try {
+        const web3 = await getWeb3();
         const account = web3.eth.accounts.privateKeyToAccount(privateKey);
         const sender = account.address;