File tree Expand file tree Collapse file tree 1 file changed +17
-4
lines changed Expand file tree Collapse file tree 1 file changed +17
-4
lines changed Original file line number Diff line number Diff line change
1
+ import { BigNumberish } from 'ethers' ;
1
2
import { DateTime } from 'luxon' ;
2
3
3
4
/** Calculation bases */
@@ -44,8 +45,12 @@ export const validateDurationFormat = (str: string): DurationFormat => {
44
45
* @param {(string | number) } str
45
46
* @returns {number }
46
47
*/
47
- export const parseSeconds = ( str : string | number ) : number => {
48
+ export const parseSeconds = ( str : string | number | bigint ) : bigint => {
48
49
if ( typeof str === 'number' ) {
50
+ return BigInt ( str ) ;
51
+ }
52
+
53
+ if ( typeof str === 'bigint' ) {
49
54
return str ;
50
55
}
51
56
@@ -82,9 +87,17 @@ export const parseSeconds = (str: string | number): number => {
82
87
throw new Error ( 'Unknown duration type' ) ;
83
88
}
84
89
85
- return Math . ceil ( parsed ) ;
90
+ return BigInt ( Math . ceil ( parsed ) ) ;
86
91
} ;
87
92
93
+ /**
94
+ * Parses expiration time
95
+ * @param {string | BigNumberish } expire Given expiration time
96
+ * @returns {bigint }
97
+ */
98
+ export const parseExpire = ( expire : string | BigNumberish ) : bigint =>
99
+ typeof expire === 'string' ? BigInt ( nowSec ( ) ) + parseSeconds ( expire ) : parseSeconds ( expire ) ;
100
+
88
101
/**
89
102
* Converts milliseconds to seconds
90
103
*
@@ -103,7 +116,7 @@ export const nowSec = () => Math.round(DateTime.now().toSeconds());
103
116
/**
104
117
* Checks expiration time
105
118
*
106
- * @param {number } expire
119
+ * @param {BigNumberish } expire
107
120
* @returns {boolean }
108
121
*/
109
- export const isExpired = ( expire : number ) : boolean => nowSec ( ) + 1 > expire ;
122
+ export const isExpired = ( expire : BigNumberish ) : boolean => BigInt ( nowSec ( ) ) + 1n > BigInt ( expire ) ;
You can’t perform that action at this time.
0 commit comments