Skip to content

Commit b29cb5f

Browse files
Rename @cartridge/ui-next to @cartridge/ui
1 parent 5a862cc commit b29cb5f

File tree

431 files changed

+423
-133
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

431 files changed

+423
-133
lines changed

examples/next/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"dependencies": {
1616
"@cartridge/connector": "workspace:*",
1717
"@cartridge/controller": "workspace:*",
18-
"@cartridge/ui-next": "workspace:*",
18+
"@cartridge/ui": "workspace:*",
1919
"@starknet-react/chains": "catalog:",
2020
"@starknet-react/core": "catalog:",
2121
"next": "^15.1.5",

examples/next/src/app/globals.css

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
@import "@cartridge/ui-next/dist/themes/default.css";
2-
@import "@cartridge/ui-next/dist/themes/dark.css";
3-
@import "@cartridge/ui-next/dist/themes/fonts.css";
1+
@import "@cartridge/ui/dist/themes/default.css";
2+
@import "@cartridge/ui/dist/themes/dark.css";
3+
@import "@cartridge/ui/dist/themes/fonts.css";
44

55
@tailwind base;
66
@tailwind components;
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
"use client";
2+
3+
import {
4+
useAccount,
5+
useReadContract,
6+
useSendTransaction,
7+
} from "@starknet-react/core";
8+
import { useCallback, useMemo, useState } from "react";
9+
import { cairo, Call, CallData, uint256 } from "starknet";
10+
import { ConnectWallet } from "components/ConnectWallet";
11+
import { useTokenContract } from "hooks/token";
12+
import { Abi } from "starknet";
13+
import Erc20Abi from "abi/erc20.json";
14+
import { Button, Input } from "@cartridge/ui";
15+
16+
function UserBalance() {
17+
const { account } = useAccount();
18+
19+
const { data, isLoading, error } = useReadContract({
20+
abi: Erc20Abi as Abi,
21+
address:
22+
"0x07394cbe418daa16e42b87ba67372d4ab4a5df0b05c6e554d158458ce245bc10",
23+
functionName: "balanceOf",
24+
args: account ? [account] : undefined,
25+
});
26+
27+
const content = useMemo(() => {
28+
if (isLoading || !(data as [])?.length) {
29+
return <div>Loading balance</div>;
30+
}
31+
32+
if (error) {
33+
console.error(error);
34+
return <div>Error!</div>;
35+
}
36+
37+
const balance = uint256.uint256ToBN(cairo.uint256(data[0]));
38+
return <div>{balance.toString(10)}</div>;
39+
}, [data, isLoading, error]);
40+
41+
return (
42+
<div>
43+
<h2>User balance</h2>
44+
{content}
45+
</div>
46+
);
47+
}
48+
49+
function MintToken() {
50+
const { account, address } = useAccount();
51+
const [amount, setAmount] = useState("");
52+
const [amountError, setAmountError] = useState<string | undefined>();
53+
54+
const { contract } = useTokenContract();
55+
56+
const calls: Call[] = useMemo(() => {
57+
if (!address || !contract) return [];
58+
59+
const amountBn = cairo.uint256(amount);
60+
return [
61+
{
62+
contractAddress: contract.address,
63+
entrypoint: "mint",
64+
calldata: CallData.compile([address, amountBn]),
65+
},
66+
];
67+
}, [address, contract, amount]);
68+
69+
const { sendAsync, isPending, error, reset } = useSendTransaction({
70+
calls: calls,
71+
});
72+
73+
const updateAmount = useCallback(
74+
(newAmount: string) => {
75+
// soft-validate amount
76+
setAmount(newAmount);
77+
try {
78+
BigInt(newAmount);
79+
setAmountError(undefined);
80+
} catch (err) {
81+
console.error(err);
82+
setAmountError("Please input a valid number");
83+
}
84+
},
85+
[setAmount],
86+
);
87+
88+
const onMint = useCallback(() => {
89+
reset();
90+
if (account && !amountError) {
91+
sendAsync();
92+
}
93+
}, [account, amountError, reset, sendAsync]);
94+
95+
const mintButtonDisabled = useMemo(() => {
96+
if (isPending) return true;
97+
return !account || !!amountError;
98+
}, [isPending, account, amountError]);
99+
100+
return (
101+
<div>
102+
<h2>Mint token</h2>
103+
<p>
104+
<span>Amount: </span>
105+
<Input
106+
type="number"
107+
onChange={(evt) => updateAmount(evt.target.value)}
108+
/>
109+
</p>
110+
<Button disabled={mintButtonDisabled} onClick={onMint}>
111+
{isPending ? "Submitting" : "Mint"}
112+
</Button>
113+
{error && (
114+
<p>
115+
<>Error: {error}</>
116+
</p>
117+
)}
118+
</div>
119+
);
120+
}
121+
122+
export default function TokenPage() {
123+
const { address } = useAccount();
124+
125+
if (!address) {
126+
return (
127+
<div>
128+
<p>Connect Wallet</p>
129+
<ConnectWallet />
130+
</div>
131+
);
132+
}
133+
return (
134+
<div>
135+
<p>Connected: {address}</p>
136+
<UserBalance />
137+
<MintToken />
138+
</div>
139+
);
140+
}

examples/next/src/components/ColorModeToggle.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
DropdownMenuContent,
1111
DropdownMenuItem,
1212
DropdownMenuTrigger,
13-
} from "@cartridge/ui-next";
13+
} from "@cartridge/ui";
1414

