Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add wallet connection functionality #40

Merged
merged 49 commits into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
12e0b71
feat: set up basic wallet connection functionality (#32)
kristiehuang Jun 17, 2022
15e0218
feat: add gradient identicons (#39)
kristiehuang Jun 22, 2022
bbc1111
Fix timeout typing
kristiehuang Jul 1, 2022
d85ea9b
feat: Add WalletConnect QR code to ConnectWalletDialog with latest we…
kristiehuang Jul 5, 2022
b62cd44
feat: switch to using w3r's Web3ReactProvider (#50)
kristiehuang Jul 5, 2022
72c5106
feat: add fallback mainnet JSON RPC endpoint (#43)
kristiehuang Jul 5, 2022
e95f07b
fix: fix integrator provider accounts.every error
kristiehuang Jul 8, 2022
7de77ff
add flashbots RPC endpoint to fallbacks
kristiehuang Jul 8, 2022
243f85b
lint
kristiehuang Jul 8, 2022
12c8749
fix: use undistorted QR code (#53)
kristiehuang Jul 11, 2022
77fcc2f
nit: show loading state if trade is loading
kristiehuang Jul 12, 2022
ba31255
feat: give integrators option to pass in 'false' to disable our built…
kristiehuang Jul 13, 2022
fd40f63
style(lint): lint action with ESLint
Jul 13, 2022
9179e6d
Revert "feat: give integrators option to pass in 'false' to disable o…
kristiehuang Jul 13, 2022
69180be
Merge branch 'wallet-connect-flow' of https://github.com/Uniswap/widg…
kristiehuang Jul 13, 2022
495ac68
fix: bump w3r versions to fix bug
kristiehuang Jul 13, 2022
291c409
feat: add widget disconnection via hover (#61)
kristiehuang Jul 21, 2022
0463186
fix: multichain widget (#59)
kristiehuang Jul 27, 2022
b6bd985
Merge branch 'main' into wallet-connect-flow
kristiehuang Jul 28, 2022
f5f9fe4
fix: use web3react instead of activeweb3react
kristiehuang Jul 28, 2022
c9c8264
style(lint): lint action with ESLint
Jul 28, 2022
e7ef6cb
Add public rpcs
kristiehuang Jul 28, 2022
f6fa679
Merge branch 'wallet-connect-flow' of https://github.com/Uniswap/widg…
kristiehuang Jul 28, 2022
d67063c
nit
kristiehuang Jul 28, 2022
f8f7e0e
Update jsonRpcEndpoints
kristiehuang Jul 28, 2022
2875281
Update jsonRpcEndpoints to support routing
kristiehuang Jul 28, 2022
401566d
fix: catch errors (#55)
kristiehuang Aug 1, 2022
2184784
Use JsonRpcConnector built-in for custom wallet provider
kristiehuang Aug 1, 2022
3dbfcc9
revert swap.fixture
kristiehuang Aug 1, 2022
24ce4f9
Rename onClickConnectWallet to onConnectWalletClick
kristiehuang Aug 1, 2022
92b4894
Address PR reviews
kristiehuang Aug 2, 2022
5ffa949
style(lint): lint action with ESLint
Aug 2, 2022
6e7a7b0
nit
kristiehuang Aug 2, 2022
d3c4da3
feat: add hideConnectionUI prop
kristiehuang Aug 2, 2022
30cc010
Merge branch 'wallet-connect-flow' of https://github.com/Uniswap/widg…
kristiehuang Aug 2, 2022
4bf9148
update types/node and w3r/metamask versions
kristiehuang Aug 2, 2022
43ffcd4
nit
kristiehuang Aug 2, 2022
94bc505
Use ButtonContents to button contents
kristiehuang Aug 2, 2022
df0854a
fix: Use entries of jsonRpcUrlMap for connectors key
kristiehuang Aug 2, 2022
9fc1dcf
pass account as prop to ConnectedWalletChip
kristiehuang Aug 3, 2022
985298c
use promise pattern for onConnectWalletClick
kristiehuang Aug 3, 2022
df93c73
use atom for callback fxn instead of passing down all the way
kristiehuang Aug 3, 2022
1e42f3c
move onconnectclickatom to wallet.ts
kristiehuang Aug 3, 2022
affbe3f
nit
kristiehuang Aug 3, 2022
e58a7ff
nit: fix heights pxs
kristiehuang Aug 3, 2022
1ac569c
fix defaultChainid bug
kristiehuang Aug 3, 2022
e2af593
nit: PR review
kristiehuang Aug 3, 2022
3c98744
Merge branch 'main' into wallet-connect-flow
kristiehuang Aug 4, 2022
191575e
feat: [wallet connection] update tests (#62)
kristiehuang Aug 4, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
lts/*
18
75 changes: 57 additions & 18 deletions e2e/connect.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,44 +10,83 @@ import { tokens } from '@uniswap/default-token-list'

import { SwapWidget } from '../src'

const HARDHAT_ACCOUNT_DISPLAY_STRING = `${hardhat.account.address?.substring(
0,
6
)}...${hardhat.account.address?.substring(hardhat.account.address.length - 4)}`

describe('connect', () => {
let component: RenderResult
let wallet: HTMLElement
let account: HTMLElement
let connectWallet: HTMLElement
let toolbar: HTMLElement
let tokenSelect: HTMLElement

beforeEach(async () => {
component = render(<SwapWidget tokenList={tokens} />)
wallet = await component.findByTestId('wallet')
connectWallet = await component.findByTestId('connect-wallet')
toolbar = await component.findByTestId('toolbar')
tokenSelect = (await component.findAllByTestId('token-select'))[0]
})

it('prompts for wallet connection in the Toolbar', async () => {
expect(wallet.hidden).toBeTruthy()
expect(toolbar.textContent).toBe('Connect wallet to swap')
describe('with no params, using fallback JSON RPC URL', () => {
it('prompts for wallet connection in the Wallet and Toolbar', async () => {
expect(toolbar.textContent).toBe('Connecting…')
await waitFor(() => expect(toolbar.textContent).not.toBe('Connecting…'))
expect(connectWallet.textContent).toBe('Connect wallet to swap')
expect(toolbar.textContent).toBe('Connect wallet to swap')
})

it('expects widget not to be disabled', async () => {
expect(tokenSelect).toHaveProperty('disabled', true)
await waitFor(() => expect(toolbar.textContent).not.toBe('Connecting…'))
expect(tokenSelect).toHaveProperty('disabled', false)
})
})

describe('with jsonRpcEndpoint', () => {
it('prompts for wallet connection in the Wallet', async () => {
component.rerender(<SwapWidget tokenList={tokens} jsonRpcEndpoint={hardhat.url} />)
expect(wallet.hidden).toBeTruthy()
describe('with valid jsonRpcUrlMap', () => {
it('prompts for wallet connection in the Wallet and Toolbar', async () => {
component = render(<SwapWidget tokenList={tokens} jsonRpcUrlMap={{ 1: [hardhat.url] }} />)
expect(connectWallet.textContent).toBe('Connect wallet to swap')
expect(toolbar.textContent).toBe('Connecting…')
await waitFor(() => expect(toolbar.textContent).not.toBe('Connecting…'))
expect(connectWallet.textContent).toBe('Connect wallet to swap')
expect(toolbar.textContent).toBe('Connect wallet to swap')
})

it('expects widget not to be disabled', async () => {
component = render(<SwapWidget tokenList={tokens} jsonRpcUrlMap={{ 1: [hardhat.url] }} />)
expect(tokenSelect).toHaveProperty('disabled', true)
await waitFor(() => expect(toolbar.textContent).not.toBe('Connecting…'))
expect(wallet.hidden).toBeFalsy()
expect(wallet.textContent).toBe('Connect wallet to swap')
expect(toolbar.textContent).toBe('Enter an amount')
expect(tokenSelect).toHaveProperty('disabled', false)
})
})

describe('with provider', () => {
it('does not prompt for wallet connection', async () => {
component.rerender(<SwapWidget tokenList={tokens} provider={hardhat.provider} />)
expect(wallet.hidden).toBeTruthy()
describe('with wallet provider', () => {
it('displays connected account chip', async () => {
component = render(<SwapWidget tokenList={tokens} provider={hardhat.provider} />)
await waitFor(() => expect(toolbar.textContent).not.toBe('Connecting…'))
account = await component.findByTestId('account')
expect(account.textContent?.toLowerCase()).toBe(HARDHAT_ACCOUNT_DISPLAY_STRING)
})

it('does not prompt for wallet connection in toolbar', async () => {
component = render(<SwapWidget tokenList={tokens} provider={hardhat.provider} />)
expect(toolbar.textContent).toBe('Connecting…')
await waitFor(
async () => {
toolbar = (await component.findAllByTestId('toolbar'))[1]
expect(toolbar.textContent).toBe('Enter an amount')
},
{ timeout: 10000 }
)
})

it('expects widget not to be disabled', async () => {
component = render(<SwapWidget tokenList={tokens} provider={hardhat.provider} />)
expect(tokenSelect).toHaveProperty('disabled', true)
await waitFor(() => expect(toolbar.textContent).not.toBe('Connecting…'))
expect(wallet.hidden).toBeTruthy()
expect(toolbar.textContent).toBe('Enter an amount')
expect(tokenSelect).toHaveProperty('disabled', false)
})
})
})
19 changes: 11 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,14 @@
"@uniswap/token-lists": "^1.0.0-beta.30",
"@uniswap/v2-sdk": "^3.0.1",
"@uniswap/v3-sdk": "^3.8.2",
"@web3-react/core": "8.0.30-beta.0",
"@web3-react/eip1193": "8.0.23-beta.0",
"@web3-react/empty": "8.0.17-beta.0",
"@web3-react/types": "8.0.17-beta.0",
"@web3-react/url": "8.0.22-beta.0",
"@web3-react/core": "8.0.35-beta.0",
"@web3-react/eip1193": "8.0.26-beta.0",
"@web3-react/empty": "8.0.20-beta.0",
"@web3-react/metamask": "8.0.28-beta.0",
"@web3-react/network": "8.0.27-beta.0",
"@web3-react/types": "8.0.20-beta.0",
"@web3-react/url": "8.0.25-beta.0",
"@web3-react/walletconnect": "8.0.35-beta.0",
"ajv": "^6.12.3",
"cids": "^1.0.0",
"ethers": "^5.1.4",
Expand All @@ -85,6 +88,7 @@
"node-vibrant": "^3.2.1-alpha.1",
"polished": "^3.3.2",
"popper-max-size-modifier": "^0.2.0",
"qrcode": "^1.5.0",
"react-feather": "^2.0.8",
"react-popper": "^2.2.3",
"react-virtualized-auto-sizer": "^1.0.2",
Expand Down Expand Up @@ -136,7 +140,8 @@
"@types/lingui__react": "^2.8.3",
"@types/ms.macro": "^2.0.0",
"@types/multicodec": "^1.0.0",
"@types/node": "^13.13.5",
"@types/node": "^18.6.3",
"@types/qrcode": "^1.4.2",
"@types/qs": "^6.9.2",
"@types/react": "^17.0.2",
"@types/react-dom": "^17.0.1",
Expand All @@ -154,8 +159,6 @@
"@uniswap/v3-core": "1.0.0",
"@uniswap/v3-periphery": "^1.1.1",
"@walletconnect/ethereum-provider": "^1.7.1",
"@web3-react/metamask": "8.0.24-beta.0",
"@web3-react/walletconnect": "8.0.31-beta.0",
"babel-jest": "^27.5.1",
"babel-loader": "^8.2.5",
"babel-plugin-macros": "^3.1.0",
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/images/metamaskIcon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions src/assets/images/walletConnectIcon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading