Skip to content

Commit f63ff3c

Browse files
felicioiamonuwa
andauthored
update wallet connect (#828)
* chore: wallet connect updates * refactor: use sn-api endpoints to handle siwe * chore: set signOutOnDisconnect to false * u * u * Update wallet connect in changeset --------- Co-authored-by: iamonuwa <[email protected]>
1 parent 66d30c0 commit f63ff3c

File tree

17 files changed

+289
-280
lines changed

17 files changed

+289
-280
lines changed

.changeset/tame-gifts-hope.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"hub": patch
3+
---
4+
5+
update wallet connect

apps/hub/.env

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@
1616
# – https://vercel.com/docs/cli/env#exporting-development-environment-variables
1717

1818

19-
NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID="123"
19+
NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID=""
20+
NEXT_PUBLIC_STATUS_NETWORK_API_URL=""

apps/hub/.env.development

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# note: next lint doesn't use .env.development
2+
# note: use .env.local instead for now
3+
#
4+
# – https://github.com/vercel/next.js/discussions/32354
5+
6+
# .env, .env.development, and .env.production files should be included in your repository as they define defaults.
7+
# .env*.local should be added to .gitignore, as those files are intended to be ignored.
8+
# .env.local is where secrets can be stored.
9+
#
10+
# – https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables#default-environment-variables
11+
12+
# The vercel env pull sub-command will export development environment variables to a local .env file or a different file of your choice.
13+
#
14+
# `vercel env pull .env[.development].local`
15+
#
16+
# – https://vercel.com/docs/cli/env#exporting-development-environment-variables
17+
18+
19+
NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID=""
20+
NEXT_PUBLIC_STATUS_NETWORK_API_URL=""

apps/hub/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"rehype-slug": "^6.0.0",
3939
"siwe": "^2.3.2",
4040
"ts-pattern": "^5.6.2",
41-
"viem": "^2.21.1",
41+
"viem": "^2.29.1",
4242
"wagmi": "2.15.2",
4343
"zod": "^3.24.1"
4444
},

apps/hub/src/app/_components/connect-button.tsx

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,39 @@
22

33
import { Button, ShortenAddress } from '@status-im/status-network/components'
44
import { ConnectKitButton } from 'connectkit'
5-
import { useAccount } from 'wagmi'
65

76
import type { ComponentProps } from 'react'
87

98
type Props = {
109
size?: ComponentProps<typeof Button>['size']
1110
label?: string
12-
shortLabel?: string
11+
className?: string
12+
/** If true, shows the label instead of the shortened address when connected */
13+
alwaysShowLabel?: boolean
1314
}
1415

