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

Add option to load all EVM wallets from api.web3modal.org #2961

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions packages/appkit/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ export class AppKit {
this.setDefaultNetwork(options)

OptionsController.setAllWallets(options.allWallets)
OptionsController.setAllEthWallets(options.allEthWallets)
OptionsController.setIncludeWalletIds(options.includeWalletIds)
OptionsController.setExcludeWalletIds(options.excludeWalletIds)
if (options.excludeWalletIds) {
Expand Down
24 changes: 17 additions & 7 deletions packages/core/src/controllers/ApiController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,18 @@ export const ApiController = {

async fetchRecommendedWallets() {
try {
const { includeWalletIds, excludeWalletIds, featuredWalletIds } = OptionsController.state
const { includeWalletIds, excludeWalletIds, featuredWalletIds, allEthWallets } =
OptionsController.state
const exclude = [...(excludeWalletIds ?? []), ...(featuredWalletIds ?? [])].filter(Boolean)
const { data, count } = await api.get<ApiGetWalletsResponse>({
path: '/getWallets',
headers: ApiController._getApiHeaders(),
params: {
page: '1',
chains: ChainController.state.activeCaipNetwork?.id,
chains:
ChainController.state.activeCaipNetwork?.id.includes('eip155') && allEthWallets
? 'eip155:1'
: ChainController.state.activeCaipNetwork?.id,
entries: recommendedEntries,
include: includeWalletIds?.join(','),
exclude: exclude?.join(',')
Expand All @@ -182,7 +186,8 @@ export const ApiController = {
},

async fetchWallets({ page }: Pick<ApiGetWalletsRequest, 'page'>) {
const { includeWalletIds, excludeWalletIds, featuredWalletIds } = OptionsController.state
const { includeWalletIds, excludeWalletIds, featuredWalletIds, allEthWallets } =
OptionsController.state

const exclude = [
...state.recommended.map(({ id }) => id),
Expand All @@ -195,7 +200,10 @@ export const ApiController = {
params: {
page: String(page),
entries,
chains: ChainController.state.activeCaipNetwork?.id,
chains:
ChainController.state.activeCaipNetwork?.id.includes('eip155') && allEthWallets
? 'eip155:1'
: ChainController.state.activeCaipNetwork?.id,
include: includeWalletIds?.join(','),
exclude: exclude.join(',')
}
Expand All @@ -221,7 +229,6 @@ export const ApiController = {
params: {
page: '1',
entries: String(ids.length),
chains: ChainController.state.activeCaipNetwork?.id,
include: ids?.join(',')
}
})
Expand All @@ -236,7 +243,7 @@ export const ApiController = {
},

async searchWallet({ search }: Pick<ApiGetWalletsRequest, 'search'>) {
const { includeWalletIds, excludeWalletIds } = OptionsController.state
const { includeWalletIds, excludeWalletIds, allEthWallets } = OptionsController.state
state.search = []
const { data } = await api.get<ApiGetWalletsResponse>({
path: '/getWallets',
Expand All @@ -245,7 +252,10 @@ export const ApiController = {
page: '1',
entries: '100',
search: search?.trim(),
chains: ChainController.state.activeCaipNetwork?.id,
chains:
ChainController.state.activeCaipNetwork?.id.includes('eip155') && allEthWallets
? 'eip155:1'
: ChainController.state.activeCaipNetwork?.id,
include: includeWalletIds?.join(','),
exclude: excludeWalletIds?.join(',')
}
Expand Down
10 changes: 10 additions & 0 deletions packages/core/src/controllers/OptionsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ import { ConstantsUtil } from '../utils/ConstantsUtil.js'

// -- Types --------------------------------------------- //
export interface OptionsControllerStatePublic {
/**
* A boolean that forces the loading of all Ethereum wallets from the API.
* Forces the chain ID to 1.
* @default false
*/
allEthWallets?: boolean
/**
* A boolean that allows you to add or remove the "All Wallets" button on the modal
* @default 'SHOW'
Expand Down Expand Up @@ -166,6 +172,10 @@ export const OptionsController = {
state.allWallets = allWallets
},

setAllEthWallets(allEthWallets: OptionsControllerState['allEthWallets']) {
state.allEthWallets = allEthWallets
},

setIncludeWalletIds(includeWalletIds: OptionsControllerState['includeWalletIds']) {
state.includeWalletIds = includeWalletIds
},
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/utils/ConstantsUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ export const ConstantsUtil = {
socials: ['google', 'x', 'discord', 'farcaster', 'github', 'apple', 'facebook'],
history: true,
analytics: true,
allWallets: true
allWallets: true,
allEthWallets: false
} as Features
}