fix: account selector in browser

This commit is contained in:
Richard Ramos 2020-12-08 16:17:08 -04:00 committed by Iuri Matias
parent 08a7baed8f
commit b0829a4615
8 changed files with 42 additions and 16 deletions

View File

@ -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()

View File

@ -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

View File

@ -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()
}
}
}

View File

@ -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: {

View File

@ -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

View File

@ -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();
}

View File

@ -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

View File

@ -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