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

Pass headers to score API #757

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
14 changes: 9 additions & 5 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

interface Options {
url?: string;
headers?: any;
}

interface Strategy {
Expand Down Expand Up @@ -215,7 +216,8 @@
network: string,
addresses: string[],
snapshot: number | string = 'latest',
scoreApiUrl = 'https://score.snapshot.org/api/scores'
scoreApiUrl = 'https://score.snapshot.org/api/scores',
options: Options = {}

Check warning on line 220 in src/utils.ts

View check run for this annotation

Codecov / codecov/patch

src/utils.ts#L219-L220

Added lines #L219 - L220 were not covered by tests
) {
try {
const params = {
Expand All @@ -225,9 +227,9 @@
strategies,
addresses
};
const res = await fetch(scoreApiUrl, {
const res = await fetch(options.url || scoreApiUrl, {

Check warning on line 230 in src/utils.ts

View check run for this annotation

Codecov / codecov/patch

src/utils.ts#L230

Added line #L230 was not covered by tests
method: 'POST',
headers: { 'Content-Type': 'application/json' },
headers: { 'Content-Type': 'application/json', ...options.headers },

Check warning on line 232 in src/utils.ts

View check run for this annotation

Codecov / codecov/patch

src/utils.ts#L232

Added line #L232 was not covered by tests
body: JSON.stringify({ params })
});
const obj = await res.json();
Expand All @@ -252,7 +254,8 @@
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
'Content-Type': 'application/json',
...options?.headers

Check warning on line 258 in src/utils.ts

View check run for this annotation

Codecov / codecov/patch

src/utils.ts#L257-L258

Added lines #L257 - L258 were not covered by tests
},
body: JSON.stringify({
jsonrpc: '2.0',
Expand Down Expand Up @@ -289,7 +292,8 @@
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
'Content-Type': 'application/json',
Comment on lines 294 to +295
Copy link
Contributor

Choose a reason for hiding this comment

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

Could be extract into a jsonHeaders object, and reused like ...jsonHeaders

...options?.headers

Check warning on line 296 in src/utils.ts

View check run for this annotation

Codecov / codecov/patch

src/utils.ts#L295-L296

Added lines #L295 - L296 were not covered by tests
},
body: JSON.stringify({
jsonrpc: '2.0',
Expand Down
Loading