Skip to content

Commit 100ee2b

Browse files
authored
fix: calling remote config in appkit core (#5274)
1 parent a09d984 commit 100ee2b

3 files changed

Lines changed: 137 additions & 1 deletion

File tree

.changeset/silver-llamas-watch.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
'@reown/appkit': patch
3+
'pay-test-exchange': patch
4+
'@reown/appkit-adapter-bitcoin': patch
5+
'@reown/appkit-adapter-ethers': patch
6+
'@reown/appkit-adapter-ethers5': patch
7+
'@reown/appkit-adapter-solana': patch
8+
'@reown/appkit-adapter-wagmi': patch
9+
'@reown/appkit-utils': patch
10+
'@reown/appkit-cdn': patch
11+
'@reown/appkit-cli': patch
12+
'@reown/appkit-codemod': patch
13+
'@reown/appkit-common': patch
14+
'@reown/appkit-controllers': patch
15+
'@reown/appkit-core': patch
16+
'@reown/appkit-experimental': patch
17+
'@reown/appkit-pay': patch
18+
'@reown/appkit-polyfills': patch
19+
'@reown/appkit-scaffold-ui': patch
20+
'@reown/appkit-siwe': patch
21+
'@reown/appkit-siwx': patch
22+
'@reown/appkit-testing': patch
23+
'@reown/appkit-ui': patch
24+
'@reown/appkit-universal-connector': patch
25+
'@reown/appkit-wallet': patch
26+
'@reown/appkit-wallet-button': patch
27+
---
28+
29+
Fixed an issue where remote config endpoint was being called when using appkit core

packages/appkit/src/client/appkit-base-client.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,9 @@ export abstract class AppKitBaseClient {
182182
} else {
183183
await this.unSyncExistingConnection()
184184
}
185-
this.remoteFeatures = await ConfigUtil.fetchRemoteFeatures(options)
185+
if (!options.basic && !options.manualWCControl) {
186+
this.remoteFeatures = await ConfigUtil.fetchRemoteFeatures(options)
187+
}
186188
await ApiController.fetchUsage()
187189
OptionsController.setRemoteFeatures(this.remoteFeatures)
188190
if (this.remoteFeatures.onramp) {

packages/appkit/tests/client/appkit-base-client.test.ts

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ import {
1111
ConnectionController,
1212
CoreHelperUtil,
1313
ModalController,
14+
type RemoteFeatures,
1415
SendController,
1516
WcHelpersUtil
1617
} from '@reown/appkit-controllers'
1718
import { mockChainControllerState } from '@reown/appkit-controllers/testing'
1819
import { ErrorUtil, TokenUtil } from '@reown/appkit-utils'
1920

2021
import { AppKitBaseClient } from '../../src/client/appkit-base-client'
22+
import { ConfigUtil } from '../../src/utils/ConfigUtil'
2123
import { mainnet } from '../mocks/Networks'
2224

2325
describe('AppKitBaseClient.checkAllowedOrigins', () => {
@@ -538,3 +540,106 @@ describe('AppKitBaseClient.getDisabledCaipNetworks', () => {
538540
expect(result[0]?.caipNetworkId).toBe('eip155:56')
539541
})
540542
})
543+
544+
describe('AppKitBaseClient initialization', () => {
545+
let fetchRemoteFeaturesSpy: MockInstance
546+
547+
beforeAll(() => {
548+
Object.defineProperty(globalThis, 'document', {
549+
value: {
550+
getElementsByTagName: vi.fn(),
551+
querySelector: vi.fn()
552+
},
553+
writable: true
554+
})
555+
556+
Object.defineProperty(globalThis, 'navigator', {
557+
value: {
558+
clipboard: {
559+
readText: vi.fn(() => Promise.resolve(''))
560+
}
561+
},
562+
writable: true
563+
})
564+
565+
Object.defineProperty(globalThis, 'window', {
566+
value: { location: { origin: '' } },
567+
writable: true
568+
})
569+
})
570+
571+
beforeEach(() => {
572+
vi.clearAllMocks()
573+
fetchRemoteFeaturesSpy = vi
574+
.spyOn(ConfigUtil, 'fetchRemoteFeatures')
575+
.mockResolvedValue({} as RemoteFeatures)
576+
})
577+
578+
it('should not fetch remote config if using basic mode', async () => {
579+
new (class extends AppKitBaseClient {
580+
constructor() {
581+
super({
582+
projectId: 'test-project-id',
583+
networks: [mainnet],
584+
adapters: [],
585+
sdkVersion: 'html-wagmi-1',
586+
basic: true
587+
})
588+
}
589+
590+
async injectModalUi() {}
591+
async syncIdentity() {}
592+
593+
override async syncAdapterConnections() {
594+
return Promise.resolve()
595+
}
596+
})()
597+
598+
await vi.waitFor(() => expect(fetchRemoteFeaturesSpy).not.toHaveBeenCalled())
599+
})
600+
601+
it('should not fetch remote config if using manual WC control', async () => {
602+
new (class extends AppKitBaseClient {
603+
constructor() {
604+
super({
605+
projectId: 'test-project-id',
606+
networks: [mainnet],
607+
adapters: [],
608+
sdkVersion: 'html-wagmi-1',
609+
manualWCControl: true
610+
})
611+
}
612+
613+
async injectModalUi() {}
614+
async syncIdentity() {}
615+
616+
override async syncAdapterConnections() {
617+
return Promise.resolve()
618+
}
619+
})()
620+
621+
await vi.waitFor(() => expect(fetchRemoteFeaturesSpy).not.toHaveBeenCalled())
622+
})
623+
624+
it('should fetch remote config if not using basic or manual WC control', async () => {
625+
new (class extends AppKitBaseClient {
626+
constructor() {
627+
super({
628+
projectId: 'test-project-id',
629+
networks: [mainnet],
630+
adapters: [],
631+
sdkVersion: 'html-wagmi-1'
632+
})
633+
}
634+
635+
async injectModalUi() {}
636+
async syncIdentity() {}
637+
638+
override async syncAdapterConnections() {
639+
return Promise.resolve()
640+
}
641+
})()
642+
643+
await vi.waitFor(() => expect(fetchRemoteFeaturesSpy).toHaveBeenCalled())
644+
})
645+
})

0 commit comments

Comments
 (0)