diff --git a/src/stores/sacrifice.js b/src/stores/sacrifice.js index 5900a40..844b2b9 100644 --- a/src/stores/sacrifice.js +++ b/src/stores/sacrifice.js @@ -115,6 +115,8 @@ export const useSacrificeStore = defineStore("sacrifice", { var quoteRewards = await uniswapStore.quoteExactInputSingle(amountETHBase[0]); let variant = "sacrifice"; + // here you are setting only variant, let's show by default rewardsForResultSum + output = rewardsForResultSum; if (quoteRewards.result) { // take 99.5% of quoted amount, 0.5% allowed slippage minBLOOD = quoteRewards.amount * 995n / 1000n; @@ -131,13 +133,6 @@ export const useSacrificeStore = defineStore("sacrifice", { rewardsForResultSum, }); } - } else { - /** - * case 4 - * quoter threw an error - */ - // - output = rewardsForResultSum; } console.log("variant", variant); console.log("amount", amount); @@ -151,13 +146,21 @@ export const useSacrificeStore = defineStore("sacrifice", { if (variant === "buy") { output = quoteRewards.amount } - } else if (walletStore.connected && variant === "sacrifice") { + } else if (walletStore.connected && variant === "sacrifice" && token.allowance >= amount) { /** * case 2 * user is logged in and allowance is greater or equal input and variant is sacrifice */ - output = rewardsForResultSum; - } else if (walletStore.connected && variant === "buy") { + // in this case you should use eth_call, so you are showing exact reward in cases of completing cycles + const amountSacrifice = await readContract({ + address: memeburnerStore.contract.address, + abi: memeburnerStore.contract.abi, + functionName: "sacrificeMeme", + args: [token.contractAddress, amount.toString(), minETH.toString()], + account: walletStore.address, + }); + output = amountSacrifice; + } else if (walletStore.connected && variant === "buy" && token.allowance >= amount) { /** * case 3 * user is logged in and allowance is greater or equal input and variant is buy