Skip to content

Commit 08c9d4b

Browse files
committed
fix: delegate
1 parent 4c71b34 commit 08c9d4b

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

src/app/space/[did]/share/page.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import { ShareSpace } from '@/share'
44

5-
export default function SharePage (): JSX.Element {
5+
export default function SharePage ({params}): JSX.Element {
66
return (
7-
<ShareSpace />
7+
<ShareSpace spaceDID={decodeURIComponent(params.did)}/>
88
)
99
}

src/share.tsx

+15-5
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,16 @@ function isEmail(value: string): boolean {
3232
return !isDID(value) && emailRegex.test(value)
3333
}
3434

35-
export function ShareSpace(): JSX.Element {
35+
export function ShareSpace({spaceDID}: {spaceDID: string}): JSX.Element {
3636
const [{ client }] = useW3()
3737
const [value, setValue] = useState('')
3838
const [downloadUrl, setDownloadUrl] = useState('')
3939
const [sharedEmails, setSharedEmails] = useState<{ email: string, capabilities: string[] }[]>([])
4040

4141
useEffect(() => {
42-
const spaceDid = window.location.pathname.split('/')[2]
43-
if (client && spaceDid) {
42+
if (client) {
4443
const delegations = client.delegations()
45-
.filter(d => d.capabilities.some(c => c.with === spaceDid))
44+
.filter(d => d.capabilities.some(c => c.with === spaceDID))
4645
.map(d => ({
4746
email: d.audience.did(),
4847
capabilities: d.capabilities.map(c => c.can)
@@ -75,6 +74,18 @@ export function ShareSpace(): JSX.Element {
7574
], {
7675
expiration: Infinity
7776
})
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+
}
7889

7990
const next = { email: audience.did(), capabilities: delegation.capabilities.map(c => c.can) }
8091
setSharedEmails(prev => {
@@ -101,7 +112,6 @@ export function ShareSpace(): JSX.Element {
101112
}
102113

103114
try {
104-
console.log(audience.did())
105115
const delegation = await client.createDelegation(audience, ['*'], {
106116
expiration: Infinity,
107117
})

0 commit comments

Comments
 (0)