Skip to content

Commit a6c824b

Browse files
committed
address reviewer suggestions
1 parent 77679ad commit a6c824b

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/components/SpaceCreator.tsx

+9-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { ChangeEvent } from 'react'
33
import React, { useState } from 'react'
44
import { ContentServeService, Space, useW3 } from '@w3ui/react'
55
import Loader from '../components/Loader'
6-
import { ConnectionView, DID, DIDKey } from '@ucanto/interface'
6+
import { DIDKey } from '@ucanto/interface'
77
import { DidIcon } from './DidIcon'
88
import Link from 'next/link'
99
import { FolderPlusIcon, InformationCircleIcon } from '@heroicons/react/24/outline'
@@ -53,25 +53,28 @@ export function SpaceCreatorForm({
5353
throw new Error('a payment plan is required on account to provision a new space.')
5454
}
5555

56+
const toWebDID = (input?: string) =>
57+
UcantoClient.Schema.DID.match({ method: 'web' }).from(input)
58+
5659
setSubmitted(true)
5760
try {
5861

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'
6164

6265
const storachaGateway = UcantoClient.connect({
6366
id: {
6467
did: () => gatewayId
6568
},
6669
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+
})
6972

7073
const space = await client.createSpace(name, {
7174
authorizeGatewayServices: [storachaGateway]
7275
})
7376

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')
7578
const result = await account.provision(space.did(), { provider })
7679
if (result.error) {
7780
setSubmitted(false)

0 commit comments

Comments
 (0)