@@ -3,7 +3,7 @@ import type { ChangeEvent } from 'react'
3
3
import React , { useState } from 'react'
4
4
import { ContentServeService , Space , useW3 } from '@w3ui/react'
5
5
import Loader from '../components/Loader'
6
- import { ConnectionView , 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'
@@ -53,25 +53,28 @@ export function SpaceCreatorForm({
53
53
throw new Error ( 'a payment plan is required on account to provision a new space.' )
54
54
}
55
55
56
+ const toWebDID = ( input ?: string ) =>
57
+ UcantoClient . Schema . DID . match ( { method : 'web' } ) . from ( input )
58
+
56
59
setSubmitted ( true )
57
60
try {
58
61
59
- const gatewayId = ( process . env . NEXT_PUBLIC_W3UP_GATEWAY_ID || 'did:web:w3s.link' ) as DID < 'web' >
60
- const gatewayUrl = process . env . NEXT_PUBLIC_W3UP_GATEWAY_HOST || 'https://freeway.dag.haus' as string
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://freeway.dag.haus'
61
64
62
65
const storachaGateway = UcantoClient . connect ( {
63
66
id : {
64
67
did : ( ) => gatewayId
65
68
} ,
66
69
codec : CAR . outbound ,
67
- channel : HTTP . open ( { url : new URL ( gatewayUrl ) } ) ,
68
- } ) as ConnectionView < ContentServeService >
70
+ channel : HTTP . open < ContentServeService > ( { url : new URL ( gatewayUrl ) } ) ,
71
+ } )
69
72
70
73
const space = await client . createSpace ( name , {
71
74
authorizeGatewayServices : [ storachaGateway ]
72
75
} )
73
76
74
- const provider = ( process . env . NEXT_PUBLIC_W3UP_PROVIDER || 'did:web:web3.storage' ) as DID < 'web' >
77
+ const provider = toWebDID ( process . env . NEXT_PUBLIC_W3UP_PROVIDER ) || toWebDID ( 'did:web:web3.storage' )
75
78
const result = await account . provision ( space . did ( ) , { provider } )
76
79
if ( result . error ) {
77
80
setSubmitted ( false )
0 commit comments