Skip to content

Commit

Permalink
Merge pull request #314 from levelkdev/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Federico Luzzi authored Jul 29, 2021
2 parents c708487 + 926bcd0 commit 1aad645
Show file tree
Hide file tree
Showing 27 changed files with 273 additions and 252 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dxswap-dapp",
"version": "1.0.0-beta.2",
"version": "1.0.0-beta.3",
"description": "DXswap Decentralized Application",
"devDependencies": {
"@apollo/client": "^3.3.13",
Expand Down Expand Up @@ -42,9 +42,9 @@
"cross-env": "^7.0.2",
"cypress": "^4.11.0",
"decimal.js-light": "^2.5.1",
"dxswap-core": "git://github.com/levelkdev/dxswap-core.git#v0.3.7",
"dxswap-periphery": "git://github.com/levelkdev/dxswap-periphery.git#v0.3.8",
"dxswap-sdk": "git://github.com/levelkdev/dxswap-sdk.git#v0.8.5",
"dxswap-core": "git://github.com/levelkdev/dxswap-core.git#v0.3.9",
"dxswap-periphery": "git://github.com/levelkdev/dxswap-periphery.git#v0.3.10",
"dxswap-sdk": "git://github.com/levelkdev/dxswap-sdk.git#v0.9.3",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-prettier": "^3.1.3",
Expand Down
15 changes: 12 additions & 3 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,21 @@
<meta name="title" content="Swapr" />
<meta name="description" content="A governance-enabled automated market maker with adjustable fees." />
<meta name="image" content="%PUBLIC_URL%/og.png" />
<meta property="og:title" content="Swapr" />
<meta property="og:description" content="A governance-enabled automated market maker with adjustable fees." />
<meta property="og:image" content="http://swapr.eth.link/og.png" />
<meta property="og:url" content="https://swapr.eth.link/" />
<meta property="og:site_name" content="Swapr" />
<meta property="og:type" content="website" />
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:creator" content="@SwaprEth" />
<meta name="twitter:image" content="https://ipfs.io/ipfs/QmahQRVtrrxAdZnMA5XTHWQQPqA2WxkkC1aPYgsZwy3cKA" />
<meta name="twitter:image:alt" content="Swapr" />
<meta name="twitter:title" content="Swapr" />
<meta name="twitter:description" content="A governance-enabled automated market maker with adjustable fees." />
<meta name="twitter:image" content="http://swapr.eth.link/og.png" />
<meta name="twitter:image:alt" content="Swapr" />
<meta name="twitter:site" content="@SwaprEth" />
<link rel="icon" href="%PUBLIC_URL%/favicon.png" />
<base href="/" />

<script>
;(function() {
const { pathname, hostname, protocol } = window.location
Expand Down
8 changes: 8 additions & 0 deletions src/apollo/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,13 @@ export const subgraphClients: { [chainId in ChainId]?: ApolloClient<NormalizedCa
[ChainId.XDAI]: new ApolloClient({
uri: 'https://api.thegraph.com/subgraphs/name/luzzif/swapr-xdai',
cache: new InMemoryCache()
}),
[ChainId.ARBITRUM_ONE]: new ApolloClient({
uri: 'https://api.thegraph.com/subgraphs/name/luzzif/swapr-arbitrum-one',
cache: new InMemoryCache()
}),
[ChainId.ARBITRUM_RINKEBY]: new ApolloClient({
uri: 'https://api.thegraph.com/subgraphs/name/luzzif/swapr-arbitrum-rinkeby',
cache: new InMemoryCache()
})
}
Binary file removed src/assets/images/poa-logo.png
Binary file not shown.
5 changes: 2 additions & 3 deletions src/components/CurrencyLogo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import Skeleton from 'react-loading-skeleton'
import styled from 'styled-components'

import EthereumLogo from '../../assets/images/ethereum-logo.png'
import PoaLogo from '../../assets/images/poa-logo.png'
import XDAILogo from '../../assets/images/xdai-logo.png'
import DXDLogo from '../../assets/svg/dxd.svg'
import { useActiveWeb3React } from '../../hooks'
Expand Down Expand Up @@ -49,10 +48,10 @@ const Wrapper = styled.div<{ size: string; marginRight: number; marginLeft: numb
`

const NATIVE_CURRENCY_LOGO: { [chainId in ChainId]: string } = {
[ChainId.ARBITRUM_TESTNET_V3]: EthereumLogo,
[ChainId.ARBITRUM_ONE]: EthereumLogo,
[ChainId.ARBITRUM_RINKEBY]: EthereumLogo,
[ChainId.MAINNET]: EthereumLogo,
[ChainId.RINKEBY]: EthereumLogo,
[ChainId.SOKOL]: PoaLogo,
[ChainId.XDAI]: XDAILogo
}

Expand Down
40 changes: 40 additions & 0 deletions src/components/DisclaimerBar/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React from 'react'
import styled from 'styled-components'
import { useDisclaimerBar } from '../../hooks/useShowDisclaimerBar'

export const DisclaimerBar = () => {
if (!useDisclaimerBar()) return null

return (
<Bar>
<Disclaimer>
This is an unofficial build meant for development and testing purposes.{' '}
<a href="https://swapr.eth.link/" target="_blank" rel="noopener noreferrer">
Please visit Swapr.eth
</a>
</Disclaimer>
</Bar>
)
}

const Bar = styled.div`
width: 100%;
padding: 8px;
background: rgba(242, 153, 74, 0.15);
border-bottom: 1px solid rgba(242, 153, 74, 0.5);
`

const Disclaimer = styled.p`
margin: 0;
font-weight: 500;
font-size: 12px;
line-height: 15px;
text-align: center;
color: #f2994a;
a {
font-weight: 700;
color: inherit;
text-decoration: none;
}
`
2 changes: 1 addition & 1 deletion src/components/Footer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default function Footer() {
const [darkMode, toggleDarkMode] = useDarkModeManager()

return (
<FooterFrame>
<FooterFrame>
<ButtonSecondary onClick={toggleDarkMode} p="8px 12px" ml="0.5rem" width="min-content">
{darkMode ? <Sun size={16} /> : <Moon size={16} />}
</ButtonSecondary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Pair, Token, TokenAmount } from 'dxswap-sdk'
import React, { useCallback, useState } from 'react'
import { Box, Flex } from 'rebass'
import styled from 'styled-components'
import { useAllTokens } from '../../../../../hooks/Tokens'
import CurrencySearchModal from '../../../../SearchModal/CurrencySearchModal'
import PairSearchModal from '../../../../SearchModal/PairSearchModal'
import { Card, Divider } from '../../../styleds'
Expand Down Expand Up @@ -35,7 +34,6 @@ export default function PairAndReward({
}: PairAndRewardProps) {
const [pairSearchOpen, setPairSearchOpen] = useState<boolean>(false)
const [currencySearchOpen, setCurrencySearchOpen] = useState<boolean>(false)
const allTokens = useAllTokens()

const handleOpenPairSearch = useCallback(() => {
setPairSearchOpen(true)
Expand Down Expand Up @@ -67,17 +65,6 @@ export default function PairAndReward({
[onRewardTokenChange]
)

const filterPairs = useCallback(
(pair: Pair) => {
const adjustedTokens = Object.values(allTokens)
return (
adjustedTokens.some(token => token.equals(pair.token0)) &&
adjustedTokens.some(token => token.equals(pair.token1))
)
},
[allTokens]
)

return (
<>
<Card>
Expand All @@ -103,7 +90,6 @@ export default function PairAndReward({
onDismiss={handleDismissPairSearch}
onPairSelect={handlePairSelection}
selectedPair={liquidityPair}
filterPairs={filterPairs}
/>
<CurrencySearchModal
isOpen={currencySearchOpen}
Expand Down
10 changes: 3 additions & 7 deletions src/components/NetworkSwitcherPopover/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ export default function NetworkSwitcherPopover({ children }: { children: ReactNo
const selectNetwork = useCallback(
(optionChainId: ChainId) => {
if (optionChainId === chainId) return
if (!!!account && connector instanceof CustomNetworkConnector) {
connector.changeChainId(optionChainId)
}
if (!!!account && connector instanceof CustomNetworkConnector) connector.changeChainId(optionChainId)
if (
window.ethereum &&
window.ethereum.isMetaMask &&
Expand Down Expand Up @@ -75,12 +73,10 @@ export default function NetworkSwitcherPopover({ children }: { children: ReactNo
/>
<Option
onClick={() => {
selectNetwork(ChainId.ARBITRUM_TESTNET_V3)
selectNetwork(ChainId.ARBITRUM_ONE)
}}
header={'Arbitrum'}
header={'Arbitrum one'}
logoSrc={ArbitrumLogo}
disabled={true}
clickable={false}
/>
</OptionGrid>
}
Expand Down
8 changes: 5 additions & 3 deletions src/components/Settings/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import Toggle from '../Toggle'
import TransactionSettings from '../TransactionSettings'
import SwaprVersionLogo from '../SwaprVersionLogo'
import { DarkCard } from '../Card'
import { useDisclaimerBar } from '../../hooks/useShowDisclaimerBar'

const StyledMenuIcon = styled(Settings)`
height: 18px;
Expand Down Expand Up @@ -65,9 +66,9 @@ const StyledMenu = styled.div`
text-align: left;
`

const MenuModal = styled(Modal)`
const MenuModal = styled(Modal)<{ disclaimerBar: boolean }>`
position: absolute;
top: 80px;
top: ${props => (props.disclaimerBar ? '112px' : '80px')};
right: 20px;
${({ theme }) => theme.mediaWidth.upToMedium`
position: fixed;
Expand Down Expand Up @@ -129,6 +130,7 @@ export default function SettingsTab() {
const [ttl, setTtl] = useUserTransactionTTL()
const [expertMode, toggleExpertMode] = useExpertModeManager()
const [multihop, toggleMultihop] = useMultihopManager()
const showDisclaimerBar = useDisclaimerBar()

// show confirmation view before turning on
const [showConfirmation, setShowConfirmation] = useState(false)
Expand Down Expand Up @@ -180,7 +182,7 @@ export default function SettingsTab() {
</span>
</EmojiWrapper>
)}
<MenuModal maxWidth={322} isOpen={open} onDismiss={toggle}>
<MenuModal maxWidth={322} isOpen={open} onDismiss={toggle} disclaimerBar={showDisclaimerBar}>
<MenuModalContentWrapper>
<AutoColumn gap="md" style={{ padding: '8px' }}>
<RowBetween>
Expand Down
2 changes: 1 addition & 1 deletion src/components/WalletModal/PendingView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export default function PendingView({
}
}
return (
<Flex mb="28px" justifyContent="center">
<Flex key={key} mb="28px" justifyContent="center">
<Box mr="10px">
<img src={require('../../assets/images/' + option.iconName)} alt="logo" width="24px" height="24px" />
</Box>
Expand Down
13 changes: 7 additions & 6 deletions src/components/Web3Status/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ import ArbitrumLogo from '../../assets/images/arbitrum-logo.jpg'
import { ChainId } from 'dxswap-sdk'
import { useActiveWeb3React } from '../../hooks'

const ChainLogo: any = {
const ChainLogo: { [chainId in ChainId]: string } = {
[ChainId.MAINNET]: EthereumLogo,
[ChainId.RINKEBY]: EthereumLogo,
[ChainId.ARBITRUM_TESTNET_V3]: ArbitrumLogo,
[ChainId.SOKOL]: '',
[ChainId.ARBITRUM_ONE]: ArbitrumLogo,
[ChainId.ARBITRUM_RINKEBY]: ArbitrumLogo,
[ChainId.XDAI]: XDAILogo
}

const ChainLabel: any = {
const ChainLabel: { [chainId in ChainId]: string } = {
[ChainId.MAINNET]: 'Ethereum',
[ChainId.RINKEBY]: 'Rinkeby',
[ChainId.ARBITRUM_TESTNET_V3]: 'Arbitrum',
[ChainId.SOKOL]: 'Sokol',
[ChainId.ARBITRUM_ONE]: 'Arbitrum One',
[ChainId.ARBITRUM_RINKEBY]: 'Arbitrum RInkeby',
[ChainId.XDAI]: 'xDai'
}

Expand All @@ -46,6 +46,7 @@ const IconWrapper = styled.div<{ size?: number | null }>`
justify-content: center;
& > img,
span {
border-radius: ${props => (props.size ? props.size / 2 : 15)}px;
height: ${({ size }) => (size ? size + 'px' : '30px')};
}
${({ theme }) => theme.mediaWidth.upToMedium`
Expand Down
120 changes: 120 additions & 0 deletions src/connectors/CustomWalletConnectConnector.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
// largely taken from https://github.com/NoahZinsmeister/web3-react/blob/v6/packages/walletconnect-connector/src/index.ts
// Updated to always be in sync with network connector's chain id

import { ConnectorUpdate } from '@web3-react/types'
import { AbstractConnector } from '@web3-react/abstract-connector'
import { IWalletConnectProviderOptions } from '@walletconnect/types'
import { network } from '.'

export const URI_AVAILABLE = 'URI_AVAILABLE'

export interface WalletConnectConnectorArguments extends IWalletConnectProviderOptions {
supportedChainIds?: number[]
}

export class UserRejectedRequestError extends Error {
public constructor() {
super()
this.name = this.constructor.name
this.message = 'The user rejected the request.'
}
}

function getSupportedChains({ supportedChainIds, rpc }: WalletConnectConnectorArguments): number[] | undefined {
if (supportedChainIds) {
return supportedChainIds
}

return rpc ? Object.keys(rpc).map(k => Number(k)) : undefined
}

export class CustomWalletConnectConnector extends AbstractConnector {
private readonly config: WalletConnectConnectorArguments

public walletConnectProvider?: any

constructor(config: WalletConnectConnectorArguments) {
super({ supportedChainIds: getSupportedChains(config) })

this.config = config

this.handleChainChanged = this.handleChainChanged.bind(this)
this.handleAccountsChanged = this.handleAccountsChanged.bind(this)
this.handleDisconnect = this.handleDisconnect.bind(this)
}

private handleChainChanged(chainId: number | string): void {
this.emitUpdate({ chainId })
}

private handleAccountsChanged(accounts: string[]): void {
this.emitUpdate({ account: accounts[0] })
}

private handleDisconnect(): void {
this.emitDeactivate()
// we have to do this because of a @walletconnect/web3-provider bug
if (this.walletConnectProvider) {
this.walletConnectProvider.stop()
this.walletConnectProvider.removeListener('chainChanged', this.handleChainChanged)
this.walletConnectProvider.removeListener('accountsChanged', this.handleAccountsChanged)
this.walletConnectProvider = undefined
}

this.emitDeactivate()
}

public async activate(): Promise<ConnectorUpdate> {
const WalletConnectProvider = await import('@walletconnect/web3-provider').then(m => m?.default ?? m)
this.walletConnectProvider = new WalletConnectProvider(this.config)

// ensure that the uri is going to be available, and emit an event if there's a new uri
if (!this.walletConnectProvider.wc.connected) {
await this.walletConnectProvider.wc.createSession({ chainId: await network.getChainId() })
this.emit(URI_AVAILABLE, this.walletConnectProvider.wc.uri)
}

const account = await this.walletConnectProvider
.enable()
.then((accounts: string[]): string => accounts[0])
.catch((error: Error): void => {
// TODO ideally this would be a better check
if (error.message === 'User closed modal') {
throw new UserRejectedRequestError()
}

throw error
})

this.walletConnectProvider.on('disconnect', this.handleDisconnect)
this.walletConnectProvider.on('chainChanged', this.handleChainChanged)
this.walletConnectProvider.on('accountsChanged', this.handleAccountsChanged)

return { provider: this.walletConnectProvider, account }
}

public async getProvider(): Promise<any> {
return this.walletConnectProvider
}

public async getChainId(): Promise<number | string> {
return this.walletConnectProvider.send('eth_chainId')
}

public async getAccount(): Promise<null | string> {
return this.walletConnectProvider.send('eth_accounts').then((accounts: string[]): string => accounts[0])
}

public deactivate() {
if (this.walletConnectProvider) {
this.walletConnectProvider.stop()
this.walletConnectProvider.removeListener('disconnect', this.handleDisconnect)
this.walletConnectProvider.removeListener('chainChanged', this.handleChainChanged)
this.walletConnectProvider.removeListener('accountsChanged', this.handleAccountsChanged)
}
}

public async close() {
await this.walletConnectProvider?.close()
}
}
Loading

0 comments on commit 1aad645

Please sign in to comment.