Skip to content

Commit

Permalink
fix: batch response data
Browse files Browse the repository at this point in the history
  • Loading branch information
sanyu1225 committed Dec 13, 2023
1 parent dff32e6 commit 1dcdbd3
Showing 1 changed file with 6 additions and 20 deletions.
26 changes: 6 additions & 20 deletions packages/blocto-sdk/src/providers/ethereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ export default class EthereumProvider
const allPromise = isSendRequestsEmpty
? [...otherRequests]
: [this.request(batchReqPayload), ...otherRequests];

// resolve response when all request are executed
Promise.allSettled(allPromise)
.then((responses) => {
Expand All @@ -290,16 +291,17 @@ export default class EthereumProvider
}
const originalLengthResponse = payload.map((item, index) => {
const response = responses[index];
const sendResponse = responses[0]; // allPromise[0] must be batchReqPayload
const baseResponse = {
id: String(item.id || idBase + index + 1),
jsonrpc: '2.0',
method: item.method,
};
// const sendTransactionResponse =
if (!response?.status && item.method === 'eth_sendTransaction') {
if (index !== 0 && !responses[index]) {
return {
...baseResponse,
method: 'shouldInsertSendObj',
...sendResponse,
id: String(item.id),
};
}
if (response.status === 'fulfilled') {
Expand All @@ -316,23 +318,7 @@ export default class EthereumProvider
};
}
});
const sendTransactionResponse = originalLengthResponse.find(
(obj) => obj.method === 'eth_sendTransaction'
);
const result = originalLengthResponse.map((e) => {
if (e?.method === 'shouldInsertSendObj') {
return {
...e,
...sendTransactionResponse,
id: e.id,
};
} else {
return {
...e,
};
}
});
return resolve(<Array<JsonRpcResponse>>result);
return resolve(<Array<JsonRpcResponse>>originalLengthResponse);
})
.catch((error) => {
throw ethErrors.rpc.internal(error?.message);
Expand Down

0 comments on commit 1dcdbd3

Please sign in to comment.