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

add configureSDK function with options #90

Merged
merged 3 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
23 changes: 18 additions & 5 deletions sdk/src/quotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@ import { signPermit } from './utils/permit';
import { getReferrerCode } from './utils/referrer';
import { sanityCheckAddress } from './utils/sanity_check';


/**
* Configure SDK for mocking or fallback to API_BASE_URL
*
*/
export let sdkConfig = {
apiBaseUrl: API_BASE_URL
};

export function configureSDK(options: { apiBaseUrl?: string }) {
sdkConfig = { ...sdkConfig, ...options };
}

/**
* Function to get the rainbow router contract address based on the chainId
*
Expand Down Expand Up @@ -97,7 +110,7 @@ const buildRainbowQuoteUrl = ({
? { feePercentageBasisPoints: String(feePercentageBasisPoints) }
: {}),
});
return `${API_BASE_URL}/v1/quote?` + searchParams.toString();
return `${sdkConfig.apiBaseUrl}/v1/quote?` + searchParams.toString();
};

/**
Expand Down Expand Up @@ -151,7 +164,7 @@ export const buildRainbowCrosschainQuoteUrl = ({
? { feePercentageBasisPoints: String(feePercentageBasisPoints) }
: {}),
});
return `${API_BASE_URL}/v1/quote?bridgeVersion=4&` + searchParams.toString();
return `${sdkConfig.apiBaseUrl}/v1/quote?bridgeVersion=4&` + searchParams.toString();
};

/**
Expand Down Expand Up @@ -192,7 +205,7 @@ export const buildRainbowClaimBridgeQuoteUrl = ({
source: Source.CrosschainAggregatorRelay.toString(),
toChainId: String(toChainId),
});
return `${API_BASE_URL}/v1/quote?bridgeVersion=4&` + searchParams.toString();
return `${sdkConfig.apiBaseUrl}/v1/quote?bridgeVersion=4&` + searchParams.toString();
};

/**
Expand All @@ -207,7 +220,7 @@ export const getMinRefuelAmount = async (params: {
toChainId: ChainId;
}) => {
const { chainId, toChainId } = params;
const url = `${API_BASE_URL}/v1/chains`;
const url = `${sdkConfig.apiBaseUrl}/v1/chains`;
const response = await fetch(url);
const chainsData = (await response.json()) as SocketChainsData;

Expand Down Expand Up @@ -680,4 +693,4 @@ export const getCrosschainQuoteExecutionDetails = (
value,
},
};
};
};
4 changes: 2 additions & 2 deletions sdk/src/slippage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
SlippageError,
SlippageParams,
} from './types';
import { API_BASE_URL } from './utils/constants';
import { sdkConfig } from './quotes'; // Adjust the import path as needed
BrodyHughes marked this conversation as resolved.
Show resolved Hide resolved

/**
* Function to get a slippage formatted quote url to use with backend
Expand Down Expand Up @@ -43,7 +43,7 @@ const buildRainbowSlippageUrl = ({
? { sellAmount: String(sellAmount) }
: { buyAmount: String(buyAmount) }),
});
return `${API_BASE_URL}/v1/slippage?` + searchParams.toString();
return `${sdkConfig.apiBaseUrl}/v1/slippage?` + searchParams.toString();
};

/**
Expand Down
Loading