Skip to content

Commit 8f086f9

Browse files
committed
Rework balance data
1 parent 223d168 commit 8f086f9

File tree

8 files changed

+126
-44
lines changed

8 files changed

+126
-44
lines changed

qml/common/Functions.qml

+9-6
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ Item {
2424
}
2525

2626
function formatPrice(input, digets) {
27+
return currencySymbol() + formatNumber(input, digets)
28+
}
29+
30+
function balanceResult(result) {
31+
console.debug("balance_result", result.result.BAT)
32+
}
33+
34+
function formatNumber(input, digets) {
2735

2836
if(digets === undefined) {
2937
digets = 6
@@ -34,12 +42,7 @@ Item {
3442
if (fixedPrecision < 0) {
3543
fixedPrecision = 0
3644
}
37-
38-
return currencySymbol() + input.toFixed(fixedPrecision)
39-
}
40-
41-
function balanceResult(result) {
42-
console.debug("balance_result", result.result.BAT)
45+
return input.toFixed(fixedPrecision)
4346
}
4447

4548
// Elements

qml/cover/CoverPage.qml

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import QtQuick 2.0
22
import Sailfish.Silica 1.0
3+
import "../common"
34

45
CoverBackground {
56
Label {
@@ -12,11 +13,11 @@ CoverBackground {
1213
id: coverAction
1314

1415
CoverAction {
15-
iconSource: "image://theme/icon-cover-next"
16+
iconSource: "image://theme/icon-cover-refresh"
1617
}
18+
}
1719

18-
CoverAction {
19-
iconSource: "image://theme/icon-cover-pause"
20-
}
20+
Functions {
21+
id: functions
2122
}
2223
}

qml/pages/Home.qml

+45-5
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ import "../views"
77
Page {
88

99
// Properties
10-
property var assetPrairs: []
1110
property bool loading: false
11+
property var assetPrairs: []
12+
property var assetsBalance: []
13+
property var totalBalance: 0
1214

1315
// Element values
1416
// The effective value will be restricted by ApplicationWindow.allowedOrientations
@@ -22,7 +24,7 @@ Page {
2224
}
2325

2426
function refreshData() {
25-
console.debug("Reload the data from the API")
27+
console.debug("Refresh Asset pairs")
2628
loading = true
2729
krakenApi.queryPublic(['AssetPairs'], refreshResult)
2830
}
@@ -79,6 +81,42 @@ Page {
7981
assetPrairs = results
8082

8183
loading = false
84+
85+
refreshBalanceData()
86+
}
87+
88+
89+
function refreshBalanceData() {
90+
console.debug("Refresh the balance data")
91+
krakenApi.queryPrivate(['Balance'], callbackBalanceData)
92+
}
93+
94+
function callbackBalanceData(data) {
95+
//console.debug("Balance result returned")
96+
var balance = data.result
97+
var newTotalBalance = 0
98+
var newAssetsBalance = []
99+
//console.debug("result:", JSON.stringify(balance))
100+
for (var idx in assetPrairs) {
101+
//console.debug("idx", assetPrairs[idx].key)
102+
//console.debug("Parent values", JSON.stringify(assetPrairs[idx]))
103+
if(balance[assetPrairs[idx].name]) {
104+
//console.debug("Amount of key", assetPrairs[idx].key, parseFloat(balance[assetPrairs[idx].name]))
105+
var bal = parseFloat(balance[assetPrairs[idx].name])
106+
if(bal > 0) {
107+
var assetTotal = bal * assetPrairs[idx].ticker.current
108+
newTotalBalance += assetTotal
109+
newAssetsBalance.push({
110+
name: assetPrairs[idx].name,
111+
balance: bal,
112+
total: assetTotal
113+
})
114+
}
115+
}
116+
}
117+
118+
assetsBalance = newAssetsBalance
119+
totalBalance = newTotalBalance
82120
}
83121

84122
function setCurrency(cur) {
@@ -148,15 +186,17 @@ Page {
148186
}
149187
}
150188

151-
model: [marketView, balanceView]
189+
model: [marketComponent, balanceComponent]
152190
Component {
153-
id: marketView
191+
id: marketComponent
154192
Market {
193+
id: marketView
155194
}
156195
}
157196
Component {
158-
id: balanceView
197+
id: balanceComponent
159198
Balance {
199+
id: balanceView
160200
}
161201
}
162202
}

qml/views/Balance.qml

+64-5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ SilicaFlickable {
99
anchors.fill: parent
1010
contentHeight: loginColumn.height + mainColumn.height
1111

12+
1213
// Elements
1314
Functions {
1415
id: functions
@@ -36,23 +37,81 @@ SilicaFlickable {
3637
}
3738

3839
// When credentials are set show the information needed
39-
Column {
40+
Item {
4041
visible: functions.apiKeyPresent()
4142
id: mainColumn
4243
width: parent.width
44+
height: Screen.height
4345

4446
PageHeader {
47+
id: currencyHeader
4548
title: qsTrId("balance") + " (" + settings.currency + ")"
4649
}
4750

48-
SectionHeader {
49-
text: qsTrId("total")
51+
PageHeader {
52+
id: totalBalanceHeader
53+
anchors.top: currencyHeader.bottom
54+
anchors.topMargin: 5
55+
56+
title: functions.formatPrice(totalBalance)
57+
5058
}
5159

52-
Label {
60+
SilicaListView {
61+
62+
// Element values
63+
id: assetsListView
64+
height: parent.height
65+
anchors.top: totalBalanceHeader.bottom
66+
anchors.topMargin: 5
67+
width: parent.width
68+
69+
model: assetsBalance
70+
visible: assetsBalance.length !== 0
5371
x: Theme.horizontalPageMargin
54-
text: functions.currencySymbol() + "100.00"
72+
73+
delegate: BackgroundItem {
74+
id: delegate
75+
76+
Column {
77+
id: pairLabel
78+
79+
Row {
80+
spacing: Theme.horizontalPageMargin
81+
82+
83+
Text {
84+
text: functions.formatPrice(assetsBalance[index].total)
85+
font.pixelSize: Theme.fontSizeMediumBase
86+
color: Theme.primaryColor
87+
rightPadding: 20 * Theme.pixelRatio
88+
}
89+
90+
Text {
91+
text: functions.formatNumber(assetsBalance[index].balance)
92+
font.pixelSize: Theme.fontSizeMediumBase
93+
color: Theme.primaryColor
94+
rightPadding: 20 * Theme.pixelRatio
95+
}
96+
97+
Text {
98+
text: assetsBalance[index].name
99+
font.pixelSize: Theme.fontSizeMediumBase
100+
color: Theme.primaryColor
101+
}
102+
}
103+
}
104+
105+
Separator {
106+
y: delegate.height
107+
width: parent.width
108+
}
109+
}
110+
VerticalScrollDecorator {
111+
}
55112
}
56113
}
57114

115+
116+
58117
}

qml/views/Market.qml

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ SilicaListView {
4848

4949
onClicked: pageStack.push(Qt.resolvedUrl("../pages/PairDetails.qml"), {
5050
"pair": assetPrairs[index]
51-
}) //console.log("Clicked " + assetPrairs[index].key)
51+
})
5252
}
5353
VerticalScrollDecorator {
5454
}

qml/views/PairLabel.qml

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ Item {
1313
"low": 0,
1414
"high": 0,
1515
"ask": 0,
16-
"bid": 0
16+
"bid": 0,
17+
"current": 0
1718
}
1819
})
1920
// Element values

translations/Kraken-de.ts

-11
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@
3939
<source></source>
4040
<translation type="unfinished"></translation>
4141
</message>
42-
<message id="total">
43-
<source></source>
44-
<translation type="unfinished"></translation>
45-
</message>
4642
</context>
4743
<context>
4844
<name>Balance</name>
@@ -51,13 +47,6 @@
5147
<translation type="unfinished"></translation>
5248
</message>
5349
</context>
54-
<context>
55-
<name>CoverPage</name>
56-
<message>
57-
<source>My Cover</source>
58-
<translation>Mein Cover</translation>
59-
</message>
60-
</context>
6150
<context>
6251
<name>Home</name>
6352
<message>

translations/Kraken.ts

-11
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@
3939
<source></source>
4040
<translation type="unfinished"></translation>
4141
</message>
42-
<message id="total">
43-
<source></source>
44-
<translation type="unfinished"></translation>
45-
</message>
4642
</context>
4743
<context>
4844
<name>Balance</name>
@@ -51,13 +47,6 @@
5147
<translation type="unfinished"></translation>
5248
</message>
5349
</context>
54-
<context>
55-
<name>CoverPage</name>
56-
<message>
57-
<source>My Cover</source>
58-
<translation type="unfinished"></translation>
59-
</message>
60-
</context>
6150
<context>
6251
<name>Home</name>
6352
<message>

0 commit comments

Comments
 (0)