+
)
diff --git a/src/components/borrow/Table/Columns/useDepositedColumns.tsx b/src/components/borrow/Table/Columns/useActiveColumns.tsx
similarity index 83%
rename from src/components/borrow/Table/Columns/useDepositedColumns.tsx
rename to src/components/borrow/Table/Columns/useActiveColumns.tsx
index 4fcc49c9..5cc6633f 100644
--- a/src/components/borrow/Table/Columns/useDepositedColumns.tsx
+++ b/src/components/borrow/Table/Columns/useActiveColumns.tsx
@@ -13,8 +13,13 @@ import Liquidity, {
} from 'components/borrow/Table/Columns/Liquidity'
import Manage, { MANAGE_META } from 'components/borrow/Table/Columns/Manage'
import Name, { NAME_META } from 'components/borrow/Table/Columns/Name'
+import Action from 'components/v1/Table/borrowings/Columns/Action'
-export default function useDepositedColumns() {
+interface Props {
+ v1?: boolean
+}
+
+export default function useActiveColumns(props: Props) {
return useMemo
[]>(() => {
return [
{
@@ -39,12 +44,13 @@ export default function useDepositedColumns() {
},
{
...MANAGE_META,
- cell: ({ row }) => ,
+ cell: ({ row }) =>
+ props.v1 ? : ,
},
{
...CHEVRON_META,
cell: ({ row }) => ,
},
]
- }, [])
+ }, [props.v1])
}
diff --git a/src/components/common/MarketDetails.tsx b/src/components/common/MarketDetails.tsx
index 545c3492..f06114fc 100644
--- a/src/components/common/MarketDetails.tsx
+++ b/src/components/common/MarketDetails.tsx
@@ -23,7 +23,7 @@ export default function MarketDetails({ row, type }: Props) {
symbol: displayCurrencySymbol,
} = useDisplayCurrencyPrice()
- const { asset, ltv, cap, liquidity, deposits, debt } = row.original
+ const { asset, ltv, deposits, debt } = row.original
const details: Detail[] = useMemo(() => {
const isDollar = displayCurrencySymbol === '$'
diff --git a/src/components/earn/farm/Table/Columns/useAvailableColumns.tsx b/src/components/earn/farm/Table/Columns/useAvailableColumns.tsx
index 8269d7d1..ce5560ee 100644
--- a/src/components/earn/farm/Table/Columns/useAvailableColumns.tsx
+++ b/src/components/earn/farm/Table/Columns/useAvailableColumns.tsx
@@ -2,6 +2,7 @@ import { ColumnDef } from '@tanstack/react-table'
import { useMemo } from 'react'
import Apy, { APY_META } from 'components/earn/farm/Table/Columns/Apy'
+import { Deposit, DEPOSIT_META } from 'components/earn/farm/Table/Columns/Deposit'
import DepositCap, {
DEPOSIT_CAP_META,
depositCapSortingFn,
@@ -10,8 +11,6 @@ import MaxLTV, { LTV_MAX_META } from 'components/earn/farm/Table/Columns/MaxLTV'
import Name, { NAME_META } from 'components/earn/farm/Table/Columns/Name'
import TVL, { TVL_META } from 'components/earn/farm/Table/Columns/TVL'
-import { Deposit, DEPOSIT_META } from './Deposit'
-
interface Props {
isLoading: boolean
}
diff --git a/src/components/earn/lend/Table/Columns/useDepositedColumns.tsx b/src/components/earn/lend/Table/Columns/useDepositedColumns.tsx
index d39702fe..638888fe 100644
--- a/src/components/earn/lend/Table/Columns/useDepositedColumns.tsx
+++ b/src/components/earn/lend/Table/Columns/useDepositedColumns.tsx
@@ -13,9 +13,11 @@ import DepositValue, {
} from 'components/earn/lend/Table/Columns/DepositValue'
import Manage, { MANAGE_META } from 'components/earn/lend/Table/Columns/Manage'
import Name, { NAME_META } from 'components/earn/lend/Table/Columns/Name'
+import Action from 'components/v1/Table/deposits/Columns/Action'
interface Props {
isLoading: boolean
+ v1?: boolean
}
export default function useDepositedColumns(props: Props) {
@@ -49,12 +51,13 @@ export default function useDepositedColumns(props: Props) {
},
{
...MANAGE_META,
- cell: ({ row }) => ,
+ cell: ({ row }) =>
+ props.v1 ? : ,
},
{
...CHEVRON_META,
cell: ({ row }) => ,
},
]
- }, [props.isLoading])
+ }, [props.isLoading, props.v1])
}
diff --git a/src/components/earn/lend/Table/DepositedLendsTable.tsx b/src/components/earn/lend/Table/DepositedLendsTable.tsx
index 23aaa2b4..d9ce9b68 100644
--- a/src/components/earn/lend/Table/DepositedLendsTable.tsx
+++ b/src/components/earn/lend/Table/DepositedLendsTable.tsx
@@ -14,7 +14,7 @@ type Props = {
}
export default function DepositedLendsTable(props: Props) {
- const columns = useDepositedColumns({ isLoading: props.isLoading })
+ const columns = useDepositedColumns({ isLoading: props.isLoading, v1: props.v1 })
const renderExpanded = useCallback(
(row: Row) => ,
diff --git a/src/components/portfolio/Account/Summary.tsx b/src/components/portfolio/Account/Summary.tsx
index 3818afa6..e6f5fdf2 100644
--- a/src/components/portfolio/Account/Summary.tsx
+++ b/src/components/portfolio/Account/Summary.tsx
@@ -17,6 +17,7 @@ import { DEFAULT_PORTFOLIO_STATS } from 'utils/constants'
interface Props {
accountId: string
+ v1?: boolean
}
function Content(props: Props) {
@@ -78,17 +79,17 @@ function Content(props: Props) {
options={{ suffix: 'x' }}
/>
),
- sub: DEFAULT_PORTFOLIO_STATS[4].sub,
+ sub: props.v1 ? 'Total Leverage' : DEFAULT_PORTFOLIO_STATS[4].sub,
},
]
- }, [account, assets, borrowAssets, hlsStrategies, lendingAssets, prices, vaultAprs])
+ }, [account, assets, borrowAssets, hlsStrategies, lendingAssets, prices, vaultAprs, props.v1])
return (
)
diff --git a/src/components/v1/Borrowings.tsx b/src/components/v1/Borrowings.tsx
index 75f159b2..b480f899 100644
--- a/src/components/v1/Borrowings.tsx
+++ b/src/components/v1/Borrowings.tsx
@@ -1,4 +1,4 @@
-import BorrowingsTable from 'components/borrow/Table/DepositedBorrowingsTable'
+import BorrowingsTable from 'components/borrow/Table/ActiveBorrowingsTable'
import useV1BorrowingsTableData from 'components/v1/Table/useV1BorrowingsTableData'
import { BN_ZERO } from 'constants/math'
import useBorrowEnabledAssets from 'hooks/assets/useBorrowEnabledAssets'
diff --git a/src/components/v1/Table/borrowings/Columns/Action.tsx b/src/components/v1/Table/borrowings/Columns/Action.tsx
new file mode 100644
index 00000000..2de24f32
--- /dev/null
+++ b/src/components/v1/Table/borrowings/Columns/Action.tsx
@@ -0,0 +1,20 @@
+import BorrowButton from 'components/borrow/Table/Columns/BorrowButton'
+import Manage from 'components/borrow/Table/Columns/Manage'
+
+export const MANAGE_META = {
+ accessorKey: 'manage',
+ enableSorting: false,
+ header: '',
+}
+
+interface Props {
+ data: BorrowMarketTableData
+}
+
+export default function Action(props: Props) {
+ const hasDebt = !props.data.accountDebtAmount?.isZero() ?? false
+
+ if (hasDebt) return
+
+ return
+}
diff --git a/src/components/v1/Table/deposits/Columns/Action.tsx b/src/components/v1/Table/deposits/Columns/Action.tsx
new file mode 100644
index 00000000..b08f2c52
--- /dev/null
+++ b/src/components/v1/Table/deposits/Columns/Action.tsx
@@ -0,0 +1,19 @@
+import DepositButton from 'components/v1/Table/deposits/Columns/DepositButton'
+import Manage from 'components/v1/Table/deposits/Columns/Manage'
+
+export const MANAGE_META = {
+ accessorKey: 'manage',
+ enableSorting: false,
+ header: '',
+}
+
+interface Props {
+ data: LendingMarketTableData
+}
+export default function Action(props: Props) {
+ const hasDeposits = !props.data.accountLentAmount?.isZero() ?? false
+
+ if (hasDeposits) return
+
+ return
+}
diff --git a/src/components/v1/Table/deposits/Columns/DepositButton.tsx b/src/components/v1/Table/deposits/Columns/DepositButton.tsx
new file mode 100644
index 00000000..26c9e8d9
--- /dev/null
+++ b/src/components/v1/Table/deposits/Columns/DepositButton.tsx
@@ -0,0 +1,48 @@
+import ActionButton from 'components/common/Button/ActionButton'
+import { ArrowUpLine } from 'components/common/Icons'
+import Text from 'components/common/Text'
+import { Tooltip } from 'components/common/Tooltip'
+import ConditionalWrapper from 'hocs/ConditionalWrapper'
+import useWalletBalances from 'hooks/useWalletBalances'
+import useStore from 'store'
+import { byDenom } from 'utils/array'
+
+interface Props {
+ data: LendingMarketTableData
+}
+export default function DepositButton(props: Props) {
+ const address = useStore((s) => s.address)
+ const { data: balances } = useWalletBalances(address)
+ const hasBalance = !!balances.find(byDenom(props.data.asset.denom))
+
+ return (
+
+
(
+ {`You don’t have any ${props.data.asset.symbol} in your Wallet.`}
+ }
+ contentClassName='max-w-[200px]'
+ className='ml-auto'
+ >
+ {children}
+
+ )}
+ >
+ }
+ disabled={!hasBalance}
+ color='tertiary'
+ onClick={(e) => {
+ useStore.setState({ fundAndWithdrawModal: 'fund' })
+ e.stopPropagation()
+ }}
+ text='Deposit'
+ />
+
+
+ )
+}
diff --git a/src/components/v1/Table/deposits/Columns/Manage.tsx b/src/components/v1/Table/deposits/Columns/Manage.tsx
new file mode 100644
index 00000000..28ca2bef
--- /dev/null
+++ b/src/components/v1/Table/deposits/Columns/Manage.tsx
@@ -0,0 +1,45 @@
+import { useMemo } from 'react'
+
+import DropDownButton from 'components/common/Button/DropDownButton'
+import { ArrowDownLine, ArrowUpLine } from 'components/common/Icons'
+import useLendAndReclaimModal from 'hooks/useLendAndReclaimModal'
+import useWalletBalances from 'hooks/useWalletBalances'
+import useStore from 'store'
+import { byDenom } from 'utils/array'
+
+interface Props {
+ data: LendingMarketTableData
+}
+
+export default function Manage(props: Props) {
+ const { openLend, openReclaim } = useLendAndReclaimModal()
+ const address = useStore((s) => s.address)
+ const { data: balances } = useWalletBalances(address)
+ const hasBalance = !!balances.find(byDenom(props.data.asset.denom))
+
+ console.log(balances)
+
+ const ITEMS: DropDownItem[] = useMemo(
+ () => [
+ {
+ icon: ,
+ text: 'Deposit more',
+ onClick: () => openLend(props.data),
+ disabled: !hasBalance,
+ disabledTooltip: `You don’t have any ${props.data.asset.symbol} in your Wallet.`,
+ },
+ {
+ icon: ,
+ text: 'Withdraw',
+ onClick: () => openReclaim(props.data),
+ },
+ ],
+ [hasBalance, openLend, openReclaim, props.data],
+ )
+
+ return (
+
+
+
+ )
+}
diff --git a/src/components/v1/Table/useV1BorrowingsTableData.ts b/src/components/v1/Table/useV1BorrowingsTableData.ts
index 01059116..62b544d3 100644
--- a/src/components/v1/Table/useV1BorrowingsTableData.ts
+++ b/src/components/v1/Table/useV1BorrowingsTableData.ts
@@ -1,21 +1,21 @@
import { useMemo } from 'react'
import { BN_ZERO } from 'constants/math'
+import useAccount from 'hooks/accounts/useAccount'
import useMarkets from 'hooks/markets/useMarkets'
import useDisplayCurrencyPrice from 'hooks/useDisplayCurrencyPrice'
-import useV1Positions from 'hooks/v1/useV1Positions'
import useStore from 'store'
export default function useV1BorrowingsTableData() {
const address = useStore((s) => s.address)
const markets = useMarkets()
- const { data: v1Positions } = useV1Positions(address)
- const userDebts = v1Positions?.debts ?? []
+ const { data: v1Positions } = useAccount(address)
const { convertAmount } = useDisplayCurrencyPrice()
return useMemo((): {
debtAssets: BorrowMarketTableData[]
} => {
+ const userDebts = v1Positions?.debts ?? []
const debtAssets: BorrowMarketTableData[] = []
markets
@@ -34,5 +34,5 @@ export default function useV1BorrowingsTableData() {
})
return { debtAssets }
- }, [userDebts, markets, convertAmount])
+ }, [v1Positions, markets, convertAmount])
}
diff --git a/src/components/v1/Table/useV1DepositsTableData.ts b/src/components/v1/Table/useV1DepositsTableData.ts
index 720922b5..3224a224 100644
--- a/src/components/v1/Table/useV1DepositsTableData.ts
+++ b/src/components/v1/Table/useV1DepositsTableData.ts
@@ -1,9 +1,9 @@
import { useMemo } from 'react'
import { BN_ZERO } from 'constants/math'
+import useAccount from 'hooks/accounts/useAccount'
import useMarkets from 'hooks/markets/useMarkets'
import useDisplayCurrencyPrice from 'hooks/useDisplayCurrencyPrice'
-import useV1Positions from 'hooks/v1/useV1Positions'
import useStore from 'store'
import { byDenom } from 'utils/array'
@@ -12,12 +12,12 @@ export default function useV1DepositsTableData(): {
} {
const address = useStore((s) => s.address)
const markets = useMarkets()
- const { data: v1Positions } = useV1Positions(address)
- const userCollateral = v1Positions?.lends ?? []
+ const { data: v1Positions } = useAccount(address)
const { convertAmount } = useDisplayCurrencyPrice()
return useMemo(() => {
const depositAssets: LendingMarketTableData[] = []
+ const userCollateral = v1Positions?.lends ?? []
markets.forEach((market) => {
const amount = userCollateral.find(byDenom(market.asset.denom))?.amount ?? BN_ZERO
@@ -35,5 +35,5 @@ export default function useV1DepositsTableData(): {
return {
depositAssets,
}
- }, [markets, userCollateral, convertAmount])
+ }, [markets, v1Positions, convertAmount])
}
diff --git a/src/components/v1/V1Intro.tsx b/src/components/v1/V1Intro.tsx
index b14e9eec..f8212b8a 100644
--- a/src/components/v1/V1Intro.tsx
+++ b/src/components/v1/V1Intro.tsx
@@ -12,8 +12,8 @@ export default function V1Intro() {
This is the first version (v1) of the Red Bank. It provides simple lending and borrowing,
without the use of Credit Accounts. Funds are{' '}
- not cross-collateralized and can't be used on v2 as
- collateral.
+ not cross-collateralized and can‘t be used on v2
+ as collateral.
>
}
bg='v1'
diff --git a/src/hooks/accounts/useAccount.tsx b/src/hooks/accounts/useAccount.tsx
index 980cc590..2973d98e 100644
--- a/src/hooks/accounts/useAccount.tsx
+++ b/src/hooks/accounts/useAccount.tsx
@@ -1,14 +1,20 @@
import useSWR from 'swr'
import getAccount from 'api/accounts/getAccount'
+import getV1Positions from 'api/v1/getV1Positions'
import useChainConfig from 'hooks/useChainConfig'
export default function useAccount(accountId?: string, suspense?: boolean) {
const chainConfig = useChainConfig()
+ const isV1 = isNaN(parseInt(accountId || ''))
+
+ const cacheKey = isV1
+ ? `chains/${chainConfig.id}/v1/user/${accountId}`
+ : `chains/${chainConfig.id}/accounts/${accountId}`
return useSWR(
- accountId && `chains/${chainConfig.id}/accounts/${accountId}`,
- () => getAccount(chainConfig, accountId),
+ accountId && cacheKey,
+ () => (isV1 ? getV1Positions(chainConfig, accountId) : getAccount(chainConfig, accountId)),
{
suspense: suspense,
revalidateOnFocus: false,
diff --git a/src/hooks/v1/useV1Positions.tsx b/src/hooks/v1/useV1Positions.tsx
deleted file mode 100644
index 70510ec6..00000000
--- a/src/hooks/v1/useV1Positions.tsx
+++ /dev/null
@@ -1,17 +0,0 @@
-import useSWR from 'swr'
-
-import getV1Positions from 'api/v1/getV1Positions'
-import useChainConfig from 'hooks/useChainConfig'
-
-export default function useV1Positions(user?: string, suspense?: boolean) {
- const chainConfig = useChainConfig()
-
- return useSWR(
- user && `chains/${chainConfig.id}/v1/${user}`,
- () => getV1Positions(chainConfig, user),
- {
- suspense: suspense,
- revalidateOnFocus: false,
- },
- )
-}
diff --git a/src/pages/V1Page.tsx b/src/pages/V1Page.tsx
index f20b87cf..f6fb5330 100644
--- a/src/pages/V1Page.tsx
+++ b/src/pages/V1Page.tsx
@@ -1,13 +1,17 @@
import MigrationBanner from 'components/common/MigrationBanner'
+import Summary from 'components/portfolio/Account/Summary'
import Borrowings from 'components/v1/Borrowings'
import Deposits from 'components/v1/Deposits'
import V1Intro from 'components/v1/V1Intro'
+import useStore from 'store'
export default function V1Page() {
+ const address = useStore((s) => s.address)
return (
+ {address && }