Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add liquidity pool listing view #557

Merged
merged 7 commits into from
Nov 30, 2023
Merged
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
30 changes: 30 additions & 0 deletions app/components/LiquidityPoolTable.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
.asset-image {
width: 20px;
height: 20px;
margin-right: 5px;
}

.asset-code {
display: inline-block;
width: 150px;
}

.asset-url {
font-size: 12px;
}

.amount {
display: inline-block;
width: 80px;
text-align: right;
}

.shares {
width: 50px;
text-align: center;
}

.trustlines {
width: 50px;
text-align: center;
}
125 changes: 125 additions & 0 deletions app/components/LiquidityPoolTable.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import Table from 'react-bootstrap/Table'
import { FormattedMessage } from 'react-intl'
import type { Horizon } from 'stellar-sdk'

import { type LiquidityPoolProps } from './operations/LiquidityPool'
import { liquidityPoolAsset } from '~/data/liquidity_pool_asset'
import { formatAmountToHumanReadable, getAssetCode } from '~/lib/utilities'

import styles from './LiquidityPoolTable.module.css'

interface ParentProps {
compact: boolean
// horizonURL: string
chatch marked this conversation as resolved.
Show resolved Hide resolved
}

interface LiquidityPoolRowProps extends LiquidityPoolProps, ParentProps {}

interface LiquidityPoolTableProps {
compact: boolean
records: ReadonlyArray<LiquidityPoolProps>
// horizonURL?: string
}

const fallBackAssetIcon = 'img/circle.svg'

const PoolAsset = ({
reserves,
}: {
reserves: Horizon.Reserve[]
}): React.JSX.Element => {
return (
<div>
<span>
{reserves.map(({ asset, amount }, index) => {
const assetCode = getAssetCode(asset)

const icon = liquidityPoolAsset[assetCode]?.icon || fallBackAssetIcon
const url = liquidityPoolAsset[assetCode]?.url

return (
<div key={index}>
<img
src={icon}
alt={assetCode}
className={styles['asset-image']}
/>
<span className={styles['asset-code']}>
{assetCode} <span className={styles['asset-url']}>{url}</span>
</span>
<span className={styles['amount']}>
{formatAmountToHumanReadable(amount)}
</span>
</div>
)
})}
</span>
</div>
)
}

const LiquidityPoolRow = ({
// compact,
id,
totalTrustlines,
totalShares,
reserves,
}: LiquidityPoolRowProps): React.JSX.Element => (
<tr>
<td>
<PoolAsset reserves={reserves} />
</td>
<td className={styles['shares']}>
{formatAmountToHumanReadable(totalShares)}
</td>
<td className={styles['trustlines']}>{totalTrustlines}</td>
</tr>
)

export default function LiquidityPoolTable({
compact,
records, // horizonURL,
}: LiquidityPoolTableProps) {
return (
<div>
<Table
id="liquidity-pool-table"
className="table-striped table-hover table-condensed"
>
<thead>
<tr>
<th>
<FormattedMessage id="liquidity-pool.assets" />
</th>
{/* commented out as it's not certain how to display the values. */}
{/* we also might need to reconsider what to be displayed. */}
{/* <th>
<FormattedMessage id="liquidity-pool.liquidity" />
</th>
<th>
<FormattedMessage id="liquidity-pool.apy" />
</th>
<th>
<FormattedMessage id="liquidity-pool.vol-24h" />
</th>
<th>
<FormattedMessage id="liquidity-pool.fee-24h" />
</th> */}
<th>
<FormattedMessage id="liquidity-pool.shares" />
</th>
<th>
<FormattedMessage id="liquidity-pool.trustlines" />
</th>
<th />
</tr>
</thead>
<tbody>
{records.map((pool) => (
<LiquidityPoolRow key={pool.id} compact={compact} {...pool} />
))}
</tbody>
</Table>
</div>
)
}
5 changes: 5 additions & 0 deletions app/components/layout/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ export default function Header({
<FormattedMessage id="trades" />
</NavDropdown.Item>
</LinkContainer>
<LinkContainer to="/pools">
<NavDropdown.Item>
<FormattedMessage id="liquidity-pools" />
</NavDropdown.Item>
</LinkContainer>
</NavDropdown>
</Nav>
<Nav className="ms-auto">
Expand Down
30 changes: 13 additions & 17 deletions app/components/operations/LiquidityPool.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import AccountLink from '../shared/AccountLink'
import Asset from '../shared/Asset'
import type { PropsWithChildren } from 'react'
import type { Horizon } from 'stellar-sdk'
import { getAssetCode } from '~/lib/utilities'

export interface LiquidityPoolProps extends PropsWithChildren {
id: string
totalTrustlines: string
totalShares: string
reserves: Horizon.Reserve[]
pagingToken: string
}

const LiquidityPoolDeposit = ({
sourceAccount,
Expand All @@ -10,14 +20,7 @@ const LiquidityPoolDeposit = ({
<AccountLink account={sourceAccount} /> deposited&nbsp;
{reservesDeposited
.map(({ asset, amount }: any) => {
let assetStr
if (asset === 'native') {
assetStr = 'XLM'
} else {
const [code] = asset.split(':')
assetStr = code // (<Asset code={code} issuer={address} type="unknown" />)
}
return `${amount} ${assetStr}`
return `${amount} ${getAssetCode(asset)}`
})
.join(', ')}{' '}
for&nbsp;
Expand All @@ -36,14 +39,7 @@ const LiquidityPoolWithdraw = ({
{shares || sharesRedeemed}&nbsp; shares in liquidity pool for&nbsp;
{reservesReceived
.map(({ asset, amount }: any) => {
let assetStr
if (asset === 'native') {
assetStr = 'XLM'
} else {
const [code] = asset.split(':')
assetStr = code // (<Asset code={code} issuer={address} type="unknown" />)
}
return `${amount} ${assetStr}`
return `${amount} ${getAssetCode(asset)}`
})
.join(', ')}
</span>
Expand Down
Loading