Skip to content

Commit ed4064a

Browse files
authored
add getFeeTokens to dapp client (#889)
* add getFeeTokens to dapp client * fix typo
1 parent d2329ab commit ed4064a

3 files changed

Lines changed: 35 additions & 1 deletion

File tree

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import {
4141
ModifyExplicitSessionPayload,
4242
SessionResponse,
4343
AddExplicitSessionPayload,
44+
GetFeeTokensResponse,
4445
} from './types/index.js'
4546
import { CACHE_DB_NAME, VALUE_FORWARDER_ADDRESS } from './utils/constants.js'
4647
import { ExplicitSession, ImplicitSession, ExplicitSessionConfig } from './index.js'
@@ -780,6 +781,19 @@ export class ChainSessionManager {
780781
}
781782
}
782783

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+
783797
/**
784798
* Builds, signs, and sends a batch of transactions.
785799
* @param transactions The transactions to be sent.

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { SequenceStorage, WebStorage } from './utils/storage.js'
1515
import {
1616
DappClientExplicitSessionEventListener,
1717
DappClientWalletActionEventListener,
18+
GetFeeTokensResponse,
1819
GuardConfig,
1920
LoginMethod,
2021
RandomPrivateKeyFn,
@@ -561,6 +562,19 @@ export class DappClient {
561562
return await chainSessionManager.getFeeOptions(transactions)
562563
}
563564

565+
/**
566+
* Fetches fee tokens for a chain.
567+
* @returns A promise that resolves with the fee tokens response. {@link GetFeeTokensResponse}
568+
* @throws If the fee tokens cannot be fetched. {@link InitializationError}
569+
*/
570+
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()
576+
}
577+
564578
/**
565579
* Checks if the current session has permission to execute a set of transactions on a specific chain.
566580
* @param chainId The chain ID on which to check the permissions.

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
2-
import { ExplicitSession } from '@0xsequence/wallet-core'
2+
import { ExplicitSession, Relayer } from '@0xsequence/wallet-core'
33
import { Attestation, Payload } from '@0xsequence/wallet-primitives'
44
import { Address, Hex } from 'ox'
55
import type { TypedData } from 'ox/TypedData'
@@ -180,3 +180,9 @@ export interface SendRequestOptions {
180180
timeout?: number
181181
path?: string
182182
}
183+
184+
export type GetFeeTokensResponse = {
185+
isFeeRequired: boolean
186+
tokens?: Relayer.Standard.Rpc.FeeToken[]
187+
paymentAddress?: Address.Address
188+
}

0 commit comments

Comments
 (0)