Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
alessey committed Jan 29, 2025
1 parent d47fdbc commit a95870f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
9 changes: 0 additions & 9 deletions src/core/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,3 @@ export enum Capabilities {
}
export const DEFAULT_PRIVACY_URL = 'https://base.org/privacy-policy';
export const DEFAULT_TERMS_URL = 'https://base.org/terms-of-service';
export const ALLOWABLE_REFERRERS = [
'nft',
'buy',
'swap',
'hook',
'api',
'checkout',
'wallet',
];
9 changes: 9 additions & 0 deletions src/core/network/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,12 @@ export const JSON_HEADERS = {
};
export const JSON_RPC_VERSION = '2.0';
export const ANALYTICS_API_URL = 'https://api.developer.coinbase.com/analytics';
export const ALLOWABLE_REFERRERS = [
'api',
'buy',
'checkout',
'hook',
'nft',
'swap',
'wallet',
];
11 changes: 9 additions & 2 deletions src/core/network/request.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { ALLOWABLE_REFERRERS } from '../constants';
import { JSON_HEADERS, JSON_RPC_VERSION, POST_METHOD } from './constants';
import { ALLOWABLE_REFERRERS, JSON_HEADERS, JSON_RPC_VERSION, POST_METHOD } from './constants';
import { getRPCUrl } from './getRPCUrl';

export type JSONRPCError = {
Expand Down Expand Up @@ -53,6 +52,14 @@ export function buildRequestHeaders(
referrer?: JSONRPCReferrer,
): Record<string, string> {
if (referrer) {
// if an invalid referrer is provided, default to 'api'
if (!ALLOWABLE_REFERRERS.includes(referrer)) {
return {
...JSON_HEADERS,
'OnchainKit-Referrer': 'api',
};
}

return {
...JSON_HEADERS,
'OnchainKit-Referrer': referrer,
Expand Down

0 comments on commit a95870f

Please sign in to comment.