Skip to content

Commit

Permalink
Fix/wallet issues OK-34183 OK-34129 OK-34114 OK-34112 OK-34063 OK-337…
Browse files Browse the repository at this point in the history
…70 (#6301)

* fix: force enable token in all networks

* fix: timestamp format error

* fix: all networks loading status

* fix: okx sol tx error

* fix: lint
  • Loading branch information
weatherstar authored Dec 3, 2024
1 parent f8128f7 commit e9d0589
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 25 deletions.
3 changes: 3 additions & 0 deletions packages/kit-bg/src/services/ServiceSend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class ServiceSend extends ServiceBase {
specifiedFeeRate,
prevNonce,
feeInfo,
swapInfo,
} = params;
const vault = await vaultFactory.getVault({ networkId, accountId });
return vault.buildUnsignedTx({
Expand All @@ -103,6 +104,7 @@ class ServiceSend extends ServiceBase {
specifiedFeeRate,
prevNonce,
feeInfo,
swapInfo,
});
}

Expand Down Expand Up @@ -527,6 +529,7 @@ class ServiceSend extends ServiceBase {
approveInfo,
transfersInfo,
wrappedInfo,
swapInfo,
specifiedFeeRate,
prevNonce,
feeInfo,
Expand Down
38 changes: 35 additions & 3 deletions packages/kit-bg/src/vaults/impls/sol/Vault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ import type {
IMeasureRpcStatusResult,
} from '@onekeyhq/shared/types/customRpc';
import type { IFeeInfoUnit } from '@onekeyhq/shared/types/fee';
import type { ISwapTxInfo } from '@onekeyhq/shared/types/swap/types';
import {
EDecodedTxActionType,
EDecodedTxStatus,
Expand Down Expand Up @@ -1013,19 +1014,50 @@ export default class Vault extends VaultBase {
): Promise<IUnsignedTxPro> {
const encodedTx = params.encodedTx ?? (await this.buildEncodedTx(params));
if (encodedTx) {
return this._buildUnsignedTxFromEncodedTx(encodedTx as IEncodedTxSol);
return this._buildUnsignedTxFromEncodedTx({
encodedTx: encodedTx as IEncodedTxSol,
swapInfo: params.swapInfo,
});
}
throw new OneKeyInternalError();
}

async _buildUnsignedTxFromEncodedTx(encodedTx: IEncodedTxSol) {
async _buildUnsignedTxFromEncodedTx({
encodedTx,
swapInfo,
}: {
encodedTx: IEncodedTxSol;
swapInfo?: ISwapTxInfo;
}) {
const accountAddress = await this.getAccountAddress();

let newEncodedTx = encodedTx;

// internal okx sol swap tx need to replace recentBlockhash
if (swapInfo && swapInfo.swapBuildResData.OKXTxObject) {
const nativeTx = (await parseToNativeTx(encodedTx)) as INativeTxSol;
const { recentBlockhash, lastValidBlockHeight } =
await this._getRecentBlockHash();

if (nativeTx instanceof Transaction) {
nativeTx.recentBlockhash = recentBlockhash;
nativeTx.lastValidBlockHeight = lastValidBlockHeight;
} else if (nativeTx instanceof VersionedTransaction) {
nativeTx.message.recentBlockhash = recentBlockhash;
}

newEncodedTx = bs58.encode(
nativeTx.serialize({
requireAllSignatures: false,
}),
);
}

return {
payload: {
feePayer: accountAddress,
},
encodedTx,
encodedTx: newEncodedTx,
};
}

Expand Down
1 change: 1 addition & 0 deletions packages/kit/src/components/TxAction/TxActionCommon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ function TxActionCommonListView(
<SizableText size="$bodyMd" color="$textSubdued">
{formatTime(new Date(timestamp), {
hideSeconds: true,
hideMilliseconds: true,
})}
</SizableText>
{description && description.children ? (
Expand Down
53 changes: 31 additions & 22 deletions packages/kit/src/hooks/useAllNetwork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import perfUtils, {
EPerformanceTimerLogNames,
} from '@onekeyhq/shared/src/utils/debug/perfUtils';
import { generateUUID } from '@onekeyhq/shared/src/utils/miscUtils';
import { promiseAllSettledEnhanced } from '@onekeyhq/shared/src/utils/promiseUtils';

import backgroundApiProxy from '../background/instance/backgroundApiProxy';
import { perfTokenListView } from '../components/TokenListView/perfTokenListView';
Expand Down Expand Up @@ -290,16 +291,20 @@ function useAllNetworkRequests<T>(params: {
});

try {
resp = (await Promise.all(requests)).filter(Boolean);
resp = (
await promiseAllSettledEnhanced(requests, {
continueOnError: true,
})
).filter(Boolean);
} catch (e) {
console.error(e);
resp = null;
abortAllNetworkRequests?.();
}
} else {
try {
await Promise.all(
Array.from(accountsInfoBackendIndexed).map((networkDataString) => {
const promises = Array.from(accountsInfoBackendIndexed).map(
(networkDataString) => {
const { accountId, networkId, apiAddress } = networkDataString;
console.log(
'accountsBackedIndexedRequests: =====>>>>>: ',
Expand All @@ -313,33 +318,37 @@ function useAllNetworkRequests<T>(params: {
allNetworkDataInit: allNetworkDataInit.current,
customTokensRawData,
});
}),
},
);
await promiseAllSettledEnhanced(promises, {
continueOnError: true,
});
} catch (e) {
console.error(e);
// pass
}

try {
await Promise.all(
Array.from(accountsInfoBackendNotIndexed).map(
(networkDataString) => {
const { accountId, networkId, apiAddress } = networkDataString;
console.log(
'accountsBackedNotIndexedRequests: =====>>>>>: ',
accountId,
networkId,
apiAddress,
);
return allNetworkRequests({
accountId,
networkId,
allNetworkDataInit: allNetworkDataInit.current,
customTokensRawData,
});
},
),
const promises = Array.from(accountsInfoBackendNotIndexed).map(
(networkDataString) => {
const { accountId, networkId, apiAddress } = networkDataString;
console.log(
'accountsBackedNotIndexedRequests: =====>>>>>: ',
accountId,
networkId,
apiAddress,
);
return allNetworkRequests({
accountId,
networkId,
allNetworkDataInit: allNetworkDataInit.current,
customTokensRawData,
});
},
);
await promiseAllSettledEnhanced(promises, {
continueOnError: true,
});
} catch (e) {
console.error(e);
// pass
Expand Down
12 changes: 12 additions & 0 deletions packages/kit/src/views/Home/pages/TokenListContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1004,11 +1004,23 @@ function TokenListContainer(props: ITabPageProps) {
refreshRiskyTokenListMap({
tokens: riskyTokenListMap,
});
refreshAllTokenList({
keys: `${tokenList.keys}_${smallBalanceTokenList.keys}_${riskyTokenList.keys}`,
tokens: [...tokenList.tokens, ...riskyTokenList.riskyTokens],
});
refreshAllTokenListMap({
tokens: {
...mergeTokenListMap,
...riskyTokenListMap,
},
});
}
}, [
account?.createAtNetwork,
account?.id,
allNetworksResult,
refreshAllTokenList,
refreshAllTokenListMap,
refreshRiskyTokenList,
refreshRiskyTokenListMap,
refreshSmallBalanceTokenList,
Expand Down
5 changes: 5 additions & 0 deletions packages/shared/src/utils/dateUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export type IFormatDateOptions = {
hideTimeForever?: boolean;
hideSeconds?: boolean;
formatTemplate?: string;
hideMilliseconds?: boolean;
};

export type IFormatMonthOptions = {
Expand Down Expand Up @@ -224,6 +225,10 @@ export function formatTime(date: Date | string, options?: IFormatDateOptions) {
formatTemplate = formatTemplate.replace('HH:mm:ss', 'HH:mm');
}

if (options?.hideMilliseconds) {
formatTemplate = formatTemplate.replace('.SSS', '');
}

return formatDateFns(parsedDate, formatTemplate) ?? '';
}

Expand Down
14 changes: 14 additions & 0 deletions packages/shared/src/utils/promiseUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,17 @@ export function isPromiseObject(obj: any) {
}
return false;
}

export async function promiseAllSettledEnhanced<T>(
promises: Promise<T>[],
options?: { continueOnError?: boolean },
): Promise<(T | null)[]> {
if (!options?.continueOnError) {
return Promise.all(promises);
}

const results = await Promise.allSettled(promises);
return results.map((result) =>
result.status === 'fulfilled' ? result.value : null,
);
}

0 comments on commit e9d0589

Please sign in to comment.