Skip to content

Commit

Permalink
Sign Transction: scroll to response when signatures are added
Browse files Browse the repository at this point in the history
  • Loading branch information
quietbits committed Nov 1, 2024
1 parent 5a28a76 commit 8588636
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 45 deletions.
82 changes: 44 additions & 38 deletions src/app/(sidebar)/transaction/sign/components/Overview.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";

import { useEffect, useState } from "react";
import { useEffect, useRef, useState } from "react";
import { Card, Icon, Text, Button, Select } from "@stellar/design-system";
import {
FeeBumpTransaction,
Expand All @@ -21,6 +21,7 @@ import { txHelper } from "@/helpers/txHelper";
import { delayedAction } from "@/helpers/delayedAction";
import { shortenStellarAddress } from "@/helpers/shortenStellarAddress";
import { arrayItem } from "@/helpers/arrayItem";
import { scrollElIntoView } from "@/helpers/scrollElIntoView";
import { useSignWithExtensionWallet } from "@/hooks/useSignWithExtensionWallet";

import { validate } from "@/validate";
Expand Down Expand Up @@ -56,6 +57,7 @@ export const Overview = () => {
} = transaction;

const router = useRouter();
const successResponseEl = useRef<HTMLDivElement | null>(null);

const [signError, setSignError] = useState("");

Expand Down Expand Up @@ -252,6 +254,8 @@ export const Overview = () => {

const signedTx = tx.toEnvelope().toXDR("base64");
updateSignedTx(signedTx);

scrollElIntoView(successResponseEl);
} else {
updateSignedTx("");
}
Expand Down Expand Up @@ -859,44 +863,46 @@ export const Overview = () => {
</Card>

{sign.signedTx ? (
<ValidationResponseCard
variant="success"
title="Transaction signed!"
subtitle={getAllSigsMessage()}
response={
<Box gap="xs">
<div>
<div>{sign.signedTx}</div>
</div>
</Box>
}
note={
<>
Now that this transaction is signed, you can submit it to the
network. Horizon provides an endpoint called Post Transaction
that will relay your transaction to the network and inform you
of the result.
</>
}
footerLeftEl={
<Button size="md" variant="secondary" onClick={onViewSubmitTxn}>
Submit in Transaction Submitter
</Button>
}
footerRightEl={
<div className="SignTx__Buttons">
<ViewInXdrButton xdrBlob={sign.signedTx} />

<Button
size="md"
variant="tertiary"
onClick={onWrapWithFeeBump}
>
Wrap with Fee Bump
<div ref={successResponseEl}>
<ValidationResponseCard
variant="success"
title="Transaction signed!"
subtitle={getAllSigsMessage()}
response={
<Box gap="xs">
<div>
<div>{sign.signedTx}</div>
</div>
</Box>
}
note={
<>
Now that this transaction is signed, you can submit it to the
network. Horizon provides an endpoint called Post Transaction
that will relay your transaction to the network and inform you
of the result.
</>
}
footerLeftEl={
<Button size="md" variant="secondary" onClick={onViewSubmitTxn}>
Submit in Transaction Submitter
</Button>
</div>
}
/>
}
footerRightEl={
<div className="SignTx__Buttons">
<ViewInXdrButton xdrBlob={sign.signedTx} />

<Button
size="md"
variant="tertiary"
onClick={onWrapWithFeeBump}
>
Wrap with Fee Bump
</Button>
</div>
}
/>
</div>
) : null}

{signError ? (
Expand Down
12 changes: 12 additions & 0 deletions src/helpers/scrollElIntoView.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { delayedAction } from "@/helpers/delayedAction";

export const scrollElIntoView = (
scrollEl: React.MutableRefObject<HTMLDivElement | null>,
) => {
delayedAction({
action: () => {
scrollEl?.current?.scrollIntoView({ behavior: "smooth" });
},
delay: 300,
});
};
9 changes: 2 additions & 7 deletions src/hooks/useScrollIntoView.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
import { useEffect } from "react";
import { delayedAction } from "@/helpers/delayedAction";
import { scrollElIntoView } from "@/helpers/scrollElIntoView";

export const useScrollIntoView = (
isEnabled: boolean,
scrollEl: React.MutableRefObject<HTMLDivElement | null>,
) => {
useEffect(() => {
if (isEnabled) {
delayedAction({
action: () => {
scrollEl?.current?.scrollIntoView({ behavior: "smooth" });
},
delay: 300,
});
scrollElIntoView(scrollEl);
}
}, [isEnabled, scrollEl]);
};

0 comments on commit 8588636

Please sign in to comment.