Skip to content

Commit

Permalink
Merge pull request #10 from getsafle/feature-update-get-tokens
Browse files Browse the repository at this point in the history
Updated getSupportedTokens
  • Loading branch information
apoorvq authored Jul 5, 2023
2 parents 9e99aa8 + c5fef03 commit 96f8ae7
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 31 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,10 @@
### 1.0.2 (2022-07-05)

- Updated 1Inch base URL

### 1.0.3 (2022-07-05)

- Updated getSupportedTokens method to accept dex as a parameter and return tokens only for the selected dex



1 change: 0 additions & 1 deletion constants/coins.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ module.exports ={
"https://tokens.1inch.io/0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c_1.png",
},
"polygon":{

"symbol": "MATIC",
"name": "MATIC",
"decimals": 18,
Expand Down
42 changes: 14 additions & 28 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,30 @@ const helper = require("./utils/helper");
const quickswapSdk = require("quickswap-default-token-list");
const coins = require("./constants/coins");

async function getSupportedTokens(chain) {
async function getSupportedTokens(chain, dex) {
if (!config.supportedChains.includes(chain)) {
return { error: config.errorMessages.INVALID_CHAIN };
}
const { tokens: oneInchTokens } = await getTokensOneInch(chain);

const { tokens: uniswapTokens } = await getTokensUniswap(chain);

const { tokens: quickswapTokens } = await getTokensQuickswap(chain);

const { tokens: pancakeswapTokens } = await getTokensPancakeswap(chain);

let tokens = [];

if (oneInchTokens) {
tokens.push(...oneInchTokens);

if (dex === "oneInch") {
const { tokens } = await getTokensOneInch(chain);
return { tokens };
}

if (uniswapTokens) {
tokens.push(...uniswapTokens);
if (dex === "uniswap") {
const { tokens } = await getTokensUniswap(chain);
return { tokens };
}

if (quickswapTokens) {
tokens.push(...quickswapTokens);
if (dex === "quickswap") {
const { tokens } = await getTokensQuickswap(chain);
return { tokens };
}

if (pancakeswapTokens) {
tokens.push(...pancakeswapTokens);
if (dex === "pancakeswap") {
const { tokens } = await getTokensPancakeswap(chain);
return { tokens };
}

tokens = tokens.filter(
(value, index, self) =>
index ===
self.findIndex(
(t) => t.address.toLowerCase() === value.address.toLowerCase()
)
);
return { tokens };
}

async function getTokensOneInch(chain) {
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@getsafle/safle-token-lists",
"version": "1.0.2",
"version": "1.0.3",
"description": "This is a JS SDK catering to supported tokens list on safle swaps fetched from all the supported DEXs on different chains.",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 96f8ae7

Please sign in to comment.