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

Replace web3-react with wagmi and add seif, tailwind and compass wallet connectors #1239

Merged
merged 85 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
6a6f3e8
Add seif, tailwind and compass wallet connectors
tiagofilipenunes May 29, 2024
5389446
Adjust wallet icon width and height to 100%
tiagofilipenunes May 29, 2024
b7cbc9a
Fix build issues
tiagofilipenunes May 29, 2024
359b46e
Refactor injected wallet check
tiagofilipenunes May 29, 2024
096f5fc
Add tailwind wallet svg logo
tiagofilipenunes May 29, 2024
700cdaf
Add noConnector placeholder connector and use in tailwind, seif, and …
tiagofilipenunes May 29, 2024
5971637
Check injected wallet is not metamask for getInjectedProvider, remove…
tiagofilipenunes May 29, 2024
621cbdd
Check injected connector exists on window.ethereum. If not, redirect …
tiagofilipenunes May 29, 2024
2fec028
Update tailwind logo
tiagofilipenunes May 29, 2024
df93103
Merge branch 'main' into add-sei-wallets
tiagofilipenunes May 29, 2024
9bc4ed3
Remove eslint disable comment
tiagofilipenunes May 29, 2024
2b993ae
Replace multicall3 address by the official deployment one
tiagofilipenunes May 29, 2024
b92cd93
Update tailwind wallet connector
tiagofilipenunes Jun 3, 2024
7d367d6
Rename selectableConnection to selectedConnection to avoid confusion
tiagofilipenunes Jun 3, 2024
45120c1
Changes to web3-react
tiagofilipenunes Jun 3, 2024
18fb479
Update type in web3.constants
tiagofilipenunes Jun 3, 2024
6e0caf0
Fix config types
tiagofilipenunes Jun 4, 2024
dd70409
Replace web3-react by wagmi
tiagofilipenunes Jun 5, 2024
61c9f69
Improve useWagmi connector use
tiagofilipenunes Jun 6, 2024
f0f55e5
Fix GTM events for manual/auto connect/disconnect and swap wallet
tiagofilipenunes Jun 6, 2024
d131323
Remove walletConnect from Sei
tiagofilipenunes Jun 6, 2024
7d1729a
Use async connect and disconnect to prevent race conditions
tiagofilipenunes Jun 6, 2024
64756f6
Update tanstack query to v5
tiagofilipenunes Jun 7, 2024
2f85f07
Replace throwing error with console.error in connect and disconnect w…
tiagofilipenunes Jun 7, 2024
a64cdda
Replace default rpc url in Ethereum config
tiagofilipenunes Jun 7, 2024
5ff19f3
Throw error for wallet not connected instead of success and redirecti…
tiagofilipenunes Jun 7, 2024
14aeddf
Remove console log debug
tiagofilipenunes Jun 7, 2024
4f4a3ba
Add ens registry and universal resolver to config and populate wagmiC…
tiagofilipenunes Jun 7, 2024
3c79d2f
Move tenderly faucet params to config and add sei tenderly faucet
tiagofilipenunes Jun 7, 2024
7fb4f09
Merge branch 'main' into add-sei-wallets
tiagofilipenunes Jun 7, 2024
f76d9d1
Update connector error message
tiagofilipenunes Jun 7, 2024
b2a13a2
Rename wagmi library files
tiagofilipenunes Jun 7, 2024
545420d
Remove unused dependencies and add stream-browserify
tiagofilipenunes Jun 10, 2024
28bb7c8
Rename web3 to wagmi and removed deprecated comments
tiagofilipenunes Jun 10, 2024
94dc77e
Improve wallet connect and disconnect error handling
tiagofilipenunes Jun 10, 2024
044e11e
Add back button to restart wallet connection
tiagofilipenunes Jun 10, 2024
b9d4da8
Rename function to return on wallet connect error and move gtm specif…
tiagofilipenunes Jun 10, 2024
2450eda
Refactor and update wagmi library
tiagofilipenunes Jun 10, 2024
f2b6391
Change e2e workflow to install using lockfile
tiagofilipenunes Jun 10, 2024
b7641ce
Update e2e playwright docker version
tiagofilipenunes Jun 10, 2024
b7385f9
Revert e2e changes
tiagofilipenunes Jun 10, 2024
d6b39a3
Try installing build-essentials on e2e workflow
tiagofilipenunes Jun 10, 2024
79bb2de
Revert changes to e2e workflow
tiagofilipenunes Jun 10, 2024
0f94f08
Add allowed domains to Gnosis Safe
tiagofilipenunes Jun 10, 2024
7dae6ae
Remove use-async-effect package
tiagofilipenunes Jun 10, 2024
4f89291
Update free RPCs for Ethereum and Sei
tiagofilipenunes Jun 10, 2024
f0ee866
Remove unused exports
tiagofilipenunes Jun 10, 2024
0ad275a
Document wagmi functions
tiagofilipenunes Jun 10, 2024
9a56295
Refactor wagmi library
tiagofilipenunes Jun 10, 2024
5eef201
Fix dev mode safe connector error
tiagofilipenunes Jun 11, 2024
37a3dbc
Update node type and force vite plugin rewrite version as next one br…
tiagofilipenunes Jun 11, 2024
848f57d
Hide safe connector if not in an iframe
tiagofilipenunes Jun 11, 2024
ccf0572
Update yarn lock
tiagofilipenunes Jun 11, 2024
8fc79e9
Clean-up code
tiagofilipenunes Jun 11, 2024
511a5d1
Add install build-essential to e2e workflow
tiagofilipenunes Jun 11, 2024
888d459
Merge branch 'main' into add-sei-wallets
tiagofilipenunes Jun 11, 2024
f1301b6
[CI] Update Screenshots
tiagofilipenunes Jun 11, 2024
da0c3f8
Add check to remove placeholder connectors
tiagofilipenunes Jun 12, 2024
4d5ecf7
Merge branch 'main' into add-sei-wallets
tiagofilipenunes Jun 12, 2024
cd66fbe
[CI] Update Screenshots
tiagofilipenunes Jun 12, 2024
868bb69
Merge branch 'main' into add-sei-wallets
tiagofilipenunes Jun 13, 2024
36bac6b
[CI] Update Screenshots
tiagofilipenunes Jun 13, 2024
f83c847
Remove stream-browserify
tiagofilipenunes Jun 14, 2024
3b7a592
Use output tag
tiagofilipenunes Jun 14, 2024
03fdb26
Remove SupportedChainId and remove EnumConnectionType
tiagofilipenunes Jun 14, 2024
1d3b19f
Change WalletIcon props
tiagofilipenunes Jun 14, 2024
daad90d
Remove isImposter and pass imposterAccount
tiagofilipenunes Jun 14, 2024
6f9af5a
Remove void from useEffect in wagmi lib
tiagofilipenunes Jun 14, 2024
d308ece
Add comment to iFrame check for safe wallet
tiagofilipenunes Jun 14, 2024
b7bdb30
Change getAccount to use hook instead and get chainId directly from c…
tiagofilipenunes Jun 14, 2024
7bb56df
Return icon directly in walletIcon
tiagofilipenunes Jun 14, 2024
72f6f6b
Change utils config type
tiagofilipenunes Jun 14, 2024
5f553e7
[CI] Update Screenshots
tiagofilipenunes Jun 14, 2024
53a3ccb
Add blockedConnectors to config and use rdns instead of name to check…
tiagofilipenunes Jun 17, 2024
82f609b
Add instructions to readme for selectedConnectors and blockedConnectors
tiagofilipenunes Jun 17, 2024
92f0c8a
Fix typo in comment
tiagofilipenunes Jun 17, 2024
3bebc9d
Fix connection on error clean-up and attempt to disconnect connector
tiagofilipenunes Jun 17, 2024
8e62723
Merge branch 'main' into add-sei-wallets
tiagofilipenunes Jun 17, 2024
9989a48
Fix merge changes:
tiagofilipenunes Jun 17, 2024
4d690a1
Set lazy loading and change alt text
tiagofilipenunes Jun 18, 2024
59df230
Remove unnecessary useMemo and useCallback, replace imposter useCallb…
tiagofilipenunes Jun 18, 2024
f1224bb
Merge branch 'main' into add-sei-wallets
tiagofilipenunes Jun 18, 2024
dc5d87d
[CI] Update Screenshots
tiagofilipenunes Jun 18, 2024
ccf265d
Merge branch 'main' into add-sei-wallets
tiagofilipenunes Jun 18, 2024
f38be59
[CI] Update Screenshots
tiagofilipenunes Jun 18, 2024
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
19 changes: 11 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@playwright/test": "^1.43.1",
"@sentry/react": "^7.48.0",
"@sentry/vite-plugin": "^0.7.2",
"@tailwindzone/connect-web3-react": "^1.0.0",
"@tanstack/react-query": "^4.14.5",
"@tanstack/react-query-devtools": "^4.14.5",
"@tanstack/react-router": "^1.4.9",
Expand All @@ -37,13 +38,15 @@
"@typescript-eslint/parser": "^5.59.9",
"@vitejs/plugin-react": "^3.1.0",
"@walletconnect/ethereum-provider": "^2.9.2",
"@web3-react/coinbase-wallet": "8.2.2",
"@web3-react/core": "8.2.2",
"@web3-react/gnosis-safe": "8.2.3",
"@web3-react/metamask": "8.2.3",
"@web3-react/network": "8.2.2",
"@web3-react/types": "8.2.2",
"@web3-react/walletconnect-v2": "^8.5.0",
"@web3-react/coinbase-wallet": "8.2.3",
"@web3-react/core": "8.2.3",
"@web3-react/eip1193": "8.2.3",
"@web3-react/empty": "^8.2.3",
"@web3-react/gnosis-safe": "8.2.4",
"@web3-react/metamask": "8.2.4",
"@web3-react/network": "8.2.3",
"@web3-react/types": "8.2.3",
"@web3-react/walletconnect-v2": "8.5.1",
"autoprefixer": "^10.4.12",
"body-scroll-lock": "^4.0.0-beta.0",
"buffer": "^6.0.3",
Expand Down Expand Up @@ -127,4 +130,4 @@
"devDependencies": {
"@types/d3": "^7.4.3"
}
}
}
8 changes: 8 additions & 0 deletions src/assets/logos/compassWallet.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions src/assets/logos/seifWallet.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions src/assets/logos/tailwindWallet.svg
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/components/core/menu/mainMenu/MainMenuRightWallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { ReactComponent as IconWallet } from 'assets/icons/wallet.svg';
import { ReactComponent as IconWarning } from 'assets/icons/warning.svg';
import { ReactComponent as IconCopy } from 'assets/icons/copy.svg';
import { ReactComponent as IconCoinbaseLogo } from 'assets/logos/coinbase.svg';
import { ReactComponent as IconCompassWalletLogo } from 'assets/logos/compassWallet.svg';
import { ReactComponent as IconTailwindWalletLogo } from 'assets/logos/tailwindWallet.svg';
import { ReactComponent as IconSeifWalletLogo } from 'assets/logos/seifWallet.svg';
import { ReactComponent as IconGnosisLogo } from 'assets/logos/gnosis.svg';
import { ReactComponent as IconImposterLogo } from 'assets/logos/imposter.svg';
import { ReactComponent as IconMetaMaskLogo } from 'assets/logos/metamask.svg';
Expand Down Expand Up @@ -39,6 +42,12 @@ const WalletIcon = ({ isImposter }: { isImposter: boolean }) => {
return <IconCoinbaseLogo {...iconProps} />;
case 'gnosisSafe':
return <IconGnosisLogo {...iconProps} />;
case 'tailwindWallet':
return <IconTailwindWalletLogo {...iconProps} />;
case 'compassWallet':
return <IconCompassWalletLogo {...iconProps} />;
case 'seifWallet':
return <IconSeifWalletLogo {...iconProps} />;
default:
return <IconWallet {...iconProps} />;
}
Expand Down
10 changes: 8 additions & 2 deletions src/config/sei/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ export const commonConfig: AppConfig = {
mode: 'development',
appUrl: 'https://sei.carbondefi.xyz',
carbonApi: 'https://sei-api.carbondefi.xyz/v1/',
selectableConnectionTypes: ['injected', 'coinbaseWallet'],
selectableConnectionTypes: [
'injected',
'coinbaseWallet',
'tailwindWallet',
'compassWallet',
'seifWallet',
],
walletConnectProjectId: '',
isSimulatorEnabled: false,
policiesLastUpdated: '27 May, 2024',
Expand Down Expand Up @@ -49,7 +55,7 @@ export const commonConfig: AppConfig = {
voucher: '0xA4682A2A5Fe02feFF8Bd200240A41AD0E6EaF8d5',
},
utils: {
multicall: '0xe033Bed7cae4114Af84Be1e9F1CA7DEa07Dfe1Cf',
multicall: '0xcA11bde05977b3631167028862bE2a173976CA11',
},
},
tokenListOverride: [
Expand Down
34 changes: 34 additions & 0 deletions src/libs/web3/noconnector.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Actions, Connector } from '@web3-react/types';
tiagofilipenunes marked this conversation as resolved.
Show resolved Hide resolved

