diff --git a/src/pages/_borrow/BorrowModal/BorrowModal.tsx b/src/pages/_borrow/BorrowModal/BorrowModal.tsx
index f8f9f32..4ccffc3 100644
--- a/src/pages/_borrow/BorrowModal/BorrowModal.tsx
+++ b/src/pages/_borrow/BorrowModal/BorrowModal.tsx
@@ -13,40 +13,23 @@ export interface BorrowModalProps {
export const BorrowModal = ({ modalId, onClose, currency, totalSupplied }: BorrowModalProps) => {
const { name, ticker } = currency;
- const { wallet, walletBalances, signTransaction, refetchBalances } = useWallet();
- const { prices } = usePools();
+ const { walletBalances, refetchBalances } = useWallet();
const closeModal = () => {
refetchBalances();
onClose();
};
- // Modal is impossible to open before the wallet is loaded.
- if (!wallet || !walletBalances || !prices) return null;
-
- const isTrustline = walletBalances[ticker].trustLine;
+ const isTrustline = walletBalances?.[ticker].trustLine;
return (
{/* Invisible backdrop that closes the modal on click */}
diff --git a/src/pages/_borrow/BorrowModal/BorrowStep.tsx b/src/pages/_borrow/BorrowModal/BorrowStep.tsx
index 9e47072..2ac10aa 100644
--- a/src/pages/_borrow/BorrowModal/BorrowStep.tsx
+++ b/src/pages/_borrow/BorrowModal/BorrowStep.tsx
@@ -1,10 +1,11 @@
import { Button } from '@components/Button';
import { CryptoAmountSelector } from '@components/CryptoAmountSelector';
import { Loading } from '@components/Loading';
-import { type BalanceRecord, type PriceRecord, type Wallet, useWallet } from '@contexts/wallet-context';
+import { usePools } from '@contexts/pool-context';
+import { useWallet } from '@contexts/wallet-context';
import { contractClient as loanManagerClient } from '@contracts/loan_manager';
import { getIntegerPart, to7decimals } from '@lib/converters';
-import { SCALAR_7, fromCents, toCents } from '@lib/formatting';
+import { SCALAR_7, formatAPR, fromCents, toCents } from '@lib/formatting';
import type { SupportedCurrency } from 'currencies';
import { type ChangeEvent, useState } from 'react';
import { CURRENCY_BINDINGS, CURRENCY_BINDINGS_ARR, type CurrencyBinding } from 'src/currency-bindings';
@@ -17,21 +18,22 @@ const HEALTH_FACTOR_EXCELLENT_THRESHOLD = 2.0;
export interface BorrowStepProps {
onClose: () => void;
currency: CurrencyBinding;
- totalSupplied: bigint;
- wallet: Wallet;
- walletBalances: BalanceRecord;
- prices: PriceRecord;
}
-export const BorrowStep = ({ onClose, currency, totalSupplied, wallet, walletBalances, prices }: BorrowStepProps) => {
+export const BorrowStep = ({ onClose, currency }: BorrowStepProps) => {
const { name, ticker, contractId: loanCurrencyId } = currency;
- const { signTransaction } = useWallet();
+ const { signTransaction, wallet, walletBalances } = useWallet();
+ const { pools, prices } = usePools();
const [isBorrowing, setIsBorrowing] = useState(false);
const [loanAmount, setLoanAmount] = useState('0');
const [collateralTicker, setCollateralTicker] = useState('XLM');
const [collateralAmount, setCollateralAmount] = useState('0');
+ if (!pools || !prices || !walletBalances) return null;
+
+ const { apr, availableBalance } = pools[ticker];
+
const collateralOptions: SupportedCurrency[] = CURRENCY_BINDINGS_ARR.filter((c) => c.ticker !== ticker).map(
({ ticker }) => ticker,
);
@@ -50,9 +52,6 @@ export const BorrowStep = ({ onClose, currency, totalSupplied, wallet, walletBal
const healthFactor =
loanAmountCents && loanAmountCents > 0n ? Number(collateralAmountCents) / Number(loanAmountCents) : 0;
- // TODO: get this from the contract.
- const interestRate = '7.5%';
-
const handleCancel = () => {
setLoanAmount('0');
setCollateralAmount('0');
@@ -124,7 +123,7 @@ export const BorrowStep = ({ onClose, currency, totalSupplied, wallet, walletBal
const isBorrowDisabled =
!isTrustline || loanAmount === '0' || collateralAmount === '0' || healthFactor < HEALTH_FACTOR_MIN_THRESHOLD;
- const maxLoan = (totalSupplied / 10_000_000n).toString();
+ const maxLoan = (availableBalance / 10_000_000n).toString();
const maxCollateral = getIntegerPart(collateralBalance.trustLine ? collateralBalance.balanceLine.balance : '0');
@@ -147,7 +146,7 @@ export const BorrowStep = ({ onClose, currency, totalSupplied, wallet, walletBal
collateral, causing you to lose some of your collateral.
The interest rate changes as the amount of assets borrowed from the pools changes.
- The annual interest rate is currently {interestRate}.
+ The annual interest rate is currently {formatAPR(apr)}.
Amount to borrow
void;
currency: CurrencyBinding;
- wallet: Wallet;
- signTransaction: SignTransaction;
- refetchBalances: () => void;
}
-export const TrustLineStep = ({ onClose, currency, wallet, signTransaction, refetchBalances }: TrustLineStepProps) => {
+export const TrustLineStep = ({ onClose, currency }: TrustLineStepProps) => {
const { name, ticker } = currency;
+ const { wallet, signTransaction, refetchBalances } = useWallet();
const [isCreating, setIsCreating] = useState(false);
+ // Modal is impossible to open without a wallet connection.
+ if (!wallet) return null;
+
const handleAddTrustlineClick = async () => {
try {
setIsCreating(true);