Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions src/services/ecosystem/handlers/wallet.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { describe, it, expect, beforeEach } from 'vitest'
import { handleChainId } from './wallet'
import { walletStore } from '@/stores/wallet'
import type { HandlerContext } from '../types'

describe('handleChainId', () => {
const mockContext: HandlerContext = {
appId: 'test-app',
appName: 'Test App',
origin: 'https://test.com',
permissions: [],
}

beforeEach(() => {
// Reset store state
walletStore.setState(() => ({
wallets: [],
currentWalletId: null,
selectedChain: 'bfmeta',
chainPreferences: {},
isLoading: false,
isInitialized: false,
migrationRequired: false,
}))
})

it('should return the currently selected chain ID', async () => {
// Set a different chain
walletStore.setState((state) => ({
...state,
selectedChain: 'ethereum',
}))

const chainId = await handleChainId({}, mockContext)
expect(chainId).toBe('ethereum')
})

it('should return bfmeta if that is the selected chain', async () => {
walletStore.setState((state) => ({
...state,
selectedChain: 'bfmeta',
}))

const chainId = await handleChainId({}, mockContext)
expect(chainId).toBe('bfmeta')
})
})
4 changes: 2 additions & 2 deletions src/services/ecosystem/handlers/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { MethodHandler, BioAccount } from '../types'
import { BioErrorCodes } from '../types'
import { HandlerContext } from './context'
import { getChainProvider } from '@/services/chain-adapter/providers'
import { walletStore } from '@/stores/wallet'

// 兼容旧 API,逐步迁移到 HandlerContext
let _showWalletPicker: ((opts?: { chain?: string; exclude?: string }) => Promise<BioAccount | null>) | null = null
Expand Down Expand Up @@ -104,8 +105,7 @@ export const handlePickWallet: MethodHandler = async (params, context) => {

/** bio_chainId - Get current chain ID */
export const handleChainId: MethodHandler = async (_params, _context) => {
// TODO: Get from current selected chain
return 'bfmeta'
return walletStore.state.selectedChain
}

/** bio_getBalance - Get balance */
Expand Down