fix(wallet): fix account selector in the SendModal
This commit is contained in:
parent
de867f9218
commit
9448cd7fd4
|
@ -32,7 +32,7 @@ QtObject:
|
|||
|
||||
proc countChanged(self: Model) {.signal.}
|
||||
|
||||
proc getCount(self: Model): int {.slot.} =
|
||||
proc getCount*(self: Model): int {.slot.} =
|
||||
self.items.len
|
||||
|
||||
QtProperty[int] count:
|
||||
|
@ -73,6 +73,17 @@ QtObject:
|
|||
of ModelRole.CurrencyBalance:
|
||||
result = newQVariant(item.getCurrencyBalance())
|
||||
|
||||
proc rowData(self: Model, index: int, column: string): string {.slot.} =
|
||||
if (index >= self.items.len):
|
||||
return
|
||||
let item = self.items[index]
|
||||
case column:
|
||||
of "name": result = $item.getName()
|
||||
of "symbol": result = $item.getSymbol()
|
||||
of "balance": result = $item.getBalance()
|
||||
of "address": result = $item.getAddress()
|
||||
of "currencyBalance": result = $item.getCurrencyBalance()
|
||||
|
||||
proc setItems*(self: Model, items: seq[Item]) =
|
||||
self.beginResetModel()
|
||||
self.items = items
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import strformat
|
||||
import ../account_tokens/model as account_tokens
|
||||
|
||||
type
|
||||
Item* = object
|
||||
|
@ -11,6 +12,7 @@ type
|
|||
isWallet: bool
|
||||
isChat: bool
|
||||
currencyBalance: float64
|
||||
assets: account_tokens.Model
|
||||
|
||||
proc initItem*(
|
||||
name: string,
|
||||
|
@ -21,7 +23,8 @@ proc initItem*(
|
|||
walletType: string,
|
||||
isWallet: bool,
|
||||
isChat: bool,
|
||||
currencyBalance: float64
|
||||
currencyBalance: float64,
|
||||
assets: account_tokens.Model
|
||||
): Item =
|
||||
result.name = name
|
||||
result.address = address
|
||||
|
@ -32,6 +35,7 @@ proc initItem*(
|
|||
result.isWallet = isWallet
|
||||
result.isChat = isChat
|
||||
result.currencyBalance = currencyBalance
|
||||
result.assets = assets
|
||||
|
||||
proc `$`*(self: Item): string =
|
||||
result = fmt"""AllTokensItem(
|
||||
|
@ -45,6 +49,7 @@ proc `$`*(self: Item): string =
|
|||
isWallet: {self.isWallet},
|
||||
isChat: {self.isChat},
|
||||
currencyBalance: {self.currencyBalance},
|
||||
assets.len: {self.assets.getCount()},
|
||||
]"""
|
||||
|
||||
proc getName*(self: Item): string =
|
||||
|
@ -73,3 +78,6 @@ proc getIsChat*(self: Item): bool =
|
|||
|
||||
proc getCurrencyBalance*(self: Item): float64 =
|
||||
return self.currencyBalance
|
||||
|
||||
proc getAssets*(self: Item): account_tokens.Model =
|
||||
return self.assets
|
||||
|
|
|
@ -12,7 +12,8 @@ type
|
|||
WalletType,
|
||||
IsWallet,
|
||||
IsChat,
|
||||
CurrencyBalance
|
||||
CurrencyBalance,
|
||||
Assets
|
||||
|
||||
QtObject:
|
||||
type
|
||||
|
@ -56,6 +57,7 @@ QtObject:
|
|||
ModelRole.WalletType.int:"walletType",
|
||||
ModelRole.IsWallet.int:"isWallet",
|
||||
ModelRole.IsChat.int:"isChat",
|
||||
ModelRole.Assets.int:"assets",
|
||||
ModelRole.CurrencyBalance.int:"currencyBalance"
|
||||
}.toTable
|
||||
|
||||
|
@ -88,6 +90,8 @@ QtObject:
|
|||
result = newQVariant(item.getIsChat())
|
||||
of ModelRole.CurrencyBalance:
|
||||
result = newQVariant(item.getCurrencyBalance())
|
||||
of ModelRole.Assets:
|
||||
result = newQVariant(item.getAssets())
|
||||
|
||||
proc setItems*(self: Model, items: seq[Item]) =
|
||||
self.beginResetModel()
|
||||
|
|
|
@ -4,6 +4,8 @@ import eventemitter
|
|||
import ./io_interface, ./view, ./item, ./controller
|
||||
import ../../../../core/global_singleton
|
||||
import ../../../../../app_service/service/wallet_account/service as wallet_account_service
|
||||
import ../account_tokens/model as account_tokens
|
||||
import ../account_tokens/item as account_tokens_item
|
||||
|
||||
export io_interface
|
||||
|
||||
|
@ -33,8 +35,23 @@ method delete*[T](self: Module[T]) =
|
|||
|
||||
method refreshWalletAccounts*[T](self: Module[T]) =
|
||||
let walletAccounts = self.controller.getWalletAccounts()
|
||||
self.view.setItems(
|
||||
walletAccounts.map(w => initItem(
|
||||
|
||||
|
||||
let items = walletAccounts.map(proc (w: WalletAccountDto): Item =
|
||||
let assets = account_tokens.newModel()
|
||||
|
||||
|
||||
assets.setItems(
|
||||
w.tokens.map(t => account_tokens_item.initItem(
|
||||
t.name,
|
||||
t.symbol,
|
||||
t.balance,
|
||||
t.address,
|
||||
t.currencyBalance,
|
||||
))
|
||||
)
|
||||
|
||||
result = initItem(
|
||||
w.name,
|
||||
w.address,
|
||||
w.path,
|
||||
|
@ -43,9 +60,11 @@ method refreshWalletAccounts*[T](self: Module[T]) =
|
|||
w.walletType,
|
||||
w.isWallet,
|
||||
w.isChat,
|
||||
w.getCurrencyBalance()
|
||||
w.getCurrencyBalance(),
|
||||
assets
|
||||
))
|
||||
)
|
||||
|
||||
self.view.setItems(items)
|
||||
|
||||
method load*[T](self: Module[T]) =
|
||||
singletonInstance.engine.setRootContextProperty("walletSectionAccounts", newQVariant(self.view))
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
import NimQml
|
||||
import NimQml, sequtils, sugar
|
||||
|
||||
import ../../../../../app_service/service/wallet_account/service as wallet_account_service
|
||||
import ./io_interface
|
||||
import ../account_tokens/model as account_tokens
|
||||
import ../account_tokens/item as account_tokens_item
|
||||
|
||||
QtObject:
|
||||
type
|
||||
|
@ -15,6 +17,7 @@ QtObject:
|
|||
walletType: string
|
||||
isChat: bool
|
||||
currencyBalance: float64
|
||||
assets: account_tokens.Model
|
||||
|
||||
proc setup(self: View) =
|
||||
self.QObject.setup
|
||||
|
@ -98,6 +101,15 @@ QtObject:
|
|||
QtProperty[QVariant] currencyBalance:
|
||||
read = getCurrencyBalance
|
||||
notify = currencyBalanceChanged
|
||||
|
||||
proc getAssets(self: View): QVariant {.slot.} =
|
||||
return newQVariant(self.assets)
|
||||
|
||||
proc assetsChanged(self: View) {.signal.}
|
||||
|
||||
QtProperty[QVariant] assets:
|
||||
read = getAssets
|
||||
notify = assetsChanged
|
||||
|
||||
proc update(self: View, address: string, accountName: string, color: string) {.slot.} =
|
||||
self.delegate.update(address, accountName, color)
|
||||
|
@ -118,4 +130,18 @@ proc setData*(self: View, dto: wallet_account_service.WalletAccountDto) =
|
|||
self.isChat = dto.isChat
|
||||
self.isChatChanged()
|
||||
self.currencyBalance = dto.getCurrencyBalance()
|
||||
self.currencyBalanceChanged()
|
||||
self.currencyBalanceChanged()
|
||||
|
||||
let assets = account_tokens.newModel()
|
||||
|
||||
assets.setItems(
|
||||
dto.tokens.map(t => account_tokens_item.initItem(
|
||||
t.name,
|
||||
t.symbol,
|
||||
t.balance,
|
||||
t.address,
|
||||
t.currencyBalance,
|
||||
))
|
||||
)
|
||||
self.assets = assets
|
||||
self.assetsChanged()
|
|
@ -1 +1 @@
|
|||
Subproject commit 31cfc8833ab3a7ca231826033e98764a7a160ee9
|
||||
Subproject commit 41cc8cfbd941fb438636e9346b752ff57ec3638b
|
|
@ -4,7 +4,11 @@ QtObject {
|
|||
id: root
|
||||
property var chatsModelInst: chatsModel
|
||||
property var walletModelInst: walletModel
|
||||
|
||||
property var accounts: walletSectionAccounts.model
|
||||
property var currentAccount: walletSectionCurrent
|
||||
property var profileModelInst: profileModel
|
||||
property var assets: walletSectionAccountTokens.model
|
||||
property MessageStore messageStore: MessageStore { }
|
||||
|
||||
function setCommunityMuted(communityId, checked) {
|
||||
|
|
|
@ -705,6 +705,7 @@ Item {
|
|||
this.active = false
|
||||
}
|
||||
sourceComponent: SendModal {
|
||||
store: appMain.rootStore
|
||||
onOpened: {
|
||||
walletModel.gasView.getGasPrice()
|
||||
}
|
||||
|
|
|
@ -32,13 +32,14 @@ Item {
|
|||
if (!assets) {
|
||||
return
|
||||
}
|
||||
|
||||
selectedAsset = {
|
||||
name: assets.rowData(0, "name"),
|
||||
symbol: assets.rowData(0, "symbol"),
|
||||
value: assets.rowData(0, "value"),
|
||||
fiatBalanceDisplay: assets.rowData(0, "fiatBalanceDisplay"),
|
||||
value: assets.rowData(0, "balance"),
|
||||
fiatBalanceDisplay: assets.rowData(0, "currencyBalance"),
|
||||
address: assets.rowData(0, "address"),
|
||||
fiatBalance: assets.rowData(0, "fiatBalance")
|
||||
fiatBalance: assets.rowData(0, "currencyBalance")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -83,7 +84,7 @@ Item {
|
|||
MenuItem {
|
||||
id: itemContainer
|
||||
property bool isFirstItem: index === 0
|
||||
property bool isLastItem: index === assets.rowCount() - 1
|
||||
property bool isLastItem: index === assets.count - 1
|
||||
|
||||
width: parent.width
|
||||
height: 72
|
||||
|
@ -124,13 +125,13 @@ Item {
|
|||
StyledText {
|
||||
font.pixelSize: 15
|
||||
height: 22
|
||||
text: parseFloat(value).toFixed(4) + " " + symbol
|
||||
text: parseFloat(balance).toFixed(4) + " " + symbol
|
||||
}
|
||||
StyledText {
|
||||
font.pixelSize: 15
|
||||
anchors.right: parent.right
|
||||
height: 22
|
||||
text: fiatBalanceDisplay.toUpperCase()
|
||||
text: currencyBalance.toString().toUpperCase()
|
||||
color: Style.current.secondaryText
|
||||
}
|
||||
}
|
||||
|
@ -162,7 +163,7 @@ Item {
|
|||
cursorShape: Qt.PointingHandCursor
|
||||
anchors.fill: itemContainer
|
||||
onClicked: {
|
||||
root.selectedAsset = { address, name, value, symbol, fiatBalance, fiatBalanceDisplay }
|
||||
root.selectedAsset = { address, name, balance, symbol, currencyBalance, fiatBalanceDisplay: "" }
|
||||
select.menu.close()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -198,8 +198,8 @@ Item {
|
|||
if (!selectedAccount || !selAddressSource.selectedSource || (selAddressSource.selectedSource && selAddressSource.selectedSource.value !== RecipientSelector.Type.Account)) {
|
||||
return
|
||||
}
|
||||
const { address, name, iconColor, assets, fiatBalance } = selectedAccount
|
||||
root.selectedRecipient = { address, name, iconColor, assets, fiatBalance, type: RecipientSelector.Type.Account }
|
||||
const { address, name, color, assets, fiatBalance } = selectedAccount
|
||||
root.selectedRecipient = { address, name, color, assets, fiatBalance, type: RecipientSelector.Type.Account }
|
||||
}
|
||||
onIsValidChanged: root.validate()
|
||||
}
|
||||
|
@ -240,10 +240,10 @@ Item {
|
|||
selAccount.visible = true
|
||||
inpAddress.visible = selContact.visible = false
|
||||
root.height = Qt.binding(function() { return selAccount.height + txtLabel.height })
|
||||
const { iconColor, assets, fiatBalance } = selAccount.selectedAccount
|
||||
const { color, assets, fiatBalance } = selAccount.selectedAccount
|
||||
address = selAccount.selectedAccount.address
|
||||
name = selAccount.selectedAccount.name
|
||||
root.selectedRecipient = { address, name, iconColor, assets, fiatBalance, type: RecipientSelector.Type.Account }
|
||||
root.selectedRecipient = { address, name, color, assets, fiatBalance, type: RecipientSelector.Type.Account }
|
||||
if (root.selectedType !== RecipientSelector.Type.Account) root.selectedType = RecipientSelector.Type.Account
|
||||
root.isValid = selAccount.isValid
|
||||
break;
|
||||
|
|
|
@ -18,6 +18,7 @@ ModalPopup {
|
|||
property alias selectFromAccount: selectFromAccount
|
||||
property alias selectRecipient: selectRecipient
|
||||
property alias stack: stack
|
||||
property var store
|
||||
|
||||
//% "Send"
|
||||
title: qsTrId("command-button-send")
|
||||
|
@ -34,7 +35,7 @@ ModalPopup {
|
|||
function sendTransaction() {
|
||||
stack.currentGroup.isPending = true
|
||||
let success = false
|
||||
if(txtAmount.selectedAsset.address == ""){
|
||||
if(txtAmount.selectedAsset.address === ""){
|
||||
success = walletModel.transactionsView.transferEth(
|
||||
selectFromAccount.selectedAccount.address,
|
||||
selectRecipient.selectedRecipient.address,
|
||||
|
@ -84,9 +85,9 @@ ModalPopup {
|
|||
|
||||
StatusAccountSelector {
|
||||
id: selectFromAccount
|
||||
accounts: walletModel.accountsView.accounts
|
||||
accounts: root.store.accounts
|
||||
selectedAccount: {
|
||||
const currAcc = walletModel.accountsView.currentAccount
|
||||
const currAcc = root.store.currentAccount
|
||||
if (currAcc.walletType !== Constants.watchWalletType) {
|
||||
return currAcc
|
||||
}
|
||||
|
@ -105,7 +106,7 @@ ModalPopup {
|
|||
}
|
||||
RecipientSelector {
|
||||
id: selectRecipient
|
||||
accounts: walletModel.accountsView.accounts
|
||||
accounts: root.store.accounts
|
||||
contacts: profileModel.contacts.addedContacts
|
||||
//% "Recipient"
|
||||
label: qsTrId("recipient")
|
||||
|
|
|
@ -81,7 +81,7 @@ Item {
|
|||
visible: parent.visible
|
||||
anchors.fill: parent
|
||||
source: parent
|
||||
color: root.fromAccount && root.fromAccount.iconColor ? root.fromAccount.iconColor : Style.current.blue
|
||||
color: root.fromAccount && root.fromAccount.color ? root.fromAccount.color : Style.current.blue
|
||||
}
|
||||
}
|
||||
SVGImage {
|
||||
|
@ -190,7 +190,7 @@ Item {
|
|||
PropertyChanges {
|
||||
target: ovlToWallet
|
||||
visible: true
|
||||
color: root.toAccount.iconColor
|
||||
color: root.toAccount.color
|
||||
}
|
||||
PropertyChanges {
|
||||
target: txtToPrimary
|
||||
|
|
Loading…
Reference in New Issue