فهرست منبع

Merge branch 'im-dev' into single-im-chat

wkw 1 ماه پیش
والد
کامیت
62ff7fbc5c
2فایلهای تغییر یافته به همراه29 افزوده شده و 22 حذف شده
  1. 21 21
      src/stores/modules/walletStore.js
  2. 8 1
      src/views/login/importWallet/index.vue

+ 21 - 21
src/stores/modules/walletStore.js

@@ -78,27 +78,27 @@ export const useWalletStore = defineStore("useWalletStore", {
         if (!web3) throw new Error("区块链连接失败");
 
         // 助记词路径
-        if (isMnemonic) {
-          let wordArray;
-          if (Array.isArray(this.words)) {
-            if (this.words.length === 1 && typeof this.words[0] === "string") {
-              wordArray = this.words[0].trim().split(/[\s,]+/).filter(Boolean);
-            } else {
-              wordArray = this.words.flat().map(w => String(w).trim()).filter(Boolean);
-            }
-          } else {
-            wordArray = String(this.words)
-              .trim()
-              .split(/[\s,]+/)
-              .filter(Boolean);
-          }
-          if (![12, 24].includes(wordArray.length)) {
-            throw new Error("助记词应为12或24个单词");
-          }
-          const mnemonic = wordArray.join(" ");
-          const hdwallet = web3.eth.accounts.wallet.create(1, mnemonic);
-          this.privateKey = hdwallet[0].privateKey;
-        }        
+        // if (isMnemonic) {
+        //   let wordArray;
+        //   if (Array.isArray(this.words)) {
+        //     if (this.words.length === 1 && typeof this.words[0] === "string") {
+        //       wordArray = this.words[0].trim().split(/[\s,]+/).filter(Boolean);
+        //     } else {
+        //       wordArray = this.words.flat().map(w => String(w).trim()).filter(Boolean);
+        //     }
+        //   } else {
+        //     wordArray = String(this.words)
+        //       .trim()
+        //       .split(/[\s,]+/)
+        //       .filter(Boolean);
+        //   }
+        //   if (![12, 24].includes(wordArray.length)) {
+        //     throw new Error("助记词应为12或24个单词");
+        //   }
+        //   const mnemonic = wordArray.join(" ");
+        //   const hdwallet = web3.eth.accounts.wallet.create(1, mnemonic);
+        //   this.privateKey = hdwallet[0].privateKey;
+        // }        
         if (!/^0x[0-9a-fA-F]{64}$/.test(this.privateKey)) {
           throw new Error("私钥格式不正确");
         }

+ 8 - 1
src/views/login/importWallet/index.vue

@@ -76,6 +76,7 @@ import _ from "lodash";
 import { cryptoEncode } from "@/utils/crypto.js"
 import { useRoute } from "vue-router";
 import { useWalletStore } from "@/stores/modules/walletStore";
+import { createAccent } from "@/api/path/login.api";
  
 
 const router = useRouter();
@@ -103,7 +104,13 @@ const onSubmit = async () => {
   data.password = cryptoEncode(data.password) 
   walletStore.accountPassword = data.password ;
   walletStore.accountHint = form.value.promptMessage;
-  await walletStore.loginWithPrivateKey(type != 0);
+  if(type == 1){
+    const res = await createAccent({words: form.value.userKey.trim().split(',')});
+    let walletData = JSON.parse(atob(res.data.content));
+    walletStore.account = walletData.address;
+    walletStore.privateKey = walletData.privateKey;
+  }
+  await walletStore.loginWithPrivateKey();
   loading.value = false;
   router.push({
     path: "/wallet",