-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
226 additions
and
23 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 |
---|---|---|
@@ -1,8 +1,36 @@ | ||
import { Button } from '@mui/material'; | ||
import { LoadingButton } from '@mui/lab'; | ||
import { styled } from '@mui/material/styles'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { | ||
usePriorityAccount, | ||
usePriorityConnector, | ||
usePriorityIsActivating, | ||
usePriorityIsActive, | ||
} from '../hooks/connectorHooks'; | ||
|
||
export const SwapButton = styled(Button)({ | ||
export const Button = styled(LoadingButton)({ | ||
textTransform: 'none', | ||
borderRadius: 0, | ||
padding: '12px 16px', | ||
}); | ||
|
||
export const SwapButton = () => { | ||
const { t } = useTranslation(); | ||
const connector = usePriorityConnector(); | ||
const isActive = usePriorityIsActive(); | ||
const isActivating = usePriorityIsActivating(); | ||
const account = usePriorityAccount(); | ||
|
||
return ( | ||
<Button | ||
variant="contained" | ||
disableElevation | ||
fullWidth | ||
color={isActive ? 'primary' : 'success'} | ||
onClick={isActive ? undefined : async () => connector.activate()} | ||
loading={isActivating} | ||
> | ||
{isActive ? t(`swap.submit`) : t(`swap.connectWallet`)} | ||
</Button> | ||
); | ||
}; |
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,21 +1,79 @@ | ||
import { Typography } from '@mui/material'; | ||
import { Box, Menu, MenuItem, Typography } from '@mui/material'; | ||
import { styled } from '@mui/material/styles'; | ||
import { useState } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { | ||
usePriorityAccount, | ||
usePriorityConnector, | ||
} from '../hooks/connectorHooks'; | ||
import { Header } from './Header'; | ||
|
||
export const WalletTypography = styled(Typography)(({ theme }) => ({ | ||
transition: theme.transitions.create(['color']), | ||
'&:hover': { | ||
color: theme.palette.grey[200], | ||
cursor: 'pointer', | ||
}, | ||
})); | ||
|
||
export const WalletHeader: React.FC = () => { | ||
const { t } = useTranslation(); | ||
const [menuAnchor, setMenuAnchor] = useState<null | HTMLElement>(null); | ||
const open = Boolean(menuAnchor); | ||
const connector = usePriorityConnector(); | ||
const account = usePriorityAccount(); | ||
const walletAddress = account | ||
? `${account.substring(0, 7)}...${account.substring(account.length - 7)}` | ||
: null; | ||
|
||
const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => { | ||
setMenuAnchor(event.currentTarget); | ||
}; | ||
|
||
const handleClose = () => { | ||
setMenuAnchor(null); | ||
}; | ||
|
||
const handleDisconnect = () => { | ||
connector.deactivate(); | ||
handleClose(); | ||
}; | ||
|
||
return ( | ||
<Header height={40}> | ||
<Typography | ||
variant="body2" | ||
noWrap | ||
align="right" | ||
sx={{ flexGrow: 1 }} | ||
color="grey.500" | ||
mt={2} | ||
<Box sx={{ display: 'flex', flex: 1, justifyContent: 'flex-end' }}> | ||
<WalletTypography | ||
variant="body2" | ||
noWrap | ||
align="right" | ||
color="grey.500" | ||
mt={2} | ||
id="wallet" | ||
aria-controls={open ? 'wallet-menu' : undefined} | ||
aria-haspopup="true" | ||
aria-expanded={open ? 'true' : undefined} | ||
onClick={handleClick} | ||
> | ||
{walletAddress | ||
? t(`header.walletConnected`, { walletAddress }) | ||
: t(`header.walletNotConnected`)} | ||
</WalletTypography> | ||
</Box> | ||
<Menu | ||
id="wallet-menu" | ||
anchorEl={menuAnchor} | ||
open={open} | ||
onClose={handleClose} | ||
MenuListProps={{ | ||
'aria-labelledby': 'wallet-menu', | ||
}} | ||
anchorReference="anchorEl" | ||
anchorOrigin={{ vertical: 'bottom', horizontal: 'center' }} | ||
> | ||
{t(`header.walletConnected`, { walletAddress: '0000000000' })} | ||
</Typography> | ||
<MenuItem dense onClick={handleDisconnect}> | ||
{t(`header.disconnect`)} | ||
</MenuItem> | ||
</Menu> | ||
</Header> | ||
); | ||
}; |
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,34 @@ | ||
import { getPriorityConnector } from '@web3-react/core'; | ||
import { | ||
hooks as metaMaskHooks, | ||
metaMask, | ||
} from '../services/connectors/metaMask'; | ||
|
||
export const { | ||
useSelectedChainId, | ||
useSelectedAccounts, | ||
useSelectedIsActivating, | ||
useSelectedError, | ||
useSelectedAccount, | ||
useSelectedIsActive, | ||
useSelectedProvider, | ||
useSelectedENSNames, | ||
useSelectedENSName, | ||
useSelectedWeb3React, | ||
usePriorityConnector, | ||
usePriorityChainId, | ||
usePriorityAccounts, | ||
usePriorityIsActivating, | ||
usePriorityError, | ||
usePriorityAccount, | ||
usePriorityIsActive, | ||
usePriorityProvider, | ||
usePriorityENSNames, | ||
usePriorityENSName, | ||
usePriorityWeb3React, | ||
} = getPriorityConnector( | ||
[metaMask, metaMaskHooks], | ||
// [walletConnect, walletConnectHooks], | ||
// [walletLink, walletLinkHooks], | ||
// [network, networkHooks], | ||
); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Eip1193Bridge } from '@ethersproject/experimental'; | ||
import { JsonRpcProvider } from '@ethersproject/providers'; | ||
import { initializeConnector } from '@web3-react/core'; | ||
import { EIP1193 } from '@web3-react/eip1193'; | ||
import { URLS } from '../chains'; | ||
|
||
class Eip1193BridgeWithoutAccounts extends Eip1193Bridge { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
request(request: { method: string; params?: any[] }): Promise<any> { | ||
if ( | ||
request.method === 'eth_requestAccounts' || | ||
request.method === 'eth_accounts' | ||
) | ||
return Promise.resolve([]); | ||
return super.request(request); | ||
} | ||
} | ||
|
||
const ethersProvider = new JsonRpcProvider(URLS[1][0], 1); | ||
const eip1193Provider = new Eip1193BridgeWithoutAccounts( | ||
ethersProvider.getSigner(), | ||
ethersProvider, | ||
); | ||
|
||
export const [eip1193, hooks] = initializeConnector<EIP1193>( | ||
(actions) => new EIP1193(actions, eip1193Provider), | ||
[1], | ||
); |
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,4 @@ | ||
import { initializeConnector } from '@web3-react/core'; | ||
import { Empty, EMPTY } from '@web3-react/empty'; | ||
|
||
export const [empty, hooks] = initializeConnector<Empty>(() => EMPTY); |
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,6 @@ | ||
import { initializeConnector } from '@web3-react/core'; | ||
import { MetaMask } from '@web3-react/metamask'; | ||
|
||
export const [metaMask, hooks] = initializeConnector<MetaMask>( | ||
(actions) => new MetaMask(actions), | ||
); |
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,8 @@ | ||
import { initializeConnector } from '@web3-react/core'; | ||
import { Network } from '@web3-react/network'; | ||
import { URLS } from '../chains'; | ||
|
||
export const [network, hooks] = initializeConnector<Network>( | ||
(actions) => new Network(actions, URLS), | ||
Object.keys(URLS).map((chainId) => Number(chainId)), | ||
); |
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,8 @@ | ||
import { initializeConnector } from '@web3-react/core'; | ||
import { Url } from '@web3-react/url'; | ||
import { URLS } from '../chains'; | ||
|
||
export const [url, hooks] = initializeConnector<Url>( | ||
(actions) => new Url(actions, URLS[1][0]), | ||
[1], | ||
); |
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,17 @@ | ||
import { initializeConnector } from '@web3-react/core'; | ||
import { WalletConnect } from '@web3-react/walletconnect'; | ||
import { URLS } from '../chains'; | ||
|
||
export const [walletConnect, hooks] = initializeConnector<WalletConnect>( | ||
(actions) => | ||
new WalletConnect(actions, { | ||
rpc: Object.keys(URLS).reduce<{ [chainId: number]: string }>( | ||
(accumulator, chainId) => { | ||
accumulator[Number(chainId)] = URLS[Number(chainId)][0]; | ||
return accumulator; | ||
}, | ||
{}, | ||
), | ||
}), | ||
Object.keys(URLS).map((chainId) => Number(chainId)), | ||
); |
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,11 @@ | ||
import { initializeConnector } from '@web3-react/core'; | ||
import { WalletLink } from '@web3-react/walletlink'; | ||
import { URLS } from '../chains'; | ||
|
||
export const [walletLink, hooks] = initializeConnector<WalletLink>( | ||
(actions) => | ||
new WalletLink(actions, { | ||
url: URLS[1][0], | ||
appName: 'lifi-widget', | ||
}), | ||
); |
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