@@ -7,7 +7,7 @@ export default class AddSessionView {
7
7
private _store : Store ;
8
8
9
9
label = '' ;
10
- permissionType = 'admin' ; // Expected values: admin | read-only | custom | liquidity | payments
10
+ permissionType = 'admin' ; // Expected values: admin | read-only | custodial | custom | liquidity | payments
11
11
editing = false ;
12
12
permissions : { [ key : string ] : boolean } = {
13
13
openChannel : false ,
@@ -30,6 +30,7 @@ export default class AddSessionView {
30
30
expirationDate = '' ;
31
31
showAdvanced = false ;
32
32
proxy = '' ;
33
+ custodialBalance = 0 ;
33
34
34
35
constructor ( store : Store ) {
35
36
makeAutoObservable (
@@ -52,6 +53,8 @@ export default class AddSessionView {
52
53
return LIT . SessionType . TYPE_MACAROON_ADMIN ;
53
54
} else if ( this . permissionType === 'read-only' ) {
54
55
return LIT . SessionType . TYPE_MACAROON_READONLY ;
56
+ } else if ( this . permissionType === 'custodial' ) {
57
+ return LIT . SessionType . TYPE_MACAROON_ACCOUNT ;
55
58
}
56
59
57
60
return LIT . SessionType . TYPE_MACAROON_CUSTOM ;
@@ -125,6 +128,10 @@ export default class AddSessionView {
125
128
this . proxy = proxy ;
126
129
}
127
130
131
+ setCustodialBalance ( balance : number ) {
132
+ this . custodialBalance = balance ;
133
+ }
134
+
128
135
setPermissionType ( permissionType : string ) {
129
136
this . permissionType = permissionType ;
130
137
@@ -150,6 +157,12 @@ export default class AddSessionView {
150
157
this . permissions . receive = true ;
151
158
break ;
152
159
160
+ case 'custodial' :
161
+ this . setAllPermissions ( false ) ;
162
+ this . permissions . send = true ;
163
+ this . permissions . receive = true ;
164
+ break ;
165
+
153
166
case 'custom' :
154
167
// We don't need to change anything, let the user customize permissions how they want
155
168
break ;
@@ -203,19 +216,32 @@ export default class AddSessionView {
203
216
204
217
async handleCustomSubmit ( ) {
205
218
let label = this . label ;
219
+ let accountId = '' ;
206
220
207
221
// Automatically generate human friendly labels for custom sessions
208
222
if ( label === '' ) {
209
223
label = `My ${ this . permissionType } session` ;
210
224
}
211
225
226
+ if ( this . permissionType === 'custodial' ) {
227
+ const custodialAccountId = await this . registerCustodialAccount ( ) ;
228
+
229
+ // Return immediately to prevent a session being created when there is an error creating the custodial account
230
+ if ( ! custodialAccountId ) {
231
+ return ;
232
+ }
233
+
234
+ accountId = custodialAccountId ;
235
+ }
236
+
212
237
const session = await this . _store . sessionStore . addSession (
213
238
label ,
214
239
this . sessionType ,
215
240
this . sessionDate ,
216
241
true ,
217
242
this . sessionProxy ,
218
243
this . getMacaroonPermissions ,
244
+ accountId ,
219
245
) ;
220
246
221
247
if ( session ) {
@@ -224,6 +250,21 @@ export default class AddSessionView {
224
250
}
225
251
}
226
252
253
+ async registerCustodialAccount ( ) : Promise < string | undefined > {
254
+ try {
255
+ const response = await this . _store . api . lit . createAccount (
256
+ this . custodialBalance ,
257
+ this . sessionDate ,
258
+ ) ;
259
+
260
+ if ( response . account ) {
261
+ return response . account . id ;
262
+ }
263
+ } catch ( error ) {
264
+ this . _store . appView . handleError ( error , 'Unable to register custodial account' ) ;
265
+ }
266
+ }
267
+
227
268
//
228
269
// Private helper functions
229
270
//
0 commit comments