Skip to content

Commit

Permalink
feat: display token addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastiendan committed Oct 13, 2023
1 parent af9f9ca commit abcbdbe
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
12 changes: 10 additions & 2 deletions packages/frontend/src/components/MultiStepForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,11 @@ const MultiStepForm = () => {
value={{ transactionType, setTransactionType }}
>
<Col
span={currentStep > 0 ? 3 : 1}
xs={currentStep > 0 ? 8 : 1}
sm={currentStep > 0 ? 8 : 1}
md={currentStep > 0 ? 6 : 1}
lg={currentStep > 0 ? 3 : 1}
xl={currentStep > 0 ? 3 : 1}
style={{
opacity: currentStep > 0 ? 1 : 0,
transition: 'all 0.4s ease 0.1s, opacity 0.4s ease 0.2s',
Expand All @@ -133,7 +137,11 @@ const MultiStepForm = () => {
</Space>
</Col>
<Col
span={6}
xs={12}
sm={12}
md={8}
lg={6}
xl={6}
style={{
transition: 'all 0.4s ease 0.1s',
}}
Expand Down
32 changes: 31 additions & 1 deletion packages/frontend/src/components/steps/Step1.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import {
Segmented,
Select,
Space,
Tag,
Tooltip,
message,
} from 'antd'
import { SegmentedValue } from 'antd/lib/segmented'
import { ethers } from 'ethers'
Expand All @@ -26,6 +29,8 @@ import SubnetSelect from '../SubnetSelect'
import useCheckTokenOnSubnet from '../../hooks/useCheckTokenOnReceivingSubnet'
import useTokenBalance from '../../hooks/useTokenBalance'
import { ERROR } from '../../constants/wordings'
import { CopyOutlined } from '@ant-design/icons'
import { shortenAddress } from '../../utils'

const TransactionTypeSelector = styled(Segmented)`
margin-bottom: 1rem;
Expand Down Expand Up @@ -68,6 +73,11 @@ const Step1 = ({ onFinish, onPrev }: StepProps) => {
[setTransactionType]
)

const copyTokenAddress = useCallback(() => {
navigator.clipboard.writeText(token?.addr || '')
message.info(`${token?.symbol} token address copied to clipboard!`)
}, [token])

const { balance } = useTokenBalance(sendingSubnet, token)

useEffect(() => {
Expand Down Expand Up @@ -128,7 +138,27 @@ const Step1 = ({ onFinish, onPrev }: StepProps) => {
<Form.Item
label="Token"
name="token"
extra={balance !== undefined ? `${balance} ${token?.symbol}` : null}
extra={
balance !== undefined ? (
<div style={{ marginTop: '0.4rem' }}>
<Tag color="gold">
{balance} {token?.symbol}
</Tag>
(<Tag>{token?.symbol}</Tag>:{' '}
<Tooltip title={token?.addr}>
{shortenAddress(token?.addr || '')}
</Tooltip>{' '}
<Button
type="text"
size="small"
shape="circle"
icon={<CopyOutlined />}
onClick={copyTokenAddress}
/>
)
</div>
) : null
}
rules={[
{
required: true,
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export function shortenAddress(
address: string,
prefixSuffixLength: number = 5
) {
return `${address.slice(0, prefixSuffixLength)}...${address.slice(
return `${address.slice(0, prefixSuffixLength + 2)}...${address.slice(
address.length - prefixSuffixLength
)}`
}
Expand Down

0 comments on commit abcbdbe

Please sign in to comment.