diff --git a/components/BorrowForm.tsx b/components/BorrowForm.tsx index 511ef76b..fbd89872 100644 --- a/components/BorrowForm.tsx +++ b/components/BorrowForm.tsx @@ -323,7 +323,13 @@ function BorrowForm({ onSuccess, token }: BorrowFormProps) { />
- +

{t('loan-origination-fee')}

diff --git a/components/swap/SwapReviewRouteInfo.tsx b/components/swap/SwapReviewRouteInfo.tsx index 1a2dd555..7949704b 100644 --- a/components/swap/SwapReviewRouteInfo.tsx +++ b/components/swap/SwapReviewRouteInfo.tsx @@ -582,29 +582,29 @@ const SwapReviewRouteInfo = ({ {borrowAmount ? (
-

+

{t('loan-origination-fee')}

-

+

~ {' '} - {inputBank!.name} ( - - %) + + {inputBank!.name} +

) : null} diff --git a/components/trade/AdvancedTradeForm.tsx b/components/trade/AdvancedTradeForm.tsx index 86c78838..a263c8e8 100644 --- a/components/trade/AdvancedTradeForm.tsx +++ b/components/trade/AdvancedTradeForm.tsx @@ -401,8 +401,8 @@ const AdvancedTradeForm = () => { allowNegative={false} isNumericString={true} decimalScale={6} - name="amountIn" - id="amountIn" + name="price" + id="price" className="ml-2 w-full bg-transparent font-mono focus:outline-none" placeholder="0.00" value={tradeForm.price} @@ -439,8 +439,8 @@ const AdvancedTradeForm = () => { allowNegative={false} isNumericString={true} decimalScale={minOrderDecimals} - name="amountIn" - id="amountIn" + name="base" + id="base" className="ml-2 w-full bg-transparent font-mono focus:outline-none" placeholder="0.00" value={tradeForm.baseSize} @@ -466,8 +466,8 @@ const AdvancedTradeForm = () => { allowNegative={false} isNumericString={true} decimalScale={tickDecimals} - name="amountIn" - id="amountIn" + name="quote" + id="quote" className="ml-2 w-full bg-transparent font-mono focus:outline-none" placeholder="0.00" value={tradeForm.quoteSize} @@ -629,7 +629,7 @@ const AdvancedTradeForm = () => { />
) : null} - + ) } diff --git a/components/trade/TradeSummary.tsx b/components/trade/TradeSummary.tsx index 1b7688a8..8151281c 100644 --- a/components/trade/TradeSummary.tsx +++ b/components/trade/TradeSummary.tsx @@ -17,8 +17,10 @@ import Slippage from './Slippage' const TradeSummary = ({ mangoAccount, + useMargin, }: { mangoAccount: MangoAccount | undefined + useMargin: boolean }) => { const { t } = useTranslation(['common', 'trade']) const { group } = useMangoGroup() @@ -70,6 +72,36 @@ const TradeSummary = ({ : Math.trunc(simulatedHealthRatio) }, [group, mangoAccount, selectedMarket, tradeForm]) + const balanceBank = useMemo(() => { + if ( + !group || + !selectedMarket || + selectedMarket instanceof PerpMarket || + !useMargin + ) + return + if (tradeForm.side === 'buy') { + return group.getFirstBankByTokenIndex(selectedMarket.quoteTokenIndex) + } else { + return group.getFirstBankByTokenIndex(selectedMarket.baseTokenIndex) + } + }, [group, selectedMarket, tradeForm.side]) + + const borrowAmount = useMemo(() => { + if (!balanceBank || !mangoAccount) return 0 + let borrowAmount + const balance = mangoAccount.getTokenDepositsUi(balanceBank) + if (tradeForm.side === 'buy') { + const remainingBalance = balance - parseFloat(tradeForm.quoteSize) + borrowAmount = remainingBalance < 0 ? Math.abs(remainingBalance) : 0 + } else { + const remainingBalance = balance - parseFloat(tradeForm.baseSize) + borrowAmount = remainingBalance < 0 ? Math.abs(remainingBalance) : 0 + } + + return borrowAmount + }, [balanceBank, mangoAccount, tradeForm]) + return (
@@ -87,6 +119,30 @@ const TradeSummary = ({

+ {borrowAmount ? ( +
+ +

{t('loan-origination-fee')}

+
+

+ ~ + {' '} + {balanceBank!.name} +

+
+ ) : null}

{t('free-collateral')}

diff --git a/public/locales/en/common.json b/public/locales/en/common.json index 7d4bae2f..a9600e59 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -84,8 +84,8 @@ "liability-weight": "Liability Weight", "liquidity": "Liquidity", "loading": "Loading", - "loan-origination-fee": "Loan Origination Fee", - "loan-origination-fee-tooltip": "The fee for opening a borrow. This is paid to the Mango DAO Treasury", + "loan-origination-fee": "Borrow Fee", + "loan-origination-fee-tooltip": "{{fee}} fee for opening a borrow.", "mango": "Mango", "mango-stats": "Mango Stats", "market": "Market", diff --git a/public/locales/es/common.json b/public/locales/es/common.json index 1b992c47..b66276ab 100644 --- a/public/locales/es/common.json +++ b/public/locales/es/common.json @@ -83,8 +83,8 @@ "liability-weight": "Liability Weight", "liquidity": "Liquidity", "loading": "Loading", - "loan-origination-fee": "Loan Origination Fee", - "loan-origination-fee-tooltip": "The fee for opening a borrow. This is paid to the Mango DAO Treasury", + "loan-origination-fee": "Borrow Fee", + "loan-origination-fee-tooltip": "{{fee}} fee for opening a borrow.", "mango": "Mango", "market": "Market", "max": "Max", diff --git a/public/locales/ru/common.json b/public/locales/ru/common.json index 1b992c47..b66276ab 100644 --- a/public/locales/ru/common.json +++ b/public/locales/ru/common.json @@ -83,8 +83,8 @@ "liability-weight": "Liability Weight", "liquidity": "Liquidity", "loading": "Loading", - "loan-origination-fee": "Loan Origination Fee", - "loan-origination-fee-tooltip": "The fee for opening a borrow. This is paid to the Mango DAO Treasury", + "loan-origination-fee": "Borrow Fee", + "loan-origination-fee-tooltip": "{{fee}} fee for opening a borrow.", "mango": "Mango", "market": "Market", "max": "Max", diff --git a/public/locales/zh/common.json b/public/locales/zh/common.json index 1b992c47..b66276ab 100644 --- a/public/locales/zh/common.json +++ b/public/locales/zh/common.json @@ -83,8 +83,8 @@ "liability-weight": "Liability Weight", "liquidity": "Liquidity", "loading": "Loading", - "loan-origination-fee": "Loan Origination Fee", - "loan-origination-fee-tooltip": "The fee for opening a borrow. This is paid to the Mango DAO Treasury", + "loan-origination-fee": "Borrow Fee", + "loan-origination-fee-tooltip": "{{fee}} fee for opening a borrow.", "mango": "Mango", "market": "Market", "max": "Max", diff --git a/public/locales/zh_tw/common.json b/public/locales/zh_tw/common.json index 1b992c47..b66276ab 100644 --- a/public/locales/zh_tw/common.json +++ b/public/locales/zh_tw/common.json @@ -83,8 +83,8 @@ "liability-weight": "Liability Weight", "liquidity": "Liquidity", "loading": "Loading", - "loan-origination-fee": "Loan Origination Fee", - "loan-origination-fee-tooltip": "The fee for opening a borrow. This is paid to the Mango DAO Treasury", + "loan-origination-fee": "Borrow Fee", + "loan-origination-fee-tooltip": "{{fee}} fee for opening a borrow.", "mango": "Mango", "market": "Market", "max": "Max",