export interface NoConnectorArgs {
actions: Actions;
name: string;
url: string;
}

export class NoConnectorError extends Error {
public constructor(name: string) {
super(`${name} not installed, redirecting to website...`);
this.name = NoConnectorError.name;
Object.setPrototypeOf(this, NoConnectorError.prototype);
tiagofilipenunes marked this conversation as resolved.
Show resolved Hide resolved
}
}

export class NoConnector extends Connector {
/** {@inheritdoc Connector.provider} */
public declare readonly provider: undefined;
tiagofilipenunes marked this conversation as resolved.
Show resolved Hide resolved
name: string;
url: string;

constructor({ actions, name, url }: NoConnectorArgs) {
super(actions);
this.name = name;
this.url = url;
}
public activate() {
setTimeout(() => {
window.open(this.url, '_blank');
}, 3000);
throw new NoConnectorError(this.name);
}
}
119 changes: 108 additions & 11 deletions src/libs/web3/web3.connectors.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
import { StaticJsonRpcProvider } from '@ethersproject/providers';
import { initializeConnector } from '@web3-react/core';
import { CoinbaseWallet } from '@web3-react/coinbase-wallet';
import { EIP1193 } from '@web3-react/eip1193';
import { MetaMask } from '@web3-react/metamask';
import { WalletConnect } from '@web3-react/walletconnect-v2';
import { Network } from '@web3-react/network';
import { GnosisSafe } from '@web3-react/gnosis-safe';
import { CoinbaseWallet } from '@web3-react/coinbase-wallet';
import {
RPC_HEADERS,
RPC_URLS,
SupportedChainId,
} from 'libs/web3/web3.constants';
import { Connection } from 'libs/web3/web3.types';
import { TailwindConnector } from '@tailwindzone/connect-web3-react';
import iconMetaMask from 'assets/logos/metamask.svg';
import iconWalletConnect from 'assets/logos/walletConnect.svg';
import iconCoinbase from 'assets/logos/coinbase.svg';
import iconTailwindWallet from 'assets/logos/tailwindWallet.svg';
import iconCompassWallet from 'assets/logos/compassWallet.svg';
import iconSeifWallet from 'assets/logos/seifWallet.svg';
import iconGnosis from 'assets/logos/gnosis.svg';
import carbonLogo from 'assets/logos/carbon.svg';
import { StaticJsonRpcProvider } from '@ethersproject/providers';
import config from 'config';
import {
RPC_HEADERS,
RPC_URLS,
SupportedChainId,
} from 'libs/web3/web3.constants';
import { Connection } from 'libs/web3/web3.types';
import { getInjectedProvider } from 'libs/web3/web3.utils';
import { NoConnector } from 'libs/web3/noconnector';

