fix: fix defaultTokenList use in QML
This commit is contained in:
parent
103f02b289
commit
17aa8d274e
|
@ -7,7 +7,8 @@ type
|
||||||
Name = UserRole + 1,
|
Name = UserRole + 1,
|
||||||
Symbol = UserRole + 2,
|
Symbol = UserRole + 2,
|
||||||
HasIcon = UserRole + 3,
|
HasIcon = UserRole + 3,
|
||||||
Address = UserRole + 4
|
Address = UserRole + 4,
|
||||||
|
Decimals = UserRole + 5
|
||||||
|
|
||||||
QtObject:
|
QtObject:
|
||||||
type TokenList* = ref object of QAbstractListModel
|
type TokenList* = ref object of QAbstractListModel
|
||||||
|
@ -38,6 +39,17 @@ QtObject:
|
||||||
result.tokens = @[]
|
result.tokens = @[]
|
||||||
result.setup
|
result.setup
|
||||||
|
|
||||||
|
proc rowData(self: TokenList, index: int, column: string): string {.slot.} =
|
||||||
|
if (index >= self.tokens.len):
|
||||||
|
return
|
||||||
|
let token = self.tokens[index]
|
||||||
|
case column:
|
||||||
|
of "name": result = token["name"].getStr
|
||||||
|
of "symbol": result = token["symbol"].getStr
|
||||||
|
of "hasIcon": result = $token["hasIcon"].getBool
|
||||||
|
of "address": result = token["address"].getStr
|
||||||
|
of "decimals": result = $token["decimals"].getInt
|
||||||
|
|
||||||
method rowCount(self: TokenList, index: QModelIndex = nil): int =
|
method rowCount(self: TokenList, index: QModelIndex = nil): int =
|
||||||
return self.tokens.len
|
return self.tokens.len
|
||||||
|
|
||||||
|
@ -53,10 +65,12 @@ QtObject:
|
||||||
of TokenRoles.Symbol: result = newQVariant(token["symbol"].getStr)
|
of TokenRoles.Symbol: result = newQVariant(token["symbol"].getStr)
|
||||||
of TokenRoles.HasIcon: result = newQVariant(token{"hasIcon"}.getBool)
|
of TokenRoles.HasIcon: result = newQVariant(token{"hasIcon"}.getBool)
|
||||||
of TokenRoles.Address: result = newQVariant(token["address"].getStr)
|
of TokenRoles.Address: result = newQVariant(token["address"].getStr)
|
||||||
|
of TokenRoles.Decimals: result = newQVariant(token["decimals"].getInt)
|
||||||
|
|
||||||
method roleNames(self: TokenList): Table[int, string] =
|
method roleNames(self: TokenList): Table[int, string] =
|
||||||
{TokenRoles.Name.int:"name",
|
{TokenRoles.Name.int:"name",
|
||||||
TokenRoles.Symbol.int:"symbol",
|
TokenRoles.Symbol.int:"symbol",
|
||||||
TokenRoles.HasIcon.int:"hasIcon",
|
TokenRoles.HasIcon.int:"hasIcon",
|
||||||
TokenRoles.Address.int:"address"}.toTable
|
TokenRoles.Address.int:"address",
|
||||||
|
TokenRoles.Decimals.int:"decimals"}.toTable
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,19 @@ Item {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
property var tokens: {
|
||||||
|
const count = walletModel.defaultTokenList.rowCount()
|
||||||
|
const toks = []
|
||||||
|
for (var i = 0; i < count; i++) {
|
||||||
|
toks.push({
|
||||||
|
"address": walletModel.defaultTokenList.rowData(i, 'address'),
|
||||||
|
"name": walletModel.defaultTokenList.rowData(i, 'name'),
|
||||||
|
"decimals": parseInt(walletModel.defaultTokenList.rowData(i, 'decimals'), 10),
|
||||||
|
"symbol": walletModel.defaultTokenList.rowData(i, 'symbol')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return toks
|
||||||
|
}
|
||||||
property var token: {
|
property var token: {
|
||||||
if (commandParametersObject.contract === "") {
|
if (commandParametersObject.contract === "") {
|
||||||
return {
|
return {
|
||||||
|
@ -35,13 +48,14 @@ Item {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let count = walletModel.defaultTokenList.items.count
|
const count = root.tokens.length
|
||||||
for (let i = 0; i < count; i++) {
|
for (var i = 0; i < count; i++) {
|
||||||
let token = walletModel.defaultTokenList.items.get(i)
|
let token = root.tokens[i]
|
||||||
if (commandParametersObject.contract === token.address) {
|
if (token.address === commandParametersObject.contract) {
|
||||||
return token
|
return token
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {}
|
return {}
|
||||||
}
|
}
|
||||||
property string tokenAmount: {
|
property string tokenAmount: {
|
||||||
|
|
|
@ -5,14 +5,29 @@ import "../../../imports"
|
||||||
import "../../../shared"
|
import "../../../shared"
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
|
property var tokens: {
|
||||||
|
const count = walletModel.defaultTokenList.rowCount()
|
||||||
|
const toks = []
|
||||||
|
for (var i = 0; i < count; i++) {
|
||||||
|
toks.push({
|
||||||
|
"address": walletModel.defaultTokenList.rowData(i, 'address'),
|
||||||
|
"symbol": walletModel.defaultTokenList.rowData(i, 'symbol')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return toks
|
||||||
|
}
|
||||||
|
|
||||||
function checkIfHistoryIsBeingFetched() {
|
function checkIfHistoryIsBeingFetched() {
|
||||||
if (walletModel.isFetchingHistory(walletModel.currentAccount.address)) {
|
if (walletModel.isFetchingHistory(walletModel.currentAccount.address)) {
|
||||||
loadingImg.active = true;
|
loadingImg.active = true
|
||||||
} else {
|
} else {
|
||||||
walletModel.loadTransactionsForAccount(walletModel.currentAccount.address)
|
walletModel.loadTransactionsForAccount(
|
||||||
|
walletModel.currentAccount.address)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
id: root
|
||||||
|
|
||||||
Loader {
|
Loader {
|
||||||
id: loadingImg
|
id: loadingImg
|
||||||
active: false
|
active: false
|
||||||
|
@ -50,12 +65,12 @@ Item {
|
||||||
radius: 8
|
radius: 8
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
// TODO: test if this work. I could not obtain any transaction history
|
const count = root.tokens.length
|
||||||
for (let i = 0; i < walletModel.defaultTokenList.items.count; i++) {
|
for (var i = 0; i < count; i++) {
|
||||||
let token = walletModel.defaultTokenList.items.get(i)
|
let token = root.tokens[i]
|
||||||
if (token.address == contract) {
|
if (token.address === contract) {
|
||||||
transactionListItem.symbol = token.symbol
|
transactionListItem.symbol = token.symbol
|
||||||
break;
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -82,7 +97,9 @@ Item {
|
||||||
id: assetIcon
|
id: assetIcon
|
||||||
width: 40
|
width: 40
|
||||||
height: 40
|
height: 40
|
||||||
source: "../../img/tokens/" + (transactionListItem.symbol != "" ? transactionListItem.symbol : "ETH") + ".png"
|
source: "../../img/tokens/"
|
||||||
|
+ (transactionListItem.symbol
|
||||||
|
!= "" ? transactionListItem.symbol : "ETH") + ".png"
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
anchors.top: parent.top
|
anchors.top: parent.top
|
||||||
anchors.topMargin: 12
|
anchors.topMargin: 12
|
||||||
|
@ -103,8 +120,8 @@ Item {
|
||||||
anchors.leftMargin: 22
|
anchors.leftMargin: 22
|
||||||
height: 15
|
height: 15
|
||||||
width: 15
|
width: 15
|
||||||
color: to != walletModel.currentAccount.address ? "#4360DF" : "green"
|
color: to !== walletModel.currentAccount.address ? "#4360DF" : "green"
|
||||||
text: to != walletModel.currentAccount.address ? "↑" : "↓"
|
text: to !== walletModel.currentAccount.address ? "↑" : "↓"
|
||||||
}
|
}
|
||||||
|
|
||||||
StyledText {
|
StyledText {
|
||||||
|
@ -125,7 +142,9 @@ Item {
|
||||||
width: children[0].width + children[1].width
|
width: children[0].width + children[1].width
|
||||||
|
|
||||||
StyledText {
|
StyledText {
|
||||||
text: to != walletModel.currentAccount.address ? "To " : "From "
|
text: to !== walletModel.currentAccount.address ?
|
||||||
|
qsTr("To ") :
|
||||||
|
qsTr("From ")
|
||||||
anchors.right: addressValue.left
|
anchors.right: addressValue.left
|
||||||
color: Style.current.darkGrey
|
color: Style.current.darkGrey
|
||||||
anchors.top: parent.top
|
anchors.top: parent.top
|
||||||
|
@ -196,3 +215,4 @@ Designer {
|
||||||
D{i:0;autoSize:true;height:480;width:640}
|
D{i:0;autoSize:true;height:480;width:640}
|
||||||
}
|
}
|
||||||
##^##*/
|
##^##*/
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue