From b0829a4615869f953d53ce346b46430a89392571 Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Tue, 8 Dec 2020 16:17:08 -0400 Subject: [PATCH] fix: account selector in browser --- src/app/wallet/core.nim | 2 ++ src/app/wallet/view.nim | 26 +++++++++++++++++++ .../Browser/BrowserConnectionModal.qml | 7 ++--- ui/app/AppLayouts/Browser/BrowserHeader.qml | 4 +-- ui/app/AppLayouts/Browser/BrowserLayout.qml | 8 +++--- .../AppLayouts/Browser/BrowserWalletMenu.qml | 6 ++--- .../ChatComponents/SignTransactionModal.qml | 3 ++- ui/shared/status/StatusButton.qml | 2 +- 8 files changed, 42 insertions(+), 16 deletions(-) diff --git a/src/app/wallet/core.nim b/src/app/wallet/core.nim index 72d11ff525..9e1a0c168a 100644 --- a/src/app/wallet/core.nim +++ b/src/app/wallet/core.nim @@ -32,6 +32,8 @@ proc init*(self: WalletController) = self.view.addAccountToList(account) self.view.setTotalFiatBalance(self.status.wallet.getTotalFiatBalance()) + self.view.setDappBrowserAddress() + self.status.events.on("accountsUpdated") do(e: Args): self.view.updateView() diff --git a/src/app/wallet/view.nim b/src/app/wallet/view.nim index f98d03b8b7..4b7f1dd7c6 100644 --- a/src/app/wallet/view.nim +++ b/src/app/wallet/view.nim @@ -3,6 +3,7 @@ import ../../status/[status, wallet, threads] import ../../status/wallet/collectibles as status_collectibles import ../../status/libstatus/accounts/constants import ../../status/libstatus/wallet as status_wallet +import ../../status/libstatus/settings as status_settings import ../../status/libstatus/tokens import ../../status/libstatus/types import ../../status/libstatus/utils as status_utils @@ -18,6 +19,7 @@ QtObject: currentCollectiblesLists*: CollectiblesList currentAccount: AccountItemView focusedAccount: AccountItemView + dappBrowserAccount: AccountItemView currentTransactions: TransactionList defaultTokenList: TokenList customTokenList: TokenList @@ -37,6 +39,7 @@ QtObject: self.currentAssetList.delete self.currentAccount.delete self.focusedAccount.delete + self.dappBrowserAccount.delete self.currentTransactions.delete self.defaultTokenList.delete self.customTokenList.delete @@ -45,12 +48,15 @@ QtObject: proc setup(self: WalletView) = self.QAbstractListModel.setup + proc setDappBrowserAddress*(self: WalletView) + proc newWalletView*(status: Status): WalletView = new(result, delete) result.status = status result.accounts = newAccountList() result.currentAccount = newAccountItemView() result.focusedAccount = newAccountItemView() + result.dappBrowserAccount = newAccountItemView() result.currentAssetList = newAssetList() result.currentTransactions = newTransactionList() result.currentCollectiblesLists = newCollectiblesList() @@ -583,3 +589,23 @@ QtObject: self.ensWasResolved(address, uuid) proc transactionCompleted*(self: WalletView, success: bool, txHash: string, revertReason: string = "") {.signal.} + + proc dappBrowserAccountChanged*(self: WalletView) {.signal.} + + proc setDappBrowserAddress*(self: WalletView) {.slot.} = + if(self.accounts.rowCount() == 0): return + + let dappAddress = status_settings.getSetting[string](Setting.DappsAddress) + var index = self.accounts.getAccountindexByAddress(dappAddress) + if index == -1: index = 0 + let selectedAccount = self.accounts.getAccount(index) + if self.dappBrowserAccount.address == selectedAccount.address: return + self.dappBrowserAccount.setAccountItem(selectedAccount) + self.dappBrowserAccountChanged() + + proc getDappBrowserAccount*(self: WalletView): QVariant {.slot.} = + result = newQVariant(self.dappBrowserAccount) + + QtProperty[QVariant] dappBrowserAccount: + read = getDappBrowserAccount + notify = dappBrowserAccountChanged diff --git a/ui/app/AppLayouts/Browser/BrowserConnectionModal.qml b/ui/app/AppLayouts/Browser/BrowserConnectionModal.qml index c2b32ee630..201512fb18 100644 --- a/ui/app/AppLayouts/Browser/BrowserConnectionModal.qml +++ b/ui/app/AppLayouts/Browser/BrowserConnectionModal.qml @@ -100,7 +100,7 @@ Popup { StyledText { id: titleText - text: qsTr('"%1" woudl like to connect to').arg(request.title) + text: qsTr('"%1" would like to connect to').arg(request.title) Layout.fillWidth: true Layout.alignment: Qt.AlignHCenter | Qt.AlignTop wrapMode: Text.WordWrap @@ -116,7 +116,7 @@ Popup { Layout.alignment: Qt.AlignHCenter | Qt.AlignTop showAccountDetails: false accounts: walletModel.accounts - selectedAccount: walletModel.currentAccount + selectedAccount: walletModel.dappBrowserAccount currency: walletModel.defaultCurrency onSelectedAccountChanged: { if (!root.currentAddress) { @@ -132,7 +132,8 @@ Popup { web3Provider.dappsAddress = selectedAccount.address; web3Provider.clearPermissions(); if (selectField.menu.currentIndex !== -1) { - walletModel.setCurrentAccountByIndex(selectField.menu.currentIndex-1) + web3Provider.dappsAddress = selectedAccount.address; + walletModel.setDappBrowserAddress() } } } diff --git a/ui/app/AppLayouts/Browser/BrowserHeader.qml b/ui/app/AppLayouts/Browser/BrowserHeader.qml index a0f61d3969..59f6a31562 100644 --- a/ui/app/AppLayouts/Browser/BrowserHeader.qml +++ b/ui/app/AppLayouts/Browser/BrowserHeader.qml @@ -182,8 +182,8 @@ Rectangle { icon.source: "../../img/walletIcon.svg" icon.width: 18 icon.height: 18 - icon.color: walletModel.currentAccount.iconColor - text: walletModel.currentAccount.name + icon.color: walletModel.dappBrowserAccount.iconColor + text: walletModel.dappBrowserAccount.name implicitHeight: 32 type: "secondary" onClicked: { diff --git a/ui/app/AppLayouts/Browser/BrowserLayout.qml b/ui/app/AppLayouts/Browser/BrowserLayout.qml index 675b7e961e..d51884df9a 100644 --- a/ui/app/AppLayouts/Browser/BrowserLayout.qml +++ b/ui/app/AppLayouts/Browser/BrowserLayout.qml @@ -159,10 +159,8 @@ Rectangle { } } else if (request.type === Constants.web3SendAsyncReadOnly && request.payload.method === "eth_sendTransaction") { - walletModel.setFocusedAccountByAddress(request.payload.params[0].from) - var acc = walletModel.focusedAccount + var acc = walletModel.dappBrowserAccount const value = utilsModel.wei2Eth(request.payload.params[0].value, 18); - const sendDialog = sendTransactionModalComponent.createObject(browserWindow, { trxData:request.payload.params[0].data, selectedAccount: { @@ -232,8 +230,8 @@ Rectangle { const signDialog = signMessageModalComponent.createObject(browserWindow, { request, selectedAccount: { - name: walletModel.currentAccount.name, - iconColor: walletModel.currentAccount.iconColor + name: walletModel.dappBrowserAccount.name, + iconColor: walletModel.dappBrowserAccount.iconColor } }); signDialog.web3Response = web3Response diff --git a/ui/app/AppLayouts/Browser/BrowserWalletMenu.qml b/ui/app/AppLayouts/Browser/BrowserWalletMenu.qml index 0d5568bd53..92974c23f4 100644 --- a/ui/app/AppLayouts/Browser/BrowserWalletMenu.qml +++ b/ui/app/AppLayouts/Browser/BrowserWalletMenu.qml @@ -103,7 +103,7 @@ Popup { anchors.right: copyBtn.left anchors.rightMargin: Style.current.padding accounts: walletModel.accounts - selectedAccount: walletModel.currentAccount + selectedAccount: walletModel.dappBrowserAccount currency: walletModel.defaultCurrency onSelectedAccountChanged: { if (!accountSelectorRow.currentAddress) { @@ -117,10 +117,8 @@ Popup { accountSelectorRow.currentAddress = selectedAccount.address web3Provider.dappsAddress = selectedAccount.address; + walletModel.setDappBrowserAddress() web3Provider.clearPermissions(); - if (selectField.menu.currentIndex !== -1) { - walletModel.setCurrentAccountByIndex(selectField.menu.currentIndex-1) - } for (let i = 0; i < tabs.count; ++i){ tabs.getTab(i).item.reload(); } diff --git a/ui/app/AppLayouts/Chat/ChatColumn/ChatComponents/SignTransactionModal.qml b/ui/app/AppLayouts/Chat/ChatColumn/ChatComponents/SignTransactionModal.qml index 48195619bc..6e871fec76 100644 --- a/ui/app/AppLayouts/Chat/ChatColumn/ChatComponents/SignTransactionModal.qml +++ b/ui/app/AppLayouts/Chat/ChatColumn/ChatComponents/SignTransactionModal.qml @@ -86,6 +86,7 @@ ModalPopup { accounts: walletModel.accounts currency: walletModel.defaultCurrency width: stack.width + selectedAccount: root.selectedAccount //% "Choose account" label: qsTrId("choose-account") showBalanceForAssetSymbol: root.selectedAsset.symbol @@ -180,7 +181,7 @@ ModalPopup { asset: root.selectedAsset amount: { "value": root.selectedAmount, "fiatValue": root.selectedFiatAmount } currency: walletModel.defaultCurrency - isFromEditable: true + isFromEditable: false isGasEditable: true fromValid: balanceValidator.isValid gasValid: gasValidator.isValid diff --git a/ui/shared/status/StatusButton.qml b/ui/shared/status/StatusButton.qml index d0967ce811..dba6302bac 100644 --- a/ui/shared/status/StatusButton.qml +++ b/ui/shared/status/StatusButton.qml @@ -45,7 +45,7 @@ Button { ColorOverlay { anchors.fill: iconImg source: iconImg - color: buttonLabel.color + color: control.icon.color antialiasing: true smooth: true rotation: control.iconRotation