11import { AXIOS_INSTANCE } from './lib/api/beam-axios-client' ;
2+ import { getPlayerAPI } from './lib/api/beam.player-api.generated' ;
23import { BeamConfiguration } from './lib/config' ;
4+ import { beamIcon } from './lib/icon' ;
35import {
46 BeamProvider ,
57 announceProvider ,
68 beamProviderInfo ,
79} from './lib/provider' ;
810import { StorageKeys , StorageService } from './lib/storage' ;
911import { SessionManager } from './sessionManager' ;
10- import { ClientConfig } from './types' ;
11- import { getPlayerAPI } from './lib/api/beam.player-api.generated' ;
12- import { beamIcon } from './lib/icon' ;
12+ import { ChainId , ClientConfig } from './types' ;
1313
1414export class BeamClient {
1515 readonly #config: BeamConfiguration ;
@@ -42,14 +42,7 @@ export class BeamClient {
4242 storage : this . #storage,
4343 } ) ;
4444
45- AXIOS_INSTANCE . interceptors . request . use ( ( config ) => {
46- config . baseURL = this . #config. getChainConfig ( ) . apiUrl ;
47- config . headers . set (
48- 'x-api-key' ,
49- this . #config. getChainConfig ( ) . publishableKey ,
50- ) ;
51- return config ;
52- } ) ;
45+ this . #setAxiosInterceptors( ) ;
5346 }
5447
5548 /**
@@ -61,6 +54,25 @@ export class BeamClient {
6154 this . #storage = new StorageService < StorageKeys > ( storage ) ;
6255 }
6356
57+ /**
58+ * Get the current chain configuration
59+ */
60+ public get chain ( ) {
61+ return this . #config. getChainConfig ( ) ;
62+ }
63+
64+ /**
65+ * Set the chainId for the current client
66+ * @param chainId
67+ */
68+ public switchChain ( chainId : ChainId ) {
69+ if ( this . #config. chainId === chainId ) return ;
70+
71+ this . #config. setChainId ( chainId ) ;
72+
73+ this . #setAxiosInterceptors( ) ;
74+ }
75+
6476 /**
6577 * Instantiate a new provider
6678 * @param options
@@ -156,6 +168,22 @@ export class BeamClient {
156168 ) ;
157169 }
158170
171+ /**
172+ * Set the axios interceptors for the current chain
173+ */
174+ #setAxiosInterceptors( ) {
175+ if ( ! this . #config. chainId ) return ;
176+
177+ AXIOS_INSTANCE . interceptors . request . use ( ( config ) => {
178+ config . baseURL = this . #config. getChainConfig ( ) . apiUrl ;
179+ config . headers . set (
180+ 'x-api-key' ,
181+ this . #config. getChainConfig ( ) . publishableKey ,
182+ ) ;
183+ return config ;
184+ } ) ;
185+ }
186+
159187 /**
160188 * Base64 encoded SVG Beam logo
161189 */
0 commit comments