-
Notifications
You must be signed in to change notification settings - Fork 184
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
18 changed files
with
132 additions
and
130 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
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 was deleted.
Oops, something went wrong.
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,28 @@ | ||
import { createContext, useContext, type ReactNode } from "react"; | ||
import { Address } from "viem"; | ||
|
||
export type Config = { | ||
chainId: number; | ||
worldAddress: Address; | ||
gasTankAddress: Address; | ||
}; | ||
|
||
/** @internal */ | ||
const Context = createContext<Config | null>(null); | ||
|
||
export type Props = { | ||
config: Config; | ||
children: ReactNode; | ||
}; | ||
|
||
export function MUDAccountKitProvider({ config, children }: Props) { | ||
const currentConfig = useContext(Context); | ||
if (currentConfig) throw new Error("`MUDAccountKitProvider` can only be used once."); | ||
return <Context.Provider value={config}>{children}</Context.Provider>; | ||
} | ||
|
||
export function useConfig(): Config { | ||
const config = useContext(Context); | ||
if (!config) throw new Error("`useConfig` be used within a `MUDAccountKitProvider`."); | ||
return config; | ||
} |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
export { LoginButton } from "../LoginButton"; | ||
export { useLoginDialog } from "../useLoginDialog"; | ||
export { useLoginRequirements } from "../useLoginRequirements"; | ||
export { MUDLoginProvider } from "../Context"; | ||
export { useLoginDialog } from "../useAccountModal"; | ||
export { useLoginRequirements } from "../useAccountRequirements"; | ||
export { MUDLoginProvider } from "../MUDAccountKitProvider"; | ||
export { useAppAccountClient } from "../useAppAccountClient"; |
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,46 @@ | ||
import { useConnectModal } from "@rainbow-me/rainbowkit"; | ||
import { useCallback, useMemo } from "react"; | ||
import { useStore } from "zustand"; | ||
import { createStore } from "zustand/vanilla"; | ||
|
||
const store = createStore(() => ({ open: false })); | ||
|
||
export type UseAccountModalResult = { | ||
readonly openConnectModal: (() => void) | undefined; | ||
readonly connectPending: boolean; | ||
readonly accountModalOpen: boolean; | ||
readonly openAccountModal: () => void; | ||
readonly closeAccountModal: () => void; | ||
readonly toggleAccountModal: (open: boolean) => void; | ||
}; | ||
|
||
export function useAccountModal(): UseAccountModalResult { | ||
const { openConnectModal, connectModalOpen } = useConnectModal(); | ||
const connectPending = !openConnectModal || connectModalOpen; | ||
|
||
const accountModalOpen = useStore(store, (state) => state.open); | ||
|
||
const openAccountModal = useCallback(() => { | ||
store.setState({ open: true }); | ||
}, []); | ||
|
||
const closeAccountModal = useCallback(() => { | ||
store.setState({ open: false }); | ||
}, []); | ||
|
||
const toggleAccountModal = useCallback((open: boolean) => { | ||
store.setState({ open }); | ||
}, []); | ||
|
||
return useMemo( | ||
() => ({ | ||
openConnectModal, | ||
connectPending, | ||
accountModalOpen, | ||
openAccountModal, | ||
closeAccountModal, | ||
toggleAccountModal, | ||
}), | ||
[closeAccountModal, connectPending, accountModalOpen, openConnectModal, openAccountModal, toggleAccountModal], | ||
); | ||
} |
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
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
Oops, something went wrong.