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
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# 更新日志

## [1.0.6] - 2026-02-18

修复 BSC 转账广播链路并透传 tokenAddress

<!-- last-commit: b6845de129e00e7720e0f12402c89008b995b93f -->

## [1.0.5] - 2026-02-18

修复 miniapp Crypto 授权手势校验与错误提示
Expand Down Expand Up @@ -257,4 +263,3 @@ DWEB 安装资源与发布流程优化
DWEB 安装资源与版本发布流程优化

<!-- last-commit: 5c166987badd06a0a81f4fd5a48ef6763d586be0 -->

4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"author": [
"@bfmeta.info"
],
"version": "1.0.5",
"change_log": "修复 miniapp Crypto 授权手势校验与错误提示",
"version": "1.0.6",
"change_log": "修复 BSC 转账广播链路并透传 tokenAddress",
"categories": [
"application",
"wallet"
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@biochain/keyapp",
"private": true,
"version": "1.0.5",
"version": "1.0.6",
"type": "module",
"packageManager": "pnpm@10.28.0",
"scripts": {
Expand Down Expand Up @@ -218,5 +218,5 @@
"packages/*",
"miniapps/*"
],
"lastChangelogCommit": "873c9bdfd2492f1222f46a649a07055ca64bf6a5"
"lastChangelogCommit": "b6845de129e00e7720e0f12402c89008b995b93f"
}
2 changes: 2 additions & 0 deletions src/hooks/use-send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ export function useSend(options: UseSendOptions = {}): UseSendReturn {
fromAddress,
toAddress,
amount: state.amount ?? undefined,
tokenAddress: state.asset?.contractAddress,
})
: await fetchBioforestFee(chainConfig!, fromAddress!);

Expand Down Expand Up @@ -327,6 +328,7 @@ export function useSend(options: UseSendOptions = {}): UseSendReturn {
fromAddress,
toAddress: state.toAddress,
amount: state.amount,
tokenAddress: state.asset.contractAddress,
});

if (result.status === 'password') {
Expand Down
61 changes: 60 additions & 1 deletion src/hooks/use-send.web3.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,16 @@ vi.mock('@/services/chain-adapter/providers', async () => {
};
});

import { submitWeb3Transfer } from './use-send.web3';
import { fetchWeb3Fee, submitWeb3Transfer } from './use-send.web3';

type MockChainProvider = {
supportsFullTransaction: boolean;
supportsBuildTransaction?: boolean;
supportsFeeEstimate?: boolean;
buildTransaction: (intent: unknown) => Promise<unknown>;
signTransaction: (unsignedTx: unknown, options: { privateKey: Uint8Array }) => Promise<unknown>;
broadcastTransaction: (signedTx: unknown) => Promise<string>;
estimateFee?: (unsignedTx: unknown) => Promise<{ standard: { amount: Amount } }>;
};

function createChainConfig(): ChainConfig {
Expand Down Expand Up @@ -151,4 +154,60 @@ describe('submitWeb3Transfer', () => {

expect(result).toEqual({ status: 'ok', txHash: 'tx-hash' });
});

it('passes tokenAddress to buildTransaction', async () => {
const provider = createMockProvider();
mockGetChainProvider.mockReturnValue(provider);

await submitWeb3Transfer({
chainConfig: createChainConfig(),
walletId: 'wallet-1',
password: 'pwd',
fromAddress: 'TFromAddress',
toAddress: 'TToAddress',
amount: Amount.fromRaw('1000000', 6, 'USDT'),
tokenAddress: 'TTokenContract',
});

expect(provider.buildTransaction).toHaveBeenCalledWith(
expect.objectContaining({
tokenAddress: 'TTokenContract',
}),
);
});
});

describe('fetchWeb3Fee', () => {
beforeEach(() => {
vi.clearAllMocks();
});

it('passes tokenAddress to buildTransaction', async () => {
const provider: MockChainProvider = createMockProvider({
supportsFullTransaction: true,
supportsFeeEstimate: true,
supportsBuildTransaction: true,
buildTransaction: vi.fn(async () => ({ data: { txID: 'mock-tx' } })),
estimateFee: vi.fn(async () => ({
standard: { amount: Amount.fromRaw('1000', 6, 'TRX') },
})),
});

mockGetChainProvider.mockReturnValue(provider);

const result = await fetchWeb3Fee({
chainConfig: createChainConfig(),
fromAddress: 'TFromAddress',
toAddress: 'TToAddress',
amount: Amount.fromRaw('1000000', 6, 'USDT'),
tokenAddress: 'TTokenContract',
});

expect(provider.buildTransaction).toHaveBeenCalledWith(
expect.objectContaining({
tokenAddress: 'TTokenContract',
}),
);
expect(result.amount.toRawString()).toBe('1000');
});
});
13 changes: 12 additions & 1 deletion src/hooks/use-send.web3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,16 @@ export interface FetchWeb3FeeParams {
fromAddress: string;
toAddress: string;
amount?: Amount | undefined;
tokenAddress?: string | undefined;
}

export async function fetchWeb3Fee({ chainConfig, fromAddress, toAddress, amount }: FetchWeb3FeeParams): Promise<Web3FeeResult> {
export async function fetchWeb3Fee({
chainConfig,
fromAddress,
toAddress,
amount,
tokenAddress,
}: FetchWeb3FeeParams): Promise<Web3FeeResult> {
const chainProvider = getChainProvider(chainConfig.id);

if (!chainProvider.supportsFeeEstimate || !chainProvider.supportsBuildTransaction) {
Expand All @@ -151,6 +158,7 @@ export async function fetchWeb3Fee({ chainConfig, fromAddress, toAddress, amount
from: fromAddress,
to: toAddress,
amount: estimateAmount,
tokenAddress,
});

const feeEstimate = await chainProvider.estimateFee!(unsignedTx);
Expand Down Expand Up @@ -185,6 +193,7 @@ export interface SubmitWeb3Params {
fromAddress: string;
toAddress: string;
amount: Amount;
tokenAddress?: string | undefined;
}

export async function submitWeb3Transfer({
Expand All @@ -194,6 +203,7 @@ export async function submitWeb3Transfer({
fromAddress,
toAddress,
amount,
tokenAddress,
}: SubmitWeb3Params): Promise<SubmitWeb3Result> {
// Get mnemonic from wallet storage
let secret: string;
Expand Down Expand Up @@ -228,6 +238,7 @@ export async function submitWeb3Transfer({
from: fromAddress,
to: toAddress,
amount,
tokenAddress,
});

// Sign transaction
Expand Down
Loading