Here is an article on how to customize the Web3Modal wallet offering for WalletConnect:
Customizing the Web3Modal Wallet Offering Using WalletConnect
When using Web3Modal to interact with dApps, one of the most important features you want to implement is a customizable wallet menu. This allows users to easily navigate through the different options and settings in your dApp, making it more user-friendly and intuitive.
In this article, we will walk you through how to customize the Web3Modal wallet menu for WalletConnect using JavaScript.
Setting Up WalletConnect
Before we start customizing your wallet menu, make sure WalletConnect is set up correctly. Go to dApp Settings > Wallets & Connectors > WalletConnect and make sure the correct provider URL is entered in the “Wallet Provider” field. You can also enable or disable WalletConnect by toggling the switch next to it.
Create your own wallet offer
To create your own wallet menu, you will need to use the web3Modal
Web3Modal object and its various methods to interact with wallets. Here is a sample code snippet that shows how to customize the wallet offer:
“javascript
const web3Modal = require('web3modal');
const { WalletConnectProvider } = require('@web3connect/web3connect');
// Create a new WalletConnect provider instance
const provider = new WalletConnectProvider({
url: ' // Replace with the web address of your wallet provider
// Optional: enter the amount of ETH to send for each transaction
options: {
Gas price: 50,
maxGas: 20000,
account: '0xYourWalletAddress',
chainId: 1, // Ethereum
},
});
// Get an instance of web3Modal
const web3 = new web3Modal({
provider,
enabledChainIds: [1],
});
// Define a function to show the wallet menu
async function showWalletMenu() {
const wallets = await web3.listAccounts();
const walletMenuItems = [];
// Loop through each wallet and create an item in the wallet menu
for (const wallet account) {
leave item;
// Check if the user has WalletConnect enabled for this account
if (account === '0xYourWalletAddress') {
item = {
label: "Wallet",
description: "This is your default wallet",
iconUrl: ' // Replace with the URL of the wallet icon
options: {
action: 'wallet',
},
};
} else if (account.startsWith('0x')) {
item = {
label: "Wallet Connection",
description: "Connect to another wallet or chain",
iconUrl: ' // Replace with the URL of the wallet icon
options: {
action: 'connect-wallet',
},
};
} else if (account.startsWith('0x...')) {
item = {
label: WalletConnectProvider.label,
description: "Wallet Connect Service Provider for ${account}",
iconUrl: ' // Replace with the URL of the wallet icon
options: {
action: 'wallet-connect',
},
};
} else {
item = {
label:Account ${i + 1},
description:account details ${i + 1}`,
iconUrl: ‘ // Replace the account icon URL
options: {
action: ‘account-details’,
},
};
}
walletMenuItems.push(item);
}
return { walletMenuItems };
}
// Show the wallet menu on load
web3.on(‘connected’, () => showWalletMenu());
//Shows the wallet menu when the user clicks on the wallet account
walletConnection.