@@ -21,14 +21,29 @@ const checkLoginData = function (transaction, loginCode, loginContract) {
21
21
} ;
22
22
23
23
class WebTransportLink {
24
- constructor ( esrUtil , pollingInterval = 2000 ) {
24
+ constructor (
25
+ esrUtil ,
26
+ pollingInterval = 1000 ,
27
+ transactionCheckInterval = 500 ,
28
+ pollTimeout = 10 * 60 * 1000 , // 10 minutes
29
+ transactionCheckTimeout = 30 * 1000 // 30 seconds
30
+ ) {
31
+ if ( ! esrUtil || ! esrUtil . rpc ) {
32
+ throw new Error ( "Invalid esrUtil or esrUtil.rpc not found " + esrUtil ) ;
33
+ }
34
+
25
35
this . dialog = new Dialog ( ) ;
26
36
this . esrUtil = esrUtil ;
27
37
this . rpc = esrUtil . rpc ;
28
38
this . pollingInterval = pollingInterval ;
39
+ this . transactionCheckInterval = transactionCheckInterval ;
40
+ this . pollTimeout = pollTimeout ;
41
+ this . transactionCheckTimeout = transactionCheckTimeout ;
29
42
this . login = this . login . bind ( this ) ;
30
43
this . restore = this . restore . bind ( this ) ;
31
44
this . logout = this . logout . bind ( this ) ;
45
+ this . checkTransactionId = this . checkTransactionId . bind ( this ) ;
46
+
32
47
}
33
48
34
49
getContractFromTransaction ( transactions ) {
@@ -45,6 +60,17 @@ class WebTransportLink {
45
60
const data = response . text ( ) ;
46
61
return data ;
47
62
} catch ( e ) {
63
+ //console.error("error polling: " + e)
64
+ return ;
65
+ }
66
+ }
67
+
68
+ async checkTransactionId ( txId ) {
69
+ try {
70
+ const transactionInfo = await this . rpc . history_get_transaction ( txId ) ;
71
+ return transactionInfo ;
72
+ } catch ( e ) {
73
+ //console.log("checkTransactionId error: " + e)
48
74
return ;
49
75
}
50
76
}
@@ -74,7 +100,7 @@ class WebTransportLink {
74
100
throw new UALHyphaWalletError (
75
101
"No transaction has been passed to sign transaction"
76
102
) ;
77
- const { pollingInterval } = this ;
103
+ const { pollingInterval, transactionCheckInterval , pollTimeout , transactionCheckTimeout } = this ;
78
104
const uid = getTransactionUID ( transaction ) ;
79
105
const callbackUrl = `${ CALLBACK_HOST } /transaction?uid=${ uid } &tx_id={{tx}}` ;
80
106
const esr = await this . esrUtil . encodeESR (
@@ -100,9 +126,9 @@ class WebTransportLink {
100
126
101
127
await this . dialog . showDialog ( dialog ) ;
102
128
103
- const txId = await poll ( this . checkForConfirmation , uid , pollingInterval ) ;
129
+ const txId = await poll ( this . checkForConfirmation , uid , pollingInterval , pollTimeout ) ;
104
130
105
- const transactionInfo = await this . rpc . history_get_transaction ( txId ) ;
131
+ const transactionInfo = await poll ( this . checkTransactionId , txId , transactionCheckInterval , transactionCheckTimeout ) ;
106
132
107
133
this . dialog . hide ( ) ;
108
134
return transactionInfo ;
0 commit comments