Skip to content

Commit

Permalink
fix: add checking of transaction executed using viem (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
yvesfracari authored Apr 4, 2024
1 parent 10e9fc3 commit fccc190
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 28 deletions.
9 changes: 9 additions & 0 deletions src/app/history/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { OrderProvider } from "#/contexts/ordersContext";

export default function Layout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return <OrderProvider>{children}</OrderProvider>;
}
13 changes: 1 addition & 12 deletions src/app/history/order/[orderHash]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,7 @@ export default function OrderPage({
const orderDateTime = formatDateTime(
epochToDate(Number(stopLossOrder?.blockTimestamp))
);
const orderExpirationDateTime = formatDateTime(
epochToDate(
Number(stopLossOrder?.blockTimestamp) +
Number(stopLossOrder?.stopLossData?.validityBucketSeconds)
)
);

const amountIn =
Number(stopLossOrder?.stopLossData?.tokenAmountIn) /
10 ** Number(stopLossOrder?.stopLossData?.tokenIn.decimals);
Expand Down Expand Up @@ -125,12 +120,6 @@ export default function OrderPage({
>
{orderDateTime}
</OrderInformation>
<OrderInformation
label="Expiration Time"
tooltipText="The date and time at which an order will expire and effectively be cancelled."
>
{orderExpirationDateTime}
</OrderInformation>
</div>
<Separator className="my-3" />
<div className="flex flex-col gap-y-1">
Expand Down
13 changes: 11 additions & 2 deletions src/app/txpending/[safeTxHash]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,27 @@ import { useRouter } from "next/navigation";
import { useEffect } from "react";

import { Spinner } from "#/components/Spinner";
import { ChainId, publicClientsFromIds } from "#/lib/publicClients";

export default function Page({
params: { safeTxHash },
}: {
params: { safeTxHash: string };
}) {
const { sdk } = useSafeAppsSDK();
const { sdk, safe } = useSafeAppsSDK();
const publicClient = publicClientsFromIds[safe.chainId as ChainId];
const router = useRouter();

async function redirectToHistoryOnTxExecuted() {
const tx = await sdk.txs.getBySafeTxHash(safeTxHash);
if (tx.txStatus === TransactionStatus.SUCCESS) {
if (tx.txStatus === TransactionStatus.SUCCESS && tx.txHash) {
const confirmationBlocks = await publicClient.getTransactionConfirmations(
{
hash: tx.txHash as `0x${string}`,
}
);

if (confirmationBlocks < 3) return;
// Wait 1 second for the subgraph to index the transaction
setTimeout(() => {
router.push("/history");
Expand Down
25 changes: 11 additions & 14 deletions src/components/RootLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import React from "react";
import { ReactFlowProvider } from "reactflow";

import { NetworksContextProvider } from "#/contexts/networks";
import { OrderProvider } from "#/contexts/ordersContext";

import { Footer } from "./Footer";
import { Header } from "./Header";
Expand All @@ -33,19 +32,17 @@ export function RootLayout({ children }: React.PropsWithChildren) {
<SafeProvider loader={<SafeLoader />}>
<NetworksContextProvider>
<ReactFlowProvider>
<OrderProvider>
<div className="flex flex-col h-screen">
<Header linkUrl={"/builder"} imageSrc={"/assets/stoploss.svg"}>
{path !== "/history" && <HistoryButton />}
</Header>
<div className="size-full bg-background">{children}</div>
<Footer
githubLink="https://github.com/bleu-fi/composable-cow-hub"
discordLink="https://discord.gg/cowprotocol"
/>
</div>
<Toaster />
</OrderProvider>
<div className="flex flex-col h-screen">
<Header linkUrl={"/builder"} imageSrc={"/assets/stoploss.svg"}>
{path !== "/history" && <HistoryButton />}
</Header>
<div className="size-full bg-background">{children}</div>
<Footer
githubLink="https://github.com/bleu-fi/composable-cow-hub"
discordLink="https://discord.gg/cowprotocol"
/>
</div>
<Toaster />
</ReactFlowProvider>
</NetworksContextProvider>
</SafeProvider>
Expand Down

0 comments on commit fccc190

Please sign in to comment.