-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #92 from lidofinance/fix/autoconnect-terms-handle-…
…errors Handle connection errors in AcceptTermsModal
- Loading branch information
Showing
23 changed files
with
171 additions
and
50 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
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,4 +1,5 @@ | ||
export enum CHAINS { | ||
Mainnet = 1, | ||
Goerli = 5, | ||
Holesky = 17000, | ||
} |
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
60 changes: 60 additions & 0 deletions
60
packages/connect-wallet-modal/src/components/WalletsModal/components/AcceptTermsModal.tsx
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,60 @@ | ||
import React from 'react'; | ||
import { Button, Modal } from '@reef-knot/ui-react'; | ||
import styled, { css } from '@reef-knot/ui-react/styled-wrapper'; | ||
import { helpers } from '@reef-knot/web3-react'; | ||
import { Terms, WalletModalConnectTermsProps } from '../../Terms'; | ||
import { CommonButtonsContainer } from '../styles'; | ||
import { useReefKnotContext } from '@reef-knot/core-react'; | ||
|
||
export interface AcceptTermsModalProps { | ||
open: boolean; | ||
termsProps: WalletModalConnectTermsProps; | ||
termsChecked: boolean; | ||
onContinue?: () => unknown; | ||
error: Error | undefined; | ||
} | ||
|
||
const ErrorBlock = styled.div` | ||
${({ theme: { fontSizesMap, spaceMap, borderRadiusesMap } }) => css` | ||
background: var(--lido-color-error); | ||
color: var(--lido-color-errorContrast); | ||
font-size: ${fontSizesMap.xxs}px; | ||
line-height: 1.6em; | ||
padding: ${spaceMap.lg}px; | ||
margin-top: ${spaceMap.sm}px; | ||
margin-bottom: ${spaceMap.md}px; | ||
border-radius: ${borderRadiusesMap.lg}px; | ||
`} | ||
`; | ||
|
||
export const AcceptTermsModal = ({ | ||
open, | ||
termsProps, | ||
termsChecked, | ||
onContinue, | ||
error, | ||
}: AcceptTermsModalProps) => { | ||
const { chains: supportedChains } = useReefKnotContext(); | ||
let errorMessage = error?.message; | ||
if (error && error.name == 'UnsupportedChainIdError') { | ||
errorMessage = helpers.getUnsupportedChainError(supportedChains).message; | ||
} | ||
|
||
return ( | ||
<Modal title="Confirm connection" open={open}> | ||
<Terms {...termsProps} /> | ||
{error && <ErrorBlock> {errorMessage} </ErrorBlock>} | ||
<CommonButtonsContainer> | ||
<Button | ||
fullwidth | ||
disabled={!termsChecked} | ||
onClick={() => { | ||
onContinue?.(); | ||
}} | ||
> | ||
Connect | ||
</Button> | ||
</CommonButtonsContainer> | ||
</Modal> | ||
); | ||
}; |
File renamed without changes.
2 changes: 2 additions & 0 deletions
2
packages/connect-wallet-modal/src/components/WalletsModal/components/index.ts
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,2 @@ | ||
export * from './LidoModalLogo'; | ||
export * from './AcceptTermsModal'; |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Chain } from 'wagmi/chains'; | ||
|
||
export const getUnsupportedChainError = (supportedChains: Chain[]) => { | ||
// Get names of supported chains to suggest them in case of "unsupported network" error | ||
const supportedChainsNames = (() => { | ||
const chains = supportedChains | ||
.map(({ name }) => name) | ||
.filter((chainName) => chainName !== 'unknown'); | ||
const lastChain = chains.pop(); | ||
return [chains.join(', '), lastChain].filter((chain) => chain).join(' or '); | ||
})(); | ||
|
||
return new Error( | ||
`Unsupported chain. Please switch to ${supportedChainsNames} in your wallet and restart the page.`, | ||
); | ||
}; |
Oops, something went wrong.