Skip to content

Commit

Permalink
feat: integrate sdk + nft contract for onboarding (#11)
Browse files Browse the repository at this point in the history
* feat: clean up components for profile and nft fetching

* feat: add smart contract for nft

* feat: integrate sdk + nft contract for onboarding
  • Loading branch information
rthomare authored Jun 7, 2023
1 parent e3dc165 commit f50b0e7
Show file tree
Hide file tree
Showing 39 changed files with 3,385 additions and 1,366 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@ tsconfig*.tsbuildinfo
.npmrc
yarn-error.log
lerna-debug.log
.tool-versions
.tool-versions

# example ignores
examples/contracts/**/out
12 changes: 12 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[submodule "examples/contracts/DAAppNFT/lib/openzeppelin-contracts"]
path = examples/contracts/DAAppNFT/lib/openzeppelin-contracts
url = https://github.com/openzeppelin/openzeppelin-contracts
[submodule "examples/contracts/DAAppNFT/lib/forge-std"]
path = examples/contracts/DAAppNFT/lib/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "examples/contracts/DAAppNFT/lib/ds-test"]
path = examples/contracts/DAAppNFT/lib/ds-test
url = https://github.com/dapphub/ds-test
[submodule "examples/contracts/DAAppNFT/lib/solmate"]
path = examples/contracts/DAAppNFT/lib/solmate
url = https://github.com/transmissions11/solmate
7 changes: 5 additions & 2 deletions examples/alchemy-daapp/.env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# When adding additional environment variables, the schema in "/src/env.mjs"
# should be updated accordingly.

NFT_CONTRACT_ADDRESS=""
ALCHEMY_API_URL=""
ALCHEMY_API_URL=https://polygon-mumbai.g.alchemy.com/v2/your-api-key

NEXT_PUBLIC_NFT_CONTRACT_ADDRESS=0xYOURADDRESSHERE
NEXT_PUBLIC_SIMPLE_ACCOUNT_FACTORY_ADDRESS=0xYOURADDRESSHERE
NEXT_PUBLIC_PAYMASTER_POLICY_ID=some-policy-id
1 change: 1 addition & 0 deletions examples/alchemy-daapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"lint": "next lint"
},
"dependencies": {
"@alchemy/aa-core": "file:../../packages/core",
"@chakra-ui/react": "^2.6.1",
"@emotion/react": "^11.11.0",
"@emotion/styled": "^11.11.0",
Expand Down
25 changes: 6 additions & 19 deletions examples/alchemy-daapp/src/clients/appState.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useAccount } from "wagmi";
import { useNFTsQuery } from "./nfts";
import { useNFTsQuery } from "../surfaces/profile/NftSection";
import { useEffect, useState } from "react";

export type AppState =
Expand All @@ -26,7 +26,8 @@ export type AppState =

export function useAppState(): AppState {
const { address, isConnected } = useAccount();
const nfts = useNFTsQuery(address);
const scwAddress = address ? localStorage.getItem(address) : undefined;

const [state, setState] = useState<AppState>({
state: "UNCONNECTED",
eoaAddress: undefined,
Expand All @@ -42,21 +43,7 @@ export function useAppState(): AppState {
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) {
if (!scwAddress) {
setState({
state: "NO_SCW",
eoaAddress: address as `0x${string}`,
Expand All @@ -66,9 +53,9 @@ export function useAppState(): AppState {
setState({
state: "HAS_SCW",
eoaAddress: address as `0x${string}`,
scwAddress: scwAttribute.value!,
scwAddress: scwAddress!,
});
}
}, [address, isConnected, nfts]);
}, [address, isConnected, scwAddress]);
return state;
}
23 changes: 23 additions & 0 deletions examples/alchemy-daapp/src/clients/nftContract.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export const NFTContractABI = {
abi: [
{
inputs: [
{
internalType: "address",
name: "recipient",
type: "address",
},
],
name: "mintTo",
outputs: [
{
internalType: "uint256",
name: "",
type: "uint256",
},
],
stateMutability: "payable",
type: "function",
},
],
};
72 changes: 0 additions & 72 deletions examples/alchemy-daapp/src/clients/onboarding.ts

This file was deleted.

163 changes: 0 additions & 163 deletions examples/alchemy-daapp/src/components/onboarding/OnboardingPage.tsx

This file was deleted.

27 changes: 27 additions & 0 deletions examples/alchemy-daapp/src/configs/clientConfigs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Chain, polygonMumbai, sepolia } from "viem/chains";

export interface DAAppConfiguration {
nftContractAddress: `0x${string}`;
simpleAccountFactoryAddress: `0x${string}`;
gasManagerPolicyId: string;
rpcUrl: string;
chain: Chain;
}

// TODO: Replace with your own contract addresses and policy ids, feel free to add or remove chains.
export const daappConfigurations: Record<number, DAAppConfiguration> = {
[polygonMumbai.id]: {
nftContractAddress: "0x5679b0de84bba361d31b2e7152ab20f0f8565245",
simpleAccountFactoryAddress: "0x9406Cc6185a346906296840746125a0E44976454",
gasManagerPolicyId: "469689aa-4fdd-43bd-a721-697f7d5e2c5d",
rpcUrl: `/api/rpc/proxy?chainId=${polygonMumbai.id}`,
chain: polygonMumbai,
},
[sepolia.id]: {
nftContractAddress: "0x5679b0de84bba361d31b2e7152ab20f0f8565245",
simpleAccountFactoryAddress: "0xc8c5736988F4Ea76B9f620dc678c23d5cBf3C83c",
gasManagerPolicyId: "97ca8953-1692-40ff-9cb8-202accb1416c",
rpcUrl: `/api/rpc/proxy?chainId=${sepolia.id}`,
chain: sepolia,
},
};
Loading

0 comments on commit f50b0e7

Please sign in to comment.