Skip to content

Commit

Permalink
Axios bug fixes (#36)
Browse files Browse the repository at this point in the history
* removed axios package and used fetch instead

* updated changelog
  • Loading branch information
vignesha22 authored Sep 20, 2023
1 parent bf5f9de commit 66692f8
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 119 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Changelog
## [1.2.7] - 2023-09-20
### Fixes
- Fixed the issue on usage of axios when paymaster is called via react native by replacing it to fetch.

## [1.2.6] - 2023-09-12
### Fixes
- Fixed the issue on setting gas prices by the user if specified on estimate step
Expand Down
113 changes: 11 additions & 102 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 6 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@etherspot/prime-sdk",
"version": "1.2.6",
"version": "1.2.7",
"description": "Etherspot Prime (Account Abstraction) SDK",
"keywords": [
"ether",
Expand Down Expand Up @@ -51,18 +51,17 @@
},
"dependencies": {
"@apollo/client": "3.4.0",
"@lifi/sdk": "^2.2.3",
"@lifi/sdk": "2.2.3",
"@nerdwallet/apollo-cache-policies": "1.2.1",
"@thehubbleproject/bls": "0.5.1",
"apollo-link-ws": "^1.0.20",
"@walletconnect/universal-provider": "^2.10.0",
"axios": "1.3.4",
"apollo-link-ws": "1.0.20",
"@walletconnect/universal-provider": "2.10.0",
"class-transformer": "0.5.1",
"class-validator": "0.14.0",
"commander": "^10.0.1",
"commander": "10.0.1",
"cross-fetch": "3.1.5",
"ethers": "5.7.0",
"prettier": "^2.8.8",
"prettier": "2.8.8",
"reflect-metadata": "0.1.13"
},
"devDependencies": {
Expand Down
28 changes: 18 additions & 10 deletions src/sdk/base/VerifyingPaymasterAPI.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import axios from 'axios';
import { ethers } from 'ethers';
import fetch from 'cross-fetch';
import { calcPreVerificationGas } from './calcPreVerificationGas';
import { PaymasterAPI } from './PaymasterAPI';
import { UserOperationStruct } from '../contracts/account-abstraction/contracts/core/BaseAccount';
Expand Down Expand Up @@ -39,7 +39,7 @@ export class VerifyingPaymasterAPI extends PaymasterAPI {
// userOp.preVerificationGas contains a promise that will resolve to an error.
await ethers.utils.resolveProperties(userOp);
// eslint-disable-next-line no-empty
} catch (_) {}
} catch (_) { }
const pmOp: Partial<UserOperationStruct> = {
sender: userOp.sender,
nonce: userOp.nonce,
Expand All @@ -57,15 +57,23 @@ export class VerifyingPaymasterAPI extends PaymasterAPI {
op.preVerificationGas = calcPreVerificationGas(op);

// Ask the paymaster to sign the transaction and return a valid paymasterAndData value.
const paymasterAndData = await axios
.post<PaymasterResponse>(this.paymasterUrl, {
jsonrpc: '2.0',
id: 1,
method: 'pm_sponsorUserOperation',
params: [await toJSON(op), this.entryPoint, this.context, this.chainId, this.api_key],
const paymasterAndData = await fetch(this.paymasterUrl, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({ params: [await toJSON(op), this.entryPoint, this.context, this.chainId, this.api_key], jsonrpc: '2', id: 2 }),
})
.then(async (res) => {
const response = await await res.json();
if (response.error) {
throw new Error(response.error);
}
return response
})
.then((res) => {
return res.data
.catch((err) => {
throw new Error(err.message);
})

return paymasterAndData;
Expand Down

0 comments on commit 66692f8

Please sign in to comment.