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: migrate from @web3modal to @reown/appkit #474

Open
wants to merge 51 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
d3c58e1
feat: sync evm connector with app kit declare global
helciofranco Jan 28, 2025
522963f
feat: add @reown/appkit as external, same as wagmi etc
helciofranco Jan 29, 2025
4c5a462
feat: migrate from web3modal and walletconnect to @reown/appkit
helciofranco Jan 29, 2025
d0fa9fd
chore: update comment about deprecated web3 modal
helciofranco Jan 29, 2025
2c2c689
feat: migrate solana connector to @reown/appkit
helciofranco Jan 29, 2025
5c22105
feat: add @reown-connector – to allow users to connect SVM/EVM in sam…
helciofranco Jan 31, 2025
9629380
feat: remove unused packages
helciofranco Jan 31, 2025
8ce49c2
feat: remove useless subscription channel
helciofranco Jan 31, 2025
3b807f6
fix: remove unused stuff
helciofranco Jan 31, 2025
fb92513
feat: add appkit to the next example
helciofranco Jan 31, 2025
8d9a43d
feat: remove vite
helciofranco Jan 31, 2025
5b3ec5d
feat: add appkit to the e2e-tests runner
helciofranco Jan 31, 2025
d69f4b5
feat: move connect ownership to the reown connector
helciofranco Jan 31, 2025
c0f2031
fix: evm flow with signature
helciofranco Feb 2, 2025
ea65d0d
feat: remove eth unused code
helciofranco Feb 2, 2025
ca67eb5
chore: add missing type def
helciofranco Feb 3, 2025
54f9434
feat: simplify a lot how we handle connection and reconnection in evm
helciofranco Feb 3, 2025
d35e841
fix: flow where connecting dialog doesn't close
helciofranco Feb 3, 2025
ff99973
fix: add missing emitConnect everywhere
helciofranco Feb 3, 2025
e17ff6c
chore: remove unused code
helciofranco Feb 3, 2025
88d0a80
docs: add changeset
helciofranco Feb 3, 2025
c8a8f13
chore: remove useless method
helciofranco Feb 3, 2025
f412704
chore: sync implementation with evm
helciofranco Feb 3, 2025
36d8382
fix: adjust reconnecting flow
helciofranco Feb 3, 2025
ef02024
fix: add sanity check
helciofranco Feb 4, 2025
e72b6bc
feat: add custom name and metadata when signing eth
helciofranco Feb 4, 2025
d67e460
fix: remove useless code since phantom is not signing anything yet
helciofranco Feb 4, 2025
e7e6d89
test: sync e2e tests with new label
helciofranco Feb 4, 2025
0631e04
feat: add getFuelPredicateAddresses back
helciofranco Feb 4, 2025
0f2a0ae
feat: remove unused metadata
helciofranco Feb 4, 2025
75ff873
chore: remove unused comment
helciofranco Feb 4, 2025
470a666
chore: remove unused script
helciofranco Feb 4, 2025
b216a69
feat: make appkit optional
helciofranco Feb 4, 2025
f05fcd5
chore: viem and wagmi should be externals
helciofranco Feb 4, 2025
4c2b77e
feat: add missing react query devtoolst to the nextjs example
helciofranco Feb 4, 2025
05c35bd
feat: share wagmi config between ssr and appkit instance (client)
helciofranco Feb 4, 2025
61851b1
chore: remove connectkit since we don't need it anymore
helciofranco Feb 4, 2025
2cc5348
chore: remove unused import
helciofranco Feb 4, 2025
fd58c1f
chore: remove references to the deprecated docs from web3modal
helciofranco Feb 4, 2025
f8b3cfe
chore: remove dependency on wagmi from predicate evm
helciofranco Feb 4, 2025
696f799
chore: we dont need wagmi in reown connector anymore
helciofranco Feb 4, 2025
43eb30c
fix: resolve ssr event emitter reference
helciofranco Feb 4, 2025
fb5f602
fix: remove console.logs and missing methods
helciofranco Feb 4, 2025
8d58512
chore: remove unused comment
helciofranco Feb 4, 2025
2bb40f0
chore: clean react-next e2e runner
helciofranco Feb 4, 2025
022afbd
test: allow user to use mainnet in e2e
helciofranco Feb 5, 2025
bdef867
Merge branch 'main' of github.com:FuelLabs/fuel-connectors into hf/fe…
helciofranco Feb 6, 2025
bc90683
chore: sync viem version and remove wagmi
helciofranco Feb 6, 2025
5ee0561
chore: sync ts version
helciofranco Feb 6, 2025
93838e8
chore: revert tsup
helciofranco Feb 6, 2025
e49901b
chore: remove unused override
helciofranco Feb 6, 2025
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
10 changes: 10 additions & 0 deletions .changeset/large-toys-rest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"@fuel-connectors/reown-connector": minor
"@fuel-connectors/svm-predicates": minor
"@fuel-connectors/evm-connector": minor
"@fuels/connectors": minor
"@fuel-connectors/common": minor
"@fuels/react": minor
---

