-
Borrow {name}
- {!isTrustline ? (
-
- Create a trustline for {ticker} in your wallet first!
-
-
- ) : null}
-
- Borrow {name} using another asset as a collateral. The value of the collateral must exceed the value of the
- borrowed asset. You will receive the collateral back to your wallet after repaying the loan in full.
-
-
- The higher the value of the collateral is to the value of the borrowed asset, the safer this loan is. This is
- visualised by the health factor.
-
-
- The loan will be available for liquidation if the value of the borrowed asset raises to the value of the
- 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}.
-
-
Amount to borrow
-
-
-
Amount of collateral
-
-
-
Health Factor
-
-
-
-
- {/* Invisible backdrop that closes the modal on click */}
-
-
+ >
);
};
diff --git a/src/pages/_borrow/BorrowModal/TrustlineStep.tsx b/src/pages/_borrow/BorrowModal/TrustlineStep.tsx
new file mode 100644
index 0000000..493e765
--- /dev/null
+++ b/src/pages/_borrow/BorrowModal/TrustlineStep.tsx
@@ -0,0 +1,56 @@
+import { Button } from '@components/Button';
+import { Loading } from '@components/Loading';
+import { createAddTrustlineTransaction, sendTransaction } from '@lib/horizon';
+import { useState } from 'react';
+import type { CurrencyBinding } from 'src/currency-bindings';
+import type { SignTransaction, Wallet } from 'src/stellar-wallet';
+
+export interface TrustLineStepProps {
+ onClose: () => void;
+ currency: CurrencyBinding;
+ wallet: Wallet;
+ signTransaction: SignTransaction;
+ refetchBalances: () => void;
+}
+
+export const TrustLineStep = ({ onClose, currency, wallet, signTransaction, refetchBalances }: TrustLineStepProps) => {
+ const { name, ticker } = currency;
+
+ const [isCreating, setIsCreating] = useState(false);
+
+ const handleAddTrustlineClick = async () => {
+ try {
+ setIsCreating(true);
+ const tx = await createAddTrustlineTransaction(wallet.address, currency);
+ const signedTx = await signTransaction(tx.toXDR());
+ await sendTransaction(signedTx);
+ alert(`Succesfully created a trustline for ${ticker}!`);
+ } catch (err) {
+ alert('Error creating a trustline :(');
+ console.error('Error creating trustline:', err);
+ }
+ refetchBalances();
+ setIsCreating(false);
+ };
+
+ return (
+ <>
+
+ You don't have a trustline for {name} in your wallet. Laina cannot transfer you the tokens without a trustline.
+
+
+
+ Cancel
+
+ {!isCreating ? (
+ Create Trustline
+ ) : (
+
+
+ Creating
+
+ )}
+
+ >
+ );
+};
diff --git a/src/pages/_borrow/BorrowableAsset.tsx b/src/pages/_borrow/BorrowableAsset.tsx
index 234d93b..69bc644 100644
--- a/src/pages/_borrow/BorrowableAsset.tsx
+++ b/src/pages/_borrow/BorrowableAsset.tsx
@@ -7,7 +7,7 @@ import { contractClient as loanManagerClient } from '@contracts/loan_manager';
import { isBalanceZero } from '@lib/converters';
import type { CurrencyBinding } from 'src/currency-bindings';
import { useWallet } from 'src/stellar-wallet';
-import { BorrowModal } from './BorrowModal';
+import { BorrowModal } from './BorrowModal/BorrowModal';
interface BorrowableAssetCardProps {
currency: CurrencyBinding;
diff --git a/src/pages/_lend/DepositModal.tsx b/src/pages/_lend/DepositModal.tsx
index 3d96582..19bb3bd 100644
--- a/src/pages/_lend/DepositModal.tsx
+++ b/src/pages/_lend/DepositModal.tsx
@@ -25,7 +25,7 @@ export const DepositModal = ({ modalId, onClose, currency }: DepositModalProps)
const amountCents = price ? toCents(price, BigInt(amount) * SCALAR_7) : undefined;
- if (!balance || !balance.trustline) return null;
+ if (!balance || !balance.trustLine) return null;
const max = getIntegerPart(balance.balanceLine.balance);
diff --git a/src/pages/_lend/LendableAsset.tsx b/src/pages/_lend/LendableAsset.tsx
index fd80c3b..eb1a05f 100644
--- a/src/pages/_lend/LendableAsset.tsx
+++ b/src/pages/_lend/LendableAsset.tsx
@@ -24,7 +24,7 @@ export const LendableAsset = ({ currency }: LendableAssetProps) => {
const balance: Balance | undefined = walletBalances?.[ticker];
- const isPoor = !balance?.trustline || isBalanceZero(balance.balanceLine.balance);
+ const isPoor = !balance?.trustLine || isBalanceZero(balance.balanceLine.balance);
const fetchAvailableContractBalance = useCallback(async () => {
if (!contractClient) return;
diff --git a/src/stellar-wallet.tsx b/src/stellar-wallet.tsx
index 9194286..c50a05c 100644
--- a/src/stellar-wallet.tsx
+++ b/src/stellar-wallet.tsx
@@ -44,7 +44,7 @@ export type WalletContext = {
signTransaction: SignTransaction;
};
-type SignTransaction = (
+export type SignTransaction = (
tx: XDR_BASE64,
opts?: {
network?: string;