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 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 =
var i = 0
for account in self.accounts:

View File

@ -15,10 +15,22 @@ ModalPopup {
sendModalContent.amountInput.text = ""
sendModalContent.amountInput.forceActiveFocus(Qt.MouseFocusReason)
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 {
id: sendModalContent
accounts: walletModel.accounts
}
footer: StyledButton {

View File

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

View File

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