From f3367f58b54a04d5e1e1c6132b07114d44da1c81 Mon Sep 17 00:00:00 2001 From: danilo neves cruz Date: Thu, 23 Nov 2023 19:28:46 -0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20migrate=20to=20wagmi+viem=20v2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/+html.tsx | 1 + app/_layout.tsx | 34 +++++---- app/index.tsx | 12 +-- app/pomelo+api.ts | 14 +--- babel.config.js | 1 + bun.lockb | Bin 853914 -> 847674 bytes package.json | 8 +- utils/AlchemyConnector.ts | 153 -------------------------------------- utils/alchemyConnector.ts | 130 ++++++++++++++++++++++++++++++++ utils/constants.ts | 3 + 10 files changed, 169 insertions(+), 187 deletions(-) delete mode 100644 utils/AlchemyConnector.ts create mode 100644 utils/alchemyConnector.ts diff --git a/app/+html.tsx b/app/+html.tsx index eb12d94c..b3e51b4b 100644 --- a/app/+html.tsx +++ b/app/+html.tsx @@ -1,3 +1,4 @@ +// @ts-expect-error -- missing types import { ScrollViewStyleReset } from "expo-router/html"; import React, { type ReactNode } from "react"; diff --git a/app/_layout.tsx b/app/_layout.tsx index e16237eb..4241d352 100644 --- a/app/_layout.tsx +++ b/app/_layout.tsx @@ -3,21 +3,20 @@ import "expo-webauthn"; import FontAwesome from "@expo/vector-icons/FontAwesome"; import InterBold from "@tamagui/font-inter/otf/Inter-Bold.otf"; import Inter from "@tamagui/font-inter/otf/Inter-Medium.otf"; +import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; import { type FontSource, useFonts } from "expo-font"; import { Slot, SplashScreen } from "expo-router"; import { StatusBar } from "expo-status-bar"; -import React, { useEffect } from "react"; +import React, { useEffect, useState } from "react"; import * as Sentry from "sentry-expo"; import { TamaguiProvider } from "tamagui"; import { TextEncoder } from "text-encoding"; -import { WagmiConfig, configureChains, createConfig } from "wagmi"; -import { alchemyProvider } from "wagmi/providers/alchemy"; -import { publicProvider } from "wagmi/providers/public"; +import { WagmiProvider, createConfig, http } from "wagmi"; import metadata from "../package.json"; import tamaguiConfig from "../tamagui.config"; -import AlchemyConnector from "../utils/AlchemyConnector"; -import { alchemyAPIKey, chain } from "../utils/constants"; +import alchemyConnector from "../utils/alchemyConnector"; +import { chain, httpURL } from "../utils/constants"; export { ErrorBoundary } from "expo-router"; @@ -35,11 +34,12 @@ Sentry.init({ autoSessionTracking: true, }); -const { publicClient, webSocketPublicClient } = configureChains( - [chain], - [alchemyAPIKey ? alchemyProvider({ apiKey: alchemyAPIKey }) : publicProvider()], -); -const wagmiConfig = createConfig({ connectors: [new AlchemyConnector()], publicClient, webSocketPublicClient }); +const wagmiConfig = createConfig({ + chains: [chain], + connectors: [alchemyConnector()], + transports: { [chain.id]: http(httpURL) }, +}); +const queryClient = new QueryClient(); export default function RootLayout() { const [loaded, error] = useFonts({ @@ -47,24 +47,28 @@ export default function RootLayout() { InterBold: InterBold as FontSource, ...FontAwesome.font, }); + const [mounted, setMounted] = useState(false); useEffect(() => { if (error) throw error; }, [error]); useEffect(() => { + setMounted(true); if (loaded) SplashScreen.hideAsync().catch(() => {}); }, [loaded]); - if (!loaded) return; + if (!loaded || !mounted) return; return ( <> - - - + + + + + ); diff --git a/app/index.tsx b/app/index.tsx index 4f3ff44f..d7f5e02e 100644 --- a/app/index.tsx +++ b/app/index.tsx @@ -4,7 +4,7 @@ import { deviceName } from "expo-device"; import React, { useCallback } from "react"; import { Button, Spinner, Text, XStack, YStack } from "tamagui"; import { UAParser } from "ua-parser-js"; -import { useAccount, useConnect, useDisconnect, usePrepareSendTransaction, useSendTransaction } from "wagmi"; +import { useAccount, useConnect, useDisconnect, useSendTransaction } from "wagmi"; import base64URLEncode from "../utils/base64URLEncode"; import { rpId, turnkeyAPIPublicKey, turnkeyAPIPrivateKey, turnkeyOrganizationId } from "../utils/constants"; @@ -14,13 +14,12 @@ import handleError from "../utils/handleError"; export default function Home() { const { connect, - isLoading: isConnecting, + isPending: isConnecting, connectors: [connector], } = useConnect(); const { address } = useAccount(); const { disconnect } = useDisconnect(); - const { config: sendConfig } = usePrepareSendTransaction({ to: "0xE72185a9f4Ce3500d6dC7CCDCfC64cf66D823bE8" }); - const { sendTransaction, data: txHash, isLoading: isSending } = useSendTransaction(sendConfig); + const { sendTransaction, data: txHash, isPending: isSending } = useSendTransaction(); const createAccount = useCallback(() => { const name = `exactly, ${new Date().toISOString()}`; @@ -81,6 +80,7 @@ export default function Home() { }, []); const connectAccount = useCallback(() => { + if (!connector) throw new Error("no connector"); connect({ connector }); }, [connect, connector]); @@ -89,7 +89,7 @@ export default function Home() { }, [disconnect]); const send = useCallback(() => { - sendTransaction?.(); + sendTransaction({ to: "0xE72185a9f4Ce3500d6dC7CCDCfC64cf66D823bE8" }); }, [sendTransaction]); return ( @@ -97,7 +97,7 @@ export default function Home() { {txHash} -