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

build: Upgrade web3modal to appkit. #1237

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ import { setupMintbaseWallet } from "@near-wallet-selector/mintbase-wallet";
import { setupBitteWallet } from "@near-wallet-selector/bitte-wallet";
import { setupOKXWallet } from "@near-wallet-selector/okx-wallet";
import { setupEthereumWallets } from "@near-wallet-selector/ethereum-wallets";
import { createWeb3Modal } from "@web3modal/wagmi";
import { reconnect, http, createConfig, type Config } from "@wagmi/core";
import { type Chain } from "@wagmi/core/chains";
import { WagmiAdapter } from "@reown/appkit-adapter-wagmi";
import { createAppKit } from "@reown/appkit/react";
import { defineChain } from "@reown/appkit/networks";
import type { CreateConnectorFn } from "@wagmi/core";
import { injected, walletConnect } from "@wagmi/connectors";
import { CONTRACT_ID } from "../../../constants";

Expand All @@ -39,11 +40,13 @@ declare global {
}
}

// Get a project ID at https://cloud.walletconnect.com
// Get a project ID at https://cloud.reown.com
const projectId = "30147604c5f01d0bc4482ab0665b5697";

const near: Chain = {
const near = defineChain({
id: 398,
caipNetworkId: "eip155:398",
chainNamespace: "eip155",
name: "NEAR Protocol Testnet",
nativeCurrency: {
decimals: 18,
Expand All @@ -61,33 +64,42 @@ const near: Chain = {
},
},
testnet: true,
};
});

