From e6262ea8f88f658643a299df0acc2ff762aa95bf Mon Sep 17 00:00:00 2001 From: weatherstar Date: Mon, 20 Feb 2023 22:06:13 +0800 Subject: [PATCH] fix: batch transfer token issues OK-17550 OK-17542 (#2597) * fix: missing actions * fix: handle get fee error on sol * chore: enable bulksender on prod * fix: lint --- packages/engine/src/managers/covalent.ts | 1 - packages/engine/src/vaults/impl/sol/Vault.ts | 35 ++++++++++++++++++- packages/kit/src/views/Wallet/Tools/index.tsx | 11 ++---- 3 files changed, 37 insertions(+), 10 deletions(-) diff --git a/packages/engine/src/managers/covalent.ts b/packages/engine/src/managers/covalent.ts index 61e7f57a5c2..225c0a9e9bc 100644 --- a/packages/engine/src/managers/covalent.ts +++ b/packages/engine/src/managers/covalent.ts @@ -788,7 +788,6 @@ export async function parseCovalentTxToDecodedTx( } return false; }) - .slice(0, 10) .map((event) => createOutputActionFromCovalentLogEvent({ event, diff --git a/packages/engine/src/vaults/impl/sol/Vault.ts b/packages/engine/src/vaults/impl/sol/Vault.ts index 6ac56e7c13d..f14921855c9 100644 --- a/packages/engine/src/vaults/impl/sol/Vault.ts +++ b/packages/engine/src/vaults/impl/sol/Vault.ts @@ -473,13 +473,46 @@ export default class Vault extends VaultBase { override async buildEncodedTxFromBatchTransfer( transferInfos: ITransferInfo[], ): Promise { + let retryTime = 0; + let lastRpcErrorMessage = ''; + const maxRetryTimes = 5; const client = await this.getClient(); const transferInfo = transferInfos[0]; const { from, to: firstReceiver, isNFT } = transferInfo; const feePayer = new PublicKey(from); const nativeTx = new Transaction(); - [, nativeTx.recentBlockhash] = await client.getFees(); + + const doGetFee = async () => { + try { + const [, recentBlockhash] = await client.getFees(); + return recentBlockhash; + } catch (error: any) { + const rpcErrorData = error?.data as + | { + code: number; + message: string; + data: any; + } + | undefined; + if (error && rpcErrorData) { + lastRpcErrorMessage = rpcErrorData.message; + } + } + }; + + do { + retryTime += 1; + if (retryTime > maxRetryTimes) { + throw new Error( + `Solana getFees retry times exceeded: ${lastRpcErrorMessage || ''}`, + ); + } + const recentBlockhash = await doGetFee(); + nativeTx.recentBlockhash = recentBlockhash; + await wait(1000); + } while (!nativeTx.recentBlockhash); + nativeTx.feePayer = feePayer; for (let i = 0; i < transferInfos.length; i += 1) { diff --git a/packages/kit/src/views/Wallet/Tools/index.tsx b/packages/kit/src/views/Wallet/Tools/index.tsx index ff9341e6598..ad2b1fff26f 100644 --- a/packages/kit/src/views/Wallet/Tools/index.tsx +++ b/packages/kit/src/views/Wallet/Tools/index.tsx @@ -122,7 +122,6 @@ const ToolsPage: FC = () => { (s) => s.settings?.annualReportEntryEnabled ?? false, ); - const enableDevMode = useAppSelector((s) => s.settings?.devMode?.enable); const tools = useTools(network?.id); const responsivePadding = useMemo(() => { @@ -149,17 +148,14 @@ const ToolsPage: FC = () => { if ( !network?.settings.supportBatchTransfer || - (network.impl === IMPL_EVM && - !batchTransferContractAddress[network.id]) || - !enableDevMode + (network.impl === IMPL_EVM && !batchTransferContractAddress[network.id]) ) { allItems = allItems.filter((n) => n.key !== 'bulkSender'); } if ( - (network?.impl === IMPL_EVM && - !batchTransferContractAddress[network?.id]) || - !enableDevMode + network?.impl === IMPL_EVM && + !batchTransferContractAddress[network?.id] ) { allItems = allItems.filter((n) => n.key !== 'bulkSender'); } @@ -183,7 +179,6 @@ const ToolsPage: FC = () => { network?.settings.supportBatchTransfer, network?.id, annualReportEntryEnabled, - enableDevMode, tools, ]);