1515
export function ColorModeToggle() {
1616
const { setTheme } = useTheme();
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
"use client";
2+
3+
import { useAccount, useConnect, useDisconnect } from "@starknet-react/core";
4+
import ControllerConnector from "@cartridge/connector/controller";
5+
import React, { useEffect, useState, useRef } from "react";
6+
import { Button } from "@cartridge/ui";
7+
8+
export function ConnectWallet() {
9+
const { connect, connectors } = useConnect();
10+
const { disconnect } = useDisconnect();
11+
const { address } = useAccount();
12+
13+
const controller = connectors[0] as ControllerConnector;
14+
const [isDragging, setIsDragging] = useState(false);
15+
const [position, setPosition] = useState({ x: -1000, y: -1000 });
16+
const dragRef = useRef<{ startX: number; startY: number }>(undefined);
17+
18+
useEffect(() => {
19+
setPosition({
20+
x: window.innerWidth - 220,
21+
y: window.innerHeight - 220,
22+
});
23+
}, []);
24+
25+
const [username, setUsername] = useState<string>();
26+
useEffect(() => {
27+
if (!address) return;
28+
controller.username()?.then((n) => setUsername(n));
29+
}, [address, controller]);
30+
31+
const handleMouseDown = (e: React.MouseEvent) => {
32+
setIsDragging(true);
33+
dragRef.current = {
34+
startX: e.pageX - position.x,
35+
startY: e.pageY - position.y,
36+
};
37+
};
38+
39+
const handleMouseMove = (e: React.MouseEvent) => {
40+
if (!isDragging || !dragRef.current) return;
41+
42+
setPosition({
43+
x: e.pageX - dragRef.current.startX,
44+
y: e.pageY - dragRef.current.startY,
45+
});
46+
};
47+
48+
const handleMouseUp = () => {
49+
setIsDragging(false);
50+
dragRef.current = undefined;
51+
};
52+
53+
const registerSessionUrl =
54+
"http://localhost:3001/session?public_key=0x2cb057c18198ae4555a144bfdace051433b9a545dc88224de58fa04e323f269&redirect_uri=http://localhost:3002&policies=%5B%7B%22target%22:%220x03661Ea5946211b312e8eC71B94550928e8Fd3D3806e43c6d60F41a6c5203645%22,%22method%22:%22attack%22,%22description%22:%22Attack%20the%20beast%22%7D,%7B%22target%22:%220x03661Ea5946211b312e8eC71B94550928e8Fd3D3806e43c6d60F41a6c5203645%22,%22method%22:%22claim%22,%22description%22:%22Claim%20your%20tokens%22%7D%5D&rpc_url=http://localhost:8001/x/starknet/sepolia";
55+
56+
const openRegisterSessionUrl = () => {
57+
window.open(registerSessionUrl, "_blank", "noopener,noreferrer");
58+
};
59+
60+
return (
61+
<div
62+
style={{ position: "relative" }}
63+
onMouseMove={handleMouseMove}
64+
onMouseUp={handleMouseUp}
65+
onMouseLeave={handleMouseUp}
66+
>
67+
{address && (
68+
<>
69+
<p>Account: {address} </p>
70+
{username && <p>Username: {username}</p>}
71+
</>
72+
)}
73+
{address ? (
74+
<Button onClick={() => disconnect()}>Disconnect</Button>
75+
) : (
76+
<div className="flex gap-1">
77+
<Button onClick={() => connect({ connector: controller })}>
78+
Connect
79+
</Button>
80+
{/* <Button onClick={() => connect({ connector: session })}>
81+
Create Session
82+
</Button> */}
83+
<Button onClick={openRegisterSessionUrl}>Register Session</Button>
84+
</div>
85+
)}
86+
87+
{/* Draggable test overlay */}
88+
<div
89+
onMouseDown={handleMouseDown}
90+
style={{
91+
position: "fixed",
92+
top: position.y,
93+
left: position.x,
94+
width: 200,
95+
height: 200,
96+
backgroundColor: "rgba(255, 0, 0, 0.3)",
97+
border: "2px solid red",
98+
cursor: isDragging ? "grabbing" : "grab",
99+
zIndex: 10001,
100+
display: "flex",
101+
alignItems: "center",
102+
justifyContent: "center",
103+
userSelect: "none",
104+
}}
105+
>
106+
<div
107+
style={{
108+
color: "white",
109+
textAlign: "center",
110+
textShadow: "1px 1px 2px rgba(0,0,0,0.8)",
111+
pointerEvents: "none",
112+
}}
113+
>
114+
Drag me around
115+
<br />
116+
(Clickjacking Test)
117+
</div>
118+
</div>
119+
</div>
120+
);
121+
}

examples/next/src/components/DelegateAccount.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useAccount } from "@starknet-react/core";
44
import { useCallback, useEffect, useState } from "react";
55
import { constants } from "starknet";
66
import ControllerConnector from "@cartridge/connector/controller";
7-
import { Button, Input } from "@cartridge/ui-next";
7+
import { Button, Input } from "@cartridge/ui";
88

