Skip to content

Commit a555de5

Browse files
committed
note on https option in localhost
1 parent 4ae5f6b commit a555de5

File tree

10 files changed

+81
-79
lines changed

10 files changed

+81
-79
lines changed

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,8 @@
4747
"**/dist": true,
4848
"pnpm-lock.yaml": true,
4949
"**/node_modules": true
50+
},
51+
"[caddyfile]": {
52+
"editor.defaultFormatter": "matthewpi.caddyfile-support"
5053
}
5154
}

Caddyfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Client App
2+
https://client.localhost {
3+
reverse_proxy localhost:6901
4+
}
5+
6+
# Server - Workers
7+
https://server.localhost {
8+
reverse_proxy localhost:6900
9+
}

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ pnpm --filter='server' db:bootstrap
6767
pnpm --filter='server' db:bootstrap:remote
6868
```
6969

70+
> [!NOTE]
71+
> if you want https setup for local development:
72+
>
73+
> - install [caddy](https://caddyserver.com/docs/install),
74+
> - run `caddy run --config=Caddyfile`
75+
> - set `VITE_SERVER_URL` to `https://server.localhost` in `client/.env`
76+
7077
### Start dev for worker and client
7178

7279
```shell

client/.env.example

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
VITE_DISABLE_DIALOG=false
21
VITE_ENVIRONMENT="development"
3-
VITE_DIALOG_HOST="https://exp.porto.sh/dialog"
4-
VITE_SERVER_URL="http://localhost:6900"
52

6-
CLOUDFLARE_API_TOKEN=""
7-
CLOUDFLARE_ACCOUNT_ID=""
3+
# or `https://server.localhost` if you're running local dev with Caddy
4+
VITE_SERVER_URL="http://localhost:6900"

