on f6af024 help sign in
bridge/src/components/AddressButton.tsx
36 lines 901 B history raw
1import * as need from 'lib/need';
2import { Button, ButtonProps } from '@tlon/indigo-react';
3import { useCallback } from 'react';
4import { useForm } from 'react-final-form';
5import { useWallet } from 'store/wallet';
7interface AddressButtonProps {
8 inputName: string;
9 children?: React.ReactNode;
10 rest?: ButtonProps;
13export const AddressButton = ({
14 inputName,
15 children,
16 ...rest
17}: AddressButtonProps) => {
18 const { change, focus } = useForm();
19 const { wallet }: any = useWallet();
20 const address = need.addressFromWallet(wallet);
22 const onClick = useCallback(
23 (event: React.MouseEvent<HTMLSpanElement>) => {
24 event.stopPropagation();
25 change(inputName, address);
26 focus(inputName);
27 },
28 [address, change, focus, inputName]
29 );
31 return (
32 <Button onClick={onClick} {...rest} className={'secondary'} type="button">
33 {children}
34 </Button>
35 );
36};