@@ -212,6 +212,16 @@ function formatPermissionsRequest(
212
212
} ;
213
213
}
214
214
215
+ /**
216
+ * Checks if a value is defined (not null or undefined).
217
+ *
218
+ * @param value - The value to check.
219
+ * @returns A boolean indicating whether the value is defined.
220
+ */
221
+ function isDefined < TValue > ( value : TValue | null | undefined ) : value is TValue {
222
+ return value !== undefined && value !== null ;
223
+ }
224
+
215
225
/**
216
226
* Asserts that a value is defined (not null or undefined).
217
227
*
@@ -223,7 +233,7 @@ function assertIsDefined<TValue>(
223
233
value : TValue | null | undefined ,
224
234
message ?: string ,
225
235
) : asserts value is TValue {
226
- if ( value === null || value === undefined ) {
236
+ if ( ! isDefined ( value ) ) {
227
237
throw new Error ( message ?? 'Invalid parameters: value is required' ) ;
228
238
}
229
239
}
@@ -319,21 +329,14 @@ function formatNativeTokenStreamPermission({
319
329
} ,
320
330
} = permission ;
321
331
322
- const isInitialAmountSpecified =
323
- initialAmount !== undefined && initialAmount !== null ;
324
-
325
- const isMaxAmountSpecified = maxAmount !== undefined && maxAmount !== null ;
326
-
327
- const isStartTimeSpecified = startTime !== undefined && startTime !== null ;
328
-
329
332
const optionalFields = {
330
- ...( isInitialAmountSpecified && {
333
+ ...( isDefined ( initialAmount ) && {
331
334
initialAmount : toHexOrThrow ( initialAmount ) ,
332
335
} ) ,
333
- ...( isMaxAmountSpecified && {
336
+ ...( isDefined ( maxAmount ) && {
334
337
maxAmount : toHexOrThrow ( maxAmount ) ,
335
338
} ) ,
336
- ...( isStartTimeSpecified && {
339
+ ...( isDefined ( startTime ) && {
337
340
startTime : Number ( startTime ) ,
338
341
} ) ,
339
342
...( justification ? { justification } : { } ) ,
@@ -380,21 +383,14 @@ function formatErc20TokenStreamPermission({
380
383
} ,
381
384
} = permission ;
382
385
383
- const isInitialAmountSpecified =
384
- initialAmount !== undefined && initialAmount !== null ;
385
-
386
- const isMaxAmountSpecified = maxAmount !== undefined && maxAmount !== null ;
387
-
388
- const isStartTimeSpecified = startTime !== undefined && startTime !== null ;
389
-
390
386
const optionalFields = {
391
- ...( isInitialAmountSpecified && {
387
+ ...( isDefined ( initialAmount ) && {
392
388
initialAmount : toHexOrThrow ( initialAmount ) ,
393
389
} ) ,
394
- ...( isMaxAmountSpecified && {
390
+ ...( isDefined ( maxAmount ) && {
395
391
maxAmount : toHexOrThrow ( maxAmount ) ,
396
392
} ) ,
397
- ...( isStartTimeSpecified && {
393
+ ...( isDefined ( startTime ) && {
398
394
startTime : Number ( startTime ) ,
399
395
} ) ,
400
396
...( justification ? { justification } : { } ) ,
@@ -430,10 +426,8 @@ function formatNativeTokenPeriodicPermission({
430
426
data : { periodAmount, periodDuration, startTime, justification } ,
431
427
} = permission ;
432
428
433
- const isStartTimeSpecified = startTime !== undefined && startTime !== null ;
434
-
435
429
const optionalFields = {
436
- ...( isStartTimeSpecified && {
430
+ ...( isDefined ( startTime ) && {
437
431
startTime : Number ( startTime ) ,
438
432
} ) ,
439
433
...( justification ? { justification } : { } ) ,
@@ -475,10 +469,8 @@ function formatErc20TokenPeriodicPermission({
475
469
} ,
476
470
} = permission ;
477
471
478
- const isStartTimeSpecified = startTime !== undefined && startTime !== null ;
479
-
480
472
const optionalFields = {
481
- ...( isStartTimeSpecified && {
473
+ ...( isDefined ( startTime ) && {
482
474
startTime : Number ( startTime ) ,
483
475
} ) ,
484
476
...( justification ? { justification } : { } ) ,
0 commit comments