Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Feat/ethers provider rpc update #364

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion commitlintrc.ts
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
export default { extends: ["@commitlint/config-conventional"] };
export default {
extends: ["@commitlint/config-conventional"],
rules: {
"body-max-line-length": [2, "always", Infinity],
},
};
8 changes: 6 additions & 2 deletions components/global/step-process-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { buttonVariants } from "@/components/ui/button";
import {
Dialog,
DialogContent,
DialogDescription,
DialogHeader,
DialogTitle,
DialogTrigger,
Expand Down Expand Up @@ -212,10 +213,13 @@ const StepProcessModal = ({
{title}
</DialogTitle>
</DialogHeader>
<DialogDescription hidden>
Shows the status of the transaction
</DialogDescription>
<div className="flex flex-col px-2 pt-3">
{steps.map((step) => (
{steps.map((step, index) => (
<div
key={step.description}
key={step.id}
className="flex items-center relative border-l-2 border-slate-300 pl-2 pb-6 last-of-type:pb-0"
>
<div
Expand Down
12 changes: 9 additions & 3 deletions components/marketplace/list-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import {
FormItem,
FormMessage,
} from "@/components/ui/form";
import { DialogDescription } from "@radix-ui/react-dialog";

export const listingFormSchema = z
.object({
Expand Down Expand Up @@ -264,11 +265,11 @@ function ListDialogInner({
</DialogTitle>
</DialogHeader>

<div>
<DialogDescription>
List your hypercert fraction for sale, allowing buyers to directly
purchase all or part of it. Adjust settings to retain portions for
yourself or set a minimum transaction amount as needed.
</div>
</DialogDescription>

{fractionsOwnedByUser.length > 1 && (
<div className="font-semibold">
Expand Down Expand Up @@ -439,8 +440,13 @@ function ListDialogInner({
<AlertDialogTrigger
disabled={!form.formState.isValid}
className={"w-full"}
asChild
>
<Button disabled={!form.formState.isValid} className="w-full">
<Button
disabled={!form.formState.isValid}
className="w-full"
type="submit"
>
{isPending && (
<LoaderCircle className="h-4 w-4 animate-spin mr-1" />
)}
Expand Down
17 changes: 7 additions & 10 deletions hooks/use-ethers-provider.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
import { HttpTransport, PublicClient } from "viem";
import { JsonRpcProvider, FallbackProvider } from "ethers";
import { PublicClient } from "viem";
import { JsonRpcProvider } from "ethers";

import { usePublicClient } from "wagmi";
import React from "react";
import { EvmClientFactory } from "@/lib/evmClient";

export function publicClientToProvider(publicClient: PublicClient) {
const { chain, transport } = publicClient;
if (!chain || !transport) return undefined;

const network = {
chainId: chain.id,
name: chain.name,
ensAddress: chain.contracts?.ensRegistry?.address,
};
if (transport.type === "fallback") {
const providers = (transport.transports as ReturnType<HttpTransport>[]).map(
({ value }) => new JsonRpcProvider(value?.url, network),
);
if (providers.length === 1) return providers[0];
return new FallbackProvider(providers);
}
return new JsonRpcProvider(transport.url, network);

const rpcUrl = EvmClientFactory.getFirstAvailableUrl(chain.id);
return new JsonRpcProvider(rpcUrl, network);
}

/** Hook to convert a viem Public Client to an ethers.js Provider. */
Expand Down
7 changes: 4 additions & 3 deletions lib/decodeContractError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import {
export function decodeContractError(error: any, defaultMessage: string) {
const abis = [TransferManagerAbi, HypercertExchangeAbi, OrderValidatorV2AAbi];
// @ts-ignore
const transactionData = error?.info?.error?.data?.originalError?.data as
| `0x${string}`
| undefined;
const transactionData = (error?.info?.error?.data?.originalError?.data ||
error?.data?.originalError?.data ||
error?.data?.data ||
error?.data) as `0x${string}` | undefined;

if (!transactionData) {
return defaultMessage;
Expand Down
17 changes: 9 additions & 8 deletions marketplace/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { SUPPORTED_CHAINS } from "@/configs/constants";
import { useRouter } from "next/navigation";
import { calculateBigIntPercentage } from "@/lib/calculateBigIntPercentage";
import { ExternalLink } from "lucide-react";
import React from "react";
import React, { useEffect } from "react";
import { clearCacheAfterListing } from "@/app/actions/clearCacheAfterListing";
import { revalidatePathServerAction } from "@/app/actions/revalidatePathServerAction";
export const useCreateOrderInSupabase = () => {
Expand Down Expand Up @@ -96,7 +96,9 @@ export const useCreateFractionalMakerAsk = ({
setExtraContent,
} = useStepProcessDialogContext();

setTitle("Create marketplace listing");
useEffect(() => {
setTitle("Create marketplace listing");
}, []);

return useMutation({
mutationKey: ["createFractionalMakerAsk"],
Expand Down Expand Up @@ -150,8 +152,8 @@ export const useCreateFractionalMakerAsk = ({
description: "Signing order",
},
{
id: "Create order",
description: "Creating order",
id: "Register",
description: "Registering order",
},
]);
setOpen(true);
Expand Down Expand Up @@ -264,7 +266,7 @@ export const useCreateFractionalMakerAsk = ({
throw new Error("Error signing order");
}

await setStep("Create order");
await setStep("Register");
try {
await createOrder({
order: maker,
Expand All @@ -276,7 +278,7 @@ export const useCreateFractionalMakerAsk = ({
} catch (e) {
console.error(e);
await setStep(
"Create order",
"Register",
"error",
e instanceof Error ? e.message : "Error registering order",
);
Expand All @@ -303,7 +305,7 @@ export const useCreateFractionalMakerAsk = ({
</div>
</div>
));
await setStep("Create order", "completed");
await setStep("Register", "completed");
},
onError: (e) => {
console.error(e);
Expand Down Expand Up @@ -353,7 +355,6 @@ export const useBuyFractionalMakerAsk = () => {
return useMutation({
mutationKey: ["buyFractionalMakerAsk"],
onError: (e) => {
console.error(e);
toast({
title: "Error",
description: e.message,
Expand Down