OSDN Git Service

update mnemonic function
authorZhiting Lin <zlin035@uottawa.ca>
Thu, 13 Aug 2020 07:57:40 +0000 (15:57 +0800)
committerZhiting Lin <zlin035@uottawa.ca>
Thu, 13 Aug 2020 07:57:40 +0000 (15:57 +0800)
src/assets/language/cn.js
src/components/MenubarComponent.vue
src/models/account.js
src/router.js
src/views/backup/backupMnemonic.vue
src/views/sideMenu/menuCreation.vue [deleted file]
src/views/wallets.vue [new file with mode: 0644]
src/views/welcome/creation.vue
src/views/welcome/mnemonic.vue
src/views/welcome/verifyMnemonic.vue

index c7fef38..a545f50 100644 (file)
@@ -227,7 +227,8 @@ const cn = {
   },
   mnemonic:{
     "title":"备份助记词",
-    "hint":"请牢记助记词,一旦丢失您的资产将无法找回!"
+    "hint":"请牢记助记词,一旦丢失您的资产将无法找回!",
+    "passwordHint":"请输入密码展示助记词"
   },
   verifyMnemonic:{
     "title":"验证助记词",
@@ -242,6 +243,7 @@ const cn = {
     BTM0005:'输入数量大于可用余额。',
     BTM0006:'输入有效的地址格式。',
     BTM0007:'钱包名称错误,请输入正确钱包名称。',
+    BTM0008:'密码不能为空'
   },
   successMsg:{
     createWallet:{
index c152dab..e886991 100644 (file)
@@ -5,7 +5,7 @@
           <div class="logo_divider"></div>
           <figure  :class="active('HOME')" v-on:click="toggleTab('HOME')"><i class="iconfont iconhome_filled"></i></figure>
           <figure  v-on:click=""><i class="iconfont iconbapp_filled"></i></figure>
-          <figure  v-on:click=""><i class="iconfont iconwallet_filled"></i></figure>
+          <figure :class="active('WALLETS')" v-on:click="toggleTab('WALLETS')"><i class="iconfont iconwallet_filled"></i></figure>
           <figure :class="active('BACKUP')" v-on:click="toggleTab('BACKUP')"><i class="iconfont iconbackup_filled"></i></figure>
         </section>
         <figure class="setting" :class="active('SETTINGS')" v-on:click="toggleTab('SETTINGS')">
                 RouteNames.BACKUP,
                 RouteNames.BACKUP_MNEMONIC,
               ]
+
+              const wallet_tab = [
+                RouteNames.WALLETS,
+              ]
               switch(name){
                 case 'HOME':{
                   if(home_tab.includes(this.$route.name)){
                   }
                   break;
                 }
+                case 'WALLETS':{
+                  if(wallet_tab.includes(this.$route.name)){
+                    return "active";
+                  }
+                  break;
+                }
 
                 default:
                   return ""
index daa751d..bebd6f7 100644 (file)
@@ -29,16 +29,21 @@ account.create = function(accountAlias, keyAlias, passwd, context) {
       resultObj.keyAlias = keyAlias
       resultObj.vMnemonic = false
 
-      _bytom.keychain.pairs[accountAlias] = resultObj
-      _bytom.currentAccount = resultObj
 
-      context[Actions.UPDATE_STORED_BYTOM](_bytom).then(() => {
-        resolve(ret)
-      })
-        .catch(error => {
-          reject(error)
-        })
+   
 
+      context[Actions.SET_MNEMONIC](resultObj['mnemonic']).then(()=>{
+        delete resultObj['mnemonic']
+
+        _bytom.keychain.pairs[accountAlias] = resultObj
+        _bytom.currentAccount = resultObj
+        context[Actions.UPDATE_STORED_BYTOM](_bytom).then(() => {
+          resolve(resultObj)
+        }).catch(e => { throw e })
+      })
+      .catch(error => {
+        reject(error)
+      })
     })
   })
   return retPromise
index b5a666d..706dc29 100644 (file)
@@ -39,7 +39,7 @@ export const RouteNames = {
   // CHANGE_PASSWORD:'changePassword',
   BACKUP:'backup',
   BACKUP_MNEMONIC:'backup-mnemonic',
-  // DESTROY:'destroy',
+  WALLETS:'wallets',
   // AUTO_LOCK:'autoLock',
   // LANGUAGE:'language',
   // KEYPAIRS:'keypairs',
@@ -213,14 +213,7 @@ const routers = [
           require(['@/views/sideMenu/homeMenu.vue'], resolve)
         },
         children: [
-          {
-            path: '/menu/account/create',
-            name: 'menu-account-creation',
-            meta: { title: '创建账户' },
-            component: resolve => {
-              require(['@/views/sideMenu/menuCreation.vue'], resolve)
-            }
-          },
+
           {
             path: '/menu/help',
             name: 'menu-help',
@@ -235,6 +228,14 @@ const routers = [
     ]
   },
   {
+    path: '/wallets',
+    name: RouteNames.WALLETS,
+    meta: { title: '钱包' },
+    component: resolve => {
+      require(['@/views/wallets.vue'], resolve)
+    }
+  },
+  {
     path: '/backup',
     name: RouteNames.BACKUP,
     meta: { title: '备份' },
index 70f7eb4..b4d2c92 100644 (file)
@@ -47,7 +47,7 @@
                 <span class="mnemonic" v-for="n in inputMnemonic">{{ n }} </span>
             </div>
             <p class="hint">{{ $t('backup.mnemonicHint') }}</p>
-            <button class="btn btn-primary">{{ $t("backup.ok") }}</button>
+            <button class="btn btn-primary" @click="back">{{ $t("backup.ok") }}</button>
         </section>
     </div>
 </template>
@@ -72,13 +72,16 @@ export default {
         ])
     },
     methods: {
+        back(){
+           this.$router.push({ name: RouteNames.BACKUP });
+        },
         ...mapActions([
         Actions.SET_MNEMONIC
       ])
     },
     mounted() {
       if (!this.mnemonic){
-        this.$router.push({ name: RouteNames.BACKUP })
+        this.back();
       }
     },
     beforeDestroy() {
diff --git a/src/views/sideMenu/menuCreation.vue b/src/views/sideMenu/menuCreation.vue
deleted file mode 100644 (file)
index 8290fab..0000000
+++ /dev/null
@@ -1,149 +0,0 @@
-<style scoped>
-  .form-item {
-      background: transparent;
-      margin: 0;
-      padding: 0;
-  }
-  .form-item .form-item-label {
-      float: none;
-      width: 200px;
-      margin: 0;
-      padding: 0;
-  }
-  .submit {
-      margin-top: 15px;
-      height: 48px;
-      padding: 15px;
-  }
-  .form{
-    border-radius:4px;
-    background: white;
-    padding: 20px 20px 28px;
-  }
-</style>
-
-<template>
-    <MenuPage :title="$t('createAccount.title')">
-        <div class="form">
-            <div class="form-item">
-                <label class="form-item-label">{{ $t('createAccount.accountAlias') }}</label>
-                <div class="form-item-content">
-                    <input type="text" v-model="formItem.accAlias">
-                </div>
-            </div>
-
-            <div class="form-item">
-                <label class="form-item-label">{{ $t('createAccount.keyPassword') }}</label>
-                <div class="form-item-content">
-                    <input type="password" v-model="formItem.passwd1">
-                </div>
-            </div>
-            <div class="form-item">
-                <label class="form-item-label">{{ $t('createAccount.confirmPassword') }}</label>
-                <div class="form-item-content">
-                    <input type="password" v-model="formItem.passwd2">
-                </div>
-            </div>
-            <div class="tips">{{tips}}</div>
-        </div>
-        <a class="btn btn-primary submit" @click="create">{{ $t('createAccount.create') }}</a>
-    </MenuPage>
-</template>
-
-<script>
-import account from "@/models/account";
-import * as Actions from '@/store/constants';
-import { mapActions, mapState, mapGetters } from 'vuex'
-
-export default {
-    name: "",
-    components: {},
-    data() {
-        return {
-            formItem: {
-                accAlias: "",
-                keyAlias: "",
-                passwd1: "",
-                passwd2: ""
-            },
-            tips: ""
-        };
-    },
-    computed: {
-      ...mapState([
-        'bytom'
-      ]),
-      ...mapGetters([
-        'net',
-        'netType'
-      ])
-    },
-    methods: {
-        create: function () {
-            if (this.formItem.accAlias == "") {
-                this.$dialog.show({
-                    body: this.$t("createAccount.inputAlias")
-                });
-                return;
-            }
-
-            if (this.formItem.passwd1 == "") {
-                this.$dialog.show({
-                    body: this.$t("createAccount.inputPass")
-                });
-                return;
-            }
-            if (this.formItem.passwd1 != this.formItem.passwd2) {
-                this.$dialog.show({
-                    body: this.$t('createAccount.passwordAgain')
-                });
-                return;
-            }
-
-            let loader = this.$loading.show({
-                container: this.fullPage ? null : this.$refs.formContainer,
-                canCancel: true,
-                onCancel: this.onCancel
-            });
-
-            account.setupNet(`${this.net}`);
-            if(this.netType === 'vapor'){
-              account.create(this.formItem.accAlias, null, this.formItem.passwd1, this).then((resp) => {
-                account.setupNet(`${this.net}vapor`);
-                return account.copy(resp.guid).then((currentRespAccount)=>{
-                  this[Actions.CREATE_NEW_BYTOM_ACCOUNT](currentRespAccount).then(()=>{
-                    loader.hide();
-                    this.$router.push('/');
-                  })
-                })
-              }).catch(err => {
-                console.log(err);
-                loader.hide();
-                this.$dialog.show({
-                  body: err.message
-                });
-              });
-            }else{
-              account.create(this.formItem.accAlias, null, this.formItem.passwd1,this).then(account => {
-                this[Actions.CREATE_NEW_BYTOM_ACCOUNT](account).then(()=>{
-                  loader.hide();
-                  this.$router.push('/');
-                })
-
-              }).catch(err => {
-                console.log(err);
-                loader.hide();
-                this.$dialog.show({
-                  body: err.message
-                });
-              });
-            }
-        },
-        ...mapActions([
-          Actions.CREATE_NEW_BYTOM_ACCOUNT,
-          Actions.UPDATE_STORED_BYTOM
-        ])
-    },
-    mounted() { }
-};
-</script>
diff --git a/src/views/wallets.vue b/src/views/wallets.vue
new file mode 100644 (file)
index 0000000..cd98129
--- /dev/null
@@ -0,0 +1,72 @@
+<style scoped>
+
+</style>
+
+<template>
+    <MenuPage :title="$t('createAccount.title')">
+        <div class="form">
+            <div class="form-item">
+                <label class="form-item-label">{{ $t('createAccount.accountAlias') }}</label>
+                <div class="form-item-content">
+                    <input type="text" v-model="formItem.accAlias">
+                </div>
+            </div>
+
+            <div class="form-item">
+                <label class="form-item-label">{{ $t('createAccount.keyPassword') }}</label>
+                <div class="form-item-content">
+                    <input type="password" v-model="formItem.passwd1">
+                </div>
+            </div>
+            <div class="form-item">
+                <label class="form-item-label">{{ $t('createAccount.confirmPassword') }}</label>
+                <div class="form-item-content">
+                    <input type="password" v-model="formItem.passwd2">
+                </div>
+            </div>
+            <div class="tips">{{tips}}</div>
+        </div>
+        <a class="btn btn-primary submit" @click="create">{{ $t('createAccount.create') }}</a>
+    </MenuPage>
+</template>
+
+<script>
+import account from "@/models/account";
+import * as Actions from '@/store/constants';
+import { mapActions, mapState, mapGetters } from 'vuex'
+
+export default {
+    name: "",
+    components: {},
+    data() {
+        return {
+            formItem: {
+                accAlias: "",
+                keyAlias: "",
+                passwd1: "",
+                passwd2: ""
+            },
+            tips: ""
+        };
+    },
+    computed: {
+      ...mapState([
+        'bytom'
+      ]),
+      ...mapGetters([
+        'net',
+        'netType'
+      ])
+    },
+    methods: {
+        create: function () {
+
+        },
+        ...mapActions([
+          Actions.CREATE_NEW_BYTOM_ACCOUNT,
+          Actions.UPDATE_STORED_BYTOM
+        ])
+    },
+    mounted() { }
+};
+</script>
index f9bb5cd..e2c4f72 100644 (file)
@@ -249,7 +249,8 @@ export default {
         ...mapActions([
           Actions.CREATE_NEW_BYTOM,
           Actions.IMPORT_BYTOM,
-          Actions.UPDATE_STORED_BYTOM
+          Actions.UPDATE_STORED_BYTOM,
+          Actions.SET_MNEMONIC
         ])
     },
     mounted() {
index 9ffa1e0..676614c 100644 (file)
         </h1>
       </div>
       <div class="divider"></div>
-      <div class="container">
-          <div>
-            <p class="hint">{{ $t('mnemonic.hint')}}</p>
-            <div class="mnemnonic-box">
-                <span class="mnemonic" v-for="n in mnemonic">{{ n }} </span>
-            </div>
+
+      <div v-if="mnemonic" class="container">
+        <div>
+          <p class="hint">{{ $t('mnemonic.hint')}}</p>
+          <div class="mnemnonic-box">
+            <span class="mnemonic" v-for="n in inputMnemonic">{{ n }} </span>
           </div>
-          <div>
-            <div class="btn btn-primary btn-round float-right" @click="$router.push({ name: 'welcome-verify-mnemonic' })"><i class="iconfont icon-right-arrow"></i></div>
+        </div>
+        <div>
+          <div class="btn btn-primary btn-round float-right" @click="$router.push({ name: 'welcome-verify-mnemonic' })">
+            <i class="iconfont icon-right-arrow"></i></div>
+        </div>
+      </div>
+      <div  class="container" v-else>
+        <div>
+          <div class="form">
+            <div class="form-item">
+              <div class="form-item-content">
+                <input type="password"
+                       id="passwd1"
+                       :placeholder="$t('mnemonic.passwordHint')"
+                       name="passwd1"
+                       ref="passwd1"
+                       v-model="passwd"
+                >
+              </div>
+            </div>
           </div>
         </div>
-     </div>
-      <Footer/>
+        <div>
+          <div class="btn btn-primary btn-round float-right" @click="showMnemonic">
+            <i class="iconfont icon-right-arrow"></i></div>
+        </div>
+
+      </div>
+    </div>
+    <Footer/>
   </div>
 </template>
 
 <script>
 import { getLanguage } from '@/assets/language'
 import { mapActions, mapGetters, mapState } from 'vuex'
+import account from "@/models/account";
+import {RouteNames} from '@/router'
+import * as Actions from '@/store/constants';
 
 export default {
     name: "",
+    data() {
+      return {
+        passwd:''
+      };
+    },
     computed: {
-        mnemonic: function () {
-            return this.currentAccount.mnemonic.split(' ')
+        inputMnemonic: function () {
+            return this.mnemonic? this.mnemonic.split(' '): null;
         },
       ...mapState([
-        'bytom'
+        'bytom',
+        'mnemonic'
       ]),
       ...mapGetters([
         'currentAccount'
       ])
     },
+    methods: {
+      showMnemonic: function () {
+          if (! this.passwd) {
+            this.$toast.error(
+              this.$t("error.BTM0008")
+            );
+            return;
+          }
+
+          const vault = this.currentAccount.vault;
+          try{
+            const mnemonic = account.decryptMnemonic(vault, this.passwd, this)
+            this[Actions.SET_MNEMONIC](mnemonic)
+          }
+          catch (e){
+            this.$toast.error(
+              e.message || e
+            );
+          }
+      },
+      ...mapActions([
+        Actions.SET_MNEMONIC
+      ])
+    },
 };
 </script>
index 33817a3..b767f18 100644 (file)
@@ -87,6 +87,7 @@ import { getLanguage } from '@/assets/language'
 import { mapActions, mapGetters, mapState } from 'vuex'
 import * as Actions from '@/store/constants';
 import { required } from "vuelidate/lib/validators";
+import {RouteNames} from '@/router'
 
 
 export default {
@@ -119,7 +120,8 @@ export default {
             return "form-item-label form-item-label-cn";
         },
       ...mapState([
-        'bytom'
+        'bytom',
+        'mnemonic'
       ]),
       ...mapGetters([
         'currentAccount'
@@ -146,7 +148,7 @@ export default {
           } else {
             const formMnemonic = this.inputMnemonic.trim()
 
-            if (formMnemonic !== this.currentAccount.mnemonic) {
+            if (formMnemonic !== this.mnemonic) {
               this.$toast.error(
                 this.$t("error.BTM0002")
               );
@@ -165,6 +167,11 @@ export default {
           Actions.UPDATE_STORED_BYTOM,
           Actions.PUSH_ALERT
         ])
+    },
+    mounted() {
+      if (!this.mnemonic){
+        this.$router.push({ name: RouteNames.MNEMONIC })
+      }
     }
 };
 </script>