const wagmiConfig: Config = createConfig({
chains: [near],
transports: {
[near.id]: http(),
},
connectors: [
walletConnect({
projectId,
metadata: {
name: "NEAR Guest Book",
description: "A guest book with comments stored on the NEAR blockchain",
url: "https://near.github.io/wallet-selector",
icons: ["https://near.github.io/wallet-selector/favicon.ico"],
},
showQrModal: false,
}),
injected({ shimDisconnect: true }),
],
const connectors: Array<CreateConnectorFn> = [
walletConnect({
projectId,
metadata: {
name: "NEAR Guest Book",
description: "A guest book with comments stored on the NEAR blockchain",
url: "https://near.github.io/wallet-selector",
icons: ["https://near.github.io/wallet-selector/favicon.ico"],
},
showQrModal: false, // showQrModal must be false
}),
injected({ shimDisconnect: true }),
];

const wagmiAdapter = new WagmiAdapter({
projectId,
connectors,
networks: [near],
});
reconnect(wagmiConfig);

const web3Modal = createWeb3Modal({
wagmiConfig: wagmiConfig,
const web3Modal = createAppKit({
adapters: [wagmiAdapter],
projectId,
enableOnramp: false,
networks: [near],
defaultNetwork: near,
enableWalletConnect: true,
features: {
analytics: true,
swaps: false,
onramp: false,
email: false, // Smart accounts (Safe contract) not available on NEAR Protocol, only EOA.
socials: false, // Smart accounts (Safe contract) not available on NEAR Protocol, only EOA.
},
coinbasePreference: "eoaOnly", // Smart accounts (Safe contract) not available on NEAR Protocol, only EOA.
allWallets: "SHOW",
});

Expand Down Expand Up @@ -154,7 +166,10 @@ export class WalletSelectorComponent implements OnInit {
setupNearMobileWallet(),
setupMintbaseWallet({ contractId: CONTRACT_ID }),
setupBitteWallet({ contractId: CONTRACT_ID }),
setupEthereumWallets({ wagmiConfig, web3Modal }),
setupEthereumWallets({
wagmiConfig: wagmiAdapter.wagmiConfig,
web3Modal,
}),
],
});

Expand Down
4 changes: 2 additions & 2 deletions examples/react/components/Content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ const Content: React.FC = () => {
</div>
<div style={{ marginTop: 30 }}>
{/* @ts-ignore */}
<w3m-button label="Log in with Ethereum" />
<appkit-button label="Log in with Ethereum" />
</div>
<SignIn />
</Fragment>
Expand All @@ -401,7 +401,7 @@ const Content: React.FC = () => {
{selector.store.getState().selectedWalletId === "ethereum-wallets" && (
<div style={{ marginTop: 30 }}>
{/* @ts-ignore */}
<w3m-button label="Log in with Ethereum" />
<appkit-button label="Log in with Ethereum" />
</div>
)}
<Form
Expand Down
84 changes: 47 additions & 37 deletions examples/react/contexts/WalletSelectorContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,11 @@ import React, {
useMemo,
} from "react";
import { distinctUntilChanged, map } from "rxjs";
import { createWeb3Modal } from "@web3modal/wagmi";
import type { GetAccountReturnType } from "@wagmi/core";
import {
reconnect,
http,
createConfig,
type Config,
watchAccount,
} from "@wagmi/core";
import { type Chain } from "@wagmi/core/chains";
import { WagmiAdapter } from "@reown/appkit-adapter-wagmi";
import { createAppKit } from "@reown/appkit/react";
import { defineChain } from "@reown/appkit/networks";
import type { CreateConnectorFn, GetAccountReturnType } from "@wagmi/core";
import { reconnect, watchAccount } from "@wagmi/core";
import { injected, walletConnect } from "@wagmi/connectors";

import { Loading } from "../components/Loading";
Expand All @@ -70,11 +65,13 @@ interface WalletSelectorContextValue {
const WalletSelectorContext =
React.createContext<WalletSelectorContextValue | null>(null);

// Get a project ID at https://cloud.walletconnect.com
// Get a project ID at https://cloud.reown.com
const projectId = "30147604c5f01d0bc4482ab0665b5697";

const near: Chain = {
const near = defineChain({
id: 398,
caipNetworkId: "eip155:398",
chainNamespace: "eip155",
name: "NEAR Protocol Testnet",
nativeCurrency: {
decimals: 18,
Expand All @@ -92,33 +89,43 @@ const near: Chain = {
},
},
testnet: true,
};
});

const wagmiConfig: Config = createConfig({
chains: [near],
transports: {
[near.id]: http(),
},
connectors: [
walletConnect({
projectId,
metadata: {
name: "NEAR Guest Book",
description: "A guest book with comments stored on the NEAR blockchain",
url: "https://near.github.io/wallet-selector",
icons: ["https://near.github.io/wallet-selector/favicon.ico"],
},
showQrModal: false,
}),
injected({ shimDisconnect: true }),
],
const connectors: Array<CreateConnectorFn> = [
walletConnect({
projectId,
metadata: {
name: "NEAR Guest Book",
description: "A guest book with comments stored on the NEAR blockchain",
url: "https://near.github.io/wallet-selector",
icons: ["https://near.github.io/wallet-selector/favicon.ico"],
},
showQrModal: false, // showQrModal must be false
}),
injected({ shimDisconnect: true }),
];

const wagmiAdapter = new WagmiAdapter({
projectId,
connectors,
networks: [near],
});
reconnect(wagmiConfig);
reconnect(wagmiAdapter.wagmiConfig);

const web3Modal = createWeb3Modal({
wagmiConfig: wagmiConfig,
const web3Modal = createAppKit({
adapters: [wagmiAdapter],
projectId,
enableOnramp: false,
networks: [near],
defaultNetwork: near,
enableWalletConnect: true,
features: {
analytics: true,
swaps: false,
onramp: false,
email: false, // Smart accounts (Safe contract) not available on NEAR Protocol, only EOA.
socials: false, // Smart accounts (Safe contract) not available on NEAR Protocol, only EOA.
},
coinbasePreference: "eoaOnly", // Smart accounts (Safe contract) not available on NEAR Protocol, only EOA.
allWallets: "SHOW",
});

Expand All @@ -136,7 +143,7 @@ export const WalletSelectorContextProvider: React.FC<{
return;
}
// Watch the connected Ethereum account and connect to the `ethereum-wallets` module automatically.
watchAccount(wagmiConfig, {
watchAccount(wagmiAdapter.wagmiConfig, {
onChange: (data: GetAccountReturnType) => {
if (!data.address || selector.store.getState().selectedWalletId) {
return;
Expand Down Expand Up @@ -187,7 +194,10 @@ export const WalletSelectorContextProvider: React.FC<{
setupNearMobileWallet(),
setupMintbaseWallet({ contractId: CONTRACT_ID }),
setupBitteWallet({ contractId: CONTRACT_ID }),
setupEthereumWallets({ wagmiConfig, web3Modal }),
setupEthereumWallets({
wagmiConfig: wagmiAdapter.wagmiConfig,
web3Modal,
}),
],
});
const _modal = setupModal(_selector, {
Expand Down
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,11 @@
"@noble/hashes": "1.4.0",
"@peersyst/near-mobile-signer": "1.1.0",
"@ramper/near": "0.0.30",
"@reown/appkit": "1.5.2",
"@reown/appkit-adapter-wagmi": "1.5.2",
"@tanstack/react-query": "5.24.8",
"@walletconnect/modal": "2.6.2",
"@walletconnect/sign-client": "2.13.0",
"@web3modal/wagmi": "5.0.6",
"@walletconnect/modal": "2.7.0",
"@walletconnect/sign-client": "2.17.0",
"better-sqlite3": "11.3.0",
"big.js": "6.2.2",
"borsh": "0.7.0",
Expand All @@ -133,8 +134,8 @@
"stream-http": "3.2.0",
"tslib": "2.7.0",
"url": "0.11.0",
"viem": "2.16.2",
"wagmi": "2.10.9",
"viem": "2.21.26",
"wagmi": "2.12.17",
"zone.js": "0.12.0"
},
"devDependencies": {
Expand Down Expand Up @@ -223,4 +224,4 @@
"webpack": "5.75.0",
"webpack-merge": "5.8.0"
}
}
}
Loading