diff --git a/components/DepositForm.tsx b/components/DepositForm.tsx index d3875f5b..9949e0ae 100644 --- a/components/DepositForm.tsx +++ b/components/DepositForm.tsx @@ -40,6 +40,7 @@ import useTokenPositionsFull from 'hooks/useAccountPositionsFull' import AccountSlotsFullNotification from './shared/AccountSlotsFullNotification' import { handleInputChange } from 'utils/account' import InlineNotification from './shared/InlineNotification' +import { Bank, Group } from '@blockworks-foundation/mango-v4' interface DepositFormProps { onSuccess: () => void @@ -67,6 +68,16 @@ export const walletBalanceForToken = ( } } +export const isTokenInsured = ( + bank: Bank | undefined, + group: Group | undefined, +) => { + if (!bank || !group) return true + const mintInfo = group.mintInfosMapByMint.get(bank.mint.toString()) + const isInsured = mintInfo?.groupInsuranceFund + return isInsured +} + function DepositForm({ onSuccess, token }: DepositFormProps) { const { t } = useTranslation(['common', 'account', 'swap']) const [inputAmount, setInputAmount] = useState('') @@ -87,10 +98,7 @@ function DepositForm({ onSuccess, token }: DepositFormProps) { const isInsured = useMemo(() => { const group = mangoStore.getState().group - if (!bank || !group) return true - const mintInfo = group.mintInfosMapByMint.get(bank.mint.toString()) - const isInsured = mintInfo?.groupInsuranceFund - return isInsured + return isTokenInsured(bank, group) }, [bank]) const tokenPositionsFull = useTokenPositionsFull([bank]) @@ -307,7 +315,7 @@ function DepositForm({ onSuccess, token }: DepositFormProps) { ) : null} {!isInsured ? ( {t('account:warning-uninsured', { token: bank?.name })}{' '} diff --git a/components/swap/SwapReviewRouteInfo.tsx b/components/swap/SwapReviewRouteInfo.tsx index 372d1a30..9796401a 100644 --- a/components/swap/SwapReviewRouteInfo.tsx +++ b/components/swap/SwapReviewRouteInfo.tsx @@ -62,6 +62,8 @@ import { RefetchOptions, RefetchQueryFilters, } from '@tanstack/react-query' +import { isTokenInsured } from '@components/DepositForm' +import InlineNotification from '@components/shared/InlineNotification' type JupiterRouteInfoProps = { amountIn: Decimal @@ -332,7 +334,7 @@ const SwapReviewRouteInfo = ({ setSelectedRoute, show, }: JupiterRouteInfoProps) => { - const { t } = useTranslation(['common', 'swap', 'trade']) + const { t } = useTranslation(['common', 'account', 'swap', 'trade']) const slippage = mangoStore((s) => s.swap.slippage) const wallet = useWallet() const [showRoutesModal, setShowRoutesModal] = useState(false) @@ -605,7 +607,7 @@ const SwapReviewRouteInfo = ({ outputBank, outputTokenInfo.decimals, ) - }, [selectedRoute]) + }, [inputBank, outputBank, outputTokenInfo, selectedRoute]) const coinGeckoPriceDifference = useMemo(() => { return amountOut?.toNumber() @@ -621,6 +623,11 @@ const SwapReviewRouteInfo = ({ : new Decimal(0) }, [coingeckoPrices, amountIn, amountOut]) + const isInsured = useMemo(() => { + const group = mangoStore.getState().group + return isTokenInsured(outputBank, group) + }, [outputBank]) + return routes?.length && selectedRoute && inputTokenInfo && @@ -638,16 +645,16 @@ const SwapReviewRouteInfo = ({ >
-
+
-
+
{refetchRoute ? ( refetchRoute()} size="small" @@ -671,7 +678,7 @@ const SwapReviewRouteInfo = ({ ) : null}
-
+
@@ -837,7 +844,7 @@ const SwapReviewRouteInfo = ({

Jupiter Fees

- ≈{' '} + ≈

*/} - {borrowAmount ? ( + {borrowAmount && inputBank ? ( <>
{' '} - {inputBank!.name} + {inputBank.name}

) : null}
+ {!isInsured ? ( +
+ + {t('account:warning-uninsured', { + token: outputBank?.name, + })}{' '} + + {t('learn-more')} + + + } + /> +
+ ) : null}