Skip to content

Commit

Permalink
fix: v5 default options (#2935)
Browse files Browse the repository at this point in the history
  • Loading branch information
zoruka authored Sep 30, 2024
1 parent fa487aa commit 8b54042
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 18 deletions.
1 change: 0 additions & 1 deletion apps/laboratory/src/pages/library/solana-no-email.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const modal = createWeb3Modal({
metadata: ConstantsUtil.Metadata,
defaultChain: solana,
chains,
enableAnalytics: false,
termsConditionsUrl: 'https://walletconnect.com/terms',
privacyPolicyUrl: 'https://walletconnect.com/privacy',
customWallets: ConstantsUtil.CustomWallets,
Expand Down
1 change: 0 additions & 1 deletion apps/laboratory/src/pages/library/solana-no-socials.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const modal = createWeb3Modal({
metadata: ConstantsUtil.Metadata,
defaultChain: solana,
chains,
enableAnalytics: false,
termsConditionsUrl: 'https://walletconnect.com/terms',
privacyPolicyUrl: 'https://walletconnect.com/privacy',
customWallets: ConstantsUtil.CustomWallets,
Expand Down
1 change: 0 additions & 1 deletion apps/laboratory/src/pages/library/solana.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const modal = createWeb3Modal({
projectId: ConstantsUtil.ProjectId,
metadata: ConstantsUtil.Metadata,
chains,
enableAnalytics: false,
termsConditionsUrl: 'https://walletconnect.com/terms',
privacyPolicyUrl: 'https://walletconnect.com/privacy',
customWallets: ConstantsUtil.CustomWallets,
Expand Down
4 changes: 2 additions & 2 deletions packages/base/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,8 @@ export class AppKit<AdapterStoreState = unknown, SwitchNetworkParam = unknown> {
OptionsController.setPrivacyPolicyUrl(options.privacyPolicyUrl)
OptionsController.setCustomWallets(options.customWallets)
OptionsController.setEnableAnalytics(options.enableAnalytics)
OptionsController.setOnrampEnabled(options.enableOnramp !== false)
OptionsController.setEnableSwaps(options.enableSwaps !== false)
OptionsController.setOnrampEnabled(options.enableOnramp)
OptionsController.setEnableSwaps(options.enableSwaps)

if (options.metadata) {
OptionsController.setMetadata(options.metadata)
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/controllers/ApiController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ export const ApiController = {
ApiController.fetchNetworkImages(),
ApiController.fetchConnectorImages()
]
if (OptionsController.state.enableAnalytics === undefined) {
if (OptionsController.state.enableAnalytics) {
promises.push(ApiController.fetchAnalyticsConfig())
}
state.prefetchPromise = Promise.race([Promise.allSettled(promises)])
Expand Down
38 changes: 30 additions & 8 deletions packages/core/src/controllers/OptionsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { subscribeKey as subKey } from 'valtio/vanilla/utils'
import { proxy } from 'valtio/vanilla'
import type { CustomWallet, Metadata, ProjectId, SdkVersion, Tokens } from '../utils/TypeUtil.js'
import { ApiController } from './ApiController.js'
import { ConstantsUtil } from '../utils/ConstantsUtil.js'

// -- Types --------------------------------------------- //
export interface OptionsControllerState {
Expand Down Expand Up @@ -62,7 +63,7 @@ export interface OptionsControllerState {
isSiweEnabled?: boolean
/**
* Enable analytics to get more insights on your users activity within your WalletConnect Cloud's dashboard.
* @default false
* @default true
* @see https://cloud.walletconnect.com/
*/
enableAnalytics?: boolean
Expand Down Expand Up @@ -102,7 +103,13 @@ type StateKey = keyof OptionsControllerState
const state = proxy<OptionsControllerState>({
projectId: '',
sdkType: 'w3m',
sdkVersion: 'html-wagmi-undefined'
sdkVersion: 'html-wagmi-undefined',
enableAnalytics: ConstantsUtil.DEFAULT_FEATURES.analytics,
enableOnramp: ConstantsUtil.DEFAULT_FEATURES.onramp,
enableSwaps: ConstantsUtil.DEFAULT_FEATURES.swaps,
allWallets: ConstantsUtil.DEFAULT_FEATURES.allWallets,
disableAppend: ConstantsUtil.DEFAULT_FEATURES.disableAppend,
enableEIP6963: ConstantsUtil.DEFAULT_FEATURES.enableEIP6963
})

// -- Controller ---------------------------------------- //
Expand All @@ -121,7 +128,9 @@ export const OptionsController = {
state.projectId = projectId
},

setAllWallets(allWallets: OptionsControllerState['allWallets']) {
setAllWallets(
allWallets: OptionsControllerState['allWallets'] = ConstantsUtil.DEFAULT_FEATURES.allWallets
) {
state.allWallets = allWallets
},

Expand Down Expand Up @@ -164,7 +173,10 @@ export const OptionsController = {
state.isUniversalProvider = isUniversalProvider
},

setEnableAnalytics(enableAnalytics: OptionsControllerState['enableAnalytics']) {
setEnableAnalytics(
enableAnalytics: OptionsControllerState['enableAnalytics'] = ConstantsUtil.DEFAULT_FEATURES
.analytics
) {
state.enableAnalytics = enableAnalytics
},

Expand All @@ -176,23 +188,33 @@ export const OptionsController = {
state.metadata = metadata
},

setOnrampEnabled(enableOnramp: OptionsControllerState['enableOnramp']) {
setOnrampEnabled(
enableOnramp: OptionsControllerState['enableOnramp'] = ConstantsUtil.DEFAULT_FEATURES.onramp
) {
state.enableOnramp = enableOnramp
},

setDisableAppend(disableAppend: OptionsControllerState['disableAppend']) {
setDisableAppend(
disableAppend: OptionsControllerState['disableAppend'] = ConstantsUtil.DEFAULT_FEATURES
.disableAppend
) {
state.disableAppend = disableAppend
},

setEIP6963Enabled(enableEIP6963: OptionsControllerState['enableEIP6963']) {
setEIP6963Enabled(
enableEIP6963: OptionsControllerState['enableEIP6963'] = ConstantsUtil.DEFAULT_FEATURES
.enableEIP6963
) {
state.enableEIP6963 = enableEIP6963
},

setHasMultipleAddresses(hasMultipleAddresses: OptionsControllerState['hasMultipleAddresses']) {
state.hasMultipleAddresses = hasMultipleAddresses
},

setEnableSwaps(enableSwaps: OptionsControllerState['enableSwaps']) {
setEnableSwaps(
enableSwaps: OptionsControllerState['enableSwaps'] = ConstantsUtil.DEFAULT_FEATURES.swaps
) {
state.enableSwaps = enableSwaps
}
}
11 changes: 10 additions & 1 deletion packages/core/src/utils/ConstantsUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,16 @@ export const ConstantsUtil = {
solana: 'So11111111111111111111111111111111111111111'
} as const satisfies Record<Chain, string>,

CONVERT_SLIPPAGE_TOLERANCE: 1
CONVERT_SLIPPAGE_TOLERANCE: 1,

DEFAULT_FEATURES: {
swaps: true,
onramp: true,
analytics: true,
allWallets: 'SHOW',
disableAppend: false,
enableEIP6963: false
} as const
}

export type CoinbasePaySDKChainNameValues =
Expand Down
2 changes: 1 addition & 1 deletion packages/core/tests/controllers/ApiController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ describe('ApiController', () => {
})

it('should prefetch with analytics', () => {
OptionsController.state.enableAnalytics = undefined
OptionsController.state.enableAnalytics = true
const fetchSpy = vi.spyOn(ApiController, 'fetchFeaturedWallets').mockResolvedValue()
const fetchNetworkImagesSpy = vi.spyOn(ApiController, 'fetchNetworkImages').mockResolvedValue()
const recommendedWalletsSpy = vi
Expand Down
10 changes: 8 additions & 2 deletions packages/core/tests/controllers/OptionsController.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import { describe, expect, it } from 'vitest'
import { OptionsController } from '../../index.js'
import { ConstantsUtil, OptionsController } from '../../index.js'

// -- Tests --------------------------------------------------------------------
describe('OptionsController', () => {
it('should have valid default state', () => {
expect(OptionsController.state).toEqual({
projectId: '',
sdkType: 'w3m',
sdkVersion: 'html-wagmi-undefined'
sdkVersion: 'html-wagmi-undefined',
allWallets: ConstantsUtil.DEFAULT_FEATURES.allWallets,
disableAppend: ConstantsUtil.DEFAULT_FEATURES.disableAppend,
enableAnalytics: ConstantsUtil.DEFAULT_FEATURES.analytics,
enableEIP6963: ConstantsUtil.DEFAULT_FEATURES.enableEIP6963,
enableOnramp: ConstantsUtil.DEFAULT_FEATURES.onramp,
enableSwaps: ConstantsUtil.DEFAULT_FEATURES.swaps
})
})

Expand Down

0 comments on commit 8b54042

Please sign in to comment.