Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Draft
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
1 change: 1 addition & 0 deletions packages/kit-bg/src/vaults/impls/btc/Vault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,7 @@ export default class VaultBtc extends VaultBase {
}

unsignedTx.encodedTx = encodedTxNew;
unsignedTx.txSize = encodedTxNew.txSize;

return Promise.resolve(unsignedTx);
}
Expand Down
16 changes: 16 additions & 0 deletions packages/kit/src/utils/gasFee.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import BigNumber from 'bignumber.js';

import type { IDecodedTxExtraSol } from '@onekeyhq/core/src/chains/sol/types';
import type { IUnsignedTxPro } from '@onekeyhq/core/src/types';
import { ETranslations } from '@onekeyhq/shared/src/locale';
import { EFeeType } from '@onekeyhq/shared/types/fee';
import type {
Expand Down Expand Up @@ -484,3 +485,18 @@ export function calculateTxExtraFee({ decodedTx }: { decodedTx: IDecodedTx }) {

return extraFeeNative;
}

export function isSameUnsignedTxs({
unsignedTxs,
unsignedTxsWithFeeInfo,
}: {
unsignedTxs: IUnsignedTxPro[];
unsignedTxsWithFeeInfo: IUnsignedTxPro[];
}) {
return unsignedTxs.every((unsignedTx, index) => {
if (unsignedTx.txSize) {
return unsignedTx.txSize === unsignedTxsWithFeeInfo[index]?.txSize;
}
return true;
});
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useCallback, useMemo } from 'react';
import { useCallback, useMemo, useRef } from 'react';

import BigNumber from 'bignumber.js';
import { isNaN, isNil } from 'lodash';
Expand All @@ -21,6 +21,7 @@ import {
useSignatureConfirmActions,
useUnsignedTxsAtom,
} from '@onekeyhq/kit/src/states/jotai/contexts/signatureConfirm';
import { isSameUnsignedTxs } from '@onekeyhq/kit/src/utils/gasFee';
import { useSettingsPersistAtom } from '@onekeyhq/kit-bg/src/states/jotai/atoms';
import { ETranslations } from '@onekeyhq/shared/src/locale';
import { appLocale } from '@onekeyhq/shared/src/locale/appLocale';
Expand Down Expand Up @@ -72,13 +73,15 @@ function TxAdvancedSettings(props: IProps) {
const [unsignedTxs] = useUnsignedTxsAtom();
const [{ decodedTxs }] = useDecodedTxsAtom();
const [settings] = useSettingsPersistAtom();
const { updateTxAdvancedSettings } = useSignatureConfirmActions().current;
const { updateTxAdvancedSettings, updateUnsignedTxs } =
useSignatureConfirmActions().current;
const [selectedFee] = useSendSelectedFeeInfoAtom();
const vaultSettings = usePromiseResult(
async () =>
backgroundApiProxy.serviceNetwork.getVaultSettings({ networkId }),
[networkId],
).result;
const latestUnsignedTxs = useRef(unsignedTxs);

const isInternalSwapTx = useMemo(
() => unsignedTxs.length === 1 && unsignedTxs[0].swapInfo,
Expand All @@ -97,6 +100,8 @@ function TxAdvancedSettings(props: IProps) {

let txString = '';

const unsignedTxsWithFeeInfo = [];

for (let i = 0; i < unsignedTxs.length; i += 1) {
const unsignedTx = unsignedTxs[i];
const unsignedTxWithFeeInfo =
Expand All @@ -107,6 +112,8 @@ function TxAdvancedSettings(props: IProps) {
accountId,
});

unsignedTxsWithFeeInfo.push(unsignedTxWithFeeInfo);

const encodedTx = unsignedTxWithFeeInfo.encodedTx as IEncodedTxEvm;

if (!isNil(encodedTx.nonce)) {
Expand All @@ -121,8 +128,24 @@ function TxAdvancedSettings(props: IProps) {
}
}

if (
!isSameUnsignedTxs({
unsignedTxs: latestUnsignedTxs.current,
unsignedTxsWithFeeInfo,
})
) {
latestUnsignedTxs.current = unsignedTxsWithFeeInfo;
updateUnsignedTxs(unsignedTxsWithFeeInfo);
}

return txString;
}, [unsignedTxs, selectedFee?.feeInfos, accountId, networkId]);
}, [
unsignedTxs,
selectedFee?.feeInfos,
networkId,
accountId,
updateUnsignedTxs,
]);

const abiContent = useMemo(() => {
if (!decodedTxs || decodedTxs.length === 0) {
Expand Down
Loading