Files
js/@3rdweb-sdk/react/hooks/useImportContract.ts
T
Nacho IacovinoandJonas Daniels ad9e643737 Add Import flow (#690)
* WIP Import contract

* Don't read twice

* Make UI a bit nicer

* Fix import contract flow flash

Co-authored-by: Jonas Daniels <[email protected]>
2022-12-02 19:05:55 -08:00

27 lines
689 B
TypeScript

import { useDashboardEVMChainId } from "./useActiveChainId";
import { useMutation } from "@tanstack/react-query";
export function useImportContract() {
const chainId = useDashboardEVMChainId();
return useMutation(async (contractAddress: string) => {
const res = await fetch(
`https://contract-importer-qj32.zeet-nftlabs.zeet.app/import`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
contractAddress,
chainId,
}),
},
);
if (res.status >= 400) {
throw new Error(await res.text().then((r) => r));
}
return res.json();
});
}