Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v4 fix: issues OK-27103 OK-26732 OK-26731 OK-25715 OK-22633 #4506

Merged
merged 7 commits into from
Apr 26, 2024
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
15 changes: 15 additions & 0 deletions packages/engine/src/dbs/simple/entity/SimpleDbEntityHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,21 @@ class SimpleDbEntityHistory extends SimpleDbEntityBase<ISimpleDbEntityHistoryDat
return null;
}

async getMinPendingNonce(props: {
accountId: string;
networkId: string;
}): Promise<number | null> {
const nonceList = await this.getPendingNonceList(props);
if (nonceList.length) {
const nonce = Math.min(...nonceList);
if (Number.isNaN(nonce) || nonce === Infinity || nonce === -Infinity) {
return null;
}
return nonce;
}
return null;
}

_getAccountHistoryInList({
allData,
accountId,
Expand Down
8 changes: 8 additions & 0 deletions packages/engine/src/vaults/VaultBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,14 @@ export abstract class VaultBaseChainOnly extends VaultContext {
return 0;
}

async isEarliestPendingTx({
encodedTx,
}: {
encodedTx: IEncodedTx;
}): Promise<boolean> {
return true;
}

async fetchBalanceDetails({
password,
useRecycleBalance,
Expand Down
10 changes: 9 additions & 1 deletion packages/engine/src/vaults/impl/algo/Vault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,15 @@ export default class Vault extends VaultBase {
groupId = Buffer.from(nativeTx.grp).toString('base64');
}
if (nativeTx.note) {
notes.push(nativeTx.note.toString());
let noteString = nativeTx.note.toString();
if (noteString.length === 1) {
try {
noteString = `0x${Buffer.from(noteString).toString('hex')}`;
} catch {
// pass
}
}
notes.push(noteString);
}
}

Expand Down
29 changes: 22 additions & 7 deletions packages/engine/src/vaults/impl/evm/Vault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import debugLogger from '@onekeyhq/shared/src/logger/debugLogger';
import { memoizee } from '@onekeyhq/shared/src/utils/cacheUtils';
import { toBigIntHex } from '@onekeyhq/shared/src/utils/numberUtils';

import simpleDb from '../../../dbs/simple/simpleDb';
import { NotImplemented, OneKeyInternalError } from '../../../errors';
import * as covalentApi from '../../../managers/covalent';
import { getAccountNameInfoByImpl } from '../../../managers/impl';
Expand Down Expand Up @@ -184,13 +185,14 @@ export enum IDecodedTxEvmType {

function decodeUnsignedTxFeeData(unsignedTx: UnsignedTx) {
return {
feeLimit: unsignedTx.feeLimit?.toFixed(),
feePricePerUnit: unsignedTx.feePricePerUnit?.toFixed(),
maxPriorityFeePerGas:
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
unsignedTx.payload?.maxPriorityFeePerGas?.toFixed(),
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
maxFeePerGas: unsignedTx.payload?.maxFeePerGas?.toFixed(),
feeLimit: new BigNumber(unsignedTx.feeLimit ?? 0).toFixed(),
feePricePerUnit: new BigNumber(unsignedTx.feePricePerUnit ?? 0).toFixed(),
maxPriorityFeePerGas: new BigNumber(
unsignedTx.payload?.maxPriorityFeePerGas ?? 0,
).toFixed(),
maxFeePerGas: new BigNumber(
unsignedTx.payload?.maxFeePerGas ?? 0,
).toFixed(),
};
}

Expand Down Expand Up @@ -806,6 +808,19 @@ export default class Vault extends VaultBase {
};
}

override async isEarliestPendingTx({
encodedTx,
}: {
encodedTx: IEncodedTxEvm;
}): Promise<boolean> {
const minPendingNonce = await simpleDb.history.getMinPendingNonce({
accountId: this.accountId,
networkId: this.networkId,
});

return new BigNumber(encodedTx.nonce ?? 0).isEqualTo(minPendingNonce ?? 0);
}

buildEncodedTxFromWrapperTokenDeposit({
amount,
from,
Expand Down
15 changes: 15 additions & 0 deletions packages/kit-bg/src/services/ServiceTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,4 +293,19 @@ export default class ServiceTransaction extends ServiceBase {
const vault = await engine.getChainOnlyVault(networkId);
return vault.getTransactionDetail(txId);
}

@backgroundMethod()
async isEarliestPendingTx({
accountId,
networkId,
encodedTx,
}: {
accountId: string;
networkId: string;
encodedTx: IEncodedTx;
}) {
const { engine } = this.backgroundApi;
const vault = await engine.getVault({ accountId, networkId });
return vault.isEarliestPendingTx({ encodedTx });
}
}
106 changes: 55 additions & 51 deletions packages/kit/src/views/Send/components/SendEditFeeOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,60 +50,62 @@ function SendEditFeeOverview(props: Props) {
let minFeeNative = '';
let totalFeeNative = '';
const displayDecimal = feeInfo?.feeDecimals;
if (isEIP1559Fee) {
const { min, max } = calculateTotalFeeRange(
{
eip1559: true,
limit,
price1559: price as EIP1559Fee,
},
displayDecimal,
);
const minFee = min;
totalFeeNative = calculateTotalFeeNative({
amount: max,
info: feeInfo,
});
if (feeInfo) {
if (isEIP1559Fee) {
const { min, max } = calculateTotalFeeRange(
{
eip1559: true,
limit,
price1559: price as EIP1559Fee,
},
displayDecimal,
);
const minFee = min;
totalFeeNative = calculateTotalFeeNative({
amount: max,
info: feeInfo,
});

minFeeNative = calculateTotalFeeNative({
amount: minFee,
info: feeInfo,
});
} else if (isBtcForkChain) {
let btcFee;
if (btcCustomFee) {
btcFee = parseInt(btcCustomFee);
minFeeNative = calculateTotalFeeNative({
amount: minFee,
info: feeInfo,
});
} else if (isBtcForkChain) {
let btcFee;
if (btcCustomFee) {
btcFee = parseInt(btcCustomFee);
} else {
const priceIndex = feeInfo.prices.findIndex((i) => i === price);
btcFee = feeInfo.feeList?.[priceIndex];
}
const totalFee = calculateTotalFeeRange(
{
limit,
price: price as string,
btcFee,
isBtcForkChain: true,
},
displayDecimal,
).max;
totalFeeNative = calculateTotalFeeNative({
amount: totalFee,
info: feeInfo,
displayDecimal,
});
} else {
const priceIndex = feeInfo.prices.findIndex((i) => i === price);
btcFee = feeInfo.feeList?.[priceIndex];
const totalFee = calculateTotalFeeRange(
{
limit,
price: price as string,
},
displayDecimal,
).max;
totalFeeNative = calculateTotalFeeNative({
amount: totalFee,
info: feeInfo,
displayDecimal,
});
}
const totalFee = calculateTotalFeeRange(
{
limit,
price: price as string,
btcFee,
isBtcForkChain: true,
},
displayDecimal,
).max;
totalFeeNative = calculateTotalFeeNative({
amount: totalFee,
info: feeInfo,
displayDecimal,
});
} else {
const totalFee = calculateTotalFeeRange(
{
limit,
price: price as string,
},
displayDecimal,
).max;
totalFeeNative = calculateTotalFeeNative({
amount: totalFee,
info: feeInfo as IFeeInfo,
displayDecimal,
});
}

if (onlyCurrency) {
Expand All @@ -130,6 +132,8 @@ function SendEditFeeOverview(props: Props) {
);
}

if (!feeInfo) return null;

return (
<Box>
<Text typography="Body2Strong" textAlign="center">
Expand Down
73 changes: 59 additions & 14 deletions packages/kit/src/views/Send/modals/SendEditFee/SendEditFee.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { cloneDeep, last } from 'lodash';
import { useIntl } from 'react-intl';

import {
Alert,
Box,
Button,
Center,
Expand Down Expand Up @@ -137,18 +138,24 @@ function ScreenSendEditFee({ ...rest }) {
}
return encodedTx as IEncodedTxEvm;
}, [autoConfirmAfterFeeSaved, encodedTx]);
const { feeInfoPayload, feeInfoLoading, getSelectedFeeInfoUnit } =
useFeeInfoPayload({
networkId,
accountId,
encodedTx: encodedTxForFeeInfo,
fetchAnyway: true,
ignoreFetchFeeCalling: oldSendConfirmParams?.ignoreFetchFeeCalling,
useFeeInTx: oldSendConfirmParams?.feeInfoUseFeeInTx,
forBatchSend,
pollingInterval: FEE_INFO_POLLING_INTERVAL,
shouldStopPolling: feeType === ESendEditFeeTypes.advanced,
});
const {
feeInfoPayload,
feeInfoLoading,
getSelectedFeeInfoUnit,
feeInfoError,
} = useFeeInfoPayload({
networkId,
accountId,
encodedTx: encodedTxForFeeInfo,
fetchAnyway: true,
ignoreFetchFeeCalling: autoConfirmAfterFeeSaved
? false
: oldSendConfirmParams?.ignoreFetchFeeCalling,
useFeeInTx: oldSendConfirmParams?.feeInfoUseFeeInTx,
forBatchSend,
pollingInterval: FEE_INFO_POLLING_INTERVAL,
shouldStopPolling: feeType === ESendEditFeeTypes.advanced,
});

const isEIP1559Fee = feeInfoPayload?.info?.eip1559;
const isBtcForkChain = feeInfoPayload?.info?.isBtcForkChain;
Expand Down Expand Up @@ -419,6 +426,35 @@ function ScreenSendEditFee({ ...rest }) {
],
);

const errorHint = useMemo(() => {
if (!feeInfoError) {
return null;
}

// @ts-expect-error
const { className, key }: { className?: string; key?: string } =
feeInfoError;

let message: string | null = null;
if (className === 'OneKeyError') {
if (key !== 'onekey_error') {
message = intl.formatMessage({
// @ts-expect-error
id: feeInfoError.key,
});
} else {
message = feeInfoError.message;
}
} else {
message = feeInfoError.message;
}
if (message && message.length > 350) {
message = `${message.slice(0, 350)}...`;
}

return <Alert alertType="error" title={message} dismiss={false} />;
}, [feeInfoError, intl]);

useEffect(() => {
if (
!feeInfoPayload ||
Expand Down Expand Up @@ -651,8 +687,17 @@ function ScreenSendEditFee({ ...rest }) {
if (isBtcForkChain || feeType === ESendEditFeeTypes.advanced) {
return !formState.isValid;
}

if (feeInfoError) return true;

return false;
}, [isBtcForkChain, formState.isValid, feeType, feeInfoLoading]);
}, [
feeInfoLoading,
isBtcForkChain,
feeType,
feeInfoError,
formState.isValid,
]);

return (
<BaseSendModal
Expand Down Expand Up @@ -715,7 +760,7 @@ function ScreenSendEditFee({ ...rest }) {
scrollViewProps={{
children: (
<>
{content}
{errorHint || content}
<DecodeTxButtonTest
networkId={networkId}
accountId={accountId}
Expand Down
Loading
Loading