Skip to content

Commit

Permalink
add GNO token icon; stablecoin swap use underlying as target instead …
Browse files Browse the repository at this point in the history
…of source; turn on supply with permit for sDAI
  • Loading branch information
hexonaut committed May 19, 2023
1 parent 7fe8bd3 commit 9a9db10
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 24 deletions.
1 change: 1 addition & 0 deletions public/icons/tokens/gno.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/components/transactions/PSMSwap/PSMSwapModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const PSMSwapModal = () => {
}>;
return (
<BasicModal open={type === ModalType.PSMSwap} setOpen={close}>
<ModalWrapper title={<Trans>Swap</Trans>} underlyingAsset={args.underlyingAsset}>
<ModalWrapper title={<Trans>Swap to</Trans>} underlyingAsset={args.underlyingAsset}>
{(params) => <PSMSwapModalContent {...params} />}
</ModalWrapper>
</BasicModal>
Expand Down
49 changes: 27 additions & 22 deletions src/components/transactions/PSMSwap/PSMSwapModalContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,37 @@ import {
DetailsPSMSwap,
TxModalDetails,
} from 'src/components/transactions/FlowCommons/TxModalDetails';
import { useWalletBalances } from 'src/hooks/app-data-provider/useWalletBalances';
import { useModalContext } from 'src/hooks/useModal';

import {
ComputedReserveData,
useAppDataContext,
} from '../../../hooks/app-data-provider/useAppDataProvider';
import { CapType } from '../../caps/helper';
import { Link } from '../../primitives/Link';
import { ModalWrapperProps } from '../FlowCommons/ModalWrapper';
import { TxSuccessView } from '../FlowCommons/Success';
import { PSMSwapActions, PSMSwapActionType } from './PSMSwapActions';

export const PSMSwapModalContent = ({
poolReserve,
isWrongNetwork,
tokenBalance,
}: ModalWrapperProps) => {
export const PSMSwapModalContent = ({ poolReserve, isWrongNetwork }: ModalWrapperProps) => {
const { marketReferencePriceInUsd, reserves, chi, tin, tout } = useAppDataContext();
const { gasLimit, mainTxState: supplyTxState, txError } = useModalContext();
const { walletBalances } = useWalletBalances();

const validTypes = new Map<string, Array<PSMSwapActionType>>(
Object.entries({
DAI: [PSMSwapActionType.BUY_GEM, PSMSwapActionType.SDAI_DEPOSIT],
USDC: [PSMSwapActionType.SELL_GEM],
sDAI: [PSMSwapActionType.SDAI_REDEEM],
DAI: [PSMSwapActionType.SDAI_REDEEM, PSMSwapActionType.SELL_GEM],
USDC: [PSMSwapActionType.BUY_GEM],
sDAI: [PSMSwapActionType.SDAI_DEPOSIT],
})
);
const typeTargetReserveMap = new Map<string, string>(
const typeSourceReserveMap = new Map<string, string>(
Object.entries({
[PSMSwapActionType.BUY_GEM]: 'USDC',
[PSMSwapActionType.SELL_GEM]: 'DAI',
[PSMSwapActionType.SDAI_DEPOSIT]: 'sDAI',
[PSMSwapActionType.SDAI_REDEEM]: 'DAI',
[PSMSwapActionType.BUY_GEM]: 'DAI',
[PSMSwapActionType.SELL_GEM]: 'USDC',
[PSMSwapActionType.SDAI_DEPOSIT]: 'DAI',
[PSMSwapActionType.SDAI_REDEEM]: 'sDAI',
})
);
const exchangeRate = new Map<string, BigNumber>(
Expand All @@ -61,9 +60,11 @@ export const PSMSwapModalContent = ({
const [_amount, setAmount] = useState('');
const amountRef = useRef<string>('');
const [type, setType] = useState(currentValidTypes[0]);
const poolReserveSwapTo = reserves.find(
(reserve) => typeTargetReserveMap.get(type)! === reserve.symbol
const poolReserveSwapFrom = reserves.find(
(reserve) => typeSourceReserveMap.get(type)! === reserve.symbol
) as ComputedReserveData;
const sourceBalance =
walletBalances[poolReserveSwapFrom.underlyingAsset.toLowerCase()]?.amount || '0';
const currentExchangeRate = exchangeRate.get(type)!;

// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand All @@ -73,7 +74,7 @@ export const PSMSwapModalContent = ({
};

// Calculate max amount to supply
const maxAmountToSwap = new BigNumber(tokenBalance);
const maxAmountToSwap = new BigNumber(sourceBalance);
const isMaxSelected = _amount === '-1';
const amount = isMaxSelected ? maxAmountToSwap.toString(10) : _amount;

Expand Down Expand Up @@ -101,16 +102,21 @@ export const PSMSwapModalContent = ({

return (
<>
{currentValidTypes.length > 1 ? (
<Link sx={{ fontWeight: 'bold' }} href="#" onClick={handleTypeChange}>
Switch Source Token
</Link>
) : null}
<AssetInput
value={amount}
onChange={handleChange}
usdValue={amountInUsd.toString(10)}
symbol={poolReserve.symbol}
symbol={poolReserveSwapFrom.symbol}
assets={[
{
balance: maxAmountToSwap.toString(10),
symbol: poolReserve.symbol,
iconSymbol: poolReserve.iconSymbol,
symbol: poolReserveSwapFrom.symbol,
iconSymbol: poolReserveSwapFrom.iconSymbol,
},
]}
capType={CapType.supplyCap}
Expand All @@ -128,11 +134,10 @@ export const PSMSwapModalContent = ({
/>
<DetailsPSMSwap
description={<Trans>You receive</Trans>}
symbol={poolReserveSwapTo.symbol}
iconSymbol={poolReserveSwapTo.iconSymbol}
symbol={poolReserve.symbol}
iconSymbol={poolReserve.iconSymbol}
visibleDecimals={2}
value={currentExchangeRate.multipliedBy(amount ? amount : 0).toNumber()}
switchToHandle={currentValidTypes.length > 1 ? handleTypeChange : undefined}
/>
</TxModalDetails>

Expand Down
2 changes: 1 addition & 1 deletion src/ui-config/permitConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const permitByChainAndToken: {
[ChainId.mainnet]: {
'0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48': false,
'0x6b175474e89094c44da98b954eedeac495271d0f': false,
'0x7fc66500c84a76ad7e9c93437bfc5ac33e2ddae9': true,
'0x83f20f44975d03b1b09e64809b757c47f942beea': true,
'0x514910771af9ca656af840dff83e8264ecf986ca': false,
'0x2260fac5e5542a773aa44fbcfedf7c193bc2c599': false,
'0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2': false,
Expand Down

0 comments on commit 9a9db10

Please sign in to comment.