Skip to content

Commit

Permalink
Merge pull request #1239 from bancorprotocol/add-sei-wallets
Browse files Browse the repository at this point in the history
Replace web3-react with wagmi and add seif, tailwind and compass wallet connectors
  • Loading branch information
tiagofilipenunes authored Jun 19, 2024
2 parents 0c7eb38 + f38be59 commit 88b1e5a
Show file tree
Hide file tree
Showing 153 changed files with 2,910 additions and 2,036 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ jobs:
- uses: actions/setup-node@v4
with:
node-version: 20
- name: Install build-essential
run: apt-get update && apt-get install -y build-essential
- name: Install dependencies
run: yarn
- name: Install Playwright browsers and run Playwright tests
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ The file `common.ts` with type [`AppConfig`](src/config/types.ts) contains impor
- `appUrl`: The URL of the app.
- `carbonApi`: The URL of the API.
- `walletConnectProjectId`: The WalletConnect project ID If you wish to add walletConnect, make sure to add it to `selectableConnectionTypes` as well.
- `selectableConnectionTypes`: List of available connection types to be used in the wallet selection modal.
- `selectedConnectors`: List of connectors to make available by default in the wallet selection modal that will be shown even if the connector is not injected.
- `blockedConnectors`: List of EIP-6963 injected connectors names to block in the wallet selection modal.
- `isSimulatorEnabled`: Flag to enable the simulation page.
- `network`
- `name`: Network name.
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.
23 changes: 8 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@
"@babel/core": "^7.0.0-0",
"@bancor/carbon-sdk": "^0.0.97-DEV",
"@cloudflare/workers-types": "^4.20230717.0",
"@coinbase/wallet-sdk": "^3.6.3",
"@ethersproject/abi": "^5.0.0",
"@ethersproject/bytes": "^5.0.0",
"@ethersproject/providers": "^5.7.1",
"@floating-ui/react": "^0.25.4",
"@playwright/test": "^1.43.1",
"@sentry/react": "^7.48.0",
"@sentry/vite-plugin": "^0.7.2",
"@tanstack/react-query": "^4.14.5",
"@tanstack/react-query-devtools": "^4.14.5",
"@tanstack/react-query": "^5.40.1",
"@tanstack/react-query-devtools": "^5.40.1",
"@tanstack/react-router": "^1.4.9",
"@tanstack/react-table": "^8.9.3",
"@tanstack/react-virtual": "^3.0.0-beta.30",
Expand All @@ -28,22 +27,14 @@
"@typechain/ethers-v5": "^10.1.0",
"@types/body-scroll-lock": "^3.1.0",
"@types/lodash": "4.14.191",
"@types/node": "^16.7.13",
"@types/node": "^20.0.0",
"@types/numeral": "^2.0.2",
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0",
"@types/ua-parser-js": "^0.7.36",
"@typescript-eslint/eslint-plugin": "^5.59.9",
"@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",
"autoprefixer": "^10.4.12",
"body-scroll-lock": "^4.0.0-beta.0",
"buffer": "^6.0.3",
Expand Down Expand Up @@ -74,6 +65,7 @@
"lint-staged": "^14.0.1",
"lodash": "^4.17.21",
"lz-string": "^1.5.0",
"mipd": "^0.0.7",
"numbro": "^2.3.6",
"numeral": "^2.0.6",
"postcss": "^8.4.31",
Expand All @@ -88,13 +80,14 @@
"typechain": "^8.1.0",
"typescript": "^5.3.3",
"ua-parser-js": "^1.0.35",
"use-async-effect": "^2.2.7",
"valibot": "^0.28.1",
"viem": "2.x",
"vite": "5.0.13",
"vite-plugin-rewrite-all": "^1.0.1",
"vite-plugin-rewrite-all": "1.0.1",
"vite-plugin-svgr": "^2.4.0",
"vite-tsconfig-paths": "^4.2.1",
"vitest": "^0.29.8",
"wagmi": "2.9.10",
"web-vitals": "^2.1.0"
},
"scripts": {
Expand Down Expand Up @@ -127,4 +120,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.
2 changes: 1 addition & 1 deletion src/components/activity/ActivityProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const ActivityProvider: FC<Props> = ({ children, params, empty }) => {
user: params.ownerId,
});