Remove `WalletConnectorConnector` and `SolanaConnector`, replacing them with `ReownConnector`.
10 changes: 10 additions & 0 deletions .changeset/weak-rings-scream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"@fuel-connectors/reown-connector": minor
"@fuel-connectors/svm-predicates": minor
"@fuel-connectors/evm-connector": minor
"@fuels/connectors": minor
"@fuel-connectors/common": minor
"@fuels/react": minor
---

Add `ReownConnector` to handle both Ethereum and Solana wallets with the latest `@appkit/reown`.
4 changes: 2 additions & 2 deletions .github/workflows/pr-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@ jobs:
run: pnpm fuels build && pnpm fuels deploy
working-directory: packages/evm-predicates

- name: Build & Deploy Solana Predicates
- name: Build & Deploy SVM Predicates
run: pnpm fuels build && pnpm fuels deploy
if: false # @TODO: Phantom CRX is currently broken, so we're skipping this step for now
working-directory: packages/solana-connector
working-directory: packages/svm-predicates

- name: Install Playwright Browsers
run: pnpm exec playwright install --with-deps chromium
Expand Down
3 changes: 1 addition & 2 deletions e2e-tests/react-next/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
const nextConfig = {
transpilePackages: ['@fuels/connectors', '@fuels/react'],
webpack: (config) => {
// https://github.com/WalletConnect/walletconnect-monorepo/issues/1908
// https://docs.walletconnect.com/web3modal/nextjs/about#extra-configuration
// https://docs.reown.com/appkit/next/core/installation#extra-configuration
config.externals.push('pino-pretty', 'lokijs', 'encoding');

return config;
Expand Down
9 changes: 5 additions & 4 deletions e2e-tests/react-next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
"@fuels/connectors": "workspace:*",
"@fuels/react": "workspace:*",
"@radix-ui/react-toast": "1.1.5",
"@reown/appkit": "1.6.5",
"@reown/appkit-adapter-solana": "1.6.5",
"@reown/appkit-adapter-wagmi": "1.6.5",
"@tanstack/react-query": "5.35.1",
"@wagmi/connectors": "5.1.7",
"@wagmi/core": "2.13.4",
"fuels": "0.96.1",
"clsx": "2.1.1",
"connectkit": "1.8.2",
"next": "14.2.22",
"wagmi": "2.12.7"
"viem": "2.22.17",
"wagmi": "2.14.9"
},
"devDependencies": {
"@tanstack/react-query-devtools": "5.35.1",
Expand Down
9 changes: 5 additions & 4 deletions e2e-tests/react-next/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,28 @@ import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
import type React from 'react';

const queryClient = new QueryClient();

export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
const queryClient = new QueryClient();
const isDev = process.env.NODE_ENV === 'development';

return (
<html lang="en">
<body>
<QueryClientProvider client={queryClient}>
<Toast.Provider>
{children}

<Toast.Viewport
id="toast-viewport"
className="fixed bottom-0 right-0 z-[100] m-0 flex w-[420px] max-w-[100vw] list-none flex-col gap-[10px] p-[var(--viewport-padding)] outline-none [--viewport-padding:_25px]"
/>
<Toast.Root />
</Toast.Provider>
{isDev && <ReactQueryDevtools initialIsOpen={false} />}

<ReactQueryDevtools initialIsOpen={false} />
</QueryClientProvider>
</body>
</html>
Expand Down
45 changes: 33 additions & 12 deletions e2e-tests/react-next/src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
'use client';
import { defaultConnectors } from '@fuels/connectors';
import { FuelProvider } from '@fuels/react';
import { coinbaseWallet, walletConnect } from '@wagmi/connectors';
import { http, createConfig, injected } from '@wagmi/core';
import { mainnet, sepolia } from '@wagmi/core/chains';
import { createAppKit } from '@reown/appkit';
import { SolanaAdapter } from '@reown/appkit-adapter-solana';
import { WagmiAdapter } from '@reown/appkit-adapter-wagmi';
import { type AppKitNetwork, mainnet, sepolia } from '@reown/appkit/networks';
import { CHAIN_IDS, Provider, bn } from 'fuels';
import App from 'react-app/src/App';
import { ConfigProvider } from 'react-app/src/context/ConfigContext';
import COUNTER_CONTRACT_ID_LOCAL from 'react-app/src/types/contract-ids-local.json';
import COUNTER_CONTRACT_ID_MAINNET from 'react-app/src/types/contract-ids-mainnet.json';
import COUNTER_CONTRACT_ID_TESTNET from 'react-app/src/types/contract-ids-testnet.json';
import { http } from 'wagmi';
import { coinbaseWallet, injected, walletConnect } from 'wagmi/connectors';

const CHAIN_ID_NAME = process.env
.NEXT_PUBLIC_CHAIN_ID_NAME as keyof typeof CHAIN_IDS.fuel;
Expand Down Expand Up @@ -38,6 +41,13 @@ const EXPLORER_URL_MAP: Record<keyof typeof CHAIN_IDS.fuel, string> = {
mainnet: 'https://app-mainnet.fuel.network',
};

const METADATA = {
name: 'Wallet Demo',
description: 'Fuel Wallets Demo',
url: 'https://connectors.fuel.network',
icons: ['https://connectors.fuel.network/logo_white.png'],
};

const NETWORKS = [
{
chainId: CHAIN_ID,
Expand All @@ -47,15 +57,12 @@ const NETWORKS = [

const WC_PROJECT_ID = process.env.NEXT_PUBLIC_WC_PROJECT_ID || '';

const METADATA = {
name: 'Wallet Demo',
description: 'Fuel Wallets Demo',
url: 'https://connectors.fuel.network',
icons: ['https://connectors.fuel.network/logo_white.png'],
};
const networks: [AppKitNetwork, ...AppKitNetwork[]] = [mainnet, sepolia];

const wagmiConfig = createConfig({
chains: [mainnet, sepolia],
const solanaWeb3JsAdapter = new SolanaAdapter();
const wagmiAdapter = new WagmiAdapter({
networks,
projectId: WC_PROJECT_ID,
transports: {
[mainnet.id]: http(),
[sepolia.id]: http(),
Expand All @@ -77,11 +84,25 @@ const wagmiConfig = createConfig({
],
});

const appkit = createAppKit({
adapters: [wagmiAdapter, solanaWeb3JsAdapter],
enableWalletConnect: !!WC_PROJECT_ID,
projectId: WC_PROJECT_ID,
networks: networks,
allowUnsupportedChain: false,
allWallets: 'ONLY_MOBILE',
features: {
email: false,
socials: false,
analytics: false,
},
});

const FUEL_CONFIG = {
connectors: defaultConnectors({
devMode: true,
wcProjectId: WC_PROJECT_ID,
ethWagmiConfig: wagmiConfig,
appkit,
chainId: CHAIN_ID,
fuelProvider: Provider.create(PROVIDER_URL),
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const { VITE_FUEL_PROVIDER_URL, VITE_WALLET_SECRET } = process.env as Record<
string
>;

test.describe('WalletConnectConnector', () => {
test.describe('ReownConnector', () => {
let metamask: MetaMask;
test.slow();
test.beforeEach(async ({ context, extensionId, metamaskPage, page }) => {
Expand All @@ -37,7 +37,11 @@ test.describe('WalletConnectConnector', () => {
const commonConnect: ConnectorFunctions['connect'] = async (page) => {
const connectButton = getButtonByText(page, 'Connect Wallet', true);
await connectButton.click();
await getByAriaLabel(page, 'Connect to Ethereum Wallets', true).click();
await getByAriaLabel(
page,
'Connect to Ethereum / Solana Wallets',
true,
).click();
await page.getByText('Proceed').click();
await getButtonByText(page, 'MetaMask', true).click();
await metamask.connectToDapp();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import phantomExtended from './phantom/phantom';
import { test } from './setup';

// @TODO: Phantom CRX is currently broken, so we're skipping this step for now
// When someone fixes it, we should move it to "ReownConnector" because SolanaConnector doesn't exist anymore
// Find this PR to see more details and understand better.
test.skip('SolanaConnector', () => {
test.slow();

Expand Down
9 changes: 6 additions & 3 deletions examples/react-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@
"@fuels/connectors": "workspace:*",
"@fuels/react": "workspace:*",
"@radix-ui/react-toast": "1.1.5",
"@reown/appkit": "1.6.5",
"@reown/appkit-adapter-solana": "1.6.5",
"@reown/appkit-adapter-wagmi": "1.6.5",
"@tanstack/react-query": "5.35.1",
"@wagmi/connectors": "5.1.7",
"@wagmi/core": "2.13.4",
"clsx": "2.1.1",
"fuels": "0.96.1",
"react": "18.3.1",
"react-dom": "18.3.1"
"react-dom": "18.3.1",
"viem": "2.22.17",
"wagmi": "2.14.9"
},
"devDependencies": {
"@tanstack/react-query-devtools": "5.35.1",
Expand Down
2 changes: 1 addition & 1 deletion examples/react-app/src/context/ConfigContext.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { BN } from 'fuels';
import React, { createContext, useContext, type ReactNode } from 'react';
import { type ReactNode, createContext, useContext } from 'react';

interface Config {
explorerUrl: string;
Expand Down
68 changes: 48 additions & 20 deletions examples/react-app/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,57 @@ import { counter as COUNTER_CONTRACT_ID_LOCAL } from './types/contract-ids-local
import { counter as COUNTER_CONTRACT_ID_MAINNET } from './types/contract-ids-mainnet.json';
import { counter as COUNTER_CONTRACT_ID_TESTNET } from './types/contract-ids-testnet.json';

import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { ReactQueryDevtools } from '@tanstack/react-query-devtools';

import { coinbaseWallet, walletConnect } from '@wagmi/connectors';
import { http, createConfig, injected } from '@wagmi/core';
import { mainnet, sepolia } from '@wagmi/core/chains';

import { defaultConnectors } from '@fuels/connectors';
import { FuelProvider, type NetworkConfig } from '@fuels/react';
import {
type AppKitNetwork,
mainnet,
sepolia,
solana,
solanaDevnet,
solanaTestnet,
} from '@reown/appkit/networks';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
import { coinbaseWallet, injected, walletConnect } from 'wagmi/connectors';

import * as Toast from '@radix-ui/react-toast';

import { WagmiAdapter } from '@reown/appkit-adapter-wagmi';
import { CHAIN_IDS, type FuelConfig, Provider, bn } from 'fuels';
import App from './App.tsx';
import ScreenSizeIndicator from './components/screensize-indicator.tsx';
import './index.css';
import { CHAIN_IDS, type FuelConfig, Provider, bn } from 'fuels';
import { ConfigProvider } from './context/ConfigContext.tsx';
import './index.css';
import { createAppKit } from '@reown/appkit';
import { SolanaAdapter } from '@reown/appkit-adapter-solana';

const queryClient = new QueryClient();
const isDev = process.env.NODE_ENV === 'development';

// ============================================================
// WalletConnect Connector configurations
// https://docs.walletconnect.com/web3modal/javascript/about
// ReOwn Custom Connectors configurations
// https://docs.reown.com/appkit/javascript/core/custom-connectors
// ============================================================
const WC_PROJECT_ID = import.meta.env.VITE_APP_WC_PROJECT_ID;

const METADATA = {
name: 'Wallet Demo',
description: 'Fuel Wallets Demo',
url: location.href,
icons: ['https://connectors.fuel.network/logo_white.png'],
};
const wagmiConfig = createConfig({
chains: [mainnet, sepolia],
transports: {
[mainnet.id]: http(),
[sepolia.id]: http(),
},
const networks: [AppKitNetwork, ...AppKitNetwork[]] = [
mainnet,
sepolia,
solana,
solanaTestnet,
solanaDevnet,
];

const wagmiAdapter = new WagmiAdapter({
networks,
syncConnectedChain: true,
projectId: WC_PROJECT_ID,
connectors: [
injected({ shimDisconnect: false }),
walletConnect({
Expand All @@ -59,6 +71,22 @@ const wagmiConfig = createConfig({
],
});

const solanaWeb3JsAdapter = new SolanaAdapter();

const appkit = createAppKit({
adapters: [wagmiAdapter, solanaWeb3JsAdapter],
enableWalletConnect: !!WC_PROJECT_ID,
projectId: WC_PROJECT_ID,
networks,
allowUnsupportedChain: false,
allWallets: 'ONLY_MOBILE',
features: {
email: false,
socials: false,
analytics: false,
},
});

const CHAIN_ID_NAME = import.meta.env
.VITE_CHAIN_ID_NAME as keyof typeof CHAIN_IDS.fuel;
const PROVIDER_URL = import.meta.env.VITE_FUEL_PROVIDER_URL;
Expand All @@ -80,7 +108,7 @@ const FUEL_CONFIG: FuelConfig = {
connectors: defaultConnectors({
devMode: true,
wcProjectId: WC_PROJECT_ID,
ethWagmiConfig: wagmiConfig,
appkit,
chainId: CHAIN_ID,
fuelProvider: Provider.create(PROVIDER_URL),
}),
Expand Down Expand Up @@ -133,7 +161,7 @@ ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
<ScreenSizeIndicator />
</FuelProvider>

{isDev && <ReactQueryDevtools initialIsOpen={false} />}
<ReactQueryDevtools initialIsOpen={false} />
</QueryClientProvider>
</React.StrictMode>,
);
3 changes: 1 addition & 2 deletions examples/react-next/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
const nextConfig = {
transpilePackages: ['@fuels/connectors', '@fuels/react'],
webpack: (config) => {
// https://github.com/WalletConnect/walletconnect-monorepo/issues/1908
// https://docs.walletconnect.com/web3modal/nextjs/about#extra-configuration
// https://docs.reown.com/appkit/next/core/installation#extra-configuration
config.externals.push('pino-pretty', 'lokijs', 'encoding');

return config;
Expand Down
7 changes: 5 additions & 2 deletions examples/react-next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@
"dependencies": {
"@fuels/connectors": "workspace:*",
"@fuels/react": "workspace:*",
"@reown/appkit": "1.6.5",
"@reown/appkit-adapter-solana": "1.6.5",
"@reown/appkit-adapter-wagmi": "1.6.5",
"@tanstack/react-query": "5.35.1",
"connectkit": "1.8.2",
"fuels": "0.96.1",
"next": "14.2.22",
"react": "18.3.1",
"react-dom": "18.3.1",
"wagmi": "2.12.7"
"viem": "2.22.17",
"wagmi": "2.14.9"
},
"devDependencies": {
"@tanstack/react-query-devtools": "5.35.1",
Expand Down
Loading
Loading