Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
intergalacticspacehighway committed Nov 7, 2023
1 parent 3ff04ac commit b379f1c
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 680 deletions.
3 changes: 1 addition & 2 deletions apps/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@
"swiper": "^10.0.4",
"swr": "^2.2.0",
"twitter-lite": "^1.1.0",
"viem": "^1.17.1",
"wagmi": "^1.4.5"
"viem": "^1.17.1"
},
"devDependencies": {
"@babel/eslint-parser": "^7.22.9",
Expand Down
34 changes: 1 addition & 33 deletions apps/next/src/pages/wagmi-signature-test.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import { ConnectButton } from "@rainbow-me/rainbowkit";
import type { NextPage } from "next";
import { useAccount, useDisconnect, useSignMessage } from "wagmi";

import { Logger } from "app/lib/logger";

const signatureData = {
domain: {
Expand Down Expand Up @@ -55,35 +51,7 @@ const signatureData = {
};

const Home: NextPage = () => {
const { isConnected } = useAccount();
const { disconnect } = useDisconnect();
const { signMessageAsync } = useSignMessage();
Logger.log("is connected :: ", isConnected);
const signMessageAsyncTimeout = async () => {
await fetch("https://my-vercel-functions-six.vercel.app/api?delay=1000");
signMessageAsync({ message: "yo!" });
};

return (
<div>
<main>
{isConnected ? (
<button onClick={() => disconnect()}>Disconnect</button>
) : (
<ConnectButton />
)}
<button
style={{ marginLeft: 10 }}
onClick={() => signMessageAsync({ message: "yo!" })}
>
Sign message
</button>
<button style={{ marginLeft: 10 }} onClick={signMessageAsyncTimeout}>
Sign message async
</button>
</main>
</div>
);
return null;
};

export default Home;
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const useApproveToken = () => {
}
) {
const erc20Abi = require("app/abi/IERC20Permit.json");
const walletClient = wallet.getWalletClient?.();
const walletClient = await wallet.getWalletClient?.();

const walletAddress = walletClient?.account?.address;
if (walletAddress) {
Expand Down
2 changes: 1 addition & 1 deletion packages/app/hooks/creator-token/use-creator-token-buy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const useCreatorTokenBuy = (params: {
await wallet.connect();
}

const walletClient = wallet.getWalletClient?.();
const walletClient = await wallet.getWalletClient?.();
const walletAddress = walletClient?.account?.address;

if (walletAddress && profileData?.data?.profile.creator_token) {
Expand Down
2 changes: 1 addition & 1 deletion packages/app/hooks/creator-token/use-switch-chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { baseChain } from "./utils";
export const useSwitchChain = () => {
const wallet = useWallet();
const state = useSWRMutation("switchChain", async function switchChain() {
const walletClient = wallet.getWalletClient?.();
const walletClient = await wallet.getWalletClient?.();
const currentChain = await walletClient?.getChainId();
if (currentChain !== baseChain.id) {
// HACK because mobile wallets are notoriously buggy
Expand Down
76 changes: 1 addition & 75 deletions packages/app/providers/wallet-provider.web.tsx
Original file line number Diff line number Diff line change
@@ -1,77 +1,3 @@
import {
getDefaultWallets,
RainbowKitProvider,
connectorsForWallets,
} from "@rainbow-me/rainbowkit";
import { configureChains, WagmiConfig, createConfig } from "wagmi";
import * as allChains from "wagmi/chains";
import { alchemyProvider } from "wagmi/providers/alchemy";
import { publicProvider } from "wagmi/providers/public";

import { baseChain } from "app/hooks/creator-token/utils";
import { alchemyProviderApiKey } from "app/lib/wallet-public-client";
import { isDEV } from "app/utilities";

const lineaChain = {
id: 59144,
name: "Linea",
network: "mainnet",
nativeCurrency: {
decimals: 18,
name: "Ether",
symbol: "ETH",
},
rpcUrls: {
default: {
http: ["https://linea-mainnet.infura.io/v3"],
},
public: {
http: ["https://linea-mainnet.infura.io/v3"],
},
},
blockExplorers: {
default: { name: "Lineascan", url: "https://lineascan.build/" },
},
};

const allChainsArray = [
// @ts-ignore
...Object.keys(allChains).map((key) => allChains[key]),
baseChain,
lineaChain,
];

const provider = isDEV
? [publicProvider()]
: [alchemyProvider({ apiKey: alchemyProviderApiKey }), publicProvider()];

const { chains, publicClient, webSocketPublicClient } = configureChains(
allChainsArray,
provider
);

const projectId = process.env.NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID;

const { wallets } = getDefaultWallets({
appName: "Showtime",
projectId,
chains,
});
const connectors = connectorsForWallets(wallets);

const wagmiConfig = createConfig({
autoConnect: true,
connectors,
publicClient,
webSocketPublicClient,
});

export const WalletProvider = ({ children }: { children: React.ReactNode }) => {
return (
<WagmiConfig config={wagmiConfig}>
<RainbowKitProvider chains={chains} initialChain={baseChain}>
{children}
</RainbowKitProvider>
</WagmiConfig>
);
return children;
};
15 changes: 1 addition & 14 deletions packages/app/providers/web3-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,9 @@ import { useWeb3Modal } from "app/lib/react-native-web3-modal";

interface Web3ProviderProps {
children: React.ReactNode;
connected?: boolean;
client?: Web3ContextType["web3"];
}

export function Web3Provider({
children,
connected,
client,
}: Web3ProviderProps) {
export function Web3Provider({ children }: Web3ProviderProps) {
const [web3, setWeb3State] = useState<Web3ContextType["web3"] | undefined>(
undefined
);
Expand Down Expand Up @@ -115,13 +109,6 @@ export function Web3Provider({
}
}, [web3]);

// (Web only) initialises web3 provider from wagmi
useEffect(() => {
if (Platform.OS === "web" && connected) {
setWeb3(client);
}
}, [connected, client]);

return (
<Web3Context.Provider value={Web3ContextValue}>
{children}
Expand Down
11 changes: 1 addition & 10 deletions packages/app/providers/web3-provider.web.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { useAccount, useWalletClient } from "wagmi";

// @ts-expect-error
import { Web3Provider as Web3ProviderBase } from "./web3-provider.tsx";

Expand All @@ -8,12 +6,5 @@ interface Web3ProviderProps {
}

export function Web3Provider({ children }: Web3ProviderProps) {
const { isConnected } = useAccount();
const signer = useWalletClient();

return (
<Web3ProviderBase connected={isConnected} client={signer.data}>
{children}
</Web3ProviderBase>
);
return <Web3ProviderBase>{children}</Web3ProviderBase>;
}
Loading

0 comments on commit b379f1c

Please sign in to comment.