@@ -7,8 +7,10 @@ import "../views"
7
7
Page {
8
8
9
9
// Properties
10
- property var assetPrairs: []
11
10
property bool loading: false
11
+ property var assetPrairs: []
12
+ property var assetsBalance: []
13
+ property var totalBalance: 0
12
14
13
15
// Element values
14
16
// The effective value will be restricted by ApplicationWindow.allowedOrientations
22
24
}
23
25
24
26
function refreshData () {
25
- console .debug (" Reload the data from the API " )
27
+ console .debug (" Refresh Asset pairs " )
26
28
loading = true
27
29
krakenApi .queryPublic ([' AssetPairs' ], refreshResult)
28
30
}
@@ -79,6 +81,42 @@ Page {
79
81
assetPrairs = results
80
82
81
83
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
82
120
}
83
121
84
122
function setCurrency (cur ) {
@@ -148,15 +186,17 @@ Page {
148
186
}
149
187
}
150
188
151
- model: [marketView, balanceView ]
189
+ model: [marketComponent, balanceComponent ]
152
190
Component {
153
- id: marketView
191
+ id: marketComponent
154
192
Market {
193
+ id: marketView
155
194
}
156
195
}
157
196
Component {
158
- id: balanceView
197
+ id: balanceComponent
159
198
Balance {
199
+ id: balanceView
160
200
}
161
201
}
162
202
}
0 commit comments