diff --git a/packages/blocto-sdk/src/providers/ethereum.ts b/packages/blocto-sdk/src/providers/ethereum.ts index d900f4b1..389c479c 100644 --- a/packages/blocto-sdk/src/providers/ethereum.ts +++ b/packages/blocto-sdk/src/providers/ethereum.ts @@ -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) => { @@ -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') { @@ -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(>result); + return resolve(>originalLengthResponse); }) .catch((error) => { throw ethErrors.rpc.internal(error?.message);