Skip to content

Commit

Permalink
fix estimating fee issues
Browse files Browse the repository at this point in the history
  • Loading branch information
starknetdev committed Oct 9, 2023
1 parent 0fdd27f commit 15107e2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 20 deletions.
6 changes: 4 additions & 2 deletions ui/src/app/containers/BeastScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ export default function BeastScreen({ attack, flee }: BeastScreenProps) {
adventurer?.beastHealth == 0 ||
loading ||
adventurer?.level == 1 ||
adventurer.dexterity === 0,
adventurer.dexterity === 0 ||
estimatingFee,
loading: loading,
},
{
Expand All @@ -108,7 +109,8 @@ export default function BeastScreen({ attack, flee }: BeastScreenProps) {
adventurer?.beastHealth == 0 ||
loading ||
adventurer?.level == 1 ||
adventurer.dexterity === 0,
adventurer.dexterity === 0 ||
estimatingFee,
loading: loading,
},
];
Expand Down
42 changes: 24 additions & 18 deletions ui/src/app/lib/utils/syscalls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,30 @@ async function checkArcadeBalance(
if (ethBalance < FEE_CHECK_BALANCE) {
const storage: BurnerStorage = Storage.get("burners");
if (account && (account?.address ?? "0x0") in storage) {
setEstimatingFee(true);
const newAccount = new Account(
account,
account?.address,
storage[account?.address]["privateKey"],
"1"
);
const { suggestedMaxFee: estimatedFee } = await newAccount.estimateFee(
calls
);
// Add 10% to fee for safety
const formattedFee = estimatedFee * (BigInt(11) / BigInt(10));
setEstimatingFee(false);
if (ethBalance < formattedFee) {
showTopUpDialog(true);
setTopUpAccount(account?.address);
return true;
} else {
try {
setEstimatingFee(true);
const newAccount = new Account(
account,
account?.address,
storage[account?.address]["privateKey"],
"1"
);
const { suggestedMaxFee: estimatedFee } = await newAccount.estimateFee(
calls
);
// Add 10% to fee for safety
const formattedFee = estimatedFee * (BigInt(11) / BigInt(10));
setEstimatingFee(false);
if (ethBalance < formattedFee) {
showTopUpDialog(true);
setTopUpAccount(account?.address);
return true;
} else {
return false;
}
} catch (e) {
console.log(e);
setEstimatingFee(false);
return false;
}
}
Expand Down

1 comment on commit 15107e2

@vercel
Copy link

@vercel vercel bot commented on 15107e2 Oct 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.