-
Notifications
You must be signed in to change notification settings - Fork 3
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
1 parent
f16b89b
commit 25cefed
Showing
4 changed files
with
97 additions
and
1 deletion.
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
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,63 @@ | ||
import { | ||
addNetworkLatest, | ||
addNetworkNext, | ||
switchNetworkLatest, | ||
switchNetworkNext, | ||
} from "@/services/addNetwork.ts" | ||
import { walletStarknetkitLatestAtom } from "@/state/connectedWalletStarknetkitLatest" | ||
import { walletStarknetkitNextAtom } from "@/state/connectedWalletStarknetkitNext" | ||
import { Flex, Heading } from "@chakra-ui/react" | ||
import { useAtomValue } from "jotai" | ||
import { FC, useState } from "react" | ||
|
||
const SwitchNetworkLatest = () => { | ||
const wallet = useAtomValue(walletStarknetkitLatestAtom) | ||
return ( | ||
<SwitchNetwork | ||
switchNetworkFn={async () => await switchNetworkLatest(wallet)} | ||
/> | ||
) | ||
} | ||
|
||
const SwitchNetworkNext = () => { | ||
const wallet = useAtomValue(walletStarknetkitNextAtom) | ||
return ( | ||
<SwitchNetwork | ||
switchNetworkFn={async () => await switchNetworkNext(wallet)} | ||
/> | ||
) | ||
} | ||
|
||
interface SwitchNetworkProps { | ||
switchNetworkFn: () => Promise<void> | ||
} | ||
|
||
const SwitchNetwork: FC<SwitchNetworkProps> = ({ switchNetworkFn }) => { | ||
const [switchNetworkError, setSwitchNetworkError] = useState("") | ||
|
||
const handleSwitchNetwork = async () => { | ||
try { | ||
await switchNetworkFn() | ||
setSwitchNetworkError("") | ||
} catch (error) { | ||
setSwitchNetworkError((error as any).message) | ||
} | ||
} | ||
|
||
return ( | ||
<Flex direction="column" gap="3" flex="1"> | ||
<Heading as="h2">Network</Heading> | ||
<Flex | ||
as="button" | ||
color="#0097fc" | ||
fontWeight="bold" | ||
onClick={handleSwitchNetwork} | ||
> | ||
Switch network | ||
</Flex> | ||
<span className="error-message">{switchNetworkError}</span> | ||
</Flex> | ||
) | ||
} | ||
|
||
export { SwitchNetworkLatest, SwitchNetworkNext } |
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