Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed usage of web3 package #109

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "paraswap",
"name": "@nenad91/paraswap",
"version": "5.1.0",
"main": "build/index.js",
"types": "build/index.d.ts",
Expand All @@ -21,7 +21,6 @@
"lodash": "4.17.21",
"qs": "^6.9.1",
"ts-essentials": "^7.0.0",
"web3": "^1.5.0",
"paraswap-core": "1.0.2"
},
"devDependencies": {
Expand Down
28 changes: 10 additions & 18 deletions src/paraswap.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import axios, { AxiosError, AxiosRequestConfig } from 'axios';
import * as qs from 'qs';
import * as _ from 'lodash';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be nice to also remove that import and directly import the lodash chunks you need import isEmpty from 'lodash/isEmpty'

import Web3 from 'web3';
import type { SendOptions } from 'web3-eth-contract';

interface SendOptions {
from: string;
gasPrice?: string;
gas?: number;
value?: number | string;
nonce?: number;
}

import {
Address,
Expand Down Expand Up @@ -32,12 +38,7 @@ export class ParaSwap {
constructor(
private network: NetworkID = 1,
private apiURL: string = API_URL,
public web3Provider?: any,
) {
if (web3Provider && !web3Provider.eth) {
this.web3Provider = new Web3(web3Provider);
}
}
) {}

private handleAPIError(e: unknown): APIError {
if (!axios.isAxiosError(e)) {
Expand All @@ -63,15 +64,6 @@ export class ParaSwap {
}
}

setWeb3Provider(web3Provider: any) {
if (!web3Provider.eth) {
this.web3Provider = new Web3(web3Provider);
} else {
this.web3Provider = web3Provider;
}
return this;
}

async getTokens() {
try {
const tokensURL = `${this.apiURL}/tokens/${this.network}`;
Expand Down Expand Up @@ -369,7 +361,7 @@ export class ParaSwap {
return new Promise(async (resolve, reject) => {
const spender = await this.getTokenTransferProxy();

const provider = _provider || this.web3Provider;
const provider = _provider;

const contract: any = new provider!.eth.Contract(ERC20_ABI, tokenAddress);

Expand Down
Loading