Skip to content

Commit

Permalink
fix example project builds
Browse files Browse the repository at this point in the history
  • Loading branch information
alecananian committed Jun 24, 2024
1 parent 6efdfde commit 3b20d88
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 19 deletions.
6 changes: 2 additions & 4 deletions examples/connect/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ import {
Button,
ConnectButton,
formatAmount,
getContractAddress,
useTreasure,
} from "@treasure-dev/tdk-react";
import { formatEther, parseEther } from "viem";

export const App = () => {
const { tdk, chainId, user } = useTreasure();
const magicAddress = getContractAddress(chainId, "MAGIC");
const { tdk, user, contractAddresses } = useTreasure();

const handleMintMagic = async (amount: number) => {
if (!user?.smartAccountAddress) {
Expand All @@ -20,7 +18,7 @@ export const App = () => {
try {
await tdk.transaction.create(
{
address: magicAddress,
address: contractAddresses.MAGIC,
abi: [
{
inputs: [
Expand Down
5 changes: 2 additions & 3 deletions examples/harvester/.env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
VITE_TDK_API_URL=http://localhost:8080
VITE_TDK_CHAIN_ID=421614
VITE_TDK_LOGIN_DOMAIN=http://localhost:5173
VITE_TDK_LOGIN_REDIRECT_URI=http://localhost:5174
VITE_TDK_CLIENT_ID=
VITE_TDK_BACKEND_WALLET=
VITE_WALLETCONNECT_PROJECT_ID=
16 changes: 9 additions & 7 deletions examples/harvester/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ import { useAccount, useChainId, useReadContracts } from "wagmi";
const MAGIC_AMOUNT = parseEther("1000");

export const App = () => {
const { address, tdk } = useTreasure();
const { tdk, user } = useTreasure();
const { address: eoaAddress = zeroAddress, isConnected: isEOAConnected } =
useAccount();
const chainId = useChainId();
const contractAddresses = useContractAddresses();
const smartAccountAddress = (address ?? zeroAddress) as AddressString;
const smartAccountAddress = (user?.smartAccountAddress ??
zeroAddress) as AddressString;

const {
data: {
Expand All @@ -38,7 +39,7 @@ export const App = () => {
refetch: refetchHarvesterData,
} = useHarvester({
chainId,
contract: "HarvesterEmerion",
contract: "HarvesterEmberwing",
userAddress: eoaAddress,
});

Expand All @@ -61,7 +62,7 @@ export const App = () => {
},
],
query: {
enabled: !!address,
enabled: !!user?.smartAccountAddress,
select: (data) => ({
eoaMagic: data[0].result ?? 0n,
eoaPermits: data[1].result ?? 0n,
Expand Down Expand Up @@ -142,14 +143,15 @@ export const App = () => {
<h1 className="font-semibold text-2xl text-ruby-900">
TDK Harvester Example
</h1>
<TreasureConnectButton />
<TreasureConnectButton appName="Zeeverse" />
</header>
<main className="space-y-6">
{address ? (
{user?.smartAccountAddress ? (
<>
<div className="space-y-2">
<h2>
<span className="font-semibold">Smart Account:</span> {address}
<span className="font-semibold">Smart Account:</span>{" "}
{user.smartAccountAddress}
</h2>
<ul className="list-disc px-8">
<li>{formatEther(smartAccountMagic)} MAGIC balance</li>
Expand Down
15 changes: 10 additions & 5 deletions examples/harvester/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,17 @@ ReactDOM.createRoot(document.getElementById("root")!).render(
<QueryClientProvider client={queryClient}>
<RainbowKitProvider>
<TreasureProvider
project="zeeverse"
chainId={import.meta.env.VITE_TDK_CHAIN_ID}
apiUri={import.meta.env.VITE_TDK_API_URL}
authConfig={{
loginDomain: import.meta.env.VITE_TDK_LOGIN_DOMAIN,
redirectUri: import.meta.env.VITE_TDK_LOGIN_REDIRECT_URI,
chainId={arbitrumSepolia.id}
clientId={import.meta.env.VITE_TDK_CLIENT_ID}
sessionOptions={{
backendWallet: import.meta.env.VITE_TDK_BACKEND_WALLET,
approvedTargets: [
"0x55d0cf68a1afe0932aff6f36c87efa703508191c", // MAGIC
"0x9d012712d24c90dded4574430b9e6065183896be", // Consumables
"0x816c0717cf263e7da4cd33d4979ad15dbb70f122", // Emberwing Harvester
"0x94c64b689336b3f0388503cc1cb4a193520dff73", // Emberwing NftHandler
],
}}
>
<App />
Expand Down

0 comments on commit 3b20d88

Please sign in to comment.