Skip to content

Commit

Permalink
fix(honey): collaterals allowance wrong
Browse files Browse the repository at this point in the history
  • Loading branch information
SnowBera committed Jan 11, 2025
1 parent 9c7b8e0 commit 0e695c6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 24 deletions.
11 changes: 6 additions & 5 deletions apps/honey/src/components/swap-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,19 @@ export function SwapCard() {
<div className="w-full">
<Card className="relative z-10 m-auto block w-full max-w-[500px] bg-background shadow-2xl">
{ModalPortal}
<CardHeader className="pb-3">
<CardHeader className="p-3 pt-6 md:p-6">
<CardTitle>
<span>{isMint ? "Mint" : "Redeem"}</span>
{isFeeLoading || fee === -1 ? (
<Skeleton className="absolute right-6 top-5 h-6 w-40" />
<Skeleton className="absolute right-3 top-5 h-6 w-40 md:right-6" />
) : (
<div className="absolute right-6 top-5 text-base font-medium text-muted-foreground">
<div className="absolute right-3 top-5 text-base font-medium text-muted-foreground md:right-6">
Static fee of <FormattedNumber value={fee ?? 0} percent />
</div>
)}
</CardTitle>
</CardHeader>
<CardContent>
<CardContent className="p-3 md:p-6">
<Tabs defaultValue={tabValue} value={tabValue} className="mb-3">
<TabsList className="w-full">
<TabsTrigger
Expand Down Expand Up @@ -132,6 +132,7 @@ export function SwapCard() {
amount={userFriendlyAmount(
fromAmount[selectedFrom?.[0]?.address!],
)}
className="text-xs"
balance={fromBalance?.[0]}
selected={selectedFrom?.[0]}
selectable={selectedFrom?.[0]?.address !== honey?.address}
Expand Down Expand Up @@ -339,7 +340,7 @@ export function SwapCard() {
token={needsApproval[0]}
spender={honeyFactoryAddress}
amount={parseUnits(
needsApproval[0].amount.toString() ?? "0",
(Number(needsApproval[0].amount) + 1).toString() ?? "0",
needsApproval[0].decimals ?? 18,
)}
onApproval={() => refreshAllowances()}
Expand Down
1 change: 1 addition & 0 deletions apps/honey/src/hooks/usePsm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ export const usePsm = (): PsmHookReturn => {
? TransactionActionType.MINT_HONEY
: TransactionActionType.REDEEM_HONEY,
onSuccess: () => {
refreshAllowances();
track(`${isMint ? "mint" : "redeem"}_honey`, {
amountCollaterals: isMint ? fromAmount : toAmount,
amountHoney: isMint
Expand Down
19 changes: 0 additions & 19 deletions packages/berajs/src/actions/honey/getHoneyPreview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,25 +83,6 @@ export const getHoneyPreview = async ({
};
}

// ======= TEMP FIX ==========
/**
* TEMP FIX: the smart contract (when not in basket mode and when the user change the honey amount) returns the collateral value in the first position
* of the array disregarding the collateral order inside the contracts.
* [TODO] when the smart contract are updated we need to remove this fix
*/
const collIdx = collateralList.findIndex(
(token) => token.address === collateral.address,
);
if (
(collIdx !== 0 && formattedResult.collaterals[collIdx] === BigInt(0)) ||
!formattedResult.collaterals[collIdx]
) {
const tempValue = formattedResult.collaterals[0];
formattedResult.collaterals[0] = formattedResult.collaterals[collIdx];
formattedResult.collaterals[collIdx] = tempValue;
}
// ==========================

const amountsWithAddress: Record<Address, bigint> = collateralList.reduce(
(agg, key, idx) => {
if (
Expand Down

0 comments on commit 0e695c6

Please sign in to comment.