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

fix(): update estimate gas rounding to 8 digits #141

Open
wants to merge 1 commit into
base: develop
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
34 changes: 9 additions & 25 deletions src/views/Logbook/Editing/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const Editing: React.FC<Props> = ({

const isSmallUp = useResponsive("sm-up");

const [estimate, setEstimate] = useState("0.05");
const [estimate, setEstimate] = useState("0.005");

const editorRef = useRef<EditorRef | null>(null);

Expand Down Expand Up @@ -87,34 +87,21 @@ export const Editing: React.FC<Props> = ({
return;
}

/* await Promise.all([
logbookContract.estimateGas.publish(id, content),
getFeeData(),
]); */

const gasNeeded =
// data: { gasPrice, maxFeePerGas, maxPriorityFeePerGas },
await logbookContract.estimateGas.publish(id, content);
const gasNeeded = await logbookContract.estimateGas.publish(id, content);

// add buffer
const maxGasNeeded = gasNeeded; // .mul(4).div(3); // +33%
const maxGasNeeded = gasNeeded.mul(4).div(3); // +33%

// console.log("get maxGasNeeded:", { maxGasNeeded, feeData });

const { gasPrice, maxPriorityFeePerGas } = feeData!;

const estimate = utils.formatUnits(
const estimate = (+utils.formatUnits(
ethers.BigNumber.from(0)
.add(gasPrice!)
.add(maxPriorityFeePerGas!)
.mul(maxGasNeeded)
);

/* console.log("get feeData:", {
gasNeeded,
feeData, // gasPrice, maxFeePerGas, maxPriorityFeePerGas,
estimate,
}); */
)).toFixed(8);

setEstimate(estimate);
}, 1300);
Expand All @@ -128,7 +115,7 @@ export const Editing: React.FC<Props> = ({
});

if (error) {
// console.error("publish error:", error);
console.error("publish error:", error);
throw error; // to close dialog
}

Expand Down Expand Up @@ -168,12 +155,9 @@ export const Editing: React.FC<Props> = ({
disabled={publishWaiting}
onClick={() => {
openDialog();
onPublish()
// .then((data) => { // published // console.log("published:", data); })
.catch((err) => {
// console.error("publish error:", err, closeDialog);
closeDialog?.();
});
onPublish().catch((err) => {
closeDialog?.();
});
}}
>
<TextIcon color="white">Publish</TextIcon>
Expand Down
10 changes: 10 additions & 0 deletions src/views/Logbook/LogList/Card/styles.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@
}
}

&:not(pre) > code,
& pre {
background-color: var(--color-grey-markdown-background);
}

& code,
& pre {
color: var(--color-black);
}

/* List
========================================================================== */
& ul,
Expand Down