99
export const DelegateAccount = () => {
1010
const [chainId] = useState<constants.StarknetChainId>(

examples/next/src/components/Header.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use client";
22

3-
import { Button } from "@cartridge/ui-next";
3+
import { Button } from "@cartridge/ui";
44
import ControllerConnector from "@cartridge/connector/controller";
55
import {
66
useAccount,

examples/next/src/components/InvalidTxn.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use client";
22

3-
import { Button } from "@cartridge/ui-next";
3+
import { Button } from "@cartridge/ui";
44
import { useAccount, useSendTransaction } from "@starknet-react/core";
55

66
const ETH_CONTRACT =

examples/next/src/components/LookupControllers.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useAccount } from "@starknet-react/core";
44
import { useCallback, useState } from "react";
55
import ControllerConnector from "@cartridge/connector/controller";
66
import { lookupAddresses, lookupUsernames } from "@cartridge/controller";
7-
import { Button } from "@cartridge/ui-next";
7+
import { Button } from "@cartridge/ui";
88

99
export function LookupControllers() {
1010
const { address, connector } = useAccount();

examples/next/src/components/ManualTransferEth.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use client";
22

3-
import { Button } from "@cartridge/ui-next";
3+
import { Button } from "@cartridge/ui";
44
import { useAccount, useNetwork } from "@starknet-react/core";
55
import { useCallback, useState } from "react";
66
import { ETH_CONTRACT_ADDRESS } from "./providers/StarknetProvider";

0 commit comments

Comments
 (0)