Skip to content

Commit 5f76a57

Browse files
committed
refactor: ui
1 parent ee79441 commit 5f76a57

File tree

6 files changed

+99
-43
lines changed

6 files changed

+99
-43
lines changed

src/app/globals.css

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,23 @@ textarea {
103103
button[type="submit"] {
104104
background-color: #cefff3;
105105
}
106+
107+
.demo-dapp-container {
108+
padding: 40px 0;
109+
}
110+
111+
/* Small screens (smartphones) - Portrait and Landscape */
112+
@media only screen and (max-width: 767px) {
113+
.demo-dapp-container {
114+
padding: 20px;
115+
}
116+
/* Your mobile styles here */
117+
}
118+
119+
/* Extra small screens (smaller smartphones) */
120+
@media only screen and (max-width: 480px) {
121+
/* Your styles for very small devices */
122+
.demo-dapp-container {
123+
padding: 16px;
124+
}
125+
}

src/app/page.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
"use client"
22

3-
import { publicProvider, StarknetConfig } from "@starknet-react/core"
4-
import { mainnet, sepolia } from "@starknet-react/chains"
5-
import { constants } from "starknet"
6-
import { CHAIN_ID } from "@/constants"
7-
import { connectors } from "@/connectors"
83
import { StarknetDapp } from "@/components/StarknetDapp"
94
import { Flex } from "@/components/ui/Flex"
5+
import { connectors } from "@/connectors"
6+
import { CHAIN_ID } from "@/constants"
7+
import { mainnet, sepolia } from "@starknet-react/chains"
8+
import { publicProvider, StarknetConfig } from "@starknet-react/core"
9+
import { constants } from "starknet"
1010

1111
export default function Home() {
1212
const chains = [
1313
CHAIN_ID === constants.NetworkName.SN_MAIN ? mainnet : sepolia,
1414
]
1515
const providers = publicProvider()
16+
1617
return (
17-
<Flex flexDirection="column" padding="40px 0">
18+
<Flex flexDirection="column" className="demo-dapp-container">
1819
{/* eslint-disable @typescript-eslint/no-explicit-any */}
1920
<StarknetConfig
2021
chains={chains}

src/components/StarknetDapp.tsx

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,21 @@ import { AccountStatus } from "./sections/AccountStatus"
77
import { AddToken } from "./sections/ERC20/AddToken"
88
import { Network } from "./sections/Network/Network"
99

10-
const StarknetDapp = () => {
11-
//useWaitForTx()
12-
13-
return (
14-
<Flex
15-
flexDirection="column"
16-
maxWidth="500px"
17-
width="100%"
18-
margin="0 auto"
19-
gap="24px"
20-
>
21-
<AccountStatus />
22-
<Connect />
23-
<Transactions />
24-
<SignMessage />
25-
<Network />
26-
<AddToken />
27-
</Flex>
28-
)
29-
}
10+
const StarknetDapp = () => (
11+
<Flex
12+
flexDirection="column"
13+
maxWidth="500px"
14+
width="100%"
15+
margin="0 auto"
16+
gap="24px"
17+
>
18+
<AccountStatus />
19+
<Connect />
20+
<Transactions />
21+
<SignMessage />
22+
<Network />
23+
<AddToken />
24+
</Flex>
25+
)
3026

3127
export { StarknetDapp }

src/components/ui/Accordion.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const Accordion: FC<AccordionProps> = ({
4848
<div style={withBorder ? styles.container : {}}>
4949
{accordionItems.map((item, index) => (
5050
<AccordionItem
51-
key={index}
51+
key={`${item.title}-${index}`}
5252
title={item.title || "Untitled Section"}
5353
isOpen={openIndices.includes(index)}
5454
onClick={() => handleClick(index)}

src/components/ui/Flex.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
import { CSSProperties, FC, ReactNode } from "react"
22

33
interface FlexProps extends CSSProperties {
4+
className?: string
45
children: ReactNode
56
}
67

7-
const Flex: FC<FlexProps> = ({ children, ...props }) => {
8-
return <div style={{ display: "flex", ...props }}>{children}</div>
8+
const Flex: FC<FlexProps> = ({ children, className, ...props }) => {
9+
return (
10+
<div className={className} style={{ display: "flex", ...props }}>
11+
{children}
12+
</div>
13+
)
914
}
1015

1116
export { Flex }

src/connectors/index.ts

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,62 @@ import {
33
isInArgentMobileAppBrowser,
44
ArgentMobileConnector,
55
} from "starknetkit/argentMobile"
6+
import {
7+
BraavosMobileConnector,
8+
isInBraavosMobileAppBrowser,
9+
} from "starknetkit/braavosMobile"
610
import { InjectedConnector } from "starknetkit/injected"
711
import { WebWalletConnector } from "starknetkit/webwallet"
812

9-
export const connectors = isInArgentMobileAppBrowser()
10-
? [
11-
ArgentMobileConnector.init({
12-
options: {
13-
url: typeof window !== "undefined" ? window.location.href : "",
14-
dappName: "Example dapp",
15-
chainId: CHAIN_ID,
16-
},
17-
}),
18-
]
19-
: [
20-
new InjectedConnector({ options: { id: "argentX" } }),
21-
new InjectedConnector({ options: { id: "braavos" } }),
13+
const isMobileDevice = () => {
14+
if (typeof window === "undefined") {
15+
return false
16+
}
17+
18+
// Primary method: User Agent + Touch support check
19+
const userAgent = navigator.userAgent.toLowerCase()
20+
const isMobileUA =
21+
/android|webos|iphone|ipad|ipod|blackberry|windows phone/.test(userAgent)
22+
const hasTouchSupport =
23+
"ontouchstart" in window || navigator.maxTouchPoints > 0
24+
25+
// Backup method: Screen size
26+
const isSmallScreen = window.innerWidth <= 768
27+
28+
// Combine checks: Must match user agent AND (touch support OR small screen)
29+
return isMobileUA && (hasTouchSupport || isSmallScreen)
30+
}
31+
32+
export const availableConnectors = () => {
33+
if (isInArgentMobileAppBrowser()) {
34+
return [
2235
ArgentMobileConnector.init({
2336
options: {
2437
url: typeof window !== "undefined" ? window.location.href : "",
2538
dappName: "Example dapp",
2639
chainId: CHAIN_ID,
2740
},
2841
}),
29-
new WebWalletConnector({ url: ARGENT_WEBWALLET_URL }),
3042
]
43+
}
44+
45+
if (isInBraavosMobileAppBrowser()) {
46+
return [BraavosMobileConnector.init({})]
47+
}
48+
49+
return [
50+
new InjectedConnector({ options: { id: "argentX" } }),
51+
new InjectedConnector({ options: { id: "braavos" } }),
52+
ArgentMobileConnector.init({
53+
options: {
54+
url: typeof window !== "undefined" ? window.location.href : "",
55+
dappName: "Example dapp",
56+
chainId: CHAIN_ID,
57+
},
58+
}),
59+
isMobileDevice() ? BraavosMobileConnector.init({}) : null,
60+
new WebWalletConnector({ url: ARGENT_WEBWALLET_URL }),
61+
].filter((connector) => connector !== null)
62+
}
63+
64+
export const connectors = availableConnectors()

0 commit comments

Comments
 (0)