diff --git a/src/app/modules/main/browser_section/current_account/module.nim b/src/app/modules/main/browser_section/current_account/module.nim index 6bff44a17d..46f553e55e 100644 --- a/src/app/modules/main/browser_section/current_account/module.nim +++ b/src/app/modules/main/browser_section/current_account/module.nim @@ -1,6 +1,7 @@ import NimQml import ../../../../global/global_singleton +import ../../../../core/eventemitter import ../../../../../app_service/service/wallet_account/service as wallet_account_service import ./io_interface, ./view, ./controller @@ -11,6 +12,7 @@ export io_interface type Module* = ref object of io_interface.AccessInterface delegate: delegate_interface.AccessInterface + events: EventEmitter view: View controller: Controller moduleLoaded: bool @@ -18,10 +20,12 @@ type proc newModule*( delegate: delegate_interface.AccessInterface, + events: EventEmitter, walletAccountService: wallet_account_service.Service, ): Module = result = Module() result.delegate = delegate + result.events = events result.currentAccountIndex = 0 result.view = newView(result) result.controller = newController(result, walletAccountService) @@ -38,6 +42,11 @@ method switchAccount*(self: Module, accountIndex: int) = method load*(self: Module) = singletonInstance.engine.setRootContextProperty("browserSectionCurrentAccount", newQVariant(self.view)) + self.events.on(SIGNAL_WALLET_ACCOUNT_DELETED) do(e:Args): + if(self.view.isAddressCurrentAccount(AccountDeleted(e).account.address)): + self.switchAccount(0) + self.view.connectedAccountDeleted() + self.controller.init() self.view.load() self.switchAccount(0) @@ -50,4 +59,4 @@ method viewDidLoad*(self: Module) = method switchAccountByAddress*(self: Module, address: string) = let accountIndex = self.controller.getIndex(address) - self.switchAccount(accountIndex) \ No newline at end of file + self.switchAccount(accountIndex) diff --git a/src/app/modules/main/browser_section/current_account/view.nim b/src/app/modules/main/browser_section/current_account/view.nim index e34ce3bf89..8b19d4272c 100644 --- a/src/app/modules/main/browser_section/current_account/view.nim +++ b/src/app/modules/main/browser_section/current_account/view.nim @@ -128,6 +128,7 @@ QtObject: self.delegate.switchAccountByAddress(address) + proc connectedAccountDeleted*(self: View) {.signal.} proc setData*(self: View, dto: wallet_account_service.WalletAccountDto) = self.name = dto.name @@ -163,3 +164,6 @@ proc setData*(self: View, dto: wallet_account_service.WalletAccountDto) = self.assets = assets self.assetsChanged() +proc isAddressCurrentAccount*(self: View, address: string): bool = + return self.address == address + diff --git a/src/app/modules/main/browser_section/module.nim b/src/app/modules/main/browser_section/module.nim index 746bb2b983..e53454a787 100644 --- a/src/app/modules/main/browser_section/module.nim +++ b/src/app/modules/main/browser_section/module.nim @@ -3,6 +3,7 @@ import io_interface import ../io_interface as delegate_interface import view import ../../../global/global_singleton +import ../../../core/eventemitter import provider/module as provider_module import bookmark/module as bookmark_module import dapps/module as dapps_module @@ -18,6 +19,7 @@ export io_interface type Module* = ref object of io_interface.AccessInterface delegate: delegate_interface.AccessInterface + events: EventEmitter view: View viewVariant: QVariant moduleLoaded: bool @@ -27,6 +29,7 @@ type currentAccountModule: current_account_module.AccessInterface proc newModule*(delegate: delegate_interface.AccessInterface, + events: EventEmitter, bookmarkService: bookmark_service.Service, settingsService: settings_service.Service, dappPermissionsService: dapp_permissions_service.Service, @@ -34,13 +37,14 @@ proc newModule*(delegate: delegate_interface.AccessInterface, walletAccountService: wallet_account_service.Service): Module = result = Module() result.delegate = delegate + result.events = events result.view = view.newView(result) result.viewVariant = newQVariant(result.view) result.moduleLoaded = false result.providerModule = provider_module.newModule(result, settingsService, providerService) result.bookmarkModule = bookmark_module.newModule(result, bookmarkService) result.dappsModule = dapps_module.newModule(result, dappPermissionsService, walletAccountService) - result.currentAccountModule = current_account_module.newModule(result, walletAccountService) + result.currentAccountModule = current_account_module.newModule(result, events, walletAccountService) method delete*(self: Module) = self.view.delete diff --git a/src/app/modules/main/module.nim b/src/app/modules/main/module.nim index 13fff2292d..4bd0506ee4 100644 --- a/src/app/modules/main/module.nim +++ b/src/app/modules/main/module.nim @@ -141,7 +141,7 @@ proc newModule*[T]( transactionService, collectible_service, walletAccountService, settingsService, savedAddressService, networkService, ) - result.browserSectionModule = browser_section_module.newModule(result, bookmarkService, settingsService, + result.browserSectionModule = browser_section_module.newModule(result, events, bookmarkService, settingsService, dappPermissionsService, providerService, walletAccountService) result.profileSectionModule = profile_section_module.newModule( result, events, accountsService, settingsService, stickersService, diff --git a/src/app/modules/main/wallet_section/module.nim b/src/app/modules/main/wallet_section/module.nim index 10d6420d33..ff428a16ab 100644 --- a/src/app/modules/main/wallet_section/module.nim +++ b/src/app/modules/main/wallet_section/module.nim @@ -107,6 +107,7 @@ method load*(self: Module) = self.events.on(SIGNAL_WALLET_ACCOUNT_SAVED) do(e:Args): self.setTotalCurrencyBalance() self.events.on(SIGNAL_WALLET_ACCOUNT_DELETED) do(e:Args): + self.switchAccount(0) self.setTotalCurrencyBalance() self.events.on(SIGNAL_WALLET_ACCOUNT_CURRENCY_UPDATED) do(e:Args): self.setTotalCurrencyBalance() diff --git a/src/app_service/service/wallet_account/service.nim b/src/app_service/service/wallet_account/service.nim index dbb53a988f..27bb1ece60 100644 --- a/src/app_service/service/wallet_account/service.nim +++ b/src/app_service/service/wallet_account/service.nim @@ -66,8 +66,8 @@ proc fetchNativeChainBalance(network: NetworkDto, accountAddress: string): float type AccountSaved = ref object of Args account: WalletAccountDto -type AccountDeleted = ref object of Args - account: WalletAccountDto +type AccountDeleted* = ref object of Args + account*: WalletAccountDto type CurrencyUpdated = ref object of Args diff --git a/ui/app/AppLayouts/Browser/popups/BrowserWalletMenu.qml b/ui/app/AppLayouts/Browser/popups/BrowserWalletMenu.qml index 0714d6f647..5691f847f8 100644 --- a/ui/app/AppLayouts/Browser/popups/BrowserWalletMenu.qml +++ b/ui/app/AppLayouts/Browser/popups/BrowserWalletMenu.qml @@ -104,6 +104,18 @@ Popup { } } + + Connections { + target: WalletStore.dappBrowserAccount + onConnectedAccountDeleted: { + popup.reload() + // This is done because when an account is deleted and the account is updated to default one, + // only the properties are updated and we need to listen to those events and update the selected account + accountSelectorRow.currentAddress = "" + accountSelector.selectedAccount = Qt.binding(function () {return WalletStore.dappBrowserAccount}) + } + } + Item { property string currentAddress: "" id: accountSelectorRow diff --git a/ui/app/AppLayouts/Wallet/WalletLayout.qml b/ui/app/AppLayouts/Wallet/WalletLayout.qml index 2a2c346a3f..cc58730f67 100644 --- a/ui/app/AppLayouts/Wallet/WalletLayout.qml +++ b/ui/app/AppLayouts/Wallet/WalletLayout.qml @@ -88,7 +88,6 @@ Item { if (newIndex > RootStore.accounts) { return } - selectedAccountIndex = newIndex RootStore.switchAccount(newIndex) } diff --git a/ui/app/AppLayouts/Wallet/views/LeftTabView.qml b/ui/app/AppLayouts/Wallet/views/LeftTabView.qml index b2383aba09..8d96706a5e 100644 --- a/ui/app/AppLayouts/Wallet/views/LeftTabView.qml +++ b/ui/app/AppLayouts/Wallet/views/LeftTabView.qml @@ -18,7 +18,6 @@ import "../stores" Rectangle { id: walletInfoContainer - property int selectedAccountIndex: 0 property var changeSelectedAccount: function(){} property var showSavedAddresses: function(showSavedAddresses){} property var emojiPopup: null @@ -162,7 +161,7 @@ Rectangle { delegate: StatusListItem { width: parent.width - highlighted: index === selectedAccountIndex + highlighted: RootStore.currentAccount.name === model.name title: model.name subTitle: Utils.toLocaleString(model.currencyBalance.toFixed(2), RootStore.locale, {"model.currency": true}) + " " + RootStore.currentCurrency.toUpperCase() icon.emoji: !!model.emoji ? model.emoji: ""