Skip to content

Commit

Permalink
fix usdc & usdc.e deposit decimals logic on upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
divine-comedian committed Dec 2, 2024
1 parent fdb5f41 commit 058091c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useState, type FC, useEffect } from 'react';
import { Button, Flex } from '@giveth/ui-design-system';
import { useAccount, useBalance } from 'wagmi';
import { useIntl } from 'react-intl';
import { ethers } from 'ethers';
import { Framework } from '@superfluid-finance/sdk-core';
import { ISuperToken, IToken } from '@/types/superFluid';
import { AddressZero } from '@/lib/constants/constants';
Expand Down Expand Up @@ -125,17 +126,26 @@ export const DepositSuperToken: FC<IDepositSuperTokenProps> = ({

// EThx is not a Wrapper Super Token and should load separately
let superTokenAsset;
let newAmount = amount;
if (superToken.symbol === 'ETHx') {
superTokenAsset = await sf.loadNativeAssetSuperToken(
superToken.id,
);
} else {
superTokenAsset = await sf.loadWrapperSuperToken(superToken.id);
}
if (token && token.decimals === 6) {
const divisor = BigInt(10 ** token.decimals);
const currentAmount = Number(amount) / Number(divisor);
newAmount = ethers.utils
.parseUnits(currentAmount.toString(), 18)
.toBigInt();
}
console.log('token', token);
console.log('supertoken', superToken);
const upgradeOperation = await superTokenAsset.upgrade({
amount: amount.toString(),
amount: newAmount.toString(),
});

const tx = await upgradeOperation.exec(signer);
const res = await tx.wait();
if (!res.status) {
Expand Down Expand Up @@ -165,7 +175,6 @@ export const DepositSuperToken: FC<IDepositSuperTokenProps> = ({
closeModal();
}
};

return (
<Wrapper>
{step === EModifySuperTokenSteps.MODIFY ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { EModifySuperTokenSteps } from './common';
import config from '@/configuration';

interface IModifySuperTokenModalProps extends IModal {
selectedToken: IToken;
selectedToken: ISuperToken | IToken;
tokenStreams: ISuperfluidStream[];
refreshBalance: () => void;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ export const StreamRow: FC<IStreamRowProps> = ({ tokenStream }) => {
),
[tokenStream],
);
console.log('tokenStream', tokenStream);
console.log('config', config.OPTIMISM_CONFIG.SUPER_FLUID_TOKENS);
// console.log('superToken', superToken);
const [showModifyModal, setShowModifyModal] = useState(false);
const { address, chain } = useAccount();
const { switchChain } = useSwitchChain();
Expand Down Expand Up @@ -119,11 +116,11 @@ export const StreamRow: FC<IStreamRowProps> = ({ tokenStream }) => {
Deposit/Withdraw
</ModifyButton>
</TableCell>
{showModifyModal && (
{showModifyModal && superToken && (
<ModifySuperTokenModal
tokenStreams={tokenStream}
setShowModal={setShowModifyModal}
selectedToken={tokenStream[0].token}
selectedToken={superToken}
refreshBalance={refetch}
/>
)}
Expand Down

0 comments on commit 058091c

Please sign in to comment.