if (activityQuery.isLoading || userStrategiesQuery.isLoading) {
if (activityQuery.isPending || userStrategiesQuery.isPending) {
return <CarbonLogoLoading className="w-[100px] flex-1 self-center" />;
}
const activities = activityQuery.data ?? [];
Expand Down
8 changes: 4 additions & 4 deletions src/components/activity/useActivityNotifiction.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { useWeb3 } from 'libs/web3';
import { useWagmi } from 'libs/wagmi';
import { useActivityQuery } from './useActivityQuery';
import { useEffect, useState } from 'react';
import { useNotifications } from 'hooks/useNotifications';

export const useActivityNotifications = () => {
const { user } = useWeb3();
const { user } = useWagmi();
const [previousUser, setPreviousUser] = useState<string | null>(null);
const [previous, setPrevious] = useState<number | null>(null);
const query = useActivityQuery({ ownerId: user });
Expand All @@ -15,7 +15,7 @@ export const useActivityNotifications = () => {
const { dispatchNotification } = useNotifications();

useEffect(() => {
if (query.isLoading) return;
if (query.isPending) return;
// We need to keep this in the same useEffect to force re-evaluate previous in next render
if (user && user !== previousUser) {
setPreviousUser(user);
Expand All @@ -35,7 +35,7 @@ export const useActivityNotifications = () => {
buyOrSell,
dispatchNotification,
previous,
query.isLoading,
query.isPending,
previousUser,
user,
]);
Expand Down
16 changes: 7 additions & 9 deletions src/components/activity/useActivityQuery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,17 @@ const isValidParams = (params: QueryActivityParams) => {
};

export const useActivityQuery = (params: QueryActivityParams = {}) => {
const { tokensMap, isLoading } = useTokens();
const { tokensMap, isPending } = useTokens();
const validParams = isValidParams(params);
return useQuery(
QueryKey.activities(params),
async () => {
return useQuery({
queryKey: QueryKey.activities(params),
queryFn: async () => {
const activities = await carbonApi.getActivity(params);
return toActivities(activities, tokensMap).sort((a, b) => {
return b.date.getTime() - a.date.getTime();
});
},
{
enabled: !isLoading && validParams,
refetchInterval: THIRTY_SEC_IN_MS,
}
);
enabled: !isPending && validParams,
refetchInterval: THIRTY_SEC_IN_MS,
});
};
4 changes: 2 additions & 2 deletions src/components/common/TokenInputField/TokenInputField.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ChangeEvent, FC, FocusEvent, useRef } from 'react';
import { SafeDecimal } from 'libs/safedecimal';
import { Token } from 'libs/tokens';
import { useWeb3 } from 'libs/web3';
import { useWagmi } from 'libs/wagmi';
import { useFiatCurrency } from 'hooks/useFiatCurrency';
import { LogoImager } from 'components/common/imager/Imager';
import { Slippage } from './Slippage';
Expand Down Expand Up @@ -49,7 +49,7 @@ export const TokenInputField: FC<Props> = (props) => {
withoutWallet,
'data-testid': testid,
} = props;
const { user } = useWeb3();
const { user } = useWagmi();
const inputRef = useRef<HTMLInputElement>(null);
const { getFiatValue, getFiatAsString } = useFiatCurrency(token);
const fiatValueUsd = getFiatValue(value, true);
Expand Down
57 changes: 57 additions & 0 deletions src/components/common/WalletIcon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
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';
import { ReactComponent as IconWalletConnectLogo } from 'assets/logos/walletConnect.svg';
import { ReactComponent as IconWallet } from 'assets/icons/wallet.svg';

type Props = {
isImposter?: boolean;
selectedWallet?: string;
icon?: string;
className?: string;
};
export const WalletIcon = ({
isImposter,
selectedWallet,
icon,
className,
}: Props) => {
if (isImposter) {
return <IconImposterLogo className={className} />;
}

// For EIP6963 injected wallets
if (icon) {
return (
<img
alt="Injected Wallet"
loading="lazy"
src={icon}
className={className}
/>
);
}

switch (selectedWallet) {
case 'MetaMask':
return <IconMetaMaskLogo className={className} />;
case 'WalletConnect':
return <IconWalletConnectLogo className={className} />;
case 'Coinbase Wallet':
return <IconCoinbaseLogo className={className} />;
case 'Safe':
return <IconGnosisLogo className={className} />;
case 'Tailwind Wallet':
return <IconTailwindWalletLogo className={className} />;
case 'Compass Wallet':
return <IconCompassWalletLogo className={className} />;
case 'Seif Wallet':
return <IconSeifWalletLogo className={className} />;
default:
return <IconWallet className={className} />;
}
};
10 changes: 5 additions & 5 deletions src/components/common/approval/ApproveToken.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Switch } from 'components/common/switch';
import { ApprovalTokenResult } from 'hooks/useApproval';
import { LogoImager } from 'components/common/imager/Imager';
import { QueryKey, useQueryClient } from 'libs/queries';
import { useWeb3 } from 'libs/web3';
import { useWagmi } from 'libs/wagmi';
import { useNotifications } from 'hooks/useNotifications';
import { useTokens } from 'hooks/useTokens';
import { carbonEvents } from 'services/events';
Expand All @@ -21,7 +21,7 @@ import seiConfig from 'config/sei/production';

type Props = {
data?: ApprovalTokenResult;
isLoading: boolean;
isPending: boolean;
error: unknown;
eventData?: StrategyEventOrTradeEvent & TokenApprovalType;
context?: 'depositStrategyFunds' | 'createStrategy' | 'trade';
Expand All @@ -31,14 +31,14 @@ const isSei = config.network.chainId === seiConfig.network.chainId;

export const ApproveToken: FC<Props> = ({
data,
isLoading,
isPending,
error,
eventData,
context,
}) => {
const inputId = useId();
const { dispatchNotification } = useNotifications();
const { user } = useWeb3();
const { user } = useWagmi();
const { getTokenById } = useTokens();
const token = getTokenById(data?.address || '');
const mutation = useSetUserApproval();
Expand Down Expand Up @@ -164,7 +164,7 @@ export const ApproveToken: FC<Props> = ({
};

if (!data || !token) {
if (isLoading) {
if (isPending) {
return <div>is loading</div>;
}
return <div>Unknown Error</div>;
Expand Down
10 changes: 5 additions & 5 deletions src/components/core/MainContent.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FC, useEffect, useRef } from 'react';
import { useWeb3 } from 'libs/web3';
import { useWagmi } from 'libs/wagmi';
import { ErrorUnsupportedNetwork } from 'components/core/error/ErrorUnsupportedNetwork';
import { ErrorNetworkConnection } from 'components/core/error/ErrorNetworkConnection';
import { useTokens } from 'hooks/useTokens';
Expand All @@ -23,7 +23,7 @@ const paths: Record<string, Pathnames> = {
};

export const MainContent: FC = () => {
const web3 = useWeb3();
const wagmi = useWagmi();
const { location } = useRouterState();
const prevPathnameRef = useRef('');
const tokens = useTokens();
Expand All @@ -47,11 +47,11 @@ export const MainContent: FC = () => {
return <Outlet />;
}

if (!web3.isSupportedNetwork) {
if (!wagmi.isSupportedNetwork) {
return <ErrorUnsupportedNetwork />;
}

if (web3.networkError) {
if (wagmi.networkError) {
return <ErrorNetworkConnection />;
}

Expand All @@ -63,7 +63,7 @@ export const MainContent: FC = () => {
return <ErrorTokenList />;
}

if (web3.isUserBlocked) {
if (wagmi.isUserBlocked) {
return <ErrorUserBlocked />;
}

Expand Down
4 changes: 2 additions & 2 deletions src/components/core/error/ErrorUnsupportedNetwork.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { ReactComponent as IconWarning } from 'assets/icons/warning.svg';
import { Button } from 'components/common/button';
import { useWeb3 } from 'libs/web3';
import { useWagmi } from 'libs/wagmi';
import { ErrorWrapper } from 'components/core/error/ErrorWrapper';
import config from 'config';

export const ErrorUnsupportedNetwork = () => {
const { disconnect, switchNetwork } = useWeb3();
const { disconnect, switchNetwork } = useWagmi();

const networkName = config.network.name;

Expand Down
4 changes: 2 additions & 2 deletions src/components/core/error/ErrorUserBlocked.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { useWeb3 } from 'libs/web3';
import { useWagmi } from 'libs/wagmi';
import { NewTabLink, externalLinks } from 'libs/routing';
import { ErrorWrapper } from 'components/core/error/ErrorWrapper';
import { Button } from 'components/common/button';
import { ReactComponent as IconWarning } from 'assets/icons/warning.svg';

export const ErrorUserBlocked = () => {
const { disconnect } = useWeb3();
const { disconnect } = useWagmi();

return (
<ErrorWrapper
Expand Down
2 changes: 1 addition & 1 deletion src/components/core/menu/mainMenu/MainMenuRight.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FC } from 'react';
import { IS_TENDERLY_FORK } from 'libs/web3';
import { IS_TENDERLY_FORK } from 'libs/wagmi';
import { useBreakpoints } from 'hooks/useBreakpoints';
import { MainMenuRightWallet } from 'components/core/menu/mainMenu/MainMenuRightWallet';
import { MainMenuRightNotifications } from 'components/core/menu/mainMenu/MainMenuRightNotifications';
Expand Down
Loading

0 comments on commit 88b1e5a

Please sign in to comment.