Skip to content

Commit dca003f

Browse files
committed
feat: support bfc swap gas
1 parent 7f4059e commit dca003f

File tree

5 files changed

+61
-3
lines changed

5 files changed

+61
-3
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ test-report.html
7373
# Temporary files created by Metro to check the health of the file watcher
7474
.metro-health-check*
7575

76-
# Ignore tamagui config file
76+
# Ignore tamagui config file
7777
.tamagui
7878

7979
# Ignore copy inject files

packages/kit-bg/src/providers/ProviderApiBfc.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,10 @@ class ProviderApiBfc extends ProviderApiBase {
188188
rawTx: TransactionBlock.from(params.blockSerialize).serialize(),
189189
sender: address ?? '',
190190
};
191+
console.log(
192+
'======>>>>> benfen blockData',
193+
TransactionBlock.from(params.blockSerialize).blockData,
194+
);
191195

192196
const result =
193197
await this.backgroundApi.serviceDApp.openSignAndSendTransactionModal({

packages/kit-bg/src/vaults/impls/bfc/Vault.ts

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,14 @@ import { BFC_TYPE_ARG, isValidBenfenAddress } from '@benfen/bfc.js/utils';
44
import BigNumber from 'bignumber.js';
55
import { isEmpty } from 'lodash';
66

7+
import type { IEncodedTxBfc } from '@onekeyhq/core/src/chains/bfc/types';
78
import type { IEncodedTxSui } from '@onekeyhq/core/src/chains/sui/types';
89
import coreChainApi from '@onekeyhq/core/src/instance/coreChainApi';
9-
import type { ISignedTxPro, IUnsignedTxPro } from '@onekeyhq/core/src/types';
10+
import type {
11+
IEncodedTx,
12+
ISignedTxPro,
13+
IUnsignedTxPro,
14+
} from '@onekeyhq/core/src/types';
1015
import { OneKeyInternalError } from '@onekeyhq/shared/src/errors';
1116
import { memoizee } from '@onekeyhq/shared/src/utils/cacheUtils';
1217
import timerUtils from '@onekeyhq/shared/src/utils/timerUtils';
@@ -22,6 +27,7 @@ import type {
2227
IMeasureRpcStatusParams,
2328
IMeasureRpcStatusResult,
2429
} from '@onekeyhq/shared/types/customRpc';
30+
import type { IFeeInfoUnit } from '@onekeyhq/shared/types/fee';
2531
import {
2632
EDecodedTxActionType,
2733
EDecodedTxStatus,
@@ -553,4 +559,33 @@ export default class Vault extends VaultBase {
553559
};
554560
return Promise.resolve(encodedTx);
555561
}
562+
563+
override async attachFeeInfoToDAppEncodedTx(params: {
564+
encodedTx: IEncodedTx;
565+
feeInfo: IFeeInfoUnit;
566+
}): Promise<IEncodedTx> {
567+
const unSignedEncodedTx = params.encodedTx as IEncodedTxBfc;
568+
const blockData = TransactionBlock.from(unSignedEncodedTx.rawTx).blockData;
569+
const { payment, budget } = blockData.gasConfig;
570+
571+
const budgetValue = new BigNumber(budget?.toString() ?? '0');
572+
if (payment && payment.length > 0 && budgetValue.gt(0)) {
573+
const client = await this.getClient();
574+
const gasPrice = await client.getObject({
575+
id: payment[0]?.objectId,
576+
options: {
577+
showContent: true,
578+
showType: true,
579+
},
580+
});
581+
if (
582+
gasPrice.data?.type ===
583+
'0x2::coin::Coin<0x00000000000000000000000000000000000000000000000000000000000000c8::busd::BUSD>'
584+
) {
585+
return Promise.resolve('');
586+
}
587+
}
588+
589+
return unSignedEncodedTx;
590+
}
556591
}

packages/kit-bg/src/vaults/impls/bfc/settings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const settings: IVaultSettings = {
3737
],
3838

3939
dappInteractionEnabled: true,
40+
preCheckDappTxFeeInfoRequired: true,
4041

4142
defaultFeePresetIndex: 0,
4243

packages/kit/src/views/SignatureConfirm/components/TxFee/TxFeeInfo.tsx

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react';
22

3+
import { TransactionBlock } from '@benfen/bfc.js/transactions';
34
import BigNumber from 'bignumber.js';
45
import { isEmpty, isNil } from 'lodash';
56
import { useIntl } from 'react-intl';
@@ -13,6 +14,7 @@ import {
1314
XStack,
1415
} from '@onekeyhq/components';
1516
import type { IEncodedTxAptos } from '@onekeyhq/core/src/chains/aptos/types';
17+
import type { IEncodedTxBfc } from '@onekeyhq/core/src/chains/bfc/types';
1618
import type { IEncodedTxBtc } from '@onekeyhq/core/src/chains/btc/types';
1719
import type { IEncodedTxDot } from '@onekeyhq/core/src/chains/dot/types';
1820
import type { IEncodedTxEvm } from '@onekeyhq/core/src/chains/evm/types';
@@ -44,7 +46,7 @@ import {
4446
BATCH_SEND_TXS_FEE_UP_RATIO_FOR_APPROVE,
4547
BATCH_SEND_TXS_FEE_UP_RATIO_FOR_SWAP,
4648
} from '@onekeyhq/shared/src/consts/walletConsts';
47-
import { IMPL_APTOS } from '@onekeyhq/shared/src/engine/engineConsts';
49+
import { IMPL_APTOS, IMPL_BFC } from '@onekeyhq/shared/src/engine/engineConsts';
4850
import type { IOneKeyRpcError } from '@onekeyhq/shared/src/errors/types/errorTypes';
4951
import {
5052
EAppEventBusNames,
@@ -387,6 +389,22 @@ function TxFeeInfo(props: IProps) {
387389
};
388390
}
389391
}
392+
393+
if (network && network.impl === IMPL_BFC && unsignedTxs.length > 0) {
394+
const { rawTx } = unsignedTxs[0].encodedTx as IEncodedTxBfc;
395+
const blockData = TransactionBlock.from(rawTx).blockData;
396+
// const { budget, price } = blockData.gasConfig;
397+
398+
// TODO: remove
399+
feeInfo.common.nativeDecimals = 9;
400+
feeInfo.common.nativeSymbol = 'BUSD';
401+
402+
// feeInfo.gas = {
403+
// ...feeInfo.gas,
404+
// gasPrice: price?.toString() ?? '0',
405+
// gasLimit: budget?.toString() ?? '1',
406+
// };
407+
}
390408
}
391409

392410
items.push({

0 commit comments

Comments
 (0)