Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 34 additions & 12 deletions apps/web-app/src/features/borrowing/components/ui/BorrowTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,22 @@ export function BorrowTable({
{asset.liquidity}
</td>
<td className="px-4 py-4 align-middle text-center">
<button
onClick={() => onBorrow(asset)}
className="rounded-lg bg-[#229EDF] hover:bg-[#1a8bc7] px-4 py-1.5 text-white text-xs font-semibold transition-colors"
>
Borrow
</button>
<div className="flex flex-col items-center gap-1">
<button
onClick={() => onBorrow(asset)}
disabled={asset.state !== "active"}
className="rounded-lg bg-[#229EDF] hover:bg-[#1a8bc7] px-4 py-1.5 text-white text-xs font-semibold transition-colors disabled:opacity-50 disabled:cursor-not-allowed"
>
Borrow
</button>
{asset.state !== "active" && (
<span className={`text-[10px] font-bold uppercase tracking-tighter ${
asset.state === 'on_ice' ? 'text-orange-500' : 'text-red-500'
}`}>
{asset.state === 'on_ice' ? 'On Ice' : asset.state}
</span>
)}
</div>
</td>
</tr>
))
Expand Down Expand Up @@ -173,12 +183,24 @@ export function BorrowTable({
/>
</div>

<button
onClick={() => onBorrow(asset)}
className="w-full rounded-lg bg-[#229EDF] hover:bg-[#1a8bc7] px-4 py-2 text-white text-sm font-semibold transition-colors"
>
Borrow
</button>
<div className="flex flex-col gap-2">
<button
onClick={() => onBorrow(asset)}
disabled={asset.state !== "active"}
className="w-full rounded-lg bg-[#229EDF] hover:bg-[#1a8bc7] px-4 py-2 text-white text-sm font-semibold transition-colors disabled:opacity-50 disabled:cursor-not-allowed"
>
Borrow
</button>
{asset.state !== "active" && (
<div className="text-center">
<span className={`text-[10px] font-bold uppercase tracking-wider ${
asset.state === 'on_ice' ? 'text-orange-500' : 'text-red-500'
}`}>
Pool is {asset.state === 'on_ice' ? 'On Ice' : asset.state}
</span>
</div>
)}
</div>
</li>
))}
</ul>
Expand Down
1 change: 1 addition & 0 deletions apps/web-app/src/features/borrowing/hooks/useBorrow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export function useBorrow() {
collateralFactorDisplay: "Aggregated",
liquidity,
isActive: p.state === "active",
state: p.state,
assetCode: token?.code ?? "?",
collateralTokenCode: "",
collateralFactor: 0,
Expand Down
13 changes: 11 additions & 2 deletions apps/web-app/src/features/borrowing/hooks/useBorrowPools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,15 @@ async function fetchPoolPools(
return [];
}

if (poolState?.tag !== "Active") return [];
const stateTag = (poolState?.tag as string) || "Active";
const state: import("@/lib/orchestrator/types/pool.types").PoolState =
stateTag === "Active"
? "active"
: stateTag === "OnIce"
? "on_ice"
: stateTag === "Frozen"
? "frozen"
: "unknown";

const pools: BorrowPool[] = [];

Expand Down Expand Up @@ -107,7 +115,8 @@ async function fetchPoolPools(
interestRate,
poolBalance,
poolBalanceUSD: "Calculating...",
isActive: true,
isActive: state === "active",
state,
contractId,
});
} catch {
Expand Down
4 changes: 4 additions & 0 deletions apps/web-app/src/features/borrowing/types/borrowing.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { PoolState } from "@/lib/orchestrator/types/pool.types";

export interface BorrowPool {
asset: string;
assetCode: string;
Expand All @@ -8,6 +10,7 @@ export interface BorrowPool {
poolBalance: string;
poolBalanceUSD: string;
isActive: boolean;
state: PoolState;
contractId: string;
}

Expand All @@ -22,6 +25,7 @@ export interface BorrowTableAsset {
collateralFactorDisplay: string;
liquidity: string;
isActive: boolean;
state: PoolState;
assetCode: string;
collateralTokenCode: string;
collateralFactor: number;
Expand Down
1 change: 1 addition & 0 deletions apps/web-app/src/features/borrowing/utils/borrowUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export function poolsToTableAssets(pools: BorrowPool[]): BorrowTableAsset[] {
collateralFactorDisplay: `${pool.collateralFactor}%`,
liquidity,
isActive: pool.isActive,
state: pool.state,
assetCode: pool.assetCode,
collateralTokenCode: pool.collateralTokenCode,
collateralFactor: pool.collateralFactor,
Expand Down
76 changes: 50 additions & 26 deletions apps/web-app/src/features/lending/components/ui/LendTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,30 @@ export function LendTable({
</td>
{!hideActions && (
<td className="px-4 py-4 align-middle text-center">
<div className="flex items-center justify-center gap-2">
<button
onClick={() => onDeposit(pool)}
className="rounded-lg bg-[#2A2A2A] hover:bg-[#333] px-4 py-1.5 text-white/70 hover:text-white text-xs font-semibold transition-colors"
>
Deposit
</button>
<button
onClick={() => onWithdraw(pool)}
className="rounded-lg bg-[#229EDF] hover:bg-[#1a8bc7] px-4 py-1.5 text-white text-xs font-semibold transition-colors"
>
Withdraw
</button>
<div className="flex flex-col items-center gap-2">
<div className="flex items-center justify-center gap-2">
<button
onClick={() => onDeposit(pool)}
disabled={pool.state !== "active"}
className="rounded-lg bg-[#2A2A2A] hover:bg-[#333] px-4 py-1.5 text-white/70 hover:text-white text-xs font-semibold transition-colors disabled:opacity-50 disabled:cursor-not-allowed"
>
Deposit
</button>
<button
onClick={() => onWithdraw(pool)}
disabled={pool.state === "frozen"}
className="rounded-lg bg-[#229EDF] hover:bg-[#1a8bc7] px-4 py-1.5 text-white text-xs font-semibold transition-colors disabled:opacity-50 disabled:cursor-not-allowed"
>
Withdraw
</button>
</div>
{pool.state !== "active" && (
<span className={`text-[10px] font-bold uppercase tracking-tighter ${
pool.state === 'on_ice' ? 'text-orange-500' : 'text-red-500'
}`}>
{pool.state === 'on_ice' ? 'On Ice' : pool.state}
</span>
)}
</div>
</td>
)}
Expand Down Expand Up @@ -154,19 +165,32 @@ export function LendTable({
</div>

{!hideActions && (
<div className="flex gap-2">
<button
onClick={() => onDeposit(pool)}
className="flex-1 rounded-lg bg-[#2A2A2A] hover:bg-[#333] px-4 py-2 text-white/70 hover:text-white text-sm font-semibold transition-colors"
>
Deposit
</button>
<button
onClick={() => onWithdraw(pool)}
className="flex-1 rounded-lg bg-[#229EDF] hover:bg-[#1a8bc7] px-4 py-2 text-white text-sm font-semibold transition-colors"
>
Withdraw
</button>
<div className="flex flex-col gap-2">
<div className="flex gap-2">
<button
onClick={() => onDeposit(pool)}
disabled={pool.state !== "active"}
className="flex-1 rounded-lg bg-[#2A2A2A] hover:bg-[#333] px-4 py-2 text-white/70 hover:text-white text-sm font-semibold transition-colors disabled:opacity-50 disabled:cursor-not-allowed"
>
Deposit
</button>
<button
onClick={() => onWithdraw(pool)}
disabled={pool.state === "frozen"}
className="flex-1 rounded-lg bg-[#229EDF] hover:bg-[#1a8bc7] px-4 py-2 text-white text-sm font-semibold transition-colors disabled:opacity-50 disabled:cursor-not-allowed"
>
Withdraw
</button>
</div>
{pool.state !== "active" && (
<div className="text-center">
<span className={`text-[10px] font-bold uppercase tracking-wider ${
pool.state === 'on_ice' ? 'text-orange-500' : 'text-red-500'
}`}>
Pool is {pool.state === 'on_ice' ? 'On Ice' : pool.state}
</span>
</div>
)}
</div>
)}
</li>
Expand Down
2 changes: 2 additions & 0 deletions apps/web-app/src/features/lending/hooks/useLend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export function useLend() {
feeApy: `${pool.interestRate.toFixed(2)}%`,
liquidity,
isActive: pool.isActive,
state: pool.state,
assetCode: pool.assetCode,
asset: pool.asset,
bTokenRate: pool.bTokenRate,
Expand Down Expand Up @@ -124,6 +125,7 @@ export function useLend() {
feeApy: p.apy > 0 ? `${p.apy.toFixed(2)}%` : "0.00%",
liquidity,
isActive: p.state === "active",
state: p.state,
assetCode: token?.code ?? "?",
asset: token?.address ?? "",
bTokenRate: undefined,
Expand Down
16 changes: 14 additions & 2 deletions apps/web-app/src/features/lending/hooks/useLendingPools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { fromSmallestUnit } from "@/lib/helpers/tokenUtils";
import { getAvailableTokens } from "@/lib/helpers/stellar/soroswap";
import { parseInterestRateFromContractResult } from "@/lib/helpers/lendingUtils";

import type { PoolState } from "@/lib/orchestrator/types/pool.types";

export interface LendingPool {
asset: string;
assetCode: string;
Expand All @@ -18,6 +20,7 @@ export interface LendingPool {
interestRate: number;
bTokenRate: string;
isActive: boolean;
state: PoolState;
contractId: string;
}

Expand Down Expand Up @@ -46,7 +49,15 @@ async function fetchLendingPools(
return [];
}

if (poolState?.tag !== "Active") return [];
const stateTag = (poolState?.tag as string) || "Active";
const state: PoolState =
stateTag === "Active"
? "active"
: stateTag === "OnIce"
? "on_ice"
: stateTag === "Frozen"
? "frozen"
: "unknown";

const pools: LendingPool[] = [];

Expand Down Expand Up @@ -109,7 +120,8 @@ async function fetchLendingPools(
poolBalanceUSD: "Calculating...",
interestRate,
bTokenRate,
isActive: true,
isActive: state === "active",
state,
contractId,
});
} catch {
Expand Down
3 changes: 3 additions & 0 deletions apps/web-app/src/features/lending/types/lending.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { PoolState } from "@/lib/orchestrator/types/pool.types";

export interface PoolData {
id: string;
name: string;
Expand All @@ -8,6 +10,7 @@ export interface PoolData {
feeApy: string;
liquidity: string;
isActive: boolean;
state: PoolState;
assetCode: string;
asset: string;
bTokenRate?: string;
Expand Down
11 changes: 11 additions & 0 deletions apps/web-app/src/features/pools/components/PoolActionModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,17 @@ export function PoolActionModal({
e.preventDefault();
if (!address) return;

// Safety check for pool state
if (pool.state === "frozen") return;
if (
pool.state === "on_ice" &&
!["withdraw", "repay", "withdrawCollateral", "claimRewards"].includes(
action
)
) {
return;
}

const onSuccess = async () => {
setAmount("");
await Promise.all([
Expand Down
Loading