-
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
8 changed files
with
114 additions
and
5 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@starknet-react-core-2cb32fda-224a-4b36-86e2-acffaa17d520.json
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,7 @@ | ||
{ | ||
"type": "patch", | ||
"comment": "Add provider option to select default chain when no wallet is connected", | ||
"packageName": "@starknet-react/core", | ||
"email": "[email protected]", | ||
"dependentChangeType": "patch" | ||
} |
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,70 @@ | ||
import { type Chain, mainnet, sepolia } from "@starknet-react/chains"; | ||
import { publicProvider, useAccount, useNetwork } from "@starknet-react/core"; | ||
import { useState } from "react"; | ||
import { Button } from "../ui/button"; | ||
import { DemoContainer } from "../starknet"; | ||
|
||
export function ChangeDefaultNetwork() { | ||
const [defaultChain, setDefaultChain] = useState<Chain>(sepolia); | ||
const chains = [mainnet, sepolia]; | ||
const provider = publicProvider(); | ||
|
||
return ( | ||
<DemoContainer hasWallet defaultChainId={defaultChain.id}> | ||
<ChangeNetworkInner | ||
defaultChain={defaultChain} | ||
setDefaultChain={setDefaultChain} | ||
/> | ||
</DemoContainer> | ||
); | ||
} | ||
|
||
function ChangeNetworkInner({ | ||
defaultChain, | ||
setDefaultChain, | ||
}: { | ||
defaultChain: Chain; | ||
setDefaultChain: (chain: Chain) => void; | ||
}) { | ||
const { chain } = useNetwork(); | ||
const chains = [sepolia, mainnet]; | ||
const { isConnected } = useAccount(); | ||
|
||
return ( | ||
<div className="flex flex-col gap-4"> | ||
<div className="h-full flex flex-col justify-center"> | ||
<p className="font-medium">Current Chain: </p> | ||
<pre>{chain.name}</pre> | ||
</div> | ||
|
||
<div className="h-full flex flex-col justify-center"> | ||
<p className="font-medium">Default Chain: </p> | ||
<pre>{defaultChain.name}</pre> | ||
</div> | ||
|
||
<div> | ||
<p className="font-medium">Change Default Chain:</p> | ||
<div className="flex gap-2 my-2"> | ||
{chains.map((chain) => ( | ||
<Button | ||
key={chain.id} | ||
onClick={() => setDefaultChain(chain)} | ||
variant={defaultChain.id === chain.id ? "default" : "outline"} | ||
> | ||
{chain.name} | ||
</Button> | ||
))} | ||
</div> | ||
</div> | ||
|
||
<div className="h-full flex flex-col justify-center"> | ||
<p className="font-medium">Behavior Explanation: </p> | ||
<pre> | ||
{isConnected | ||
? "Connected: Changing default chain won't affect current chain" | ||
: "Not Connected: Changing default chain will update current chain"} | ||
</pre> | ||
</div> | ||
</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,5 @@ | ||
import Demo from "../../components/demo"; | ||
|
||
# Change Default Network (Todo) | ||
|
||
<Demo.ChangeDefaultNetwork /> |
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