Skip to content
This repository was archived by the owner on Feb 26, 2021. It is now read-only.

Commit 7bdb07c

Browse files
authored
Merge pull request #313 from th0br0/revert309310
revert #309 and #310
2 parents 42cff65 + edb229d commit 7bdb07c

File tree

3 files changed

+10
-83
lines changed

3 files changed

+10
-83
lines changed

ui/js/ui.login.js

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -127,22 +127,7 @@ var UI = (function(UI, $, undefined) {
127127
iota.api.getAccountData(connection.seed, function(error, accountData) {
128128
UI.isLoggingIn = false;
129129

130-
if (!error) {
131-
if (accountData.balance === 0) {
132-
//if no balance found, look at the first 10 addresses
133-
iota.api.getAccountData(connection.seed, {start:0 , end:10}, function(error, accountData) {
134-
if (!error) {
135-
connection.accountData = accountData;
136-
$("#login-password").val("");
137-
$("#login-btn").loadingReset("login", {"icon": "fa-cog fa-spin fa-fw"});
138-
139-
UI.showAppScreen();
140-
}
141-
});
142-
} else {
143-
connection.accountData = accountData;
144-
}
145-
}
130+
connection.accountData = accountData;
146131

147132
if (error) {
148133
connection.seed = "";

ui/js/ui.transfers.js

Lines changed: 8 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ var UI = (function(UI, $, undefined) {
6262

6363
UI.isDoingPOW = true;
6464

65-
getUnspentInputs(connection.seed, 0, 10, amount, function(error, inputs) {
65+
getUnspentInputs(connection.seed, 0, amount, function(error, inputs) {
6666
if (error) {
6767
UI.isDoingPOW = false;
6868
UI.formError("transfer", error, {"initial": "send_it_now"});
@@ -259,15 +259,12 @@ function filterSpentAddresses(inputs) {
259259
})
260260
}
261261

262-
function getUnspentInputs(seed, start, step, threshold, inputs, cb) {
263-
// TODO: define limit in settings to stop scanning for balance
264-
var limit = 500 //connection.maxIndex
265-
end = start + step
266-
if (arguments.length === 5) {
267-
cb = arguments[4]
262+
function getUnspentInputs(seed, start, threshold, inputs, cb) {
263+
if (arguments.length === 4) {
264+
cb = arguments[3]
268265
inputs = {inputs: [], totalBalance: 0, allBalance: 0}
269266
}
270-
getInputs(seed, {start: start, end: end, threshold: threshold}, (err, res) => {
267+
iota.api.getInputs(seed, {start: start, threshold: threshold}, (err, res) => {
271268
if (err) {
272269
cb(err)
273270
return
@@ -277,13 +274,9 @@ function getUnspentInputs(seed, start, step, threshold, inputs, cb) {
277274
var collected = filtered.reduce((sum, input) => sum + input.balance, 0)
278275
var diff = threshold - collected
279276
if (diff > 0) {
280-
start = end + 1
281-
end += step
282-
if (end > limit) {
283-
cb('Not enough balance')
284-
return
285-
}
286-
getUnspentInputs(seed, start, step, diff, {inputs: inputs.inputs.concat(filtered), totalBalance: inputs.totalBalance + collected, allBalance: inputs.allBalance}, cb)
277+
var ordered = res.inputs.sort((a, b) => a.keyIndex - b.keyIndex).reverse()
278+
var end = ordered[0].keyIndex
279+
getUnspentInputs(seed, end + 1, diff, {inputs: inputs.inputs.concat(filtered), totalBalance: inputs.totalBalance + collected, allBalance: inputs.allBalance}, cb)
287280
}
288281
else {
289282
cb(null, {inputs: inputs.inputs.concat(filtered), totalBalance: inputs.totalBalance + collected, allBalance: inputs.allBalance})
@@ -292,40 +285,3 @@ function getUnspentInputs(seed, start, step, threshold, inputs, cb) {
292285
})
293286
}
294287

295-
function getInputs(seed, options, cb) {
296-
if (!options) {
297-
options = {}
298-
}
299-
var start = options.start || 0
300-
var end = options.end || 10
301-
var security = options.security || 2
302-
var threshold = options.threshold || null
303-
addresses = []
304-
for (var i = start; i <= end; i++) {
305-
addresses.push(iota.api._newAddress(seed, i, security, false))
306-
}
307-
iota.api.getBalances(addresses, 100, (err, res) => {
308-
if (err) {
309-
cb(err)
310-
return
311-
}
312-
var inputs = []
313-
var sum = 0
314-
for (var i = 0; i < addresses.length; i++) {
315-
var balance = parseInt(res.balances[i])
316-
if (balance > 0) {
317-
sum += balance
318-
inputs.push({
319-
address: addresses[i],
320-
balance: balance,
321-
keyIndex: start + i,
322-
security: security
323-
})
324-
if (threshold && sum >= threshold) {
325-
break
326-
}
327-
}
328-
}
329-
cb(null, {inputs: inputs, totalBalance: sum})
330-
})
331-
}

ui/js/ui.update.js

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -74,24 +74,10 @@ var UI = (function(UI, $, undefined) {
7474
console.log(new Date());
7575

7676
if (!error) {
77-
if (accountData.balance === 0) {
78-
//if no balance found, look at the first 10 addresses
79-
iota.api.getAccountData(connection.seed, {start:0 , end:10}, function(error, accountData) {
80-
if (!error) {
81-
connection.previousAccountData = connection.accountData;
82-
connection.accountData = accountData;
83-
UI.update();
84-
85-
}
86-
});
87-
} else {
88-
connection.previousAccountData = connection.accountData;
89-
connection.accountData = accountData;
90-
}
9177
connection.previousAccountData = connection.accountData;
9278
connection.accountData = accountData;
9379
}
94-
80+
9581
isUpdatingState = false;
9682

9783
UI.createStateInterval(UI.updateIntervalTime);

0 commit comments

Comments
 (0)