Skip to content

Commit

Permalink
Introduce redux for one of the state stores (Uniswap#742)
Browse files Browse the repository at this point in the history
* Introduce redux for one of the state stores

* Remove unused state

* Clean up hooks

* Add types for react-redux and fix error from any type on useSelector

* Strongly type the web3 provider

* Make the popup content into a POJO

* Lint errors

* Clean up method call

* Fix lint error

* Fix lint error

* Lint
  • Loading branch information
moodysalem authored May 11, 2020
1 parent ea015d1 commit 6da8e2c
Show file tree
Hide file tree
Showing 18 changed files with 355 additions and 293 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ notes.txt
package-lock.json

cypress/videos
cypress/screenshots
cypress/screenshots
cypress/fixtures/example.json
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"@material-ui/core": "^4.9.5",
"@reach/dialog": "^0.2.8",
"@reach/tooltip": "^0.2.0",
"@reduxjs/toolkit": "^1.3.5",
"@uniswap/sdk": "^2.0.3",
"@uniswap/v2-core": "1.0.0",
"@uniswap/v2-periphery": "1.0.0-beta.0",
Expand All @@ -41,6 +42,7 @@
"react-feather": "^2.0.8",
"react-ga": "^2.5.7",
"react-i18next": "^10.7.0",
"react-redux": "^7.2.0",
"react-router-dom": "^5.0.0",
"react-scripts": "^3.4.1",
"react-spring": "^8.0.27",
Expand All @@ -55,6 +57,7 @@
"@types/node": "^13.13.5",
"@types/react": "^16.9.34",
"@types/react-dom": "^16.9.7",
"@types/react-redux": "^7.1.8",
"@types/react-router-dom": "^5.0.0",
"@types/rebass": "^4.0.5",
"@types/styled-components": "^4.2.0",
Expand Down
2 changes: 1 addition & 1 deletion src/components/ExchangePage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import { withRouter, RouteComponentProps } from 'react-router-dom'
import { BigNumber } from '@ethersproject/bignumber'
import { MaxUint256 } from '@ethersproject/constants'
import { Contract } from '@ethersproject/contracts'
import { useUserAdvanced } from '../../state/application/hooks'
import { Field, SwapAction, useSwapStateReducer } from './swap-store'
import { Text } from 'rebass'
import Card, { BlueCard, GreyCard, YellowCard } from '../../components/Card'
import { AutoColumn, ColumnCenter } from '../../components/Column'
import { AutoRow, RowBetween, RowFixed } from '../Row'
import { ROUTER_ADDRESS } from '../../constants'
import { useTokenAllowance } from '../../data/Allowances'
import { useUserAdvanced } from '../../contexts/Application'
import { useAddressBalance, useAllBalances } from '../../contexts/Balances'
import { useLocalStorageTokens } from '../../contexts/LocalStorage'
import { usePair } from '../../data/Reserves'
Expand Down
39 changes: 36 additions & 3 deletions src/components/Popups/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@ import styled, { ThemeContext } from 'styled-components'
import { useMediaLayout } from 'use-media'

import { X } from 'react-feather'
import { usePopups } from '../../contexts/Application'
import { PopupContent } from '../../state/application/actions'
import { usePopups } from '../../state/application/hooks'
import { Link } from '../../theme'
import { AutoColumn } from '../Column'
import DoubleTokenLogo from '../DoubleLogo'
import Row from '../Row'
import TxnPopup from '../TxnPopup'
import { Text } from 'rebass'

const StyledClose = styled(X)`
position: absolute;
Expand Down Expand Up @@ -66,6 +72,33 @@ const Popup = styled.div`
`}
`

function PopupItem({ content, popKey }: { content: PopupContent; popKey: string }) {
if ('txn' in content) {
const {
txn: { hash, success, summary }
} = content
return <TxnPopup popKey={popKey} hash={hash} success={success} summary={summary} />
} else if ('poolAdded' in content) {
const {
poolAdded: { token0, token1 }
} = content
return (
<AutoColumn gap={'10px'}>
<Text fontSize={20} fontWeight={500}>
Pool Imported
</Text>
<Row>
<DoubleTokenLogo a0={token0?.address ?? ''} a1={token1?.address ?? ''} margin={true} />
<Text fontSize={16} fontWeight={500}>
UNI {token0?.symbol} / {token1?.symbol}
</Text>
</Row>
<Link>View on Uniswap Info.</Link>
</AutoColumn>
)
}
}

export default function App() {
const theme = useContext(ThemeContext)
// get all popups
Expand All @@ -81,7 +114,7 @@ export default function App() {
return (
<Popup key={item.key}>
<StyledClose color={theme.text2} onClick={() => removePopup(item.key)} />
{React.cloneElement(item.content, { popKey: item.key })}
<PopupItem content={item.content} popKey={item.key} />
</Popup>
)
})}
Expand All @@ -100,7 +133,7 @@ export default function App() {
return (
<Popup key={item.key}>
<StyledClose color={theme.text2} onClick={() => removePopup(item.key)} />
{React.cloneElement(item.content, { popKey: item.key })}
<PopupItem content={item.content} popKey={item.key} />
</Popup>
)
})}
Expand Down
4 changes: 2 additions & 2 deletions src/components/TxnPopup/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import React, { useState } from 'react'
import { AlertCircle, CheckCircle } from 'react-feather'

