diff --git a/scrypto-design-patterns/yield_amm/dapp/src/components/TokenizeLsu.jsx b/scrypto-design-patterns/yield_amm/dapp/src/components/TokenizeLsu.jsx index d3dfd73..ff91d10 100644 --- a/scrypto-design-patterns/yield_amm/dapp/src/components/TokenizeLsu.jsx +++ b/scrypto-design-patterns/yield_amm/dapp/src/components/TokenizeLsu.jsx @@ -1,16 +1,42 @@ +import { useEffect, useState } from "react"; +import { useAccount } from "../contexts/AccountContext.jsx"; +import { useGetEntityDetails } from "../hooks/useGetEntityDetails.js"; import { useNumericInput } from "../hooks/useNumericInput"; import TxBox from "./TxBox.jsx"; function TokenizeLsu() { - const [lsuAmount, setLsuAmount] = useNumericInput(10); + const [lsuAmount, setLsuAmount] = useNumericInput(0); + const [lsuValid, setLsuValid] = useState(false); + + const { selectedAccount } = useAccount(); + + const { info: selectedAccountData, fetchData: fetchSelectedAccountData } = + useGetEntityDetails(selectedAccount?.address); + + useEffect(() => { + fetchSelectedAccountData(); + const targetAddress = import.meta.env.VITE_API_LSU_ADDRESS; + const hasTargetAddress = + selectedAccountData?.fungible_resources?.items?.some( + (item) => item.resource_address === targetAddress, + ); + + setLsuValid(hasTargetAddress); + if (!lsuValid) { + setLsuAmount(0); + } + }, [selectedAccountData, fetchSelectedAccountData]); return (