Initial commit with 🏗️ create-eth @ 2.0.4
This commit is contained in:
40
packages/nextjs/services/store/challengeStore.ts
Normal file
40
packages/nextjs/services/store/challengeStore.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import { create } from "zustand";
|
||||
import { AssertionWithIdAndState } from "~~/components/oracle/types";
|
||||
|
||||
/**
|
||||
* Zustand Store
|
||||
*
|
||||
* You can add global state to the app using this useGlobalState, to get & set
|
||||
* values from anywhere in the app.
|
||||
*
|
||||
* Think about it as a global useState.
|
||||
*/
|
||||
|
||||
type ChallengeState = {
|
||||
// Block timestamp tracking
|
||||
timestamp: bigint | null;
|
||||
setTimestamp: (timestamp: bigint | null) => void;
|
||||
// Optimistic Oracle
|
||||
refetchAssertionStates: () => void;
|
||||
setRefetchAssertionStates: (refetchFn: () => void) => void;
|
||||
// Assertion Modal
|
||||
openAssertion: AssertionWithIdAndState | null;
|
||||
openAssertionModal: (assertion: AssertionWithIdAndState) => void;
|
||||
closeAssertionModal: () => void;
|
||||
};
|
||||
|
||||
export const useChallengeState = create<ChallengeState>(set => ({
|
||||
// Block timestamp tracking
|
||||
timestamp: null,
|
||||
setTimestamp: (timestamp: bigint | null): void => set(() => ({ timestamp })),
|
||||
// Optimistic Oracle
|
||||
refetchAssertionStates: () => {},
|
||||
setRefetchAssertionStates: (refetchFn: () => void) => set(() => ({ refetchAssertionStates: refetchFn })),
|
||||
// Assertion Modal
|
||||
openAssertion: null,
|
||||
openAssertionModal: (assertion: AssertionWithIdAndState) =>
|
||||
set(() => ({
|
||||
openAssertion: assertion,
|
||||
})),
|
||||
closeAssertionModal: () => set(() => ({ openAssertion: null })),
|
||||
}));
|
||||
25
packages/nextjs/services/store/store.ts
Normal file
25
packages/nextjs/services/store/store.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { create } from "zustand";
|
||||
import scaffoldConfig from "~~/scaffold.config";
|
||||
import { ChainWithAttributes, NETWORKS_EXTRA_DATA } from "~~/utils/scaffold-eth";
|
||||
|
||||
/**
|
||||
* Zustand Store
|
||||
*
|
||||
* You can add global state to the app using this useGlobalState, to get & set
|
||||
* values from anywhere in the app.
|
||||
*
|
||||
* Think about it as a global useState.
|
||||
*/
|
||||
|
||||
type GlobalState = {
|
||||
targetNetwork: ChainWithAttributes;
|
||||
setTargetNetwork: (newTargetNetwork: ChainWithAttributes) => void;
|
||||
};
|
||||
|
||||
export const useGlobalState = create<GlobalState>(set => ({
|
||||
targetNetwork: {
|
||||
...scaffoldConfig.targetNetworks[0],
|
||||
...NETWORKS_EXTRA_DATA[scaffoldConfig.targetNetworks[0].id],
|
||||
},
|
||||
setTargetNetwork: (newTargetNetwork: ChainWithAttributes) => set(() => ({ targetNetwork: newTargetNetwork })),
|
||||
}));
|
||||
40
packages/nextjs/services/web3/wagmiConfig.tsx
Normal file
40
packages/nextjs/services/web3/wagmiConfig.tsx
Normal file
@@ -0,0 +1,40 @@
|
||||
import { wagmiConnectors } from "./wagmiConnectors";
|
||||
import { Chain, createClient, fallback, http } from "viem";
|
||||
import { hardhat, mainnet } from "viem/chains";
|
||||
import { createConfig } from "wagmi";
|
||||
import scaffoldConfig, { DEFAULT_ALCHEMY_API_KEY, ScaffoldConfig } from "~~/scaffold.config";
|
||||
import { getAlchemyHttpUrl } from "~~/utils/scaffold-eth";
|
||||
|
||||
const { targetNetworks } = scaffoldConfig;
|
||||
|
||||
// We always want to have mainnet enabled (ENS resolution, ETH price, etc). But only once.
|
||||
export const enabledChains = targetNetworks.find((network: Chain) => network.id === 1)
|
||||
? targetNetworks
|
||||
: ([...targetNetworks, mainnet] as const);
|
||||
|
||||
export const wagmiConfig = createConfig({
|
||||
chains: enabledChains,
|
||||
connectors: wagmiConnectors(),
|
||||
ssr: true,
|
||||
client: ({ chain }) => {
|
||||
const mainnetFallbackWithDefaultRPC = [http("https://mainnet.rpc.buidlguidl.com")];
|
||||
let rpcFallbacks = [...(chain.id === mainnet.id ? mainnetFallbackWithDefaultRPC : []), http()];
|
||||
const rpcOverrideUrl = (scaffoldConfig.rpcOverrides as ScaffoldConfig["rpcOverrides"])?.[chain.id];
|
||||
if (rpcOverrideUrl) {
|
||||
rpcFallbacks = [http(rpcOverrideUrl), ...rpcFallbacks];
|
||||
} else {
|
||||
const alchemyHttpUrl = getAlchemyHttpUrl(chain.id);
|
||||
if (alchemyHttpUrl) {
|
||||
const isUsingDefaultKey = scaffoldConfig.alchemyApiKey === DEFAULT_ALCHEMY_API_KEY;
|
||||
rpcFallbacks = isUsingDefaultKey
|
||||
? [...rpcFallbacks, http(alchemyHttpUrl)]
|
||||
: [http(alchemyHttpUrl), ...rpcFallbacks];
|
||||
}
|
||||
}
|
||||
return createClient({
|
||||
chain,
|
||||
transport: fallback(rpcFallbacks),
|
||||
...(chain.id !== (hardhat as Chain).id ? { pollingInterval: scaffoldConfig.pollingInterval } : {}),
|
||||
});
|
||||
},
|
||||
});
|
||||
51
packages/nextjs/services/web3/wagmiConnectors.tsx
Normal file
51
packages/nextjs/services/web3/wagmiConnectors.tsx
Normal file
@@ -0,0 +1,51 @@
|
||||
import { connectorsForWallets } from "@rainbow-me/rainbowkit";
|
||||
import {
|
||||
baseAccount,
|
||||
ledgerWallet,
|
||||
metaMaskWallet,
|
||||
rainbowWallet,
|
||||
safeWallet,
|
||||
walletConnectWallet,
|
||||
} from "@rainbow-me/rainbowkit/wallets";
|
||||
import { rainbowkitBurnerWallet } from "burner-connector";
|
||||
import * as chains from "viem/chains";
|
||||
import scaffoldConfig from "~~/scaffold.config";
|
||||
|
||||
const { onlyLocalBurnerWallet, targetNetworks } = scaffoldConfig;
|
||||
|
||||
const wallets = [
|
||||
metaMaskWallet,
|
||||
walletConnectWallet,
|
||||
ledgerWallet,
|
||||
baseAccount,
|
||||
rainbowWallet,
|
||||
safeWallet,
|
||||
...(!targetNetworks.some(network => network.id !== (chains.hardhat as chains.Chain).id) || !onlyLocalBurnerWallet
|
||||
? [rainbowkitBurnerWallet]
|
||||
: []),
|
||||
];
|
||||
|
||||
/**
|
||||
* wagmi connectors for the wagmi context
|
||||
*/
|
||||
export const wagmiConnectors = () => {
|
||||
// Only create connectors on client-side to avoid SSR issues
|
||||
// TODO: update when https://github.com/rainbow-me/rainbowkit/issues/2476 is resolved
|
||||
if (typeof window === "undefined") {
|
||||
return [];
|
||||
}
|
||||
|
||||
return connectorsForWallets(
|
||||
[
|
||||
{
|
||||
groupName: "Supported Wallets",
|
||||
wallets,
|
||||
},
|
||||
],
|
||||
|
||||
{
|
||||
appName: "scaffold-eth-2",
|
||||
projectId: scaffoldConfig.walletConnectProjectId,
|
||||
},
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user