@@ -7,7 +7,7 @@ export default class AddSessionView {
77 private _store : Store ;
88
99 label = '' ;
10- permissionType = 'admin' ; // Expected values: admin | read-only | custom | liquidity | payments
10+ permissionType = 'admin' ; // Expected values: admin | read-only | custodial | custom | liquidity | payments
1111 editing = false ;
1212 permissions : { [ key : string ] : boolean } = {
1313 openChannel : false ,
@@ -30,6 +30,7 @@ export default class AddSessionView {
3030 expirationDate = '' ;
3131 showAdvanced = false ;
3232 proxy = '' ;
33+ custodialBalance = 0 ;
3334
3435 constructor ( store : Store ) {
3536 makeAutoObservable (
@@ -52,6 +53,8 @@ export default class AddSessionView {
5253 return LIT . SessionType . TYPE_MACAROON_ADMIN ;
5354 } else if ( this . permissionType === 'read-only' ) {
5455 return LIT . SessionType . TYPE_MACAROON_READONLY ;
56+ } else if ( this . permissionType === 'custodial' ) {
57+ return LIT . SessionType . TYPE_MACAROON_ACCOUNT ;
5558 }
5659
5760 return LIT . SessionType . TYPE_MACAROON_CUSTOM ;
@@ -125,6 +128,10 @@ export default class AddSessionView {
125128 this . proxy = proxy ;
126129 }
127130
131+ setCustodialBalance ( balance : number ) {
132+ this . custodialBalance = balance ;
133+ }
134+
128135 setPermissionType ( permissionType : string ) {
129136 this . permissionType = permissionType ;
130137
@@ -150,6 +157,12 @@ export default class AddSessionView {
150157 this . permissions . receive = true ;
151158 break ;
152159
160+ case 'custodial' :
161+ this . setAllPermissions ( false ) ;
162+ this . permissions . send = true ;
163+ this . permissions . receive = true ;
164+ break ;
165+
153166 case 'custom' :
154167 // We don't need to change anything, let the user customize permissions how they want
155168 break ;
@@ -203,19 +216,32 @@ export default class AddSessionView {
203216
204217 async handleCustomSubmit ( ) {
205218 let label = this . label ;
219+ let accountId = '' ;
206220
207221 // Automatically generate human friendly labels for custom sessions
208222 if ( label === '' ) {
209223 label = `My ${ this . permissionType } session` ;
210224 }
211225
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+
212237 const session = await this . _store . sessionStore . addSession (
213238 label ,
214239 this . sessionType ,
215240 this . sessionDate ,
216241 true ,
217242 this . sessionProxy ,
218243 this . getMacaroonPermissions ,
244+ accountId ,
219245 ) ;
220246
221247 if ( session ) {
@@ -224,6 +250,21 @@ export default class AddSessionView {
224250 }
225251 }
226252
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+
227268 //
228269 // Private helper functions
229270 //
0 commit comments