@@ -13,25 +13,27 @@ export class BasicAllowance extends JSONSerializable<
13
13
BasicAllowance . Data ,
14
14
BasicAllowance . Proto
15
15
> {
16
- public spend_limit : Coins ;
16
+ public spend_limit ? : Coins ;
17
17
18
18
/**
19
19
* @param spend_limit spend_limit allowed to be spent as fee
20
20
* @param expiration allowance's expiration
21
21
*/
22
- constructor ( spend_limit : Coins . Input , public expiration ?: Date ) {
22
+ constructor ( spend_limit ? : Coins . Input , public expiration ?: Date ) {
23
23
super ( ) ;
24
24
let hasNotPositive = false ;
25
- this . spend_limit = new Coins ( spend_limit ) ;
26
- this . spend_limit . map ( c => {
27
- // isPositive() from decimal.js returns true when the amount is 0.
28
- // but Coins.IsAllPositive() from cosmos-sdk will return false in same case.
29
- // so we use lessThanorEquenTo(0) instead of isPositive() == false
30
- if ( num ( c . amount ) . isLessThanOrEqualTo ( 0 ) ) {
31
- hasNotPositive = true ;
32
- }
33
- } ) ;
34
- if ( hasNotPositive ) {
25
+ if ( spend_limit ) {
26
+ this . spend_limit = new Coins ( spend_limit ) ;
27
+ this . spend_limit . map ( c => {
28
+ // isPositive() from decimal.js returns true when the amount is 0.
29
+ // but Coins.IsAllPositive() from cosmos-sdk will return false in same case.
30
+ // so we use lessThanorEquenTo(0) instead of isPositive() == false
31
+ if ( num ( c . amount ) . isLessThanOrEqualTo ( 0 ) ) {
32
+ hasNotPositive = true ;
33
+ }
34
+ } ) ;
35
+ }
36
+ if ( spend_limit && hasNotPositive ) {
35
37
throw new Error ( 'spend_limit must be positive' ) ;
36
38
}
37
39
}
@@ -42,7 +44,7 @@ export class BasicAllowance extends JSONSerializable<
42
44
} = data ;
43
45
44
46
return new BasicAllowance (
45
- Coins . fromAmino ( spend_limit ) ,
47
+ spend_limit ? Coins . fromAmino ( spend_limit ) : undefined ,
46
48
expiration ? new Date ( expiration ) : undefined
47
49
) ;
48
50
}
@@ -52,7 +54,7 @@ export class BasicAllowance extends JSONSerializable<
52
54
return {
53
55
type : 'cosmos-sdk/BasicAllowance' ,
54
56
value : {
55
- spend_limit : spend_limit . toAmino ( ) ,
57
+ spend_limit : spend_limit ? .toAmino ( ) ,
56
58
expiration : expiration ?. toISOString ( ) . replace ( / \. 0 0 0 Z $ / , 'Z' ) ,
57
59
} ,
58
60
} ;
@@ -61,7 +63,7 @@ export class BasicAllowance extends JSONSerializable<
61
63
public static fromData ( proto : BasicAllowance . Data ) : BasicAllowance {
62
64
const { spend_limit, expiration } = proto ;
63
65
return new BasicAllowance (
64
- Coins . fromData ( spend_limit ) ,
66
+ spend_limit ? Coins . fromData ( spend_limit ) : undefined ,
65
67
expiration ? new Date ( expiration ) : undefined
66
68
) ;
67
69
}
@@ -70,7 +72,7 @@ export class BasicAllowance extends JSONSerializable<
70
72
const { spend_limit, expiration } = this ;
71
73
return {
72
74
'@type' : '/cosmos.feegrant.v1beta1.BasicAllowance' ,
73
- spend_limit : spend_limit . toData ( ) ,
75
+ spend_limit : spend_limit ? .toData ( ) ,
74
76
expiration : expiration ?. toISOString ( ) . replace ( / \. 0 0 0 Z $ / , 'Z' ) ,
75
77
} ;
76
78
}
@@ -86,7 +88,7 @@ export class BasicAllowance extends JSONSerializable<
86
88
const { spend_limit, expiration } = this ;
87
89
return BasicAllowance_pb . fromPartial ( {
88
90
expiration,
89
- spendLimit : spend_limit . toProto ( ) ,
91
+ spendLimit : spend_limit ? .toProto ( ) ,
90
92
} ) ;
91
93
}
92
94
@@ -106,14 +108,14 @@ export namespace BasicAllowance {
106
108
export interface Amino {
107
109
type : 'cosmos-sdk/BasicAllowance' ;
108
110
value : {
109
- spend_limit : Coins . Amino ;
111
+ spend_limit ? : Coins . Amino ;
110
112
expiration ?: string ;
111
113
} ;
112
114
}
113
115
114
116
export interface Data {
115
117
'@type' : '/cosmos.feegrant.v1beta1.BasicAllowance' ;
116
- spend_limit : Coins . Data ;
118
+ spend_limit ? : Coins . Data ;
117
119
expiration ?: string ;
118
120
}
119
121
0 commit comments