@@ -23,6 +23,8 @@ import {
2323 removeEIP155ChainIdPrefix ,
2424} from '../utils/index.js' ;
2525
26+ import type { ChainService } from './chain-service.js' ;
27+
2628export const SUPPORTED_METHODS = [
2729 'eth_sendTransaction' ,
2830 'eth_sign' ,
@@ -43,7 +45,10 @@ export class WalletKitService {
4345 }
4446 | undefined ;
4547
46- private constructor ( readonly walletKit : WalletKit ) {
48+ private constructor (
49+ private chainService : ChainService ,
50+ readonly walletKit : WalletKit ,
51+ ) {
4752 walletKit . on ( 'session_proposal' , event => {
4853 console . info ( 'session_proposal' , event ) ;
4954
@@ -267,12 +272,27 @@ export class WalletKitService {
267272 ) : Promise < PendingSession | false > {
268273 const { id, params} = event ;
269274
270- const chains = Array . from (
271- new Set ( [
272- ...( params . requiredNamespaces . eip155 ?. chains ?? [ ] ) ,
273- ...( params . optionalNamespaces . eip155 ?. chains ?? [ ] ) ,
274- ] ) ,
275- ) ;
275+ const chainSet = new Set ( [
276+ ...( params . requiredNamespaces . eip155 ?. chains ?? [ ] ) ,
277+ ...( params . optionalNamespaces . eip155 ?. chains ?? [ ] ) ,
278+ ] ) ;
279+
280+ if ( / r a b b y / i. test ( event . params . proposer . metadata . name ) ) {
281+ for ( const { id : chainId } of this . chainService . getCustomChains ( ) ) {
282+ if ( chainSet . has ( chainId ) ) {
283+ continue ;
284+ }
285+
286+ const paramOptionalChains = params . optionalNamespaces . eip155 ?. chains ;
287+
288+ if ( paramOptionalChains ) {
289+ paramOptionalChains . push ( chainId ) ;
290+ chainSet . add ( chainId ) ;
291+ }
292+ }
293+ }
294+
295+ const chains = Array . from ( chainSet ) ;
276296
277297 if ( chains . length === 0 ) {
278298 await this . walletKit . rejectSession ( {
@@ -371,7 +391,10 @@ export class WalletKitService {
371391 'pending-session-request-update' ,
372392 ) ;
373393
374- static async create ( projectId : string ) : Promise < WalletKitService > {
394+ static async create (
395+ chainService : ChainService ,
396+ projectId : string ,
397+ ) : Promise < WalletKitService > {
375398 const walletKit = await WalletKit . init ( {
376399 core : new Core ( {
377400 projectId,
@@ -384,7 +407,7 @@ export class WalletKitService {
384407 } ,
385408 } ) ;
386409
387- return new WalletKitService ( walletKit ) ;
410+ return new WalletKitService ( chainService , walletKit ) ;
388411 }
389412}
390413
0 commit comments