-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch storybook framework to react vite
- Loading branch information
1 parent
657d176
commit 553ac67
Showing
14 changed files
with
311 additions
and
1,065 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { constants } from "starknet"; | ||
import { getChainName } from "@cartridge/utils"; | ||
import Controller from "@cartridge/controller"; | ||
import { SessionPolicies } from "@cartridge/presets"; | ||
import { Parameters } from "@storybook/react"; | ||
import { ConnectionContextValue } from "../src/components/Provider/connection"; | ||
import { UpgradeInterface } from "../src/hooks/upgrade"; | ||
import { ConnectCtx, ConnectionCtx } from "../src/utils/connection/types"; | ||
import { defaultTheme } from "@cartridge/presets"; | ||
|
||
export interface StoryParameters extends Parameters { | ||
connection?: { | ||
context?: ConnectionCtx; | ||
controller?: Controller; | ||
chainId?: string; | ||
upgrade?: UpgradeInterface; | ||
}; | ||
preset?: string; | ||
policies?: SessionPolicies; | ||
} | ||
|
||
export function useMockedConnection({ | ||
chainId = constants.StarknetChainId.SN_SEPOLIA, | ||
context = { | ||
type: "connect", | ||
origin: "http://localhost:3002", | ||
policies: [], | ||
resolve: () => {}, | ||
reject: () => {}, | ||
} as ConnectCtx, | ||
...rest | ||
}: StoryParameters["connection"] = {}): ConnectionContextValue { | ||
const chainName = getChainName(chainId); | ||
|
||
return { | ||
context, | ||
origin: "http://localhost:3002", | ||
rpcUrl: "http://api.cartridge.gg/x/sepolia", | ||
chainId, | ||
chainName, | ||
policies: {}, | ||
theme: defaultTheme, | ||
prefunds: [], | ||
hasPrefundRequest: false, | ||
error: undefined, | ||
setContext: () => {}, | ||
setController: () => {}, | ||
closeModal: () => {}, | ||
openModal: () => {}, | ||
logout: () => {}, | ||
openSettings: () => {}, | ||
controller: {}, | ||
upgrade: {}, | ||
...rest, | ||
}; | ||
} |
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,59 @@ | ||
import React, { PropsWithChildren } from "react"; | ||
import { QueryClient, QueryClientProvider } from "react-query"; | ||
import { ControllerThemeContext, useChakraTheme } from "../src/hooks/theme"; | ||
import { ConnectionContext } from "../src/components/Provider/connection"; | ||
import { | ||
defaultTheme, | ||
controllerConfigs, | ||
ControllerTheme, | ||
} from "@cartridge/presets"; | ||
import { mainnet } from "@starknet-react/chains"; | ||
import { StarknetConfig, publicProvider, voyager } from "@starknet-react/core"; | ||
import { useThemeEffect } from "@cartridge/ui-next"; | ||
import { ChakraProvider } from "@chakra-ui/react"; | ||
import { StoryParameters, useMockedConnection } from "./mock"; | ||
|
||
export function Provider({ | ||
children, | ||
parameters, | ||
}: { parameters: StoryParameters } & PropsWithChildren) { | ||
const connection = useMockedConnection(parameters.connection); | ||
|
||
if (parameters.preset) { | ||
const config = controllerConfigs[parameters.preset]; | ||
connection.theme = config.theme || connection.theme; | ||
connection.policies = config.policies || connection.policies; | ||
} | ||
|
||
return ( | ||
<StarknetConfig | ||
chains={[mainnet]} | ||
explorer={voyager} | ||
provider={publicProvider()} | ||
> | ||
<QueryClientProvider client={queryClient}> | ||
<ConnectionContext.Provider value={connection}> | ||
<ControllerThemeProvider theme={connection.theme}> | ||
{children} | ||
</ControllerThemeProvider> | ||
</ConnectionContext.Provider> | ||
</QueryClientProvider> | ||
</StarknetConfig> | ||
); | ||
} | ||
|
||
const queryClient = new QueryClient(); | ||
|
||
function ControllerThemeProvider({ | ||
children, | ||
theme = defaultTheme, | ||
}: PropsWithChildren<{ theme?: ControllerTheme }>) { | ||
useThemeEffect({ theme, assetUrl: "" }); | ||
const chakraTheme = useChakraTheme(theme); | ||
|
||
return ( | ||
<ControllerThemeContext.Provider value={theme}> | ||
<ChakraProvider theme={chakraTheme}>{children}</ChakraProvider> | ||
</ControllerThemeContext.Provider> | ||
); | ||
} |
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.