@@ -6,6 +6,8 @@ import { useMatch, useNavigate } from 'react-router'
66import { useLocation } from 'react-router-dom'
77import { useTheme } from 'styled-components'
88import { evmChains } from '../../../src/config'
9+ import { useTokenBalance } from '../../../src/pages/Portfolio/useTokenBalance'
10+ import { useAddress } from '../../../src/utils/useAddress'
911import daiLogo from '../../assets/images/dai-logo.svg'
1012import ethLogo from '../../assets/images/ethereum.svg'
1113import centLogo from '../../assets/images/logoCentrifuge.svg'
@@ -41,6 +43,7 @@ export type Holding = {
4143 unrealizedYield ?: Rate | null
4244 connectedNetwork ?: any
4345 hideCurrencyName ?: boolean
46+ showMigration ?: boolean
4447}
4548
4649const NetworkCell = ( { chainId } : { chainId : Holding [ 'chainId' ] } ) => {
@@ -60,14 +63,29 @@ const NetworkCell = ({ chainId }: { chainId: Holding['chainId'] }) => {
6063 )
6164}
6265
66+ const MigrateButtonCell = ( ) => {
67+ const { evm, isEvmOnSubstrate } = useWallet ( )
68+ const chainId = evm . chainId ?? undefined
69+ const address = useAddress ( chainId ? 'evm' : 'substrate' )
70+ return (
71+ < RouterLinkButton
72+ to = { isEvmAddress ( address ) && ! isEvmOnSubstrate ? 'migrate/eth' : 'migrate/cent' }
73+ small
74+ variant = "inverted"
75+ >
76+ Migrate
77+ </ RouterLinkButton >
78+ )
79+ }
80+
6381const columns : Column [ ] = [
6482 {
6583 align : 'left' ,
6684 header : 'Token' ,
6785 cell : ( token : Holding ) => {
6886 return < TokenWithIcon { ...token } />
6987 } ,
70- width : '150px ' ,
88+ width : '180px ' ,
7189 } ,
7290 {
7391 align : 'center' ,
@@ -138,9 +156,10 @@ const columns: Column[] = [
138156 align : 'right' ,
139157 header : '' , // invest redeem buttons
140158 width : 'max-content' ,
141- cell : ( { showActions, poolId, trancheId, currency, connectedNetwork } : Holding ) => {
159+ cell : ( { showActions, poolId, trancheId, currency, connectedNetwork, address , showMigration } : Holding ) => {
142160 return (
143- < Grid gap = { 1 } justifySelf = "end" >
161+ < Grid gap = { 1 } display = "flex" alignItems = "flex-end" >
162+ { showMigration && < MigrateButtonCell address = { address } /> }
144163 { showActions ? (
145164 trancheId ? (
146165 < Shelf gap = { 1 } >
@@ -221,6 +240,7 @@ export function useHoldings(address?: string, chainId?: number, showActions = tr
221240 const portfolioTokens = usePortfolioTokens ( centAddress )
222241 const currencies = usePoolCurrencies ( )
223242 const CFGPrice = useCFGTokenPrice ( )
243+ const tokenBalances = useTokenBalance ( address )
224244
225245 const tokens : Holding [ ] = [
226246 ...portfolioTokens . map ( ( token ) => ( {
@@ -259,6 +279,30 @@ export function useHoldings(address?: string, chainId?: number, showActions = tr
259279 connectedNetwork : wallet . connectedNetworkName ,
260280 }
261281 } ) ,
282+ tokenBalances . data ?. legacy && {
283+ position : Dec ( tokenBalances . data ?. legacy ?. balance || 0 ) ,
284+ marketValue : Dec ( tokenBalances . data ?. legacy ?. balance || 0 ) . mul ( Dec ( CFGPrice ?? 0 ) ) ,
285+ tokenPrice : Dec ( CFGPrice ?? 0 ) ,
286+ trancheId : '' ,
287+ poolId : '' ,
288+ currency : tokenBalances . data ?. legacy ?. currency ,
289+ showActions : false ,
290+ connectedNetwork : chainId ,
291+ showMigration : ! tokenBalances . data ?. legacy ?. balance . isZero ( ) ,
292+ chainId : 1 ,
293+ } ,
294+ tokenBalances . data ?. new && {
295+ position : Dec ( tokenBalances . data ?. new ?. balance || 0 ) ,
296+ marketValue : Dec ( tokenBalances . data ?. new ?. balance || 0 ) . mul ( Dec ( CFGPrice ?? 0 ) ) ,
297+ tokenPrice : Dec ( CFGPrice ?? 0 ) ,
298+ trancheId : '' ,
299+ poolId : '' ,
300+ currency : tokenBalances . data ?. new ?. currency ,
301+ showActions : false ,
302+ connectedNetwork : chainId ,
303+ showMigration : false ,
304+ chainId : 1 ,
305+ } ,
262306 ...( centBalances ?. currencies
263307 ?. filter ( ( currency ) => currency . balance . gtn ( 0 ) )
264308 . map ( ( currency ) => {
@@ -275,7 +319,8 @@ export function useHoldings(address?: string, chainId?: number, showActions = tr
275319 connectedNetwork : wallet . connectedNetworkName ,
276320 }
277321 } ) || [ ] ) ,
278- ...( ( wallet . connectedNetwork === 'centrifuge' && showActions ) || centBalances ?. native . balance . gtn ( 0 )
322+ ...( ( wallet . connectedNetworkName ?. toLowerCase ( ) === 'centrifuge' && showActions ) ||
323+ centBalances ?. native . balance . gtn ( 0 )
279324 ? [
280325 {
281326 currency : {
@@ -286,7 +331,7 @@ export function useHoldings(address?: string, chainId?: number, showActions = tr
286331 key : 'Native' ,
287332 isPoolCurrency : false ,
288333 isPermissioned : false ,
289- displayName : centBalances ?. native . currency . symbol ?? ' CFG',
334+ displayName : 'Legacy CFG',
290335 } ,
291336 poolId : '' ,
292337 trancheId : '' ,
@@ -295,6 +340,7 @@ export function useHoldings(address?: string, chainId?: number, showActions = tr
295340 marketValue : CFGPrice ? centBalances ?. native . balance . toDecimal ( ) . mul ( CFGPrice ) ?? Dec ( 0 ) : Dec ( 0 ) ,
296341 showActions : isPortfolioPage ,
297342 connectedNetwork : wallet . connectedNetworkName ,
343+ showMigration : ! centBalances ?. native . balance . isZero ( ) ,
298344 } ,
299345 ]
300346 : [ ] ) ,
@@ -369,10 +415,15 @@ export const TokenWithIcon = ({ poolId, currency, hideCurrencyName = false }: Ho
369415 const cent = useCentrifuge ( )
370416 const { sizes } = useTheme ( )
371417
418+ const displayEthLogo =
419+ currency ?. name ?. toLowerCase ( ) ?. includes ( 'eth' ) ||
420+ currency . name . toLowerCase ( ) === 'cfg' ||
421+ currency . symbol . toLowerCase ( ) . includes ( 'wcfg' )
422+
372423 const getIcon = ( ) => {
373424 if ( metadata ?. pool ?. icon ?. uri ) {
374425 return cent . metadata . parseMetadataUrl ( metadata . pool . icon . uri )
375- } else if ( currency ?. name ?. toLowerCase ( ) ?. includes ( 'eth' ) ) {
426+ } else if ( displayEthLogo ) {
376427 return ethLogo
377428 } else if ( currency ?. symbol ?. toLowerCase ( ) === 'dai' ) {
378429 return daiLogo
0 commit comments