client/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"#wrangler.json": "./wrangler.json"
99
},
1010
"scripts": {
11-
"dev": "vite --port 6901 --open",
11+
"dev": "vite --port 6901",
1212
"build": "vite build",
1313
"deploy": "vite build && wrangler --config='wrangler.json' deploy",
1414
"typecheck": "tsc --noEmit --project tsconfig.json"
@@ -19,6 +19,7 @@
1919
"porto": "catalog:",
2020
"react": "19.1.0",
2121
"react-dom": "19.1.0",
22+
"viem": "^2.31.7",
2223
"wagmi": "catalog:"
2324
},
2425
"devDependencies": {

client/src/App.tsx

Lines changed: 48 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1-
import { useAccount, useDisconnect, useConnectors, useCallsStatus } from 'wagmi'
1+
import {
2+
useAccount,
3+
useDisconnect,
4+
useConnectors,
5+
useCallsStatus,
6+
useSendCalls,
7+
useWaitForCallsStatus,
8+
} from 'wagmi'
29
import * as React from 'react'
10+
import { parseEther } from 'viem'
311
import { Hooks } from 'porto/wagmi'
4-
import { type Errors, Hex, Json } from 'ox'
512
import { useConnect } from 'porto/wagmi/Hooks'
13+
import { type Errors, type Hex, Json } from 'ox'
614
import { useMutation } from '@tanstack/react-query'
715

816
import {
@@ -352,90 +360,67 @@ function GrantPermissions() {
352360

353361
function Fund() {
354362
const { address, chain } = useAccount()
363+
const balance = useBalance()
355364

356-
const addFundsMutation = useMutation({
357-
mutationFn: async (event: React.FormEvent<HTMLFormElement>) => {
358-
event.preventDefault()
359-
event.stopPropagation()
360-
361-
const result = await porto.provider.request({
362-
method: 'wallet_addFunds',
363-
params: [
364-
{
365-
address,
366-
token: exp1Config.address,
367-
value: Hex.fromString('100'),
368-
},
369-
],
370-
})
365+
const sendCalls = useSendCalls()
371366

372-
return result
373-
},
374-
})
375-
const {
376-
data: txHashData,
377-
isLoading: isConfirming,
378-
isSuccess: isConfirmed,
379-
} = useCallsStatus({
380-
id: addFundsMutation.data?.id as Hex.Hex,
381-
query: {
382-
enabled: !!addFundsMutation.data?.id,
383-
refetchInterval: ({ state }) => {
384-
if (state.data?.status === 'success') return false
385-
return 1_000
386-
},
387-
},
388-
})
367+
const { isLoading: isConfirming, isSuccess: isConfirmed } =
368+
useWaitForCallsStatus({
369+
id: sendCalls.data?.id,
370+
})
389371

390-
const blockExplorer = chain?.blockExplorers?.default?.url
372+
const explorerUrl = chain?.blockExplorers?.default?.url
391373
const transactionLink = (hash: string) =>
392-
blockExplorer ? `${blockExplorer}/tx/${hash}` : hash
393-
394-
const balance = useBalance()
395-
396-
const [transactions, setTransactions] = React.useState<Set<string>>(new Set())
397-
React.useEffect(() => {
398-
if (!txHashData?.id) return
399-
const hash = txHashData.receipts?.at(0)?.transactionHash
400-
if (!hash) return
401-
setTransactions((prev) => new Set([...prev, hash]))
402-
}, [txHashData?.id, txHashData?.receipts])
374+
explorerUrl ? `${explorerUrl}/tx/${hash}` : hash
403375

404376
return (
405377
<div>
406378
<h3>
407379
[client] Fund Wallet with EXP [balance:{' '}
408380
{`${Number(balance).toFixed(2)} EXP`}]
409381
</h3>
410-
<form onSubmit={addFundsMutation.mutate}>
382+
<form
383+
onSubmit={(event) => {
384+
event.preventDefault()
385+
event.stopPropagation()
386+
sendCalls.sendCalls({
387+
calls: [
388+
{
389+
...exp1Config,
390+
args: [address!, parseEther('100')],
391+
functionName: 'mint',
392+
to: exp1Config.address,
393+
},
394+
],
395+
})
396+
}}
397+
>
411398
<button
412399
type="submit"
413-
disabled={addFundsMutation.status === 'pending'}
400+
disabled={sendCalls.status === 'pending'}
414401
style={{ marginBottom: '5px' }}
415402
>
416-
{addFundsMutation.status === 'pending' ? 'Confirming…' : 'Fund'}
403+
{sendCalls.status === 'pending' ? 'Confirming…' : 'Fund'}
417404
</button>
418405
</form>
419406
<ul style={{ listStyleType: 'none', padding: 0 }}>
420-
{Array.from(transactions).map((tx) => (
421-
<li key={tx}>
422-
<a
423-
target="_blank"
424-
rel="noopener noreferrer"
425-
href={transactionLink(tx)}
426-
>
427-
{tx}
428-
</a>
429-
</li>
430-
))}
407+
{sendCalls.data?.id && (
408+
<a
409+
target="_blank"
410+
rel="noopener noreferrer"
411+
href={transactionLink(sendCalls.data!.id)}
412+
>
413+
{sendCalls.data?.id}
414+
</a>
415+
)}
431416
</ul>
432417
<p>{isConfirming && 'Waiting for confirmation...'}</p>
433418
<p>{isConfirmed && 'Transaction confirmed.'}</p>
434-
{addFundsMutation.error && (
419+
{sendCalls.error && (
435420
<div>
436421
Error:{' '}
437-
{(addFundsMutation.error as Errors.BaseError).shortMessage ||
438-
addFundsMutation.error.message}
422+
{(sendCalls.error as Errors.BaseError).shortMessage ||
423+
sendCalls.error.message}
439424
</div>
440425
)}
441426
</div>

client/src/config.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { Dialog, Mode, Porto } from 'porto'
1+
import { http, createConfig } from 'wagmi'
22
import { baseSepolia } from 'porto/Chains'
3+
import { Dialog, Mode, Porto } from 'porto'
34
import { porto as portoConnector } from 'porto/wagmi'
4-
import { http, createConfig, createStorage } from 'wagmi'
55
import { MutationCache, QueryCache, QueryClient } from '@tanstack/react-query'
66

77
export const porto = Porto.create()
@@ -15,12 +15,10 @@ export const wagmiConfig = createConfig({
1515
chains: [baseSepolia],
1616
connectors: [
1717
portoConnector({
18-
announceProvider: false,
1918
mode: Mode.dialog({ renderer }),
2019
}),
2120
],
2221
multiInjectedProviderDiscovery: false,
23-
storage: createStorage({ storage: window.localStorage }),
2422
transports: {
2523
[baseSepolia.id]: http(),
2624
},

client/src/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { exp1Config } from '#contracts.ts'
55
export const SERVER_URL =
66
import.meta.env.VITE_SERVER_URL ??
77
(import.meta.env.DEV
8-
? 'http://localhost:6900'
8+
? 'http://localhost:6901'
99
: 'https://exp-0003-server.evm.workers.dev')
1010
export const permissions = () =>
1111
({

client/src/vite-env.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ interface Environment {
99

1010
interface ImportMetaEnv extends Environment {
1111
readonly VITE_SERVER_URL: string
12-
readonly VITE_DIALOG_HOST: string
1312
readonly VITE_DIALOG_RENDERER: 'popup' | 'iframe'
1413
readonly VITE_ENVIRONMENT: 'development' | 'production'
1514
}

pnpm-lock.yaml

Lines changed: 7 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)