diff --git a/centrifuge-app/src/components/Portfolio/Coins.tsx b/centrifuge-app/src/components/Portfolio/CoinsSvg.tsx similarity index 99% rename from centrifuge-app/src/components/Portfolio/Coins.tsx rename to centrifuge-app/src/components/Portfolio/CoinsSvg.tsx index 62d50f488b..8cfa68f8e4 100644 --- a/centrifuge-app/src/components/Portfolio/Coins.tsx +++ b/centrifuge-app/src/components/Portfolio/CoinsSvg.tsx @@ -1,6 +1,6 @@ import * as React from 'react' -export function Coins() { +export function CoinsSvg() { return ( - + Token @@ -34,7 +38,7 @@ export function InvestedTokens() { {balances.tranches.map((tranche, index) => ( - + ))} @@ -42,3 +46,44 @@ export function InvestedTokens() { ) : null } + +type TokenCardProps = AccountTokenBalance +export function TokenListItem({ balance, currency, poolId, trancheId }: TokenCardProps) { + const pool = usePool(poolId) as Pool + const isTinlakePool = poolId?.startsWith('0x') + + if (isTinlakePool) { + return null + } + + const tranche = pool.tranches.find(({ id }) => id === trancheId) + + return ( + + + {currency.name} + + + + {formatBalance(balance, tranche?.currency.symbol)} + + + + {tranche?.tokenPrice ? formatBalance(tranche.tokenPrice.toDecimal(), tranche.currency.symbol, 4) : '-'} + + + + {tranche?.tokenPrice + ? formatBalance(balance.toDecimal().mul(tranche.tokenPrice.toDecimal()), tranche.currency.symbol, 4) + : '-'} + + + ) +} diff --git a/centrifuge-app/src/components/Portfolio/Rewards.tsx b/centrifuge-app/src/components/Portfolio/Rewards.tsx index f8973fa09d..94a31c4882 100644 --- a/centrifuge-app/src/components/Portfolio/Rewards.tsx +++ b/centrifuge-app/src/components/Portfolio/Rewards.tsx @@ -4,7 +4,7 @@ import * as React from 'react' import { useTheme } from 'styled-components' import { formatBalance } from '../../utils/formatting' import { useComputeLiquidityRewards } from '../LiquidityRewards/hooks' -import { Coins } from './Coins' +import { CoinsSvg } from './CoinsSvg' export function Rewards() { const { colors } = useTheme() @@ -67,7 +67,7 @@ export function Rewards() { - + ) diff --git a/centrifuge-app/src/components/TransactionTypeChip.tsx b/centrifuge-app/src/components/Portfolio/TransactionTypeChip.tsx similarity index 95% rename from centrifuge-app/src/components/TransactionTypeChip.tsx rename to centrifuge-app/src/components/Portfolio/TransactionTypeChip.tsx index 17b07db7f6..e54a3a775d 100644 --- a/centrifuge-app/src/components/TransactionTypeChip.tsx +++ b/centrifuge-app/src/components/Portfolio/TransactionTypeChip.tsx @@ -1,11 +1,12 @@ import { StatusChip, StatusChipProps } from '@centrifuge/fabric' import * as React from 'react' -import { TransactionCardProps } from './TransactionCard' +import { TransactionCardProps } from './Transactions' type TransactionTypeProps = { type: TransactionCardProps['action'] } +// @ts-expect-error const states: { [Key in TransactionCardProps['action']]: { label: string diff --git a/centrifuge-app/src/components/Portfolio/Transactions.tsx b/centrifuge-app/src/components/Portfolio/Transactions.tsx index 1449090584..3f83842cf3 100644 --- a/centrifuge-app/src/components/Portfolio/Transactions.tsx +++ b/centrifuge-app/src/components/Portfolio/Transactions.tsx @@ -1,76 +1,86 @@ -import { useCentrifugeUtils } from '@centrifuge/centrifuge-react' -import { Box, Grid, Stack, Text } from '@centrifuge/fabric' +import { + BorrowerTransactionType, + CurrencyBalance, + InvestorTransactionType, + Pool, + SubqueryInvestorTransaction, +} from '@centrifuge/centrifuge-js' +import { formatBalance, useCentrifugeUtils } from '@centrifuge/centrifuge-react' +import { Box, Grid, IconExternalLink, Stack, Text } from '@centrifuge/fabric' import * as React from 'react' import { Link } from 'react-router-dom' +import { formatDate } from '../../utils/date' import { useAddress } from '../../utils/useAddress' -import { - TransactionCard, - TransactionCardProps, - TRANSACTION_CARD_COLUMNS, - TRANSACTION_CARD_GAP, -} from '../TransactionCard' +import { useAllTransactions, usePool, usePoolMetadata } from '../../utils/usePools' +import { TransactionTypeChip } from './TransactionTypeChip' + +export const TRANSACTION_CARD_COLUMNS = `150px 100px 250px 150px 1fr` +export const TRANSACTION_CARD_GAP = 4 type AddressTransactionsProps = { count?: number } -// const formatters = { -// investorTransactions: ({ -// timestamp, -// type, -// poolId, -// hash, -// tokenAmount, -// tokenPrice, -// currencyAmount, -// trancheId, -// }: Omit) => { -// return { -// date: new Date(timestamp).getTime(), -// action: type, -// amount: tokenAmount, -// poolId, -// hash, -// trancheId, -// } as TransactionCardProps -// }, -// borrowerTransactions: ({ timestamp, type, amount, poolId, hash }: SubqueryBorrowerTransaction) => -// ({ -// date: new Date(timestamp).getTime(), -// action: type, -// amount, -// poolId, -// hash, -// } as TransactionCardProps), -// outstandingOrders: ({ timestamp, investAmount, redeemAmount, poolId, hash, trancheId }: SubqueryOutstandingOrder) => -// ({ -// date: new Date(timestamp).getTime(), -// action: 'PENDING_ORDER', -// amount: investAmount.add(redeemAmount), -// poolId, -// hash, -// trancheId, -// } as TransactionCardProps), -// } +type SubqueryBorrowerTransaction = any +type SubqueryOutstandingOrder = any + +const formatters = { + investorTransactions: ({ + timestamp, + type, + poolId, + hash, + tokenAmount, + tokenPrice, + currencyAmount, + trancheId, + }: Omit) => { + return { + date: new Date(timestamp).getTime(), + action: type, + amount: tokenAmount, + poolId, + hash, + trancheId, + } as TransactionCardProps + }, + borrowerTransactions: ({ timestamp, type, amount, poolId, hash }: SubqueryBorrowerTransaction) => + ({ + date: new Date(timestamp).getTime(), + action: type, + amount, + poolId, + hash, + } as TransactionCardProps), + outstandingOrders: ({ timestamp, investAmount, redeemAmount, poolId, hash, trancheId }: SubqueryOutstandingOrder) => + ({ + date: new Date(timestamp).getTime(), + action: 'PENDING_ORDER', + amount: investAmount.add(redeemAmount), + poolId, + hash, + trancheId, + } as TransactionCardProps), +} export function Transactions({ count }: AddressTransactionsProps) { const { formatAddress } = useCentrifugeUtils() const address = useAddress() const formattedAddress = formatAddress(address || '') - // const allTransactions = useAllTransactions(formattedAddress) + const allTransactions = useAllTransactions(formattedAddress) const formattedTransactions: TransactionCardProps[] = [] - // if (allTransactions) { - // const { borrowerTransactions, investorTransactions, outstandingOrders } = allTransactions + if (allTransactions) { + const { borrowerTransactions, investorTransactions, outstandingOrders } = allTransactions - // investorTransactions.forEach((transaction) => - // formattedTransactions.push(formatters.investorTransactions(transaction)) - // ) - // borrowerTransactions.forEach((transaction) => - // formattedTransactions.push(formatters.borrowerTransactions(transaction)) - // ) - // outstandingOrders.forEach((transaction) => formattedTransactions.push(formatters.outstandingOrders(transaction))) - // } + investorTransactions.forEach((transaction) => + formattedTransactions.push(formatters.investorTransactions(transaction)) + ) + borrowerTransactions.forEach((transaction) => + formattedTransactions.push(formatters.borrowerTransactions(transaction)) + ) + outstandingOrders.forEach((transaction) => formattedTransactions.push(formatters.outstandingOrders(transaction))) + } const transactions = formattedTransactions.slice(0, count ?? formattedTransactions.length) @@ -99,7 +109,7 @@ export function Transactions({ count }: AddressTransactionsProps) { {transactions.map((transaction, index) => ( - + ))} @@ -108,3 +118,77 @@ export function Transactions({ count }: AddressTransactionsProps) { ) : null } + +export type TransactionCardProps = { + date: number + action: InvestorTransactionType | BorrowerTransactionType | 'PENDING_ORDER' + amount: CurrencyBalance + poolId: string + hash: string + trancheId?: string +} + +export function TransactionListItem({ date, action, amount, poolId, hash, trancheId }: TransactionCardProps) { + const pool = usePool(poolId) as Pool + const { data } = usePoolMetadata(pool) + const token = trancheId ? pool.tranches.find(({ id }) => id === trancheId) : undefined + const subScanUrl = import.meta.env.REACT_APP_SUBSCAN_URL + + if (!pool || !data) { + return null + } + + return ( + + + + + + + {formatDate(date, { + day: '2-digit', + month: '2-digit', + year: '2-digit', + })} + + + + + {!!token ? token.currency?.name : data.pool?.name} + + {!!token && ( + + {data?.pool?.name} + + )} + + + + + {formatBalance(amount, pool.currency.symbol)} + + + + {!!subScanUrl && !!hash && ( + + + + )} + + ) +} diff --git a/centrifuge-app/src/components/TokenCard.tsx b/centrifuge-app/src/components/TokenCard.tsx deleted file mode 100644 index 666cacf58a..0000000000 --- a/centrifuge-app/src/components/TokenCard.tsx +++ /dev/null @@ -1,50 +0,0 @@ -import { AccountTokenBalance, Pool } from '@centrifuge/centrifuge-js' -import { Grid, Text } from '@centrifuge/fabric' -import * as React from 'react' -import { formatBalance } from '../utils/formatting' -import { usePool } from '../utils/usePools' - -type TokenCardProps = AccountTokenBalance - -export const TOKEN_CARD_COLUMNS = `250px 200px 100px 150px 1FR` -export const TOKEN_CARD_GAP = 4 - -export function TokenCard({ balance, currency, poolId, trancheId }: TokenCardProps) { - const pool = usePool(poolId) as Pool - const isTinlakePool = poolId?.startsWith('0x') - - if (isTinlakePool) { - return null - } - - const tranche = pool.tranches.find(({ id }) => id === trancheId) - - return ( - - - {currency.name} - - - - {formatBalance(balance, currency)} - - - - {tranche?.tokenPrice ? formatBalance(tranche.tokenPrice, tranche.poolCurrency, 4, 2) : '-'} - - - - {tranche?.tokenPrice - ? formatBalance(balance.toDecimal().mul(tranche.tokenPrice.toDecimal()), tranche.poolCurrency, 4, 2) - : '-'} - - - ) -} diff --git a/centrifuge-app/src/components/TransactionCard.tsx b/centrifuge-app/src/components/TransactionCard.tsx deleted file mode 100644 index c0277a5eb4..0000000000 --- a/centrifuge-app/src/components/TransactionCard.tsx +++ /dev/null @@ -1,84 +0,0 @@ -import { BorrowerTransactionType, CurrencyBalance, InvestorTransactionType, Pool } from '@centrifuge/centrifuge-js' -import { Box, Grid, IconExternalLink, Stack, Text } from '@centrifuge/fabric' -import * as React from 'react' -import { formatDate } from '../utils/date' -import { formatBalance } from '../utils/formatting' -import { usePool, usePoolMetadata } from '../utils/usePools' -import { TransactionTypeChip } from './TransactionTypeChip' - -export type TransactionCardProps = { - date: number - action: InvestorTransactionType | BorrowerTransactionType | 'PENDING_ORDER' - amount: CurrencyBalance - poolId: string - hash: string - trancheId?: string -} - -export const TRANSACTION_CARD_COLUMNS = `150px 100px 250px 150px 1fr` -export const TRANSACTION_CARD_GAP = 4 - -export function TransactionCard({ date, action, amount, poolId, hash, trancheId }: TransactionCardProps) { - const pool = usePool(poolId) as Pool - const { data } = usePoolMetadata(pool) - const token = trancheId ? pool.tranches.find(({ id }) => id === trancheId) : undefined - const subScanUrl = import.meta.env.REACT_APP_SUBSCAN_URL - - if (!pool || !data) { - return null - } - - return ( - - - - - - - {formatDate(date, { - day: '2-digit', - month: '2-digit', - year: '2-digit', - })} - - - - - {!!token ? token.currency?.name : data.pool?.name} - - {!!token && ( - - {data?.pool?.name} - - )} - - - - - {formatBalance(amount, pool.currency)} - - - - {!!subScanUrl && !!hash && ( - - - - )} - - ) -}