import styled from 'styled-components'
import { usePopups } from '../../contexts/Application'

import { useWeb3React } from '../../hooks'
import useInterval from '../../hooks/useInterval'
import { usePopups } from '../../state/application/hooks'
import { TYPE } from '../../theme'

import { Link } from '../../theme/components'
Expand Down Expand Up @@ -35,7 +35,7 @@ export default function TxnPopup({
hash: string
success?: boolean
summary?: string
popKey?: number
popKey?: string
}) {
const { chainId } = useWeb3React()
const [count, setCount] = useState(1)
Expand Down
2 changes: 1 addition & 1 deletion src/components/WalletModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import styled from 'styled-components'
import { isMobile } from 'react-device-detect'
import { useWeb3React, UnsupportedChainIdError } from '@web3-react/core'
import { URI_AVAILABLE } from '@web3-react/walletconnect-connector'
import { useWalletModalOpen, useWalletModalToggle } from '../../state/application/hooks'

import Modal from '../Modal'
import AccountDetails from '../AccountDetails'
Expand All @@ -15,7 +16,6 @@ import { Link } from '../../theme'
import MetamaskIcon from '../../assets/images/metamask.png'
import { ReactComponent as Close } from '../../assets/images/x.svg'
import { injected, walletconnect, fortmatic, portis } from '../../connectors'
import { useWalletModalToggle, useWalletModalOpen } from '../../contexts/Application'
import { OVERLAY_READY } from '../../connectors/Fortmatic'

const CloseIcon = styled.div`
Expand Down
2 changes: 1 addition & 1 deletion src/components/Web3Status/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useTranslation } from 'react-i18next'
import { useWeb3React, UnsupportedChainIdError } from '@web3-react/core'
import { darken, lighten } from 'polished'
import { Activity } from 'react-feather'
import { useWalletModalToggle } from '../../state/application/hooks'

import Identicon from '../Identicon'
import PortisIcon from '../../assets/images/portisIcon.png'
Expand All @@ -21,7 +22,6 @@ import { useENSName } from '../../hooks'
import { shortenAddress } from '../../utils'
import { useAllTransactions } from '../../contexts/Transactions'
import { NetworkContextName } from '../../constants'
import { useWalletModalToggle } from '../../contexts/Application'
import { injected, walletconnect, walletlink, fortmatic, portis } from '../../connectors'

const SpinnerWrapper = styled(Spinner)`
Expand Down
226 changes: 0 additions & 226 deletions src/contexts/Application.tsx

This file was deleted.

Loading

0 comments on commit 6da8e2c

Please sign in to comment.