Skip to content

Commit

Permalink
Add ETH to Tokens tab, fix connect to chain
Browse files Browse the repository at this point in the history
  • Loading branch information
dmytrotkk committed Aug 22, 2024
1 parent 5594058 commit 4d8183e
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src/App.scss
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ body::-webkit-scrollbar {
}

.btnPadd {
width: inherit !important;
width: inherit;
padding-left: 8px !important;
padding-right: 8px !important;
}
Expand Down
14 changes: 9 additions & 5 deletions src/components/SchainDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ export default function SchainDetails(props: {
name: 'sFUEL',
symbol: 'sFUEL',
decimals: 18
}
},
blockExplorerUrls: [explorerUrl]
}

async function addNetwork() {
Expand Down Expand Up @@ -225,10 +226,13 @@ export default function SchainDetails(props: {
<SkBtn
startIcon={added ? <CheckCircleRoundedIcon /> : <AddCircleRoundedIcon />}
size="md"
className={cls(styles.btnAction, cmn.mri10, 'btnPadd', [
'btnPaddLoading',
loading
])}
className={cls(
styles.btnAction,
cmn.mri10,
'btnPadd',
['btnPaddLoading', loading],
[cmn.fullWidth, props.isXs]
)}
onClick={addNetwork}
disabled={loading}
text={connectBtnText()}
Expand Down
59 changes: 32 additions & 27 deletions src/components/chains/tabs/Tokens.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
*/

import { cmn, cls, styles, type MetaportCore, interfaces, SkPaper } from '@skalenetwork/metaport'

import Grid from '@mui/material/Grid'

import CopySurface from '../../CopySurface'

export default function Tokens(props: {
Expand All @@ -34,40 +32,47 @@ export default function Tokens(props: {
}) {
const tokenConnections = props.mpc.config.connections[props.schainName] ?? {}
const chainTokens = tokenConnections.erc20 ?? {}
const ethToken = tokenConnections.eth ?? {}

function findWrapperAddress(token: interfaces.Token): `0x${string}` | null | undefined {
if (!token || !token.chains) return null
const chainWithWrapper = Object.values(token.chains).find((chain) => chain.wrapper)
return chainWithWrapper ? chainWithWrapper.wrapper : null
}

const renderTokens = (tokens: any) => {
return Object.entries(tokens).flatMap(([tokenSymbol, tokenData]: [string, any]) => {
const wrapperAddress = findWrapperAddress(tokenData)
return [
<Grid key={`${tokenSymbol}`} item lg={3} md={4} sm={6} xs={12}>
<CopySurface
className={cls(styles.fullHeight)}
title={`${tokenSymbol.toUpperCase()}`}
value={tokenData.address}
tokenMetadata={props.mpc.config.tokens[tokenSymbol]}
/>
</Grid>,
...(wrapperAddress
? [
<Grid key={`w${tokenSymbol}`} item lg={3} md={4} sm={6} xs={12}>
<CopySurface
className={cls(styles.fullHeight)}
title={`w${tokenSymbol.toUpperCase()}`}
value={wrapperAddress}
tokenMetadata={props.mpc.config.tokens[tokenSymbol]}
/>
</Grid>
]
: [])
]
})
}

return (
<SkPaper gray className={cls(cmn.mtop20)}>
<Grid container spacing={2}>
{Object.keys(chainTokens).flatMap((tokenSymbol: string) => {
const wrapperAddress = findWrapperAddress(chainTokens[tokenSymbol])
return [
<Grid key={tokenSymbol} item lg={3} md={4} sm={6} xs={12}>
<CopySurface
className={cls(styles.fullHeight)}
title={tokenSymbol.toUpperCase()}
value={chainTokens[tokenSymbol].address as string}
tokenMetadata={props.mpc.config.tokens[tokenSymbol]}
/>
</Grid>,
...(wrapperAddress
? [
<Grid key={`w${tokenSymbol}`} item lg={3} md={4} sm={6} xs={12}>
<CopySurface
className={cls(styles.fullHeight)}
title={`w${tokenSymbol.toUpperCase()}`}
value={wrapperAddress}
tokenMetadata={props.mpc.config.tokens[tokenSymbol]}
/>
</Grid>
]
: [])
]
})}
{renderTokens(ethToken)}
{renderTokens(chainTokens)}
</Grid>
</SkPaper>
)
Expand Down
1 change: 1 addition & 0 deletions src/pages/Chains.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ export default function Chains(props: {
icon={<CategoryRoundedIcon color="primary" />}
/>
)}
<div className={cls(cmn.mbott20, cmn.mtop20)}></div>
</Stack>
</Container>
)
Expand Down

0 comments on commit 4d8183e

Please sign in to comment.