Skip to content

Commit

Permalink
Added optional URL param for fetchSubgraphPools.
Browse files Browse the repository at this point in the history
  • Loading branch information
johngrantuk committed Oct 19, 2020
1 parent 1a8915e commit 032745c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
27 changes: 16 additions & 11 deletions src/subgraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export async function getTokenPairs(token) {
}

// Returns all public pools
export async function getAllPublicSwapPools() {
export async function getAllPublicSwapPools(SubgraphUrl: string = '') {
const query = `
{
pools (first: 1000, where: {publicSwap: true, active: true}) {
Expand All @@ -111,16 +111,21 @@ export async function getAllPublicSwapPools() {
}
`;

const response = await fetch(SUBGRAPH_URL, {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
query,
}),
});
console.log(`Using: ${SubgraphUrl === '' ? SUBGRAPH_URL : SubgraphUrl}`);

const response = await fetch(
SubgraphUrl === '' ? SUBGRAPH_URL : SubgraphUrl,
{
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
query,
}),
}
);

const { data } = await response.json();
return data;
Expand Down
4 changes: 2 additions & 2 deletions src/wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ export class SOR {
this.tokenCost = {};
}

async fetchSubgraphPools() {
async fetchSubgraphPools(SubgraphUrl: string = '') {
this.isSubgraphFetched = false;
let previous = _.cloneDeep(this.subgraphPools);
this.subgraphPools = await sor.getAllPublicSwapPools();
this.subgraphPools = await sor.getAllPublicSwapPools(SubgraphUrl);
if (!_.isEqual(this.subgraphPools, previous)) {
this.isOnChainFetched = false; // New pools so any previous onchain info is out of date.
this.subgraphPoolsFormatted = _.cloneDeep(this.subgraphPools); // format alters pools so make copy first
Expand Down

0 comments on commit 032745c

Please sign in to comment.