-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
209 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@starknet-react/core": patch | ||
--- | ||
|
||
Fix wallet connection when wallet not authorized |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@starknet-react/core": patch | ||
--- | ||
|
||
Add hook to detect injected connectors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,4 +17,3 @@ export default function DocLayout({ children }: { children: React.ReactNode }) { | |
); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import React from "react"; | ||
|
||
import { notFound, redirect } from "next/navigation"; | ||
|
||
import { allHooks } from "@/.contentlayer/generated"; | ||
import { Mdx } from "@/components/mdx"; | ||
import { DocContainer } from "@/components/container"; | ||
|
||
type DocPageProps = { | ||
params: { | ||
slug: string[]; | ||
}; | ||
}; | ||
|
||
async function getDocFromParams({ params }: DocPageProps) { | ||
const slug = params.slug?.join("/") || ""; | ||
|
||
if (slug === "") { | ||
const redirectTo = allHooks[0]?.slugAsParams; | ||
return { doc: null, redirectTo }; | ||
} | ||
|
||
const doc = allHooks.find((doc) => doc.slugAsParams === slug); | ||
|
||
if (!doc) { | ||
return { doc: null, redirectTo: null }; | ||
} | ||
|
||
return { doc, redirectTo: null }; | ||
} | ||
|
||
export async function generateStaticParams(): Promise< | ||
DocPageProps["params"][] | ||
> { | ||
return allHooks.map((doc) => ({ | ||
slug: doc.slugAsParams.split("/"), | ||
})); | ||
} | ||
|
||
export default async function DocPage({ params }: DocPageProps) { | ||
const { doc, redirectTo } = await getDocFromParams({ params }); | ||
|
||
if (!doc) { | ||
if (redirectTo) { | ||
redirect(`/hooks/${redirectTo}`); | ||
} else { | ||
notFound(); | ||
} | ||
} | ||
|
||
return ( | ||
<DocContainer title={doc.title} section="Hooks"> | ||
<Mdx code={doc.body.code} /> | ||
</DocContainer> | ||
); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React from "react"; | ||
|
||
import { Sidebar } from "@/components/sidebar"; | ||
import { ScrollArea } from "@/components/ui/scroll-area"; | ||
import { docsSidebar } from "@/lib/sidebar"; | ||
|
||
export default function HookLayout({ children }: { children: React.ReactNode }) { | ||
return ( | ||
<div className="container flex-1 items-start md:grid md:grid-cols-[220px_minmax(0,1fr)] md:gap-6 lg:grid-cols-[240px_minmax(0,1fr)] lg:gap-10"> | ||
<aside className="fixed top-14 z-30 -ml-2 hidden h-[calc(100vh-3.5rem)] w-full shrink-0 md:sticky md:block"> | ||
<ScrollArea className="h-full py-6 pl-8 pr-6 lg:py-8"> | ||
<Sidebar items={docsSidebar} /> | ||
</ScrollArea> | ||
</aside> | ||
{children} | ||
</div > | ||
); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
--- | ||
title: useInjectedConnectors | ||
priority: 100 | ||
--- | ||
|
||
Hook for discovering injected connectors. | ||
|
||
## Usage | ||
|
||
```ts | ||
import { | ||
StarknetConfig, | ||
publicProvider, | ||
argent, | ||
braavos, | ||
useInjectedConnectors, | ||
} from "@starknet-react/core"; | ||
|
||
export default function App({ children }) { | ||
const chains = [goerli, mainnet]; | ||
const providers = [publicProvider()]; | ||
const { connectors } = useInjectedConnectors({ | ||
// Show these connectors if the user has no connector installed. | ||
recommended: [ | ||
argent(), | ||
braavos(), | ||
], | ||
// Hide recommended connectors if the user has any connector installed. | ||
includeRecommended: "onlyIfNoConnectors", | ||
// Randomize the order of the connectors. | ||
order: "random" | ||
}); | ||
|
||
return ( | ||
<StarknetConfig | ||
chains={chains} | ||
providers={providers} | ||
connectors={connectors} | ||
> | ||
{children} | ||
</StarknetConfig> | ||
); | ||
} | ||
``` | ||
|
||
## Options | ||
|
||
* `recommended?: Connector[]` | ||
- List of recommended connectors. | ||
|
||
* `includeRecommended?: "always" | "onlyIfNoConnectors"` | ||
- If `"always"`, the hook always returns the recommended connectors. | ||
- If `"onlyIfNoConnectors"`, the recommended connectors are included only if | ||
no other connector is installed. | ||
|
||
* `order?: "random" | "alphabetical"` | ||
- Control the order in which connectors are returned. | ||
- If `"random"`, connectors are shuffled. | ||
- If `"alphabetical"`, connectors are alphabetically sorted by their id. | ||
|
||
## Returns | ||
|
||
* `connectors: Connector[]` | ||
- Contains the list of injected connectors installed by the user. | ||
- All connectors are unique and sorted. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,3 +90,7 @@ | |
@apply leading-6 font-mono; | ||
font-size: 15px; | ||
} | ||
|
||
.mdx :where(ul ul, ul ol, ol ul, ol ol) { | ||
margin-top: 0; | ||
} |