Skip to content

Commit

Permalink
Fix/wallet issues OK-34285 OK-34284 (#6330)
Browse files Browse the repository at this point in the history
* feat: add disable sol priority fee to dev settings

* feat: token value NaN

* feat: sort token by value

* feat: enable batch estimate fee on several chains
  • Loading branch information
weatherstar authored Dec 12, 2024
1 parent 682e032 commit a79a418
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 17 deletions.
3 changes: 3 additions & 0 deletions packages/kit-bg/src/states/jotai/atoms/devSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export interface IDevSettings {
showDevExportPrivateKey?: boolean;
// show trading view
showTradingView?: boolean;
// disable Solana priority fee
disableSolanaPriorityFee?: boolean;
}

export type IDevSettingsKeys = keyof IDevSettings;
Expand All @@ -39,6 +41,7 @@ export const {
enableTestEndpoint: !!platformEnv.isDev || !!platformEnv.isE2E,
showDevOverlayWindow: platformEnv.isE2E ? true : undefined,
showTradingView: false,
disableSolanaPriorityFee: false,
},
},
});
Expand Down
8 changes: 8 additions & 0 deletions packages/kit-bg/src/vaults/impls/evm/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,14 @@ const settings: IVaultSettings = {
[networkIdMap.arbitrum]: true,
[networkIdMap.avalanche]: true,
[networkIdMap.base]: true,
[networkIdMap.optimism]: true,
[networkIdMap.polygon]: true,
[networkIdMap.blast]: true,
[networkIdMap.bob]: true,
[networkIdMap.metis]: true,
[networkIdMap.mode]: true,
[networkIdMap.taiko]: true,
[networkIdMap.mantle]: true,
},
};

Expand Down
41 changes: 30 additions & 11 deletions packages/kit-bg/src/vaults/impls/sol/Vault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,15 +228,21 @@ export default class Vault extends VaultBase {

nativeTx.feePayer = source;

const prioritizationFee = await client.getRecentMaxPrioritizationFees([
accountAddress,
]);
const devSettings =
await this.backgroundApi.serviceDevSetting.getDevSetting();
if (
!(devSettings.enabled && devSettings.settings?.disableSolanaPriorityFee)
) {
const prioritizationFee = await client.getRecentMaxPrioritizationFees([
accountAddress,
]);

const addPriorityFee = ComputeBudgetProgram.setComputeUnitPrice({
microLamports: prioritizationFee,
});
const addPriorityFee = ComputeBudgetProgram.setComputeUnitPrice({
microLamports: prioritizationFee,
});

nativeTx.add(addPriorityFee);
nativeTx.add(addPriorityFee);
}

for (let i = 0; i < transfersInfo.length; i += 1) {
const { amount, to, tokenInfo, nftInfo } = transfersInfo[i];
Expand Down Expand Up @@ -1078,10 +1084,16 @@ export default class Vault extends VaultBase {
}

if (feeInfo && feeInfoEditable !== false) {
encodedTxNew = await this._attachFeeInfoToEncodedTx({
encodedTx: encodedTxNew,
feeInfo,
});
const devSettings =
await this.backgroundApi.serviceDevSetting.getDevSetting();
if (
!(devSettings.enabled && devSettings.settings?.disableSolanaPriorityFee)
) {
encodedTxNew = await this._attachFeeInfoToEncodedTx({
encodedTx: encodedTxNew,
feeInfo,
});
}
}

unsignedTx.encodedTx = encodedTxNew;
Expand Down Expand Up @@ -1335,6 +1347,13 @@ export default class Vault extends VaultBase {
feeInfo: IFeeInfoUnit;
}): Promise<IEncodedTxSol> {
const { encodedTx, feeInfo } = params;

const devSettings =
await this.backgroundApi.serviceDevSetting.getDevSetting();
if (devSettings.enabled && devSettings.settings?.disableSolanaPriorityFee) {
return '';
}

const client = await this.getClient();
const accountAddress = await this.getAccountAddress();
let computeUnitPrice = '0';
Expand Down
11 changes: 9 additions & 2 deletions packages/kit/src/components/TokenListView/TokenValueView.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { useMemo } from 'react';

import BigNumber from 'bignumber.js';

import type { ISizableTextProps } from '@onekeyhq/components';
import { useSettingsPersistAtom } from '@onekeyhq/kit-bg/src/states/jotai/atoms';

Expand All @@ -18,17 +20,22 @@ function TokenValueView(props: IProps) {

const token = tokenListMap[$key];

const fiatValue = useMemo(
() => new BigNumber(token?.fiatValue ?? 0),
[token?.fiatValue],
);

const content = useMemo(
() => (
<NumberSizeableTextWrapper
formatter="value"
formatterOptions={{ currency: settings.currencyInfo.symbol }}
{...rest}
>
{token?.fiatValue ?? 0}
{fiatValue.isNaN() ? 0 : fiatValue.toFixed()}
</NumberSizeableTextWrapper>
),
[rest, settings.currencyInfo.symbol, token?.fiatValue],
[fiatValue, rest, settings.currencyInfo.symbol],
);

if (!token) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,24 @@ export const DevSettingsSection = () => {
>
<Switch size={ESwitchSize.small} />
</SectionFieldItem>
<SectionFieldItem
name="disableSolanaPriorityFee"
title="禁用 Solana 交易优先费"
subtitle={
devSettings.settings?.disableSolanaPriorityFee ? '禁用' : '启用'
}
>
<Switch
size={ESwitchSize.small}
onChange={() => {
void backgroundApiProxy.serviceDevSetting.updateDevSetting(
'disableSolanaPriorityFee',
!devSettings.settings?.disableSolanaPriorityFee,
);
}}
value={devSettings.settings?.disableSolanaPriorityFee}
/>
</SectionFieldItem>
<SectionPressItem
title="force RTL"
subtitle="强制启用 RTL 布局"
Expand Down
6 changes: 5 additions & 1 deletion packages/shared/src/config/networkIds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ export type INetworkShortCode =
| 'holesky'
| 'flare'
| 'base'
| 'ton';
| 'ton'
| 'bob'
| 'mode'
| 'taiko'
| 'metis';

const checkErrors: string[] = [];
// TODO generate getNetworkIdsMap in build time
Expand Down
8 changes: 5 additions & 3 deletions packages/shared/src/utils/tokenUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,12 @@ export function sortTokensByFiatValue({
};
}) {
return tokens.sort((a, b) => {
const aFiat = map[a.$key]?.fiatValue ?? 0;
const bFiat = map[b.$key]?.fiatValue ?? 0;
const aFiat = new BigNumber(map[a.$key]?.fiatValue ?? 0);
const bFiat = new BigNumber(map[b.$key]?.fiatValue ?? 0);

return new BigNumber(bFiat).comparedTo(aFiat);
return new BigNumber(bFiat.isNaN() ? 0 : bFiat).comparedTo(
new BigNumber(aFiat.isNaN() ? 0 : aFiat),
);
});
}

Expand Down

0 comments on commit a79a418

Please sign in to comment.