forked from blockchain/unused-My-Wallet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
poll-for-session-guid.js
45 lines (37 loc) · 1.07 KB
/
poll-for-session-guid.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
var counter = 0;
var isPolling = false;
function pollForSessionGUID() {
if (isPolling) return;
isPolling = true;
console.log('pollForSessionGUID()');
MyWallet.setLoadingText('Waiting For Authorization');
$.ajax({
dataType: 'json',
type: "GET",
url: root + 'wallet/poll-for-session-guid',
data : {format : 'plain'},
success: function (obj) {
var self = this;
if (obj.guid) {
isPolling = false;
MyWallet.makeNotice('success', 'misc-success', 'Authorization Successful');
MyWallet.setGUID(obj.guid, false);
} else {
if (counter < 600) {
++counter;
setTimeout(function() {
$.ajax(self);
}, 2000);
} else {
isPolling = false;
}
}
},
error : function() {
isPolling = false;
}
});
};
$(document).ready(function() {
pollForSessionGUID();
});