@@ -32,17 +32,16 @@ function isEmail(value: string): boolean {
32
32
return ! isDID ( value ) && emailRegex . test ( value )
33
33
}
34
34
35
- export function ShareSpace ( ) : JSX . Element {
35
+ export function ShareSpace ( { spaceDID } : { spaceDID : string } ) : JSX . Element {
36
36
const [ { client } ] = useW3 ( )
37
37
const [ value , setValue ] = useState ( '' )
38
38
const [ downloadUrl , setDownloadUrl ] = useState ( '' )
39
39
const [ sharedEmails , setSharedEmails ] = useState < { email : string , capabilities : string [ ] } [ ] > ( [ ] )
40
40
41
41
useEffect ( ( ) => {
42
- const spaceDid = window . location . pathname . split ( '/' ) [ 2 ]
43
- if ( client && spaceDid ) {
42
+ if ( client ) {
44
43
const delegations = client . delegations ( )
45
- . filter ( d => d . capabilities . some ( c => c . with === spaceDid ) )
44
+ . filter ( d => d . capabilities . some ( c => c . with === spaceDID ) )
46
45
. map ( d => ( {
47
46
email : d . audience . did ( ) ,
48
47
capabilities : d . capabilities . map ( c => c . can )
@@ -75,6 +74,18 @@ export function ShareSpace(): JSX.Element {
75
74
] , {
76
75
expiration : Infinity
77
76
} )
77
+
78
+ const res = await client . capability . access . delegate ( {
79
+ // @ts -ignore
80
+ space : DID . from ( spaceDID ) . did ( ) ,
81
+ delegations : [ delegation ] ,
82
+ } )
83
+ if ( res . error ) {
84
+ throw new Error (
85
+ `failed to share account: ${ result . error . message } ` ,
86
+ { cause : result . error }
87
+ )
88
+ }
78
89
79
90
const next = { email : audience . did ( ) , capabilities : delegation . capabilities . map ( c => c . can ) }
80
91
setSharedEmails ( prev => {
@@ -101,7 +112,6 @@ export function ShareSpace(): JSX.Element {
101
112
}
102
113
103
114
try {
104
- console . log ( audience . did ( ) )
105
115
const delegation = await client . createDelegation ( audience , [ '*' ] , {
106
116
expiration : Infinity ,
107
117
} )
0 commit comments