Skip to content

Commit

Permalink
fix(contracts): fix useWrappedContract returns
Browse files Browse the repository at this point in the history
  • Loading branch information
abstract829 committed Jul 30, 2024
1 parent 05f4768 commit f05418a
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions packages/contracts/src/useRegisteredContract.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,33 +60,34 @@ export type WrappedContract = {
* @param deploymentInfo - The deployment information for the contract.
* @returns The `WrappedContract` object.
*/
export const useWrappedContract = (deploymentInfo: ContractDeploymentInfo) => {
export const useWrappedContract = (
deploymentInfo: ContractDeploymentInfo | undefined
) => {
const sorobanContext = useSorobanReact()
const [wrappedContract, setwWrappedContract] = useState<
WrappedContract | undefined
>()
>(undefined)

const wrappedInvokeFunction = useCallback(
async (args: WrappedContractInvokeArgs) => {
const contractInvokeArgs: InvokeArgs = {
...args,
sorobanContext,
contractAddress: deploymentInfo.contractAddress,
contractAddress: deploymentInfo?.contractAddress!,
}
return contractInvoke(contractInvokeArgs)
},
[sorobanContext, deploymentInfo]
)

const createWrappedContract = () => {
useEffect(() => {
if (!deploymentInfo) return

const newWrappedContract: WrappedContract = {
deploymentInfo,
invoke: wrappedInvokeFunction,
}
setwWrappedContract(newWrappedContract)
}
useEffect(() => {
createWrappedContract()
}, [deploymentInfo, wrappedInvokeFunction])

return wrappedContract
Expand All @@ -109,7 +110,5 @@ export const useRegisteredContract = (contractId: string) => {
networkPassphrase
)

if (!deploymentInfo) return undefined

return useWrappedContract(deploymentInfo)
}

0 comments on commit f05418a

Please sign in to comment.