-
Notifications
You must be signed in to change notification settings - Fork 133
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
Showing
17 changed files
with
388 additions
and
51 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { useAccount } from "wagmi"; | ||
import { useNFTsQuery } from "./nfts"; | ||
import { useEffect, useState } from "react"; | ||
|
||
export type AppState = | ||
| { | ||
state: "LOADING"; | ||
eoaAddress: undefined; | ||
scwAddress: undefined; | ||
} | ||
| { | ||
state: "UNCONNECTED"; | ||
eoaAddress: undefined; | ||
scwAddress: undefined; | ||
} | ||
| { | ||
state: "NO_SCW"; | ||
eoaAddress: string; | ||
scwAddress: undefined; | ||
} | ||
| { | ||
state: "HAS_SCW"; | ||
eoaAddress: string; | ||
scwAddress: string; | ||
}; | ||
|
||
export function useAppState(): AppState { | ||
const { address, isConnected } = useAccount(); | ||
const nfts = useNFTsQuery(address); | ||
const [state, setState] = useState<AppState>({ | ||
state: "UNCONNECTED", | ||
eoaAddress: undefined, | ||
scwAddress: undefined, | ||
}); | ||
useEffect(() => { | ||
if (!isConnected || !address) { | ||
setState({ | ||
state: "UNCONNECTED", | ||
eoaAddress: undefined, | ||
scwAddress: undefined, | ||
}); | ||
return; | ||
} | ||
|
||
if (nfts.isLoading) { | ||
setState({ | ||
state: "LOADING", | ||
eoaAddress: undefined, | ||
scwAddress: undefined, | ||
}); | ||
return; | ||
} | ||
const scwNFT = nfts?.data?.ownedNfts.find((value) => { | ||
return value.contract.address === "0x0000000000000000"; | ||
}); | ||
const scwAttribute = scwNFT?.metadata.attributes?.find((attribute) => { | ||
attribute.trait_type === "SCW"; | ||
}); | ||
if (!scwNFT || !scwAttribute) { | ||
setState({ | ||
state: "NO_SCW", | ||
eoaAddress: address as `0x${string}`, | ||
scwAddress: undefined, | ||
}); | ||
} else { | ||
setState({ | ||
state: "HAS_SCW", | ||
eoaAddress: address as `0x${string}`, | ||
scwAddress: scwAttribute.value!, | ||
}); | ||
} | ||
}, [address, isConnected, nfts]); | ||
return state; | ||
} |
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,13 +1,14 @@ | ||
import {useQuery} from "@tanstack/react-query"; | ||
import {getNFTs} from "../http/endpoints"; | ||
import {OwnedNFTsResponse} from "../declarations/api"; | ||
import { useQuery } from "@tanstack/react-query"; | ||
import { getNFTs } from "../http/endpoints"; | ||
|
||
export function useNFTsQuery(ethAddress?: string) { | ||
return useQuery(["nfts", ethAddress], () => { | ||
if (ethAddress) { | ||
return getNFTs(ethAddress); | ||
} else { | ||
return Promise.resolve({data: []} as unknown as OwnedNFTsResponse); | ||
} | ||
return ethAddress | ||
? getNFTs(ethAddress) | ||
: Promise.resolve({ | ||
ownedNfts: [], | ||
totalCount: 0, | ||
blockHash: "0x000000000000", | ||
}); | ||
}); | ||
} |
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
18 changes: 18 additions & 0 deletions
18
examples/alchemy-daapp/src/components/connect/ConnectPage.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,18 @@ | ||
import { Center, Heading, Text, VStack } from "@chakra-ui/react"; | ||
import { ConnectButton } from "@rainbow-me/rainbowkit"; | ||
|
||
export function ConnectPage() { | ||
return ( | ||
<Center> | ||
<VStack gap={4}> | ||
<Heading size="lg">Welcome to the Alchemy exmple D🅰️🅰️pp!</Heading> | ||
<Text align="center"> | ||
We're excited for you to start using account abstraction!! <br /> | ||
Click below to connect your wallet, and create your own account | ||
abstrated smart contract wallet. | ||
</Text> | ||
<ConnectButton /> | ||
</VStack> | ||
</Center> | ||
); | ||
} |
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[default] | ||
src = 'src' | ||
out = 'out' | ||
libs = ['lib'] | ||
remappings = ['ds-test/=lib/ds-test/src/'] | ||
|
||
# See more config options https://github.com/gakonst/foundry/tree/master/config |
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 @@ | ||
## Version 1 | ||
|
||
Deployer: 0x15a411507e901f26965f0ebcd3155834b058a6b2 | ||
Deployed to: 0xb7b9424ef3d1b9086b7e53276c4aad68a1dd971c | ||
Transaction hash: 0x46f95ea67e2b103f607884a87fd25d53d619eaa7d67437f1d7cb51f7c99b6de2 |
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,2 @@ | ||
openzeppelin-contracts/=lib/openzeppelin-contracts/ | ||
forge-std/=lib/forge-std/src/ |
Oops, something went wrong.