Skip to content

Commit

Permalink
web: fix ConnectWalletFlow
Browse files Browse the repository at this point in the history
  • Loading branch information
dcposch committed Sep 30, 2024
1 parent 25681d2 commit 8da8ce3
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions apps/daimo-web/src/app/l/[[...slug]]/LinkPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import Image from "next/image";

import { CallToAction } from "../../../components/CallToAction";
import { chainsDaimoL2, Providers } from "../../../components/Providers";
import { Providers } from "../../../components/Providers";
import { I18NProvider, useI18N } from "../../../i18n/context";
import { LinkStatusDesc } from "../../../utils/linkStatus";

Expand All @@ -17,7 +17,7 @@ export default function LinkPage({
pfp: string | undefined;
}) {
return (
<Providers chains={chainsDaimoL2}>
<Providers>
<I18NProvider lang={lang}>
<LinkPageInner {...{ statusDesc, pfp }} />
</I18NProvider>
Expand Down
4 changes: 2 additions & 2 deletions apps/daimo-web/src/app/link/[[...slug]]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { Metadata } from "next";
import Image from "next/image";

import { CallToAction } from "../../../components/CallToAction";
import { Providers, chainsDaimoL2 } from "../../../components/Providers";
import { Providers } from "../../../components/Providers";
import { getI18N } from "../../../i18n";
import { getReqLang } from "../../../i18n/server";
import { getAbsoluteUrl } from "../../../utils/getAbsoluteUrl";
Expand Down Expand Up @@ -86,7 +86,7 @@ export async function generateMetadata(props: LinkProps): Promise<Metadata> {

export default async function LinkPage(props: LinkProps) {
return (
<Providers chains={chainsDaimoL2}>
<Providers>
<LinkPageInner {...props} />
</Providers>
);
Expand Down
7 changes: 4 additions & 3 deletions apps/daimo-web/src/components/ConnectWalletFlow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,11 @@ function WagmiButton({
isSuccess,
data: txHash,
} = useWriteContract();
// const { data, isLoading, isSuccess, write } = usweWrite(wagmiPrep);

const humanReadableError = useMemo(() => {
if (!error || !error.message) return undefined;
if (error == null) return undefined;

console.warn("Connect wallet error", error);
if (error.message.match(/ERC20: transfer amount exceeds balance/)) {
return i18.errors.notEnoughFunds();
} else if (error.message.match(/note does not exist/)) {
Expand All @@ -148,7 +149,7 @@ function WagmiButton({
} else if (error instanceof InsufficientFundsError) {
return i18.errors.insufficientEth();
} else {
return error.message;
return error.message || "Unknown error";
}
}, [error, i18]);

Expand Down
23 changes: 11 additions & 12 deletions apps/daimo-web/src/components/Providers.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,27 @@
"use client";

import {
RainbowKitProvider,
connectorsForWallets,
getDefaultWallets,
RainbowKitProvider,
} from "@rainbow-me/rainbowkit";
import { ConnectorsForWalletsParameters } from "@rainbow-me/rainbowkit/dist/wallets/connectorsForWallets";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import * as React from "react";
import { useMemo, useState } from "react";
import { Chain } from "viem/chains";
import { http, Transport } from "viem";
import { createConfig, WagmiProvider } from "wagmi";

import { chainConfig } from "../env";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";

export const chainsDaimoL2 = [chainConfig.chainL2] as const;
export const chains = [chainConfig.chainL2] as const;

const appInfo = {
appName: "Daimo",
learnMoreUrl: "https://daimo.com",
};

export function Providers({
chains,
children,
}: {
chains: readonly [Chain, ...Chain[]];
children: React.ReactNode;
}) {
export function Providers({ children }: { children: React.ReactNode }) {
const [mounted, setMounted] = React.useState(false);
React.useEffect(() => setMounted(true), []);

Expand All @@ -39,10 +33,15 @@ export function Providers({
const { wallets } = getDefaultWallets(walletConnectParams);
const connectors = connectorsForWallets([...wallets], walletConnectParams);

const transports: Record<string, Transport> = {};
chains.forEach((c) => {
transports[c.id] = http();
});

return createConfig({
connectors,
chains,
transports: [],
transports,
});
}, [chains]);

Expand Down

0 comments on commit 8da8ce3

Please sign in to comment.