@@ -12,34 +12,35 @@ const pollTransaction = (
12
12
} ;
13
13
14
14
const executePoll = async ( resolve , reject ) : Promise < any > => {
15
+ let response , result ;
15
16
try {
16
17
attempts += 1 ;
17
- const response = await fetch ( endpoint ( data ) , request ) ;
18
- const result = await response . json ( ) ;
19
-
20
- if ( ! response . ok ) {
21
- throw new Error ( JSON . stringify ( result ) ) ;
22
- }
18
+ response = await fetch ( endpoint ( data ) , request ) ;
19
+ result = await response . json ( ) ;
20
+ } catch ( e ) {
21
+ return reject ( e ) ;
22
+ }
23
23
24
- data = result . Token ;
24
+ if ( ! response . ok ) {
25
+ throw new Error ( JSON . stringify ( result ) ) ;
26
+ }
25
27
26
- if ( result . Status === 1 ) {
27
- return resolve ( result ) ;
28
- }
28
+ data = result . Token ;
29
29
30
- if ( result . Status === 2 ) {
31
- throw new Error ( 'Transaction Rejected' ) ;
32
- }
30
+ if ( result . Status === 1 ) {
31
+ return resolve ( result ) ;
32
+ }
33
33
34
- // Add a timeout
35
- if ( attempts === maxAttempts ) {
36
- throw new Error ( 'Timeout' ) ;
37
- }
34
+ if ( result . Status === 2 ) {
35
+ throw new Error ( 'Transaction Rejected' ) ;
36
+ }
38
37
39
- setTimeout ( executePoll , interval , resolve , reject ) ;
40
- } catch ( e ) {
41
- return reject ( e ) ;
38
+ // Add a timeout
39
+ if ( attempts === maxAttempts ) {
40
+ throw new Error ( 'Timeout' ) ;
42
41
}
42
+
43
+ setTimeout ( executePoll , interval , resolve , reject ) ;
43
44
} ;
44
45
45
46
return new Promise ( executePoll ) ;
0 commit comments