Skip to content

Commit 7e9b483

Browse files
authored
make getFeeTokens independent of chain session manager and initialize state (#890)
* make getFeeTokens independent of chain session manager and initialized state * remove getFeeTokens from chain session manager
1 parent ed4064a commit 7e9b483

3 files changed

Lines changed: 8 additions & 18 deletions

File tree

packages/wallet/dapp-client/src/ChainSessionManager.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -781,19 +781,6 @@ export class ChainSessionManager {
781781
}
782782
}
783783

784-
/**
785-
* Fetches fee tokens for a chain.
786-
* @returns {GetFeeTokensResponse}
787-
* @throws {FeeOptionError} If fetching fee tokens fails.
788-
*/
789-
async getFeeTokens(): Promise<GetFeeTokensResponse> {
790-
try {
791-
return await this.relayer.feeTokens()
792-
} catch (err) {
793-
throw new FeeOptionError(`Failed to get fee tokens: ${err instanceof Error ? err.message : String(err)}`)
794-
}
795-
}
796-
797784
/**
798785
* Builds, signs, and sends a batch of transactions.
799786
* @param transactions The transactions to be sent.

packages/wallet/dapp-client/src/DappClient.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
} from './types/index.js'
3232
import { TypedData } from 'ox/TypedData'
3333
import { KEYMACHINE_URL, NODES_URL, RELAYER_URL } from './utils/constants.js'
34+
import { getRelayerUrl, getRpcUrl } from './utils/index.js'
3435

3536
export type DappClientEventListener = (data?: any) => void
3637

@@ -568,11 +569,12 @@ export class DappClient {
568569
* @throws If the fee tokens cannot be fetched. {@link InitializationError}
569570
*/
570571
async getFeeTokens(chainId: number): Promise<GetFeeTokensResponse> {
571-
if (!this.isInitialized) throw new InitializationError('Not initialized')
572-
const chainSessionManager = this.getChainSessionManager(chainId)
573-
if (!chainSessionManager.isInitialized)
574-
throw new InitializationError(`ChainSessionManager for chain ${chainId} is not initialized.`)
575-
return await chainSessionManager.getFeeTokens()
572+
const relayer = new Relayer.Standard.Rpc.RpcRelayer(
573+
getRelayerUrl(chainId, this.relayerUrl),
574+
chainId,
575+
getRpcUrl(chainId, this.nodesUrl, this.projectAccessKey),
576+
)
577+
return await relayer.feeTokens()
576578
}
577579

578580
/**

packages/wallet/dapp-client/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export type {
2020
SendWalletTransactionPayload,
2121
SendWalletTransactionResponse,
2222
WalletActionResponse,
23+
GetFeeTokensResponse,
2324
} from './types/index.js'
2425
export { RequestActionType, TransportMode } from './types/index.js'
2526
export {

0 commit comments

Comments
 (0)