-
Notifications
You must be signed in to change notification settings - Fork 360
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fa0e71e
commit fcfae6d
Showing
12 changed files
with
157 additions
and
24 deletions.
There are no files selected for viewing
21 changes: 15 additions & 6 deletions
21
advanced/dapps/chain-abstraction-demo/app/hooks/useSendUsdc.tsx
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,54 @@ | ||
"use client"; | ||
import { Button } from "@/components/ui/button"; | ||
import useSendUsdc from "./hooks/useSendUsdc"; | ||
import { useAccount } from "wagmi"; | ||
import { useState } from "react"; | ||
import { useToast } from "@/hooks/use-toast"; | ||
import { Loader2 } from "lucide-react"; | ||
|
||
const sendToAddress = "0x81D8C68Be5EcDC5f927eF020Da834AA57cc3Bd24"; | ||
const sendAmount = 6000000; | ||
|
||
export default function Transfer() { | ||
const { sendUsdcAsync } = useSendUsdc(); | ||
const { isConnected, chain } = useAccount(); | ||
const [isLoading, setIsLoading] = useState(false); | ||
const { toast } = useToast(); | ||
|
||
const onButtonClick = async () => { | ||
const res = await sendUsdcAsync(); | ||
console.log(res); | ||
try { | ||
setIsLoading(true); | ||
const res = await sendUsdcAsync(sendToAddress, sendAmount); | ||
console.log("Transaction completed", res); | ||
toast({ | ||
title: "Transaction completed", | ||
description: res, | ||
}); | ||
} catch (error) { | ||
console.log(error); | ||
toast({ | ||
variant: "destructive", | ||
title: "Uh oh! Something went wrong.", | ||
description: "There was a problem with your request.", | ||
}); | ||
} finally { | ||
setIsLoading(false); | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
<Button onClick={onButtonClick}>Send USDC</Button> | ||
{isConnected ? ( | ||
<Button onClick={onButtonClick} disabled={isLoading}> | ||
{isLoading ? ( | ||
<> | ||
<Loader2 className="mr-2 h-4 w-4 animate-spin" /> Sending... | ||
</> | ||
) : ( | ||
<>Perform action with USDC on {chain?.name}</> | ||
)} | ||
</Button> | ||
) : null} | ||
</> | ||
); | ||
} |
9 changes: 9 additions & 0 deletions
9
advanced/dapps/chain-abstraction-demo/components/theme-provider.tsx
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,9 @@ | ||
"use client"; | ||
|
||
import * as React from "react"; | ||
import { ThemeProvider as NextThemesProvider } from "next-themes"; | ||
import { type ThemeProviderProps } from "next-themes/dist/types"; | ||
|
||
export function ThemeProvider({ children, ...props }: ThemeProviderProps) { | ||
return <NextThemesProvider {...props}>{children}</NextThemesProvider>; | ||
} |
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,5 @@ | ||
import { Hex } from "viem"; | ||
|
||
export const tokenAddresses: Record<number, Hex> = { | ||
42161: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831' // Arbitrum | ||
} |
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 |
---|---|---|
|
@@ -3843,10 +3843,10 @@ lru-cache@^10.2.0, lru-cache@^10.4.3: | |
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-10.4.3.tgz#410fc8a17b70e598013df257c2446b7f3383f119" | ||
integrity sha512-JNAzZcXrCt42VGLuYz0zfAzDfAvJWW6AfYlDBQyDV5DClI2m5sAmK+OIO7s59XfsRsWHp02jAJrRadPRGTt6SQ== | ||
|
||
lucide-react@^0.438.0: | ||
version "0.438.0" | ||
resolved "https://registry.yarnpkg.com/lucide-react/-/lucide-react-0.438.0.tgz#80cc2602c973416256ad65ded9872531626b4f70" | ||
integrity sha512-uq6yCB+IzVfgIPMK8ibkecXSWTTSOMs9UjUgZigfrDCVqgdwkpIgYg1fSYnf0XXF2AoSyCJZhoZXQwzoai7VGw== | ||
lucide-react@^0.439.0: | ||
version "0.439.0" | ||
resolved "https://registry.yarnpkg.com/lucide-react/-/lucide-react-0.439.0.tgz#eb9250e7255e56460ed37b68e807717c534395d6" | ||
integrity sha512-PafSWvDTpxdtNEndS2HIHxcNAbd54OaqSYJO90/b63rab2HWYqDbH194j0i82ZFdWOAcf0AHinRykXRRK2PJbw== | ||
|
||
merge-stream@^2.0.0: | ||
version "2.0.0" | ||
|
@@ -3993,6 +3993,11 @@ natural-compare@^1.4.0: | |
resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7" | ||
integrity sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw== | ||
|
||
next-themes@^0.3.0: | ||
version "0.3.0" | ||
resolved "https://registry.yarnpkg.com/next-themes/-/next-themes-0.3.0.tgz#b4d2a866137a67d42564b07f3a3e720e2ff3871a" | ||
integrity sha512-/QHIrsYpd6Kfk7xakK4svpDI5mmXP0gfvCoJdGpZQ2TOrQZmsW0QxjaiLn8wbIKjtm4BTSqLoix4lxYYOnLJ/w== | ||
|
||
[email protected]: | ||
version "14.2.7" | ||
resolved "https://registry.yarnpkg.com/next/-/next-14.2.7.tgz#e02d5d9622ff4b998e5c89adfd660c9bf6435970" | ||
|
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