Skip to content

Commit

Permalink
fix contract interaction dialog for splitting and merging
Browse files Browse the repository at this point in the history
  • Loading branch information
Jipperism committed Nov 21, 2023
1 parent a51d3bb commit 20a7309
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
3 changes: 2 additions & 1 deletion frontend/hooks/mergeFractionUnits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const useMergeFractionUnits = ({
console.error(receipt);
}
if (receipt?.status === "success") {
toast(mintInteractionLabels.toastSuccess, { type: "success" });
toast("Fractions successfully merged", { type: "success" });

setStep("complete");
onComplete?.();
Expand All @@ -66,6 +66,7 @@ export const useMergeFractionUnits = ({
showModal({ stepDescriptions });
setStep("preparing");
await initializeWrite(ids);
window.location.reload();
},
txPending,
readOnly: isLoading || !client || client.readonly,
Expand Down
10 changes: 4 additions & 6 deletions frontend/hooks/splitClaimUnits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ export const useSplitFractionUnits = ({
const { client, isLoading } = useHypercertClient();

const stepDescriptions = {
preparing: "Preparing to merge fraction values",
merging: "Splitting fraction units on-chain",
splitting: "Splitting fraction units on-chain",
waiting: "Awaiting confirmation",
complete: "Done splitting",
};
Expand All @@ -27,19 +26,19 @@ export const useSplitFractionUnits = ({
const publicClient = client.config.publicClient;

const initializeWrite = async (fractionId: bigint, fractions: bigint[]) => {
showModal({ stepDescriptions });
setStep("splitting");
try {
setTxPending(true);

const hash = await client.splitFractionUnits(fractionId, fractions);

setStep("waiting");
const receipt = await publicClient?.waitForTransactionReceipt({
confirmations: 3,
hash: hash,
});

setStep("waiting");

if (receipt?.status === "reverted") {
toast("Splitting failed", {
type: "error",
Expand All @@ -65,9 +64,8 @@ export const useSplitFractionUnits = ({

return {
write: async (id: bigint, fractions: bigint[]) => {
showModal({ stepDescriptions });
setStep("preparing");
await initializeWrite(id, fractions);
window.location.reload();
},
txPending,
readOnly: isLoading || !client || client.readonly,
Expand Down

0 comments on commit 20a7309

Please sign in to comment.