From 197054584977c034bb903df31e894b4a2e2e9b2b Mon Sep 17 00:00:00 2001 From: Francesco Ceccon Date: Wed, 16 Oct 2024 19:47:56 +0200 Subject: [PATCH 1/3] chains: update RPC to v0.7 --- ...ct-chains-6d856b0e-b860-43eb-819a-d712fd4c3f3c.json | 7 +++++++ packages/chains/src/starknet.ts | 10 ++-------- 2 files changed, 9 insertions(+), 8 deletions(-) create mode 100644 change/@starknet-react-chains-6d856b0e-b860-43eb-819a-d712fd4c3f3c.json diff --git a/change/@starknet-react-chains-6d856b0e-b860-43eb-819a-d712fd4c3f3c.json b/change/@starknet-react-chains-6d856b0e-b860-43eb-819a-d712fd4c3f3c.json new file mode 100644 index 00000000..fbaa50a3 --- /dev/null +++ b/change/@starknet-react-chains-6d856b0e-b860-43eb-819a-d712fd4c3f3c.json @@ -0,0 +1,7 @@ +{ + "type": "patch", + "comment": "Update RPC urls to RPC 0.7", + "packageName": "@starknet-react/chains", + "email": "francesco@ceccon.me", + "dependentChangeType": "patch" +} diff --git a/packages/chains/src/starknet.ts b/packages/chains/src/starknet.ts index cc4689bc..356e5a84 100644 --- a/packages/chains/src/starknet.ts +++ b/packages/chains/src/starknet.ts @@ -44,9 +44,9 @@ export const mainnet = { }, public: { http: [ - "https://starknet-mainnet.public.blastapi.io/rpc/v0.5", + "https://starknet-mainnet.public.blastapi.io/rpc/v0_7", "https://rpc.starknet.lava.build", - "https://free-rpc.nethermind.io/mainnet-juno/v0_5", + "https://free-rpc.nethermind.io/mainnet-juno/v0_7", ], }, }, @@ -71,18 +71,12 @@ export const sepolia = { }, testnet: true, rpcUrls: { - // alchemy: { - // http: [], - // }, blast: { http: ["https://starknet-sepolia.blastapi.io"], }, infura: { http: ["https://starknet-sepolia.infura.io/v3"], }, - // lava: { - // http: [], - // }, nethermind: { http: ["https://rpc.nethermind.io/sepolia-juno"], }, From 632a6dbd72199869b5966c227583a3cec0e661c6 Mon Sep 17 00:00:00 2001 From: Francesco Ceccon Date: Wed, 16 Oct 2024 19:48:35 +0200 Subject: [PATCH 2/3] docs: add useBalance demo --- docs/components/demo/balance.tsx | 62 ++++++++++++++++++++++++++++++++ docs/components/demo/index.ts | 6 ++-- docs/components/starknet/bar.tsx | 10 +++--- docs/components/ui/button.tsx | 4 +-- docs/pages/demo/balance.mdx | 6 ++++ docs/pages/demo/index.mdx | 2 ++ docs/sidebar.ts | 45 ++++++++++++----------- docs/vercel.json | 2 +- 8 files changed, 106 insertions(+), 31 deletions(-) create mode 100644 docs/components/demo/balance.tsx create mode 100644 docs/pages/demo/balance.mdx diff --git a/docs/components/demo/balance.tsx b/docs/components/demo/balance.tsx new file mode 100644 index 00000000..fb519d9d --- /dev/null +++ b/docs/components/demo/balance.tsx @@ -0,0 +1,62 @@ +"use client"; + +import { useAccount, useBalance } from "@starknet-react/core"; +import { DemoContainer } from "../starknet"; + +function AccountBalance({ account }: { account: `0x${string}` }) { + const { data, error } = useBalance({ + address: account, + }); + + if (data) { + return ( +
+

+ Address: + {account.slice(0, 6)}...{account.slice(-4)} +

+

+ Balance: + {`${data.formatted} ${data.symbol}`} +

+
+ ); + } + + if (error) { + return ( +
+

Error fetching balance

+
{error.message}
+
+ ); + } + + return ( +
+

Loading balance...

+
+ ); +} + +function BalanceInner() { + const { address } = useAccount(); + + return ( +
+ {address ? ( + + ) : ( +

Connect wallet to display its balance.

+ )} +
+ ); +} + +export function Balance() { + return ( + + + + ); +} diff --git a/docs/components/demo/index.ts b/docs/components/demo/index.ts index 6aaf1cfe..0a4f8542 100644 --- a/docs/components/demo/index.ts +++ b/docs/components/demo/index.ts @@ -1,5 +1,6 @@ +import { Account } from "./account"; import { AddChain } from "./add-chain"; -import { WalletPermission } from "./wallet-permission"; +import { Balance } from "./balance"; import { DeclareContract } from "./declare-contract"; import { EstimateFees } from "./estimate-fees"; import { NonceForAddress } from "./nonce-for-address"; @@ -11,11 +12,12 @@ import { StarkName } from "./stark-name"; import { StarkProfile } from "./stark-profile"; import { StarknetKit } from "./starknetkit"; import { SwitchChain } from "./switch-chain"; -import { Account } from "./account"; +import { WalletPermission } from "./wallet-permission"; export default { Account, WalletPermission, + Balance, ReadContract, SendTransaction, EstimateFees, diff --git a/docs/components/starknet/bar.tsx b/docs/components/starknet/bar.tsx index 2b140101..58f44127 100644 --- a/docs/components/starknet/bar.tsx +++ b/docs/components/starknet/bar.tsx @@ -1,21 +1,21 @@ import { useAccount, useConnect } from "@starknet-react/core"; -import type { AccountInterface } from "starknet"; import { Button } from "../ui/button"; export function WalletBar() { - const { account } = useAccount(); + const { address } = useAccount(); + return (
- {account ? : } + {address ? : }
); } -function ConnectedWallet({ account }: { account: AccountInterface }) { +function ConnectedWallet({ address }: { address: `0x${string}` }) { return (

Connected Address:

-
{account.address}
+
{address}
); } diff --git a/docs/components/ui/button.tsx b/docs/components/ui/button.tsx index 944922c5..519e5330 100644 --- a/docs/components/ui/button.tsx +++ b/docs/components/ui/button.tsx @@ -1,6 +1,6 @@ -import * as React from "react"; import { Slot } from "@radix-ui/react-slot"; -import { cva, type VariantProps } from "class-variance-authority"; +import { type VariantProps, cva } from "class-variance-authority"; +import * as React from "react"; import { cn } from "../../lib/utils"; const buttonVariants = cva( diff --git a/docs/pages/demo/balance.mdx b/docs/pages/demo/balance.mdx new file mode 100644 index 00000000..4075d050 --- /dev/null +++ b/docs/pages/demo/balance.mdx @@ -0,0 +1,6 @@ +import Demo from "../../components/demo"; + +# Token Balance + + + diff --git a/docs/pages/demo/index.mdx b/docs/pages/demo/index.mdx index 29da8aac..3742a1d2 100644 --- a/docs/pages/demo/index.mdx +++ b/docs/pages/demo/index.mdx @@ -8,6 +8,8 @@ You can find the source code for these demos [on GitHub](https://github.com/apib **[Account](/demo/account)**: Shows how to access the current account and its address. +**[Balance](/demo/balance)**: Shows how to fetch an ERC-20 token balance. + **[Estimate Fees](/demo/estimate-fees)**: Shows how to estimate fees for smart contract calls. **[Nonce for Address](/demo/nonce-for-address)**: Shows how to get the nonce for an address. diff --git a/docs/sidebar.ts b/docs/sidebar.ts index 79c073c7..d20fd04a 100644 --- a/docs/sidebar.ts +++ b/docs/sidebar.ts @@ -24,12 +24,12 @@ export const sidebar = { { text: "Explorers", link: "/docs/explorers", - } + }, ], }, { - "text": "Smart Contracts", - "items": [ + text: "Smart Contracts", + items: [ { text: "useBalance", link: "/docs/hooks/use-balance", @@ -50,11 +50,11 @@ export const sidebar = { text: "useContractFactory", link: "/docs/hooks/use-contract-factory", }, - ] + ], }, { - "text": "Wallet Actions", - "items": [ + text: "Wallet Actions", + items: [ { text: "useSendTransaction", link: "/docs/hooks/use-send-transaction", @@ -83,12 +83,15 @@ export const sidebar = { text: "useDeployAccount", link: "/docs/hooks/use-deploy-account", }, - ] + ], }, { - "text": "Connectors", - "items": [ - { text: "useInjectedConnectors", link: "/docs/hooks/use-injected-connectors" }, + text: "Connectors", + items: [ + { + text: "useInjectedConnectors", + link: "/docs/hooks/use-injected-connectors", + }, { text: "useAccount", link: "/docs/hooks/use-account" }, { text: "useConnect", @@ -98,11 +101,11 @@ export const sidebar = { text: "useDisconnect", link: "/docs/hooks/use-disconnect", }, - ] + ], }, { - "text": "Helpers", - "items": [ + text: "Helpers", + items: [ { text: "useNetwork", link: "/docs/hooks/use-network", @@ -119,11 +122,11 @@ export const sidebar = { text: "useInvalidateOnBlock", link: "/docs/hooks/use-invalidate-on-block", }, - ] + ], }, { - "text": "RPC Methods", - "items": [ + text: "RPC Methods", + items: [ { text: "useBlock", link: "/docs/hooks/use-block", @@ -144,11 +147,11 @@ export const sidebar = { text: "useTransactionReceipt", link: "/docs/hooks/use-transaction-receipt", }, - ] + ], }, { - "text": "Starknet.ID", - "items": [ + text: "Starknet.ID", + items: [ { text: "useStarkAddress", link: "/docs/hooks/use-stark-address", @@ -161,7 +164,7 @@ export const sidebar = { text: "useStarkProfile", link: "/docs/hooks/use-stark-profile", }, - ] - } + ], + }, ], } as const satisfies Sidebar; diff --git a/docs/vercel.json b/docs/vercel.json index 109ae397..bacbfbe0 100644 --- a/docs/vercel.json +++ b/docs/vercel.json @@ -6,4 +6,4 @@ "permanent": true } ] -} \ No newline at end of file +} From 67936935fc4c6123026e8b62d9814503946bbe71 Mon Sep 17 00:00:00 2001 From: Francesco Ceccon Date: Wed, 16 Oct 2024 19:51:00 +0200 Subject: [PATCH 3/3] ci: update release workflow --- .github/workflows/build.yml | 6 +++--- .github/workflows/release-documentation.yml | 6 +++--- .github/workflows/release.yml | 13 ++++++++----- package.json | 2 +- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 91fdc815..0492e8c7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -22,12 +22,12 @@ jobs: - name: Checkout uses: actions/checkout@v3 - name: Set Node version - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: 20 - - uses: pnpm/action-setup@v2 + - uses: pnpm/action-setup@v4 with: - version: 9.7 + version: 9.10.0 - name: Install dependencies run: pnpm install --strict-peer-dependencies=false --no-frozen-lockfile - name: Run check format diff --git a/.github/workflows/release-documentation.yml b/.github/workflows/release-documentation.yml index d19c620e..02a9f5e4 100644 --- a/.github/workflows/release-documentation.yml +++ b/.github/workflows/release-documentation.yml @@ -16,12 +16,12 @@ jobs: - name: Checkout uses: actions/checkout@v3 - name: Set Node version - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: 20 - - uses: pnpm/action-setup@v2 + - uses: pnpm/action-setup@v4 with: - version: 9.7 + version: 9.10.0 - name: Install dependencies run: pnpm install --strict-peer-dependencies=false --no-frozen-lockfile - name: Build Project Artifacts diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a6395f9d..975e9664 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -7,24 +7,27 @@ on: jobs: release: + environment: Release runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v2 - name: Set Node version - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: 20 - - uses: pnpm/action-setup@v2 + - uses: pnpm/action-setup@v4 with: - version: 9.7 + version: 9.10.0 + - name: Run build + run: pnpm build - name: Setup git run: | git config --global user.name "github-actions[bot]" git config --global user.email "github-actions[bot]@users.noreply.github.com" - git remote set-url origin "https://${GITHUB_TOKEN}@github.com/apibara/starknet-react" + git remote set-url origin "https://${GIT_TOKEN}@github.com/apibara/starknet-react" env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GIT_TOKEN: ${{ secrets.GIT_TOKEN }} - name: Install dependencies run: pnpm install --strict-peer-dependencies=false --no-frozen-lockfile - name: Publish package diff --git a/package.json b/package.json index 1a00021b..9fabe33c 100644 --- a/package.json +++ b/package.json @@ -29,5 +29,5 @@ "node": ">=20", "pnpm": ">=9" }, - "packageManager": "pnpm@9.7.0" + "packageManager": "pnpm@9.10.0" }