Skip to content

Commit

Permalink
Clean up address conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
sophialittlejohn committed Dec 6, 2023
1 parent 308479a commit 0896b56
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 21 deletions.
33 changes: 13 additions & 20 deletions centrifuge-app/src/components/Portfolio/CFGTransfer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,6 @@ export const CFGTransfer = ({ address }: CFGHoldingsProps) => {
const CFGPrice = useCFGTokenPrice()
const isPortfolioPage = useRouteMatch('/portfolio')

const centAddress = useMemo(
() => (address && address.startsWith('0x') ? utils.formatAddress(address) : address),
[address]
)

const evmAddress = useMemo(
() => (address && address.startsWith('0x') ? address : utils.addressToHex(address)),
[address]
)
return (
<Stack gap={3}>
<Text textAlign="center" variant="heading2">
Expand All @@ -77,11 +68,7 @@ export const CFGTransfer = ({ address }: CFGHoldingsProps) => {
<TabsItem>Send</TabsItem>
<TabsItem>Receive</TabsItem>
</Tabs>
{activeTab === 0 ? (
<SendCFG centAddress={centAddress} evmAddress={evmAddress} />
) : (
<ReceiveCFG centAddress={centAddress} evmAddress={evmAddress} />
)}
{activeTab === 0 ? <SendCFG address={address} /> : <ReceiveCFG address={address} />}
</Stack>
)}
<Stack gap={12}>
Expand All @@ -96,10 +83,10 @@ export const CFGTransfer = ({ address }: CFGHoldingsProps) => {
)
}

type SendReceiveProps = { evmAddress: string; centAddress: string }
type SendReceiveProps = { address: string }

const SendCFG = ({ evmAddress, centAddress }: SendReceiveProps) => {
const centBalances = useBalances(centAddress || evmAddress)
const SendCFG = ({ address }: SendReceiveProps) => {
const centBalances = useBalances(address)
const utils = useCentrifugeUtils()

const { execute: transferCFG, isLoading } = useCentrifugeTransaction(
Expand Down Expand Up @@ -199,8 +186,14 @@ const SendCFG = ({ evmAddress, centAddress }: SendReceiveProps) => {
)
}

const ReceiveCFG = ({ evmAddress, centAddress }: SendReceiveProps) => {
const ReceiveCFG = ({ address }: SendReceiveProps) => {
const utils = useCentrifugeUtils()
const centAddress = useMemo(
() => (address && address.startsWith('0x') ? utils.formatAddress(address) : address),
[address]
)
const { isEvmOnSubstrate } = useWallet()

return (
<Stack gap={2} px={1} py={2} backgroundColor="grayScale.50">
<Stack gap={3}>
Expand All @@ -216,9 +209,9 @@ const ReceiveCFG = ({ evmAddress, centAddress }: SendReceiveProps) => {
Ethereum Address:{' '}
</Text>
<Text variant="label1" fontSize="12px" textDecoration="underline" color="grayScale.900">
{truncate(evmAddress)}
{truncate(utils.addressToHex(address))}
</Text>
<IconButton onClick={() => copyToClipboard(evmAddress)} title="Copy address to clipboard">
<IconButton onClick={() => copyToClipboard(utils.addressToHex(address))} title="Copy address to clipboard">
<IconCopy />
</IconButton>
</Shelf>
Expand Down
2 changes: 1 addition & 1 deletion centrifuge-app/src/components/Portfolio/Holdings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const columns: Column[] = [
cell: ({ marketValue }: Row) => {
return (
<Text textOverflow="ellipsis" variant="body3">
{formatBalanceAbbreviated(marketValue, 'USDT', 2)}
{formatBalanceAbbreviated(marketValue || 0, 'USDT', 2)}
</Text>
)
},
Expand Down

0 comments on commit 0896b56

Please sign in to comment.