const onError = (error: Error) => {
console.debug(`web3-react error: ${error}`);
Expand Down Expand Up @@ -52,9 +59,18 @@ export const networkConnection: Connection = {
// INJECTED CONNECTOR
// ********************************** //

const [web3Injected, web3InjectedHooks] = initializeConnector<MetaMask>(
(actions) => new MetaMask({ actions, onError })
);
const [web3Injected, web3InjectedHooks] = getInjectedProvider('ethereum')
tiagofilipenunes marked this conversation as resolved.
Show resolved Hide resolved
? initializeConnector<MetaMask>(
tiagofilipenunes marked this conversation as resolved.
Show resolved Hide resolved
(actions) => new MetaMask({ actions, onError })
)
: initializeConnector<NoConnector>(
(actions) =>
new NoConnector({
actions,
name: 'Metamask',
url: 'https://metamask.io/',
})
);
export const injectedConnection: Connection = {
connector: web3Injected,
hooks: web3InjectedHooks,
Expand Down Expand Up @@ -136,3 +152,84 @@ export const coinbaseWalletConnection: Connection = {
name: 'Coinbase Wallet',
logoUrl: iconCoinbase,
};

// ********************************** //
// Tailwind WALLET CONNECTOR
// ********************************** //

const [web3TailwindWallet, web3TailwindWalletHooks] =
initializeConnector<TailwindConnector>(
(actions) => new TailwindConnector({ actions })
);

export const tailwindWalletConnection: Connection = {
connector: web3TailwindWallet,
hooks: web3TailwindWalletHooks,
type: 'tailwindWallet',
name: 'Tailwind Wallet',
logoUrl: iconTailwindWallet,
};

// ********************************** //
// Compass WALLET CONNECTOR
// ********************************** //

export const [web3CompassWallet, web3CompassWalletHooks] = getInjectedProvider(
tiagofilipenunes marked this conversation as resolved.
Show resolved Hide resolved
'compassEvm',
'isCompassWallet'
)
? initializeConnector<EIP1193>(
(actions) =>
new EIP1193({
actions,
provider: getInjectedProvider('compassEvm', 'isCompassWallet'),
})
)
: initializeConnector<NoConnector>(
(actions) =>
new NoConnector({
actions,
name: 'Compass Wallet',
url: 'https://compasswallet.io/',
})
);

export const compassWalletConnection: Connection = {
connector: web3CompassWallet,
hooks: web3CompassWalletHooks,
type: 'compassWallet',
name: 'Compass Wallet',
logoUrl: iconCompassWallet,
};

// ********************************** //
// Seif WALLET CONNECTOR
// ********************************** //

export const [web3SeifWallet, web3SeifWalletHooks] = getInjectedProvider(
'__seif',
'__seif'
)
? initializeConnector<EIP1193>(
(actions) =>
new EIP1193({
actions,
provider: getInjectedProvider('__seif', '__seif'),
})
)
: initializeConnector<NoConnector>(
(actions) =>
new NoConnector({
actions,
name: 'Seif Wallet',
url: 'https://seif.passkeywallet.com/',
})
);

export const seifWalletConnection: Connection = {
connector: web3SeifWallet,
hooks: web3SeifWalletHooks,
type: 'seifWallet',
name: 'Seif Wallet',
logoUrl: iconSeifWallet,
};
5 changes: 4 additions & 1 deletion src/libs/web3/web3.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ export type selectableConnectionType =
| 'injected'
| 'walletConnect'
| 'coinbaseWallet'
| 'gnosisSafe';
| 'gnosisSafe'
| 'tailwindWallet'
| 'compassWallet'
| 'seifWallet';

export type ConnectionType = 'network' | selectableConnectionType;

Expand Down
29 changes: 28 additions & 1 deletion src/libs/web3/web3.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import {
injectedConnection,
networkConnection,
walletConnectConnection,
tailwindWalletConnection,
compassWalletConnection,
seifWalletConnection,
} from 'libs/web3/web3.connectors';
import { lsService } from 'services/localeStorage';
import { UAParser } from 'ua-parser-js';
Expand All @@ -16,6 +19,28 @@ const { type } = parser.getDevice();

export const isMobile = type === 'mobile' || type === 'tablet';

/**
* Get the injected wallet provider in window
* Returns window.ethereum if window.ethereum exists, window.ethereum[flag], is true and window.ethereum is not metamask
* Otherwise, returns window[walletObject]
*
* @param flag name of the flag in window.ethereum to check. If undefined, will not check this flag and default to walletObject
* @param walletObject name of the object in window that the injected provider will populate
* @returns Injected provider in wallet or undefined if not present
*/
export function getInjectedProvider(walletObject: string, flag?: string) {
tiagofilipenunes marked this conversation as resolved.
Show resolved Hide resolved
if (typeof window === 'undefined') return;
if (window.ethereum && flag && (window as any).ethereum[flag]) {
return window.ethereum;
}

if ((window as any)[walletObject]) {
return (window as any)[walletObject];
}

return;
}

// Interface to add new chain to injected wallets as per EIP-3085 (https://github.com/ethereum/EIPs/blob/master/EIPS/eip-3085.md)
export interface AddChainParameter {
chainId: number; // EIP-3085 specifies hex string but web3-react expects number
Expand All @@ -29,7 +54,6 @@ export interface AddChainParameter {
blockExplorerUrls?: string[];
iconUrls?: string[];
}

export const getChainInfo = (): AddChainParameter => {
return {
chainId: config.network.chainId,
Expand All @@ -51,6 +75,9 @@ const connections: Record<ConnectionType, Connection> = {
walletConnect: walletConnectConnection,
gnosisSafe: gnosisSafeConnection,
network: networkConnection,
tailwindWallet: tailwindWalletConnection,
compassWallet: compassWalletConnection,
seifWallet: seifWalletConnection,
};

export const getConnection = (c: ConnectionType) => connections[c];
Expand Down
Loading
Loading