feat: enable changing the values of a select and add account to send

This commit is contained in:
Jonathan Rainville 2020-06-26 15:43:20 -04:00 committed by Iuri Matias
parent 4f4eff0ee8
commit 0bbb72a994
4 changed files with 53 additions and 13 deletions

View File

@ -29,6 +29,19 @@ QtObject:
proc getAccount*(self: AccountList, index: int): WalletAccount = self.accounts[index] proc getAccount*(self: AccountList, index: int): WalletAccount = self.accounts[index]
proc rowData(self: AccountList, index: int, column: string): string {.slot.} =
if (index >= self.accounts.len):
return
let account = self.accounts[index]
case column:
of "name": result = account.name
of "address": result = account.address
of "iconColor": result = account.iconColor
of "balance": result = account.balance
of "path": result = account.path
of "walletType": result = account.walletType
proc getAccountindexByAddress*(self: AccountList, address: string): int = proc getAccountindexByAddress*(self: AccountList, address: string): int =
var i = 0 var i = 0
for account in self.accounts: for account in self.accounts:

View File

@ -15,10 +15,22 @@ ModalPopup {
sendModalContent.amountInput.text = "" sendModalContent.amountInput.text = ""
sendModalContent.amountInput.forceActiveFocus(Qt.MouseFocusReason) sendModalContent.amountInput.forceActiveFocus(Qt.MouseFocusReason)
sendModalContent.defaultAccount = walletModel.getDefaultAccount() sendModalContent.defaultAccount = walletModel.getDefaultAccount()
const accounts = walletModel.accounts
const numAccounts = accounts.rowCount()
const accountsData = []
for (let i = 0; i < numAccounts; i++) {
accountsData.push({
name: accounts.rowData(i, 'name'),
address: accounts.rowData(i, 'address'),
iconColor: accounts.rowData(i, 'iconColor')
})
}
sendModalContent.accounts = accountsData
} }
SendModalContent { SendModalContent {
id: sendModalContent id: sendModalContent
accounts: walletModel.accounts
} }
footer: StyledButton { footer: StyledButton {

View File

@ -8,8 +8,9 @@ Item {
property alias amountText: txtAmount.text property alias amountText: txtAmount.text
property alias toText: txtTo.text property alias toText: txtTo.text
property alias passwordText: txtPassword.text property alias passwordText: txtPassword.text
property var accounts
property string defaultAccount: "0x1234" property string defaultAccount: "0x1234"
property string selectedAccount: "Account 1" property string selectedAccount: accounts[0].name
property string selectedFromAccountAddress: defaultAccount property string selectedFromAccountAddress: defaultAccount
anchors.left: parent.left anchors.left: parent.left
@ -30,20 +31,15 @@ Item {
anchors.top: txtAmount.bottom anchors.top: txtAmount.bottom
anchors.topMargin: Theme.padding anchors.topMargin: Theme.padding
selectedText: sendModalContent.selectedAccount selectedText: sendModalContent.selectedAccount
selectOptions: [ selectOptions: sendModalContent.accounts.map(function (account) {
{ return {
text: "Acount1", text: account.name,
onClicked: function () { onClicked: function () {
selectedAccount = "Account 1" selectedAccount = account.name
} selectedFromAccountAddress = account.address
},
{
text: "Acount2",
onClicked: function () {
selectedAccount = "Account 2"
} }
} }
] })
} }
Input { Input {

View File

@ -18,6 +18,10 @@ Item {
anchors.right: parent.right anchors.right: parent.right
anchors.left: parent.left anchors.left: parent.left
onSelectOptionsChanged: {
selectMenu.setupMenuItems()
}
StyledText { StyledText {
id: inputLabel id: inputLabel
text: inputBox.label text: inputBox.label
@ -67,6 +71,8 @@ Item {
} }
Menu { Menu {
property var items: []
id: selectMenu id: selectMenu
width: parent.width width: parent.width
padding: 10 padding: 10
@ -76,17 +82,30 @@ Item {
color: Theme.grey color: Theme.grey
radius: Theme.radius radius: Theme.radius
} }
Component.onCompleted: {
function setupMenuItems() {
if (selectMenu.items.length) {
// Remove old items
selectMenu.items.forEach(function (item) {
selectMenu.removeItem(item)
})
selectMenu.items = []
}
if (!selectOptions) { if (!selectOptions) {
return return
} }
selectOptions.forEach(function (element) { selectOptions.forEach(function (element) {
var item = menuItem.createObject(undefined, element) var item = menuItem.createObject(undefined, element)
selectMenu.items.push(item)
selectMenu.addItem(item) selectMenu.addItem(item)
}) })
} }
Component.onCompleted: {
setupMenuItems()
}
Component { Component {
id: menuItem id: menuItem
MenuItem { MenuItem {