1516
const ConnectButton = (props: Props) => {
1617
const {
1718
size = '32',
1819
label = 'Connect wallet',
19-
shortLabel = 'Connect',
20+
className,
21+
alwaysShowLabel = false,
2022
} = props
2123

22-
const { address, isConnected } = useAccount()
23-
2424
return (
2525
<ConnectKitButton.Custom>
26-
{({ show }) => {
26+
{({ show, isConnected, address }) => {
2727
return (
2828
<Button
2929
onClick={show}
3030
variant={isConnected ? 'secondary' : 'primary'}
3131
size={size}
32+
className={className}
3233
>
33-
{address && isConnected ? (
34+
{address && isConnected && !alwaysShowLabel ? (
3435
<ShortenAddress address={address} />
3536
) : (
36-
<>
37-
<span className="hidden whitespace-nowrap lg:block">
38-
{label}
39-
</span>
40-
<span className="block whitespace-nowrap lg:hidden">
41-
{shortLabel}
42-
</span>
43-
</>
37+
label
4438
)}
4539
</Button>
4640
)
Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,52 @@
1-
import type { Chain } from 'wagmi/chains'
1+
import { getDefaultConfig } from 'connectkit'
2+
import { defineChain } from 'viem'
3+
import { createConfig, http } from 'wagmi'
4+
import { type Chain, mainnet } from 'wagmi/chains'
25

3-
export const statusNetworkTestnet: Chain = {
4-
id: Number(1660990954),
6+
import { clientEnv } from './env.client.mjs'
7+
8+
import type {
9+
CreateConfigParameters,
10+
CreateConnectorFn,
11+
Transport,
12+
} from 'wagmi'
13+
14+
export const testnet = defineChain({
15+
id: 1660990954,
516
name: 'Status Network Testnet',
6-
nativeCurrency: {
7-
decimals: 18,
8-
name: 'Ether',
9-
symbol: 'ETH',
10-
},
17+
testnet: true,
18+
sourceId: 1660990954,
19+
nativeCurrency: { name: 'Ether', symbol: 'ETH', decimals: 18 },
1120
rpcUrls: {
1221
default: {
1322
http: ['https://public.sepolia.rpc.status.network'],
1423
},
15-
public: {
16-
http: ['https://public.sepolia.rpc.status.network'],
17-
},
1824
},
1925
blockExplorers: {
2026
default: {
2127
name: 'Status Explorer',
2228
url: 'https://sepoliascan.status.network',
2329
},
2430
},
25-
}
31+
})
32+
33+
export const getDefaultWagmiConfig = () =>
34+
getDefaultConfig({
35+
chains: [mainnet, testnet],
36+
transports: {
37+
[mainnet.id]: http(mainnet.rpcUrls.default.http[0]),
38+
[testnet.id]: http(testnet.rpcUrls.default.http[0]),
39+
},
40+
walletConnectProjectId:
41+
clientEnv.NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID as string,
42+
appName: 'Status Hub',
43+
appDescription: 'Status Network DeFi Dashboard',
44+
appUrl: 'https://status.app',
45+
appIcon: 'https://status.app/icon.png',
46+
}) as CreateConfigParameters<
47+
readonly [Chain, ...Chain[]],
48+
Record<number, Transport>,
49+
readonly CreateConnectorFn[]
50+
>
51+
52+
export const wagmiConfig = createConfig(getDefaultWagmiConfig())

apps/hub/src/app/_constants/env.client.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@ export const envSchema = z.object({
55
NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID: z
66
.string()
77
.min(1, 'WalletConnect Project ID is required.'),
8+
NEXT_PUBLIC_STATUS_NETWORK_API_URL: z.string().url(),
89
})
910

1011
export const result = envSchema.strip().safeParse({
1112
NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID:
1213
process.env.NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID,
14+
NEXT_PUBLIC_STATUS_NETWORK_API_URL:
15+
process.env.NEXT_PUBLIC_STATUS_NETWORK_API_URL,
1316
})
1417

1518
if (!result.success) {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export * from './address'
22
export * from './chain'
3+
export * from './siwe'
34
export * from './staking'
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import { clientEnv } from './env.client.mjs'
2+
3+
import type { SIWEConfig } from 'connectkit'
4+
5+
// API configuration
6+
const API_BASE_URL = clientEnv.NEXT_PUBLIC_STATUS_NETWORK_API_URL
7+
8+
const AUTH_ENDPOINTS = {
9+
verify: `${API_BASE_URL}/auth/ethereum`,
10+
session: `${API_BASE_URL}/auth/me`,
11+
logout: `${API_BASE_URL}/auth/logout`,
12+
} as const
13+
14+
// Helper for API calls
15+
const fetchAPI = async (url: string, options?: RequestInit) => {
16+
const response = await fetch(url, {
17+
credentials: 'include', // Send cookies with cross-origin requests
18+
headers: {
19+
'Content-Type': 'application/json',
20+
...options?.headers,
21+
},
22+
...options,
23+
})
24+
return response
25+
}
26+
27+
export const siweConfig: SIWEConfig = {
28+
getNonce: async () => {
29+
return Math.random().toString(36).substring(2, 15)
30+
},
31+
32+
createMessage: async () => {
33+
const payload = { timestamp: Math.floor(Date.now() / 1000) }
34+
return window.btoa(JSON.stringify(payload))
35+
},
36+
37+
verifyMessage: async ({ message, signature }) => {
38+
try {
39+
const response = await fetchAPI(AUTH_ENDPOINTS.verify, {
40+
method: 'POST',
41+
body: JSON.stringify({ payload: message, signature }),
42+
})
43+
return response.ok
44+
} catch {
45+
return false
46+
}
47+
},
48+
49+
getSession: async () => {
50+
try {
51+
const response = await fetchAPI(AUTH_ENDPOINTS.session)
52+
if (!response.ok) return null
53+
54+
const data = await response.json()
55+
return data.result ?? null
56+
} catch {
57+
return null
58+
}
59+
},
60+
61+
signOut: async () => {
62+
try {
63+
const response = await fetchAPI(AUTH_ENDPOINTS.logout, {
64+
method: 'POST',
65+
})
66+
return response.ok
67+
} catch {
68+
return false
69+
}
70+
},
71+
72+
signOutOnDisconnect: false,
73+
}

apps/hub/src/app/_providers/connectkit-provider.tsx

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)