|
1 | 1 | import type { ChangeEvent } from 'react'
|
2 | 2 |
|
3 | 3 | import React, { useState } from 'react'
|
4 |
| -import { Space, useW3 } from '@w3ui/react' |
| 4 | +import { ContentServeService, Space, useW3 } from '@w3ui/react' |
5 | 5 | import Loader from '../components/Loader'
|
6 |
| -import { DID, DIDKey } from '@ucanto/interface' |
| 6 | +import { DIDKey } from '@ucanto/interface' |
7 | 7 | import { DidIcon } from './DidIcon'
|
8 | 8 | import Link from 'next/link'
|
9 | 9 | import { FolderPlusIcon, InformationCircleIcon } from '@heroicons/react/24/outline'
|
10 | 10 | import Tooltip from './Tooltip'
|
11 | 11 | import { H3 } from './Text'
|
| 12 | +import * as UcantoClient from '@ucanto/client' |
| 13 | +import { HTTP } from '@ucanto/transport' |
| 14 | +import * as CAR from '@ucanto/transport/car' |
12 | 15 |
|
13 | 16 | export function SpaceCreatorCreating(): JSX.Element {
|
14 | 17 | return (
|
@@ -50,11 +53,28 @@ export function SpaceCreatorForm({
|
50 | 53 | throw new Error('a payment plan is required on account to provision a new space.')
|
51 | 54 | }
|
52 | 55 |
|
| 56 | + const toWebDID = (input?: string) => |
| 57 | + UcantoClient.Schema.DID.match({ method: 'web' }).from(input) |
| 58 | + |
53 | 59 | setSubmitted(true)
|
54 | 60 | try {
|
55 |
| - const space = await client.createSpace(name) |
56 | 61 |
|
57 |
| - const provider = (process.env.NEXT_PUBLIC_W3UP_PROVIDER || 'did:web:web3.storage') as DID<'web'> |
| 62 | + const gatewayId = toWebDID(process.env.NEXT_PUBLIC_W3UP_GATEWAY_ID) || toWebDID('did:web:w3s.link') |
| 63 | + const gatewayUrl = process.env.NEXT_PUBLIC_W3UP_GATEWAY_HOST || 'https://w3s.link' |
| 64 | + |
| 65 | + const storachaGateway = UcantoClient.connect({ |
| 66 | + id: { |
| 67 | + did: () => gatewayId |
| 68 | + }, |
| 69 | + codec: CAR.outbound, |
| 70 | + channel: HTTP.open<ContentServeService>({ url: new URL(gatewayUrl) }), |
| 71 | + }) |
| 72 | + |
| 73 | + const space = await client.createSpace(name, { |
| 74 | + authorizeGatewayServices: [storachaGateway] |
| 75 | + }) |
| 76 | + |
| 77 | + const provider = toWebDID(process.env.NEXT_PUBLIC_W3UP_PROVIDER) || toWebDID('did:web:web3.storage') |
58 | 78 | const result = await account.provision(space.did(), { provider })
|
59 | 79 | if (result.error) {
|
60 | 80 | setSubmitted(false)
|
|
0 commit comments