Skip to content

Commit

Permalink
fix: batch transfer token issues OK-17550 OK-17542 (#2597)
Browse files Browse the repository at this point in the history
* fix: missing actions

* fix: handle get fee error on sol

* chore: enable bulksender on prod

* fix: lint
  • Loading branch information
weatherstar authored Feb 20, 2023
1 parent d9e451e commit e6262ea
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 10 deletions.
1 change: 0 additions & 1 deletion packages/engine/src/managers/covalent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,6 @@ export async function parseCovalentTxToDecodedTx(
}
return false;
})
.slice(0, 10)
.map((event) =>
createOutputActionFromCovalentLogEvent({
event,
Expand Down
35 changes: 34 additions & 1 deletion packages/engine/src/vaults/impl/sol/Vault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -473,13 +473,46 @@ export default class Vault extends VaultBase {
override async buildEncodedTxFromBatchTransfer(
transferInfos: ITransferInfo[],
): Promise<IEncodedTx> {
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) {
Expand Down
11 changes: 3 additions & 8 deletions packages/kit/src/views/Wallet/Tools/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand All @@ -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');
}
Expand All @@ -183,7 +179,6 @@ const ToolsPage: FC = () => {
network?.settings.supportBatchTransfer,
network?.id,
annualReportEntryEnabled,
enableDevMode,
tools,
]);

Expand Down

0 comments on commit e6262ea

Please sign in to comment.