- networkToggle: function (val) {
- localStorage.bytomNet = this.network;
- account.setupNet(this.network);
- this.refreshAccounts();
- },
- accountToggle: function (selectedAccount) {
- localStorage.currentAccount = JSON.stringify(selectedAccount);
- this.currentAccount = selectedAccount;
- this.refreshAccounts();
+ netTypeToggle: function (event) {
+ const newNetType = event.target.value ==='bytom'? '' :event.target.value;
+
+ if( newNetType !== this.netType){
+ const bytom = this.bytom.clone();
+
+ bytom.settings.netType = newNetType;
+
+ account.setupNet(`${this.net}${newNetType}`)
+ if(newNetType === 'vapor'&& !this.currentAccount.vpAddress){
+ account.copy(this.currentAccount.guid).then(accounts => {
+ //update currentAccount
+ bytom.currentAccount = accounts
+
+ //update AccountList
+ const objectIndex = bytom.accountList.findIndex(a => a.guid == this.currentAccount.guid)
+ bytom.accountList[objectIndex].vpAddress = accounts.vpAddress
+
+ this[Actions.UPDATE_STORED_BYTOM](bytom).then(()=>{
+ this.refreshBalance(this.currentAccount.guid)
+ })
+ }).catch(e =>{
+ if(e.message == 'Error: wallet has exist'){
+ account.listVapor(this.currentAccount.guid).then(accounts => {
+ //update currentAccount
+ bytom.currentAccount = accounts
+
+ const objectIndex = bytom.accountList.findIndex(a => a.guid == this.currentAccount.guid)
+ bytom.accountList[objectIndex].vpAddress = accounts.vpAddress
+
+ this[Actions.UPDATE_STORED_BYTOM](bytom).then(()=>{
+ this.refreshBalance(this.currentAccount.guid)
+ })
+ })
+
+ }
+ })
+ }else{
+ this[Actions.UPDATE_STORED_BYTOM](bytom).then(()=>{
+ this.refreshBalance(this.currentAccount.guid)
+ })
+ }
+ }