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

🦊🐺🐭 Add connectors #754

Closed
wants to merge 106 commits into from
Closed
Show file tree
Hide file tree
Changes from 92 commits
Commits
Show all changes
106 commits
Select commit Hold shift + click to select a range
475c84a
Add context
dmaretskyi May 11, 2022
f59899b
Merge remote-tracking branch 'origin/master' into dmaretskyi/connectors
May 17, 2022
048c972
Add connector logic and exports
May 18, 2022
f883491
Add connector example
May 18, 2022
75f986a
Add wallet connect example
May 18, 2022
bd54c05
Apply stash changes
Jun 27, 2022
84e8a55
Update depedencies
Jun 27, 2022
c17beb4
Merge branch 'master' into HEAD
Jun 27, 2022
7873f43
Remove ethers/providers
Jun 27, 2022
4e8dc7f
Merge branch 'dmaretskyi/connectors' of https://github.com/TrueFiEng/…
Jun 27, 2022
ef2490f
Fix lint
Jun 27, 2022
520287b
Fix lint
Jun 27, 2022
9f6f1f7
Merge branch 'master' into dmaretskyi/connectors
Jun 28, 2022
5b77f2a
Apply connector rebase
Jun 29, 2022
7c93e36
Remove transaction blocker
Jun 30, 2022
7208448
Merge branch 'master' into dmaretskyi/connectors
mj426382 Jun 30, 2022
b13347a
Merge branch 'master' into dmaretskyi/connectors
mj426382 Jul 5, 2022
1a13f3d
Add metamask by default
Jul 5, 2022
a7ac27c
Add testing wallet
Jul 6, 2022
0e88662
Add coinbase and portis connectors
Jul 6, 2022
a2b48cc
Merge branch 'dmaretskyi/connectors' of https://github.com/TrueFiEng/…
Jul 6, 2022
ebadd12
Add fortmatic wallet
Jul 7, 2022
f5ce29d
Add torus connector
Jul 7, 2022
f067124
Add brave and injected connectors
Jul 8, 2022
d80c170
Merge origin/master into dmaretskyi/connectors
rzadp Jul 13, 2022
e39343b
premerge
rzadp Jul 13, 2022
42b602c
Merge origin/master into dmaretskyi/connectors
rzadp Jul 13, 2022
76dcbdd
postmerge
rzadp Jul 13, 2022
0e2e45f
Remove types from deps
rzadp Jul 13, 2022
47cd9a9
Merge origin/master into dmaretskyi/connectors
rzadp Jul 13, 2022
0f2357b
Clean up a bit
yivlad Jul 15, 2022
7c282fc
Remov some wallets
yivlad Jul 15, 2022
ecc9f72
Debugging tests
yivlad Jul 15, 2022
b551f49
Merge branch 'master' into dmaretskyi/connectors
yivlad Jul 22, 2022
9c786dc
WIP
yivlad Jul 27, 2022
29b76e8
Add readonly provider as default
yivlad Jul 27, 2022
620761b
Green tests
yivlad Jul 27, 2022
c65cf20
Lint
yivlad Jul 27, 2022
09a3d2f
Green playwright tests
yivlad Jul 28, 2022
af7a59f
Lint
yivlad Jul 28, 2022
ecc4328
Merge remote-tracking branch 'origin/master' into dmaretskyi/connectors
yivlad Jul 28, 2022
2f1d594
Lint
yivlad Jul 28, 2022
feb07ab
Update tests
yivlad Jul 28, 2022
243cb46
Record example tests
yivlad Jul 29, 2022
170494e
Revert "Record example tests"
yivlad Jul 29, 2022
ad36415
Test ambire availability
yivlad Jul 29, 2022
13a343e
Bringa back playwright tests
yivlad Jul 29, 2022
f36cad8
Upload screenshot
yivlad Jul 29, 2022
9ca2988
Debug CI
yivlad Jul 29, 2022
4c43d06
Fix screenshot paths
yivlad Jul 29, 2022
4463cd5
Fix path again
yivlad Jul 29, 2022
b975f02
Wait for ambire page to show up
yivlad Jul 29, 2022
22710ce
Wait also for metamask page
yivlad Jul 29, 2022
c99be0a
Remove debugging stuff
yivlad Jul 29, 2022
bae12a6
Lint
yivlad Jul 29, 2022
892ba36
Start fixing example-next
yivlad Jul 29, 2022
80b7b36
Fix next playwright tests
yivlad Jul 29, 2022
0ae8081
Debgging swithicng chains
yivlad Aug 1, 2022
285034a
Fix docs tests
yivlad Aug 2, 2022
c265a72
Lint
yivlad Aug 2, 2022
f6d4ba4
Merge remote-tracking branch 'origin/master' into dmaretskyi/connectors
yivlad Aug 2, 2022
ca7481a
Lint
yivlad Aug 2, 2022
4a82820
Check websocket provider
yivlad Aug 2, 2022
4bb5a6f
Fix timestamp overflow
yivlad Aug 3, 2022
749b6e5
Lint
yivlad Aug 3, 2022
a5f4080
Merge remote-tracking branch 'origin/master' into dmaretskyi/connectors
yivlad Aug 3, 2022
3d96f46
Merge remote-tracking branch 'origin/master' into dmaretskyi/connectors
yivlad Aug 3, 2022
f1c3d0e
Add test for switching accounts
yivlad Aug 5, 2022
bcb853e
Fix no multicall address error
yivlad Aug 8, 2022
de83617
Add logs
yivlad Aug 8, 2022
1c9255c
Fix change account issue
yivlad Aug 8, 2022
6397824
Lint
yivlad Aug 8, 2022
6778dbc
Merge remote-tracking branch 'origin/master' into dmaretskyi/connectors
yivlad Aug 8, 2022
18cc041
Fix test order
yivlad Aug 8, 2022
7015a80
Merge remote-tracking branch 'origin/master' into dmaretskyi/connectors
yivlad Aug 8, 2022
7da9027
Fix next tests
yivlad Aug 8, 2022
6ed9b2b
Fix ethers version mismatch
yivlad Aug 8, 2022
48c4869
Docs add timeout to playwright tests
yivlad Aug 8, 2022
1a959e2
deactivate function for connectors
yivlad Aug 9, 2022
670ef69
Example app add local provider only when testing
yivlad Aug 10, 2022
5640226
Fix coinabse wallet
yivlad Aug 10, 2022
cdcd19e
Bring bakc portis connector
yivlad Aug 10, 2022
16e599f
Lint
yivlad Aug 10, 2022
cdeb200
Reimplement polling interval logic
yivlad Aug 10, 2022
9cb87ac
Lint
yivlad Aug 10, 2022
9988309
USe typed events
yivlad Aug 10, 2022
e2d1db3
Don't use setImmediate
yivlad Aug 10, 2022
53e1c6d
Add apiNode connector
yivlad Aug 11, 2022
9dce9aa
Merge remote-tracking branch 'origin/master' into dmaretskyi/connectors
yivlad Aug 11, 2022
aa7f725
Extract connectors to separate packages
yivlad Aug 11, 2022
02384ef
Set workspace dependecies properly
yivlad Aug 11, 2022
7ec4870
Fix CI
yivlad Aug 11, 2022
d55c53c
WIP
yivlad Aug 12, 2022
6ea9884
Make all tests green
yivlad Aug 17, 2022
05da578
Fix wallet provider non static calls tracking
yivlad Aug 17, 2022
8934edd
clear local storage
yivlad Aug 18, 2022
a38f556
Merge remote-tracking branch 'origin/master' into dmaretskyi/connectors
yivlad Aug 18, 2022
d7a908d
Upgrade waffle
yivlad Aug 18, 2022
5fe407a
Delete tokens playwright tests
yivlad Aug 18, 2022
fda2c65
Fix playwright tests
yivlad Aug 18, 2022
1d830a3
Fix localStorage issue
yivlad Aug 19, 2022
e55fbca
Fix playwright tests
yivlad Aug 22, 2022
369ebde
Merge remote-tracking branch 'origin/master' into dmaretskyi/connectors
yivlad Aug 22, 2022
ee7d95d
Add transfer funds test
yivlad Aug 22, 2022
a6b375b
Lint
yivlad Aug 22, 2022
1c2582b
Make useEthers API backwards-compatible
yivlad Aug 22, 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
17 changes: 10 additions & 7 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,31 +36,34 @@ jobs:
- name: Build dependencies
run: |
set -e
cd core && pnpm run build && cd -
cd testing && pnpm run build && cd -
cd siwe && pnpm run build && cd -
cd coingecko && pnpm run build && cd -
cd playwright && pnpm run build && cd -
cd example && pnpm run build && cd -
pnpm run build
working-directory: packages
- name: Run playwright example
run: |
set -e
pnpm start &
LOCALHOST_URL='http://localhost:8545' pnpm start &
xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- pnpm test:playwright
env:
MAINNET_URL: ${{ secrets.MAINNET_PROVIDER_URL }}
DEBUG: usedapp*
working-directory: packages/example
- name: Run playwright example-next
# echo "NEXT_PUBLIC_LOCALHOST_URL=http://localhost:8545" > .env.local - couln't figure out how to set env variable the same as in previous section
yivlad marked this conversation as resolved.
Show resolved Hide resolved
run: |
set -e
echo "NEXT_PUBLIC_LOCALHOST_URL=http://localhost:8545" > .env.local
echo "NEXT_PUBLIC_MAINNET_URL=${MAINNET_URL}" >> .env.local
pnpm dev &
xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- pnpm test:playwright
env:
MAINNET_URL: ${{ secrets.MAINNET_PROVIDER_URL }}
DEBUG: usedapp*
working-directory: packages/example-next
- name: Cleanup
if: always()
run: |
rm -rf .env.local
working-directory: packages/example-next
test-docs:
runs-on: ubuntu-latest
timeout-minutes: 25
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
},
"dependencies": {
"@changesets/cli": "^2.14.1",
"ethers": "5.6.2",
"ethers": "5.6.9",
"prettier": "2.1.2",
"wsrun": "^5.2.1"
},
"resolutions": {
"ethers": "5.6.2"
"ethers": "5.6.9"
},
"devDependencies": {
"eslint-plugin-no-only-tests": "^2.6.0"
Expand Down
1 change: 1 addition & 0 deletions packages/connectors/coinbase-wallet/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# CoinbaseWalletConnector for useDApp
25 changes: 25 additions & 0 deletions packages/connectors/coinbase-wallet/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "@usedapp/coinbase-connector",
"version": "0.0.1",
"main": "dist/src/index.js",
"types": "dist/src/index.d.ts",
"repository": "git@github.com:EthWorks/useDApp.git",
"author": "Ethworks",
"license": "MIT",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@usedapp/core": "workspace:*",
yivlad marked this conversation as resolved.
Show resolved Hide resolved
"@coinbase/wallet-sdk": "^3.3.0"
},
"devDependencies": {
"typescript": "^4.6.2"
},
"scripts": {
"build": "tsc",
"test": "true",
"lint": "true",
"lint:fix": "true"
}
}
1 change: 1 addition & 0 deletions packages/connectors/coinbase-wallet/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { CoinbaseWalletConnector } from '@usedapp/core/dist/cjs/src/providers/network/connector/impls/coinbaseWallet'
21 changes: 21 additions & 0 deletions packages/connectors/coinbase-wallet/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"extends": "../../../tsconfig.json",
"compilerOptions": {
"outDir": "dist",
"module": "commonjs",
"composite": true,
"declaration": true,
"sourceMap": true,
"declarationMap": true,
"resolveJsonModule": true,
"skipLibCheck": true
},
"include": [
"src"
],
"references": [
{
"path": "../../core"
}
]
}
1 change: 1 addition & 0 deletions packages/connectors/portis/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# PortisConnector for useDApp
25 changes: 25 additions & 0 deletions packages/connectors/portis/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "@usedapp/portis-connector",
"version": "0.0.1",
"main": "dist/src/index.js",
"types": "dist/src/index.d.ts",
"repository": "git@github.com:EthWorks/useDApp.git",
"author": "Ethworks",
"license": "MIT",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@usedapp/core": "workspace:*",
yivlad marked this conversation as resolved.
Show resolved Hide resolved
"@portis/web3": "^4.0.7"
},
"devDependencies": {
"typescript": "^4.6.2"
},
"scripts": {
"build": "tsc",
"test": "true",
"lint": "true",
"lint:fix": "true"
}
}
1 change: 1 addition & 0 deletions packages/connectors/portis/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { PortisConnector } from '@usedapp/core/dist/cjs/src/providers/network/connector/impls/portis'
21 changes: 21 additions & 0 deletions packages/connectors/portis/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"extends": "../../../tsconfig.json",
"compilerOptions": {
"outDir": "dist",
"module": "commonjs",
"composite": true,
"declaration": true,
"sourceMap": true,
"declarationMap": true,
"resolveJsonModule": true,
"skipLibCheck": true
},
"include": [
"src"
],
"references": [
{
"path": "../../core"
}
]
}
1 change: 1 addition & 0 deletions packages/connectors/wallet-connect/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# WalletConnectConnector for useDApp
25 changes: 25 additions & 0 deletions packages/connectors/wallet-connect/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "@usedapp/wallet-connect-connector",
"version": "0.0.1",
"main": "dist/src/index.js",
"types": "dist/src/index.d.ts",
"repository": "git@github.com:EthWorks/useDApp.git",
"author": "Ethworks",
"license": "MIT",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@usedapp/core": "workspace:*",
yivlad marked this conversation as resolved.
Show resolved Hide resolved
"@walletconnect/web3-provider": "^1.7.8"
},
"devDependencies": {
"typescript": "^4.6.2"
},
"scripts": {
"build": "tsc",
"test": "true",
"lint": "true",
"lint:fix": "true"
}
}
1 change: 1 addition & 0 deletions packages/connectors/wallet-connect/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { WalletConnectConnector } from '@usedapp/core/dist/cjs/src/providers/network/connector/impls/walletConnect'
21 changes: 21 additions & 0 deletions packages/connectors/wallet-connect/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"extends": "../../../tsconfig.json",
"compilerOptions": {
"outDir": "dist",
"module": "commonjs",
"composite": true,
"declaration": true,
"sourceMap": true,
"declarationMap": true,
"resolveJsonModule": true,
"skipLibCheck": true
},
"include": [
"src"
],
"references": [
{
"path": "../../core"
}
]
}
24 changes: 21 additions & 3 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,24 @@
},
"peerDependencies": {
"ethers": "*",
"react": "*"
"react": "*",
"@coinbase/wallet-sdk": "*",
"@walletconnect/web3-provider": "*",
"@portis/web3": "*"
},
"peerDependenciesMeta": {
"@coinbase/wallet-sdk": {
"optional": true
},
"@walletconnect/web3-provider": {
"optional": true
},
"@portis/web3": {
"optional": true
}
},
"devDependencies": {
"@walletconnect/types": "^1.7.8",
"@ethersproject/abi": "5.6.1",
"@ethersproject/abstract-provider": "^5.6.1",
"@ethersproject/providers": "5.6.2",
Expand All @@ -49,7 +64,7 @@
"eslint": "7.22.0",
"eslint-plugin-react-hooks": "^4.3.0",
"ethereum-waffle": "4.0.0-alpha.27",
"ethers": "^5.6.8",
"ethers": "5.6.9",
"ganache": "7.0.3",
"jsdom": "^16.4.0",
"jsdom-global": "^3.0.2",
Expand All @@ -61,7 +76,10 @@
"ts-node": "^10.7.0",
"typechain": "^7.0.0",
"typescript": "^4.6.2",
"wait-for-expect": "^3.0.2"
"wait-for-expect": "^3.0.2",
"@coinbase/wallet-sdk": "^3.3.0",
"@walletconnect/web3-provider": "^1.7.8",
"@portis/web3": "^4.0.7"
},
"scripts": {
"build": "yarn run build:esm && yarn run build:cjs && yarn build:cli",
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/constants/type/Config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Chain } from '../../constants'
import { Connector } from '../../providers/network/connector/connector'
import { providers } from 'ethers'

export type BaseProviderFactory = () => providers.BaseProvider
Expand Down Expand Up @@ -89,6 +90,7 @@ export type FullConfig = {
* Enables reconnecting to last used provider when user revisits the page.
*/
autoConnect: boolean
connectors: Connector[]
/**
* Refresh standard calls each time the n-th block is mined.
*/
Expand Down
28 changes: 12 additions & 16 deletions packages/core/src/helpers/eip1193.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,33 @@
import { EventEmitter } from 'events'
import { Network } from '../providers'
import { ConnectorController } from '../providers/network/connector/connectorController'

export function subscribeToProviderEvents(
provider: EventEmitter | undefined,
onUpdate: (updatedNetwork: Partial<Network>) => void,
onDisconnect: (error: Error) => void,
onChainChanged?: (newChainId: number) => void
) {
export function subscribeToProviderEvents(connector: ConnectorController) {
const provider: EventEmitter | undefined = (connector.getProvider() as any).provider
if (provider?.on) {
const onConnectListener = (info: { chainId: string } | undefined): void => {
if (info?.chainId) {
onUpdate({ chainId: Number(info.chainId) })
}
const onConnectListener = (): void => {
void connector.connector.activate()
}
provider.on('connect', onConnectListener)

const onDisconnectListener = (error: any): void => {
onDisconnect(new Error(error))
const onDisconnectListener = (): void => {
void connector.connector.deactivate()
}
provider.on('disconnect', onDisconnectListener)

const onChainChangedListener = (chainId: string): void => {
onChainChanged?.(Number(chainId))
onUpdate({ chainId: Number(chainId) })
void connector.connector.onUpdate?.({ chainId: parseInt(chainId), accounts: connector.accounts })
}
provider.on('chainChanged', onChainChangedListener)

const onAccountsChangedListener = (accounts: string[]): void => {
onUpdate({ accounts })
void connector.connector.onUpdate?.({ chainId: connector.chainId, accounts })
}
provider.on('accountsChanged', onAccountsChangedListener)

return () => {
if (connector.connector.name === 'Fortmatic') {
return
}
provider.removeListener('connect', onConnectListener)
provider.removeListener('disconnect', onDisconnectListener)
provider.removeListener('chainChanged', onChainChangedListener)
Expand Down
Loading