Переглянути джерело

Switch account when new account is created.

Lee Morgan 11 місяців тому
батько
коміт
ca326d741e
2 змінених файлів з 24 додано та 2 видалено
  1. 22 1
      src/views/js/data/User.js
  2. 2 1
      src/views/js/pages/CreateAccount.js

+ 22 - 1
src/views/js/data/User.js

@@ -26,9 +26,30 @@ export default class User{
         this._accounts.push(account);
     }
 
+    changeAccount(account){
+        if(typeof account === "number"){
+            this._currentAccount = 0;
+        }else if(typeof account === "string"){
+            for(let i = 0; i < this._accounts.length; i++){
+                if(this._accounts[i].id === account){
+                    this._currentAccount = i;
+                    break;
+                }
+            }
+        }else{
+            for(let i = 0; i < this._accounts.length; i++){
+                if(this.__accounts[i] === account){
+                    this._currentAccount = i;
+                    break;
+                }
+            }
+        }
+    }
+
     async decryptAndAddAccount(account){
         const data = await encryptionHandler.decrypt(account.data, account.iv);
 
-        this._accounts.push(new Account(account.id, data));
+        const newAccount = new Account(account.id, data);
+        this._accounts.push(newAccount);
     }
 }

+ 2 - 1
src/views/js/pages/CreateAccount.js

@@ -35,8 +35,9 @@ export default class CreateAccount extends Page{
             .then((response)=>{
                 if(response.error) throw response;
 
-                let account = new Account(response.id, data);
+                const account = new Account(response.id, data);
                 user.addAccount(account);
+                user.changeAccount(account);
                 changePage("home");
             })
             .catch((err)=>{