-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add identi icon * refactor address input
- Loading branch information
Showing
9 changed files
with
130 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { IconButton, Stack } from '@mui/material'; | ||
import Identicon from '@polkadot/react-identicon'; | ||
|
||
import { truncateAddres, writeToClipboard } from '@/utils/functions'; | ||
|
||
import { useToast } from '@/contexts/toast'; | ||
|
||
interface AddressProps { | ||
value: string; | ||
isShort?: boolean; | ||
isCopy?: boolean; | ||
size?: number; | ||
} | ||
|
||
export const Address = ({ | ||
value, | ||
isShort, | ||
isCopy, | ||
size = 32, | ||
}: AddressProps) => { | ||
const { toastInfo } = useToast(); | ||
|
||
const onCopy = () => { | ||
if (!isCopy) return; | ||
|
||
const asyncCopy = async () => { | ||
await writeToClipboard(value); | ||
toastInfo('Address copied'); | ||
}; | ||
asyncCopy(); | ||
}; | ||
|
||
return ( | ||
<Stack direction='row' gap='0.5rem' alignItems='center'> | ||
<IconButton onClick={onCopy}> | ||
<Identicon value={value} theme='polkadot' size={size} /> | ||
</IconButton> | ||
<p>{isShort ? truncateAddres(value) : value}</p> | ||
</Stack> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { | ||
Box, | ||
Button, | ||
IconButton, | ||
Input, | ||
InputAdornment, | ||
Typography, | ||
} from '@mui/material'; | ||
import Identicon from '@polkadot/react-identicon'; | ||
|
||
import { isValidAddress, writeToClipboard } from '@/utils/functions'; | ||
|
||
import { useAccounts } from '@/contexts/account'; | ||
import { useToast } from '@/contexts/toast'; | ||
|
||
export interface AddressInputProps { | ||
onChange: (_: string) => void; | ||
address: string; | ||
} | ||
|
||
export const AddressInput = ({ onChange, address }: AddressInputProps) => { | ||
const { | ||
state: { activeAccount }, | ||
} = useAccounts(); | ||
const { toastInfo } = useToast(); | ||
|
||
const isValid = isValidAddress(address); | ||
|
||
const onCopy = () => { | ||
const asyncCopy = async () => { | ||
await writeToClipboard(address); | ||
toastInfo('Address copied'); | ||
}; | ||
asyncCopy(); | ||
}; | ||
|
||
return ( | ||
<Box> | ||
<Typography>Recipient</Typography> | ||
<Input | ||
value={address} | ||
onChange={(e) => onChange(e.target.value)} | ||
fullWidth | ||
type='text' | ||
placeholder='Address of the recipient' | ||
startAdornment={ | ||
isValid ? ( | ||
<IconButton onClick={onCopy}> | ||
<Identicon value={address} theme='polkadot' size={24} /> | ||
</IconButton> | ||
) : ( | ||
<></> | ||
) | ||
} | ||
endAdornment={ | ||
<InputAdornment position='end'> | ||
<Button | ||
variant='text' | ||
color='info' | ||
onClick={() => activeAccount && onChange(activeAccount.address)} | ||
> | ||
Me | ||
</Button> | ||
</InputAdornment> | ||
} | ||
sx={{ height: '3rem' }} | ||
error={address.length > 0 && !isValid} | ||
/> | ||
</Box> | ||
); | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export * from './AddressInput'; | ||
export * from './AmountInput'; | ||
export * from './FileInput'; | ||
export * from './RecipientInput'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './Address'; | ||
export * from './Balance'; | ||
export * from './Banner'; | ||
export * from './Buttons'; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters