Skip to content

Commit 7aa80d4

Browse files
committed
Return provider from useWallet and re-factor AddressInput stories
1 parent fad7033 commit 7aa80d4

File tree

3 files changed

+23
-37
lines changed

3 files changed

+23
-37
lines changed
Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
import React, { useEffect } from 'react';
2-
import { storiesOf } from '@storybook/react';
1+
import React from 'react';
32
import { AddressInput } from '.';
43
import { ethers } from 'ethers';
54
import { Provider, useWallet } from '@web3-ui/hooks';
65
import { Text } from '@chakra-ui/layout';
76

7+
export default {
8+
title: 'Components/AddressInput',
9+
component: AddressInput,
10+
};
11+
812
const WithUseWallet = () => {
9-
const { connectWallet, connection } = useWallet();
13+
const { provider } = useWallet();
1014
const [value, setValue] = React.useState('');
1115

12-
useEffect(() => {
13-
connectWallet!();
14-
}, []);
15-
1616
return (
1717
<>
18-
<AddressInput value={value} onChange={(e) => setValue(e)} provider={connection.signer!} />
18+
<AddressInput value={value} onChange={(e) => setValue(e)} provider={provider!} />
1919
<Text>value: {value}</Text>
2020
</>
2121
);
@@ -38,17 +38,12 @@ const Component = ({ ...props }) => {
3838
);
3939
};
4040

41-
storiesOf('Components/AddressInput', module)
42-
.add('Default', () => {
43-
return <Component />;
44-
})
45-
.add('Using @web3-hook', () => {
46-
return (
47-
<Provider network='mainnet'>
48-
<WithUseWallet />
49-
</Provider>
50-
);
51-
})
52-
.add('With label', () => {
53-
return <Component label='Address' />;
54-
});
41+
export const Default = () => <Component />;
42+
export const UsingWeb3Hooks = () => {
43+
return (
44+
<Provider network='mainnet'>
45+
<WithUseWallet />
46+
</Provider>
47+
);
48+
};
49+
export const Label = () => <Component label='Address' />;

packages/components/src/components/AddressInput/AddressInput.tsx

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,25 @@ import { JsonRpcSigner } from '@ethersproject/providers/src.ts/json-rpc-provider
66

77
export interface AddressInputProps {
88
/**
9-
* @dev The provider or signer to fetch the address from the ens
10-
* @type JsonRpcSigner or ethers.providers.Web3Provider
9+
* The provider or signer to fetch the address from the ens
1110
*/
1211
provider: ethers.providers.Web3Provider | JsonRpcSigner;
1312
/**
14-
* @dev The value for the input
15-
* @type string
16-
* @default ''
13+
* The value for the input
1714
*/
1815
value: string;
1916
/**
20-
* @dev The label for the input
21-
* @type string
22-
* @default null
17+
* The label for the input
2318
*/
2419
label?: string;
2520
/**
26-
* @dev Change handler for the text input
27-
* @type (value: string) => void
21+
* Change handler for the text input
2822
*/
2923
onChange: (value: string) => void;
3024
}
3125

3226
/**
33-
* @dev A text input component that is used to get the address of the user from the ens. You can also pass all the styling props of the Chakra UI Input component.
34-
* @param provider The provider or signer to fetch the address from the ens
35-
* @param value The value for the input
36-
* @param onChange Change hanlder for the text input
37-
* @returns JSX.Element
27+
* A text input component that is used to get the address of the user from the ens. You can also pass all the styling props of the Chakra UI Input component.
3828
*/
3929
export const AddressInput: React.FC<AddressInputProps & InputProps> = ({
4030
provider,

packages/hooks/src/hooks/useWallet.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,6 @@ export function useWallet() {
2929
ens,
3030
},
3131
connected: context?.connected,
32+
provider: context?.provider,
3233
};
3334
}

0 commit comments